Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into inline_dynamic_offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
tehrengruber committed Dec 1, 2024
2 parents ff00b55 + 99c5300 commit bd02cc7
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 244 deletions.
7 changes: 7 additions & 0 deletions src/gt4py/cartesian/frontend/gtscript_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,13 @@ def visit_Assign(self, node: ast.Assign) -> list:
loc=nodes.Location.from_ast_node(t),
)

if self.backend_name in ["gt:gpu"]:
raise GTScriptSyntaxError(
message=f"Assignment to non-zero offsets in K is not available in {self.backend_name} as an unsolved bug remains."
"Please refer to https://github.com/GridTools/gt4py/issues/1754.",
loc=nodes.Location.from_ast_node(t),
)

if not self._is_known(name):
if name in self.temp_decls:
field_decl = self.temp_decls[name]
Expand Down
14 changes: 5 additions & 9 deletions src/gt4py/next/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import enum
import os
import pathlib
import tempfile
from typing import Final


Expand Down Expand Up @@ -51,37 +50,34 @@ def env_flag_to_bool(name: str, default: bool) -> bool:
)


_PREFIX: Final[str] = "GT4PY"

#: Master debug flag
#: Changes defaults for all the other options to be as helpful for debugging as possible.
#: Does not override values set in environment variables.
DEBUG: Final[bool] = env_flag_to_bool(f"{_PREFIX}_DEBUG", default=False)
DEBUG: Final[bool] = env_flag_to_bool("GT4PY_DEBUG", default=False)


#: Verbose flag for DSL compilation errors
VERBOSE_EXCEPTIONS: bool = env_flag_to_bool(
f"{_PREFIX}_VERBOSE_EXCEPTIONS", default=True if DEBUG else False
"GT4PY_VERBOSE_EXCEPTIONS", default=True if DEBUG else False
)


#: Where generated code projects should be persisted.
#: Only active if BUILD_CACHE_LIFETIME is set to PERSISTENT
BUILD_CACHE_DIR: pathlib.Path = (
pathlib.Path(os.environ.get(f"{_PREFIX}_BUILD_CACHE_DIR", tempfile.gettempdir()))
/ "gt4py_cache"
pathlib.Path(os.environ.get("GT4PY_BUILD_CACHE_DIR", pathlib.Path.cwd())) / ".gt4py_cache"
)


#: Whether generated code projects should be kept around between runs.
#: - SESSION: generated code projects get destroyed when the interpreter shuts down
#: - PERSISTENT: generated code projects are written to BUILD_CACHE_DIR and persist between runs
BUILD_CACHE_LIFETIME: BuildCacheLifetime = BuildCacheLifetime[
os.environ.get(f"{_PREFIX}_BUILD_CACHE_LIFETIME", "persistent" if DEBUG else "session").upper()
os.environ.get("GT4PY_BUILD_CACHE_LIFETIME", "persistent" if DEBUG else "session").upper()
]

#: Build type to be used when CMake is used to compile generated code.
#: Might have no effect when CMake is not used as part of the toolchain.
CMAKE_BUILD_TYPE: CMakeBuildType = CMakeBuildType[
os.environ.get(f"{_PREFIX}_CMAKE_BUILD_TYPE", "debug" if DEBUG else "release").upper()
os.environ.get("GT4PY_CMAKE_BUILD_TYPE", "debug" if DEBUG else "release").upper()
]
3 changes: 3 additions & 0 deletions src/gt4py/next/iterator/ir_utils/domain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from gt4py.next.iterator import ir as itir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms import trace_shifts
from gt4py.next.iterator.transforms.constant_folding import ConstantFolding


def _max_domain_sizes_by_location_type(offset_provider: Mapping[str, Any]) -> dict[str, int]:
Expand Down Expand Up @@ -168,6 +169,8 @@ def domain_union(*domains: SymbolicDomain) -> SymbolicDomain:
lambda current_expr, el_expr: im.call("maximum")(current_expr, el_expr),
[domain.ranges[dim].stop for domain in domains],
)
# constant fold expression to keep the tree small
start, stop = ConstantFolding.apply(start), ConstantFolding.apply(stop) # type: ignore[assignment] # always an itir.Expr
new_domain_ranges[dim] = SymbolicRange(start, stop)

return SymbolicDomain(domains[0].grid_type, new_domain_ranges)
11 changes: 5 additions & 6 deletions src/gt4py/next/iterator/transforms/inline_lambdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def new_name(name):

if all(eligible_params):
new_expr.location = node.location
return new_expr
else:
new_expr = ir.FunCall(
fun=ir.Lambda(
Expand All @@ -111,11 +110,11 @@ def new_name(name):
args=[arg for arg, eligible in zip(node.args, eligible_params) if not eligible],
location=node.location,
)
for attr in ("type", "recorded_shifts", "domain"):
if hasattr(node.annex, attr):
setattr(new_expr.annex, attr, getattr(node.annex, attr))
itir_inference.copy_type(from_=node, to=new_expr, allow_untyped=True)
return new_expr
for attr in ("type", "recorded_shifts", "domain"):
if hasattr(node.annex, attr):
setattr(new_expr.annex, attr, getattr(node.annex, attr))
itir_inference.copy_type(from_=node, to=new_expr, allow_untyped=True)
return new_expr


@dataclasses.dataclass
Expand Down
5 changes: 4 additions & 1 deletion src/gt4py/next/iterator/transforms/remap_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from gt4py.eve import NodeTranslator, PreserveLocationVisitor, SymbolTableTrait
from gt4py.next.iterator import ir
from gt4py.next.iterator.type_system import inference as type_inference


class RemapSymbolRefs(PreserveLocationVisitor, NodeTranslator):
Expand Down Expand Up @@ -46,7 +47,9 @@ def visit_SymRef(
self, node: ir.SymRef, *, name_map: Dict[str, str], active: Optional[Set[str]] = None
):
if active and node.id in active:
return ir.SymRef(id=name_map.get(node.id, node.id))
new_ref = ir.SymRef(id=name_map.get(node.id, node.id))
type_inference.copy_type(from_=node, to=new_ref, allow_untyped=True)
return new_ref
return node

def generic_visit( # type: ignore[override]
Expand Down
7 changes: 5 additions & 2 deletions src/gt4py/next/iterator/type_system/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ def _set_node_type(node: itir.Node, type_: ts.TypeSpec) -> None:
node.type = type_


def copy_type(from_: itir.Node, to: itir.Node, allow_untyped=False) -> None:
def copy_type(from_: itir.Node, to: itir.Node, allow_untyped: bool = False) -> None:
"""
Copy type from one node to another.
This function mainly exists for readability reasons.
"""
assert allow_untyped is not None or isinstance(from_.type, ts.TypeSpec)
_set_node_type(to, from_.type) # type: ignore[arg-type]
if from_.type is None:
assert allow_untyped
return
_set_node_type(to, from_.type)


def on_inferred(callback: Callable, *args: Union[ts.TypeSpec, ObservableTypeSynthesizer]) -> None:
Expand Down
Loading

0 comments on commit bd02cc7

Please sign in to comment.