gt4py.cartesian.gtc.dace package¶
Subpackages¶
Submodules¶
gt4py.cartesian.gtc.dace.oir_to_tasklet module¶
- class gt4py.cartesian.gtc.dace.oir_to_tasklet.Context(code: list[str], targets: set[str], inputs: dict[str, dace.memlet.Memlet], outputs: dict[str, dace.memlet.Memlet], tree: gt4py.cartesian.gtc.dace.treeir.TreeRoot)[source]¶
Bases:
object
- class gt4py.cartesian.gtc.dace.oir_to_tasklet.OIRToTasklet[source]¶
Bases:
NodeVisitorTranslate the numerical code from OIR to DaCe Tasklets.
This visitor should neither attempt transformations nor do any control flow work. Control flow is the responsibility of OIRToTreeIR.
- _node_visitor_cache_: ClassVar[dict[type, str] | None] = {}¶
Cache for visitor method names per node class to speed up dispatching. Note that we cache the visitor method name, not the bound method itself, to avoid implicitly caching the visitor state, which could lead to unexpected behavior.
- visit_AbsoluteKIndex(node: AbsoluteKIndex, **kwargs: Any) None[source]¶
- visit_AssignStmt(node: AssignStmt, ctx: Context) None[source]¶
- visit_BuiltInLiteral(node: BuiltInLiteral, **_kwargs: Any) str[source]¶
- visit_CartesianOffset(node: CartesianOffset, **kwargs: Any) None[source]¶
- visit_CodeBlock(node: CodeBlock, root: TreeRoot) tuple[Tasklet, dict[str, Memlet], dict[str, Memlet]][source]¶
Entry point to gather all code, inputs and outputs.
- visit_HorizontalExecution(node: HorizontalExecution, **kwargs: Any) None[source]¶
- visit_HorizontalRestriction(node: HorizontalRestriction, **kwargs: Any) None[source]¶
- visit_LocalScalar(node: LocalScalar, **kwargs: Any) None[source]¶
- visit_NativeFuncCall(node: NativeFuncCall, **kwargs: Any) str[source]¶
- visit_NativeFunction(node: NativeFunction, **_kwargs: Any) str[source]¶
- visit_ScalarDecl(node: ScalarDecl, **kwargs: Any) None[source]¶
- visit_UnboundedInterval(node: UnboundedInterval, **kwargs: Any) None[source]¶
- visit_VariableKOffset(node: VariableKOffset, **kwargs: Any) None[source]¶
- visit_VerticalLoop(node: VerticalLoop, **kwargs: Any) None[source]¶
- visit_VerticalLoopSection(node: VerticalLoopSection, **kwargs: Any) None[source]¶
- gt4py.cartesian.gtc.dace.oir_to_tasklet._field_offset_postfix(node: FieldAccess) str[source]¶
- gt4py.cartesian.gtc.dace.oir_to_tasklet._memlet_subset(node: FieldAccess, data_domains: list[int], ctx: Context) Subset[source]¶
- gt4py.cartesian.gtc.dace.oir_to_tasklet._memlet_subset_cartesian(node: FieldAccess, data_domains: list[int], ctx: Context) Subset[source]¶
Generates the memlet subset for a field access with a cartesian offset.
Note that we pass data dimensions as a full array into the Tasklet. For cases with data dimensions we thus need a Range subset. We could use the more narrow Indices subset for cases without data dimensions. For the sake of simplicity, we choose to always return a Range.
- gt4py.cartesian.gtc.dace.oir_to_tasklet._memlet_subset_variable_offset(node: FieldAccess, data_domains: list[int], ctx: Context) Subset[source]¶
Generates the memlet subset for a field access with a variable K offset or an absolute K index.
While we know that we are reading at one specific i/j/k access, the K-access point is only determined at runtime. We thus pass the K-axis as array into the Tasklet.
- gt4py.cartesian.gtc.dace.oir_to_tasklet._tasklet_name(node: FieldAccess | ScalarAccess, is_target: bool, postfix: str = '') str[source]¶
gt4py.cartesian.gtc.dace.oir_to_treeir module¶
- gt4py.cartesian.gtc.dace.oir_to_treeir.ControlFlow: TypeAlias = gt4py.cartesian.gtc.oir.HorizontalExecution | gt4py.cartesian.gtc.oir.While | gt4py.cartesian.gtc.oir.MaskStmt | gt4py.cartesian.gtc.oir.HorizontalRestriction¶
All control flow OIR nodes
- gt4py.cartesian.gtc.dace.oir_to_treeir.DEFAULT_STORAGE_TYPE = {<DeviceType.CPU: 1>: <StorageType.Default: 1>, <DeviceType.GPU: 2>: <StorageType.GPU_Global: 5>}¶
Default dace residency types per device type.
- class gt4py.cartesian.gtc.dace.oir_to_treeir.OIRToTreeIR(builder: StencilBuilder)[source]¶
Bases:
NodeVisitorTranslate the GT4Py OIR into a Dace-centric TreeIR.
TreeIR is built to be a minimum representation of DaCe’s Schedule Tree. No transformation is done on TreeIR, though should be done once the TreeIR has been properly turned into a Schedule Tree.
This class _does not_ deal with Tasklet representation, it defers that work to the OIRToTasklet visitor.
- _group_statements(node: HorizontalExecution | While | MaskStmt | HorizontalRestriction) list[CodeBlock | HorizontalExecution | While | MaskStmt | HorizontalRestriction][source]¶
Group the body of a control flow node into CodeBlocks and other ControlFlow.
This function only groups statements. The job of visiting the groups statements is left to the caller.
- _insert_evaluation_tasklet(node: MaskStmt | While, ctx: Context) tuple[str, AssignStmt][source]¶
Evaluate condition in a separate tasklet to avoid sympy problems down the line.
- _node_visitor_cache_: ClassVar[dict[type, str] | None] = {}¶
Cache for visitor method names per node class to speed up dispatching. Note that we cache the visitor method name, not the bound method itself, to avoid implicitly caching the visitor state, which could lead to unexpected behavior.
- visit_AbsoluteKIndex(node: AbsoluteKIndex, field: FieldAccess, ctx: Context, **kwargs: Any) str[source]¶
- visit_BuiltInLiteral(node: BuiltInLiteral, **kwargs: Any) str[source]¶
- visit_CartesianOffset(node: CartesianOffset, field: FieldAccess, ctx: Context, **_kwargs: Any) str[source]¶
- visit_FieldAccess(node: FieldAccess, **kwargs: Any) str[source]¶
- visit_HorizontalExecution(node: HorizontalExecution, ctx: Context) None[source]¶
- visit_HorizontalMask(node: HorizontalMask, ctx: Context) str[source]¶
- visit_HorizontalRestriction(node: HorizontalRestriction, ctx: Context) None[source]¶
Translate region concept into If control flow in TreeIR.
- visit_Interval(node: Interval, loop_order: LoopOrder, axis_start: str, axis_end: str) Bounds[source]¶
- visit_LocalScalar(node: LocalScalar, **kwargs: Any) None[source]¶
- visit_RuntimeAxisBound(node: RuntimeAxisBound, **kwargs: Any) None[source]¶
- visit_ScalarAccess(node: ScalarAccess, **kwargs: Any) str[source]¶
- visit_VariableKOffset(node: VariableKOffset, field: FieldAccess, ctx: Context, **kwargs: Any) str[source]¶
- visit_VerticalLoop(node: VerticalLoop, ctx: Context) None[source]¶
- gt4py.cartesian.gtc.dace.oir_to_treeir._is_boolean_scalar(expression: Expr) TypeGuard[ScalarAccess][source]¶
- gt4py.cartesian.gtc.dace.oir_to_treeir._resolve_map_schedule(device_type: DeviceType) ScheduleType[source]¶
Optimal kernel schedule type based on target device.
gt4py.cartesian.gtc.dace.treeir module¶
- class gt4py.cartesian.gtc.dace.treeir.Axis(*values)[source]¶
Bases:
StrEnum- I = 'I'¶
- J = 'J'¶
- K = 'K'¶
- class gt4py.cartesian.gtc.dace.treeir.Bounds(*, start: str, end: str)[source]¶
Bases:
Node- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.Context(root: 'TreeRoot', current_scope: 'TreeScope', field_extents: 'dict[str, definitions.Extent]', block_extents: 'dict[int, definitions.Extent]')[source]¶
Bases:
object
- class gt4py.cartesian.gtc.dace.treeir.ContextPushPop(ctx: Context, node: TreeScope)[source]¶
Bases:
objectAppend the node to the scope, then push/pop the scope.
- class gt4py.cartesian.gtc.dace.treeir.HorizontalLoop(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], bounds_i: Bounds, bounds_j: Bounds, schedule: ScheduleType)[source]¶
Bases:
TreeScope- schedule: ScheduleType¶
- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.IfElse(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], if_condition_code: str)[source]¶
Bases:
TreeScope- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.ParallelVerticalLoop(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], iteration_variable: SymbolRef, bounds_k: Bounds, schedule: ScheduleType)[source]¶
Bases:
TreeScope- iteration_variable: SymbolRef¶
- schedule: ScheduleType¶
- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.SequentialVerticalLoop(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], iteration_variable: SymbolRef, bounds_k: Bounds, loop_order: LoopOrder)[source]¶
Bases:
TreeScope- iteration_variable: SymbolRef¶
- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.Tasklet(*, parent: TreeScope | None, tasklet: Tasklet, inputs: dict[str, Memlet], outputs: dict[str, Memlet])[source]¶
Bases:
TreeNode- tasklet: Tasklet¶
- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.TreeNode(*, parent: TreeScope | None)[source]¶
Bases:
Node- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.TreeRoot(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], name: str, containers: dict[str, Data], dimensions: dict[str, tuple[bool, bool, bool]], shift: dict[str, dict[Axis, int]], symbols: dict[str, typeclass])[source]¶
Bases:
TreeScope- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.TreeScope(*, parent: TreeScope | None, children: list[TreeScope | TreeNode])[source]¶
Bases:
TreeNode- scope(ctx: Context) ContextPushPop[source]¶
- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
- class gt4py.cartesian.gtc.dace.treeir.While(*, parent: TreeScope | None, children: list[TreeScope | TreeNode], condition_code: str)[source]¶
Bases:
TreeScope- classmethod update_forward_refs(localns: dict[str, Any] | None = None) type[_DataModelT]¶
Update Data Model class meta-information replacing forwarded type annotations with actual types.
- Parameters:
localns – locals
dictused in the evaluation of the annotations (globals are automatically taken frommodel.__module__).- Returns:
The provided class (so it can be used as a decorator too).
gt4py.cartesian.gtc.dace.treeir_to_stree module¶
- class gt4py.cartesian.gtc.dace.treeir_to_stree.Context(tree: 'tn.ScheduleTreeRoot', current_scope: 'tn.ScheduleTreeScope')[source]¶
Bases:
object- current_scope: ScheduleTreeScope¶
A reference to the current scope node.
- tree: ScheduleTreeRoot¶
A reference to the tree root.
- class gt4py.cartesian.gtc.dace.treeir_to_stree.ContextPushPop(ctx: Context, node: ScheduleTreeScope)[source]¶
Bases:
objectAppend the node to the scope, then push/pop the scope
- class gt4py.cartesian.gtc.dace.treeir_to_stree.TreeIRToScheduleTree[source]¶
Bases:
NodeVisitorTranslate TreeIR temporary IR to DaCe’s Schedule Tree.
TreeIR should have undone most of the DSL specificity when translating from OIR. This should be a rather direct translation. No transformation should happen here, they should all be done on the resulting Schedule Tree.
- _node_visitor_cache_: ClassVar[dict[type, str] | None] = {}¶
Cache for visitor method names per node class to speed up dispatching. Note that we cache the visitor method name, not the bound method itself, to avoid implicitly caching the visitor state, which could lead to unexpected behavior.
- visit_HorizontalLoop(node: HorizontalLoop, ctx: Context) None[source]¶
- visit_ParallelVerticalLoop(node: ParallelVerticalLoop, ctx: Context) None[source]¶
- visit_SequentialVerticalLoop(node: SequentialVerticalLoop, ctx: Context) None[source]¶
- gt4py.cartesian.gtc.dace.treeir_to_stree._loop_region_for(node: SequentialVerticalLoop, ctx: Context) LoopRegion[source]¶
Translates a sequential vertical loop into a Dace LoopRegion to be used in tn.ForScope.
- Parameters:
node – Vertical loop to translate
- Returns:
DaCe LoopRegion to use in tn.ForScope