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

code: list[str]

Tasklet code, line by line.

inputs: dict[str, Memlet]

Mapping connector names to memlets flowing into the Tasklet.

outputs: dict[str, Memlet]

Mapping connector names to memlets flowing out of the Tasklet.

targets: set[str]

Names of fields / scalars that we’ve already written to. Used for read-after-write analysis.

tree: TreeRoot

Schedule tree (root) in which this Tasklet will be inserted.

class gt4py.cartesian.gtc.dace.oir_to_tasklet.OIRToTasklet[source]

Bases: NodeVisitor

Translate 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_BinaryOp(node: BinaryOp, **kwargs: Any) → str[source]
visit_BuiltInLiteral(node: BuiltInLiteral, **_kwargs: Any) → str[source]
visit_CacheDesc(node: CacheDesc, **kwargs: Any) → None[source]
visit_CartesianOffset(node: CartesianOffset, **kwargs: Any) → None[source]
visit_Cast(node: Cast, **kwargs: Any) → str[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_Decl(node: Decl, **kwargs: Any) → None[source]
visit_FieldAccess(node: FieldAccess, ctx: Context, is_target: bool) → str[source]
visit_FieldDecl(node: FieldDecl, **kwargs: Any) → None[source]
visit_HorizontalExecution(node: HorizontalExecution, **kwargs: Any) → None[source]
visit_HorizontalRestriction(node: HorizontalRestriction, **kwargs: Any) → None[source]
visit_IJCache(node: IJCache, **kwargs: Any) → None[source]
visit_Interval(node: Interval, **kwargs: Any) → None[source]
visit_IteratorAccess(node: IteratorAccess, ctx: Context, **kwargs: Any) → str[source]
visit_KCache(node: KCache, **kwargs: Any) → None[source]
visit_Literal(node: Literal, **kwargs: Any) → str[source]
visit_LocalScalar(node: LocalScalar, **kwargs: Any) → None[source]
visit_MaskStmt(node: MaskStmt, **kwargs: Any) → None[source]
visit_NativeFuncCall(node: NativeFuncCall, **kwargs: Any) → str[source]
visit_NativeFunction(node: NativeFunction, **_kwargs: Any) → str[source]
visit_ScalarAccess(node: ScalarAccess, ctx: Context, is_target: bool) → str[source]
visit_ScalarDecl(node: ScalarDecl, **kwargs: Any) → None[source]
visit_Stencil(node: Stencil, **kwargs: Any) → None[source]
visit_Temporary(node: Temporary, **kwargs: Any) → None[source]
visit_TernaryOp(node: TernaryOp, **kwargs: Any) → str[source]
visit_UnaryOp(node: UnaryOp, **kwargs: Any) → str[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]
visit_While(node: While, **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: NodeVisitor

Translate 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_AxisBound(node: AxisBound, axis_start: str, axis_end: str) → str[source]
visit_BinaryOp(node: BinaryOp, **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_Cast(node: Cast, **kwargs: Any) → str[source]
visit_CodeBlock(node: CodeBlock, ctx: Context) → None[source]
visit_Decl(node: Decl, **kwargs: Any) → None[source]
visit_FieldAccess(node: FieldAccess, **kwargs: Any) → str[source]
visit_FieldDecl(node: FieldDecl, **kwargs: Any) → None[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_IteratorAccess(node: IteratorAccess, ctx: Context, **kwargs: Any) → str[source]
visit_Literal(node: Literal, **kwargs: Any) → str[source]
visit_LocalScalar(node: LocalScalar, **kwargs: Any) → None[source]
visit_MaskStmt(node: MaskStmt, ctx: Context) → None[source]
visit_RuntimeAxisBound(node: RuntimeAxisBound, **kwargs: Any) → None[source]
visit_ScalarAccess(node: ScalarAccess, **kwargs: Any) → str[source]
visit_Stencil(node: Stencil) → TreeRoot[source]
visit_TernaryOp(node: TernaryOp, **kwargs: Any) → str[source]
visit_UnaryOp(node: UnaryOp, **kwargs: Any) → str[source]
visit_VariableKOffset(node: VariableKOffset, field: FieldAccess, ctx: Context, **kwargs: Any) → str[source]
visit_VerticalLoop(node: VerticalLoop, ctx: Context) → None[source]
visit_VerticalLoopSection(node: VerticalLoopSection, ctx: Context, loop_order: LoopOrder) → None[source]
visit_While(node: While, 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.oir_to_treeir.get_dace_shape(field: FieldDecl, extent: Extent, k_bound: tuple[int, int]) → list[symbol][source]
gt4py.cartesian.gtc.dace.oir_to_treeir.get_dace_strides(field: FieldDecl, symbols: dict[str, typeclass]) → list[symbol][source]

gt4py.cartesian.gtc.dace.treeir module

class gt4py.cartesian.gtc.dace.treeir.Axis(*values)[source]

Bases: StrEnum

I = 'I'
J = 'J'
K = 'K'
static dims_3d() → Generator[Axis, None, None][source]
static dims_horizontal() → Generator[Axis, None, None][source]
domain_dace_symbol()[source]
domain_symbol() → SymbolRef[source]
iteration_dace_symbol()[source]
iteration_symbol() → SymbolRef[source]
to_idx() → int[source]
class gt4py.cartesian.gtc.dace.treeir.Bounds(*, start: str, end: str)[source]

Bases: Node

end: str
start: str
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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

block_extents: dict[int, Extent]
current_scope: TreeScope
field_extents: dict[str, Extent]
root: TreeRoot
class gt4py.cartesian.gtc.dace.treeir.ContextPushPop(ctx: Context, node: TreeScope)[source]

Bases: object

Append 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

bounds_i: Bounds
bounds_j: Bounds
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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

if_condition_code: str

Condition as ScheduleTree worthy code

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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

bounds_k: Bounds
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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

bounds_k: Bounds
iteration_variable: SymbolRef
loop_order: LoopOrder
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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

inputs: dict[str, Memlet]

Mapping tasklet.in_connectors to Memlets

outputs: dict[str, Memlet]

Mapping tasklet.out_connectors to Memlets

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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

parent: TreeScope | None
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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

containers: dict[str, Data]

Mapping field/scalar names to data descriptors.

dimensions: dict[str, tuple[bool, bool, bool]]

Mapping field names to shape-axis.

name: str
shift: dict[str, dict[Axis, int]]

Mapping field names to dict[axis] -> shift.

symbols: dict[str, typeclass]

Mapping between type and symbol name.

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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

children: list[TreeScope | 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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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

condition_code: str

Condition as ScheduleTree worthy code

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 dict used in the evaluation of the annotations (globals are automatically taken from model.__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: object

Append the node to the scope, then push/pop the scope

class gt4py.cartesian.gtc.dace.treeir_to_stree.TreeIRToScheduleTree[source]

Bases: NodeVisitor

Translate 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_IfElse(node: IfElse, ctx: Context) → None[source]
visit_ParallelVerticalLoop(node: ParallelVerticalLoop, ctx: Context) → None[source]
visit_SequentialVerticalLoop(node: SequentialVerticalLoop, ctx: Context) → None[source]
visit_Tasklet(node: Tasklet, ctx: Context) → None[source]
visit_TreeRoot(node: TreeRoot) → ScheduleTreeRoot[source]

Construct a schedule tree from TreeIR.

visit_While(node: While, 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

gt4py.cartesian.gtc.dace.treeir_to_stree._loop_region_while(node: While) → LoopRegion[source]

Translates a while loop into a Dace LoopRegion to be used in tn.WhileScope.

Parameters:

node – While loop to translate

Returns:

DaCe LoopRegion to use in tn.WhileScope

gt4py.cartesian.gtc.dace.utils module

gt4py.cartesian.gtc.dace.utils.array_dimensions(array: Array) → list[bool][source]
gt4py.cartesian.gtc.dace.utils.data_type_to_dace_typeclass(data_type: DataType) → typeclass[source]
gt4py.cartesian.gtc.dace.utils.get_dace_debuginfo(node: LocNode) → DebugInfo[source]
gt4py.cartesian.gtc.dace.utils.get_dace_symbol(name: SymbolRef, dtype: DataType = DataType.INT32) → symbol[source]
gt4py.cartesian.gtc.dace.utils.replace_strides(arrays: list[Array], layout_info: LayoutInfo) → dict[str, str][source]

Module contents