gt4py.cartesian.gtc.passes package¶
Subpackages¶
- gt4py.cartesian.gtc.passes.oir_optimizations package
- Submodules
- gt4py.cartesian.gtc.passes.oir_optimizations.caches module
FillFlushToLocalKCachesFillFlushToLocalKCaches._fill_limits()FillFlushToLocalKCaches._fill_stmts()FillFlushToLocalKCaches._flush_stmts()FillFlushToLocalKCaches._node_visitor_cache_FillFlushToLocalKCaches._requires_splitting()FillFlushToLocalKCaches._split_entry_level()FillFlushToLocalKCaches._split_section_with_multiple_fills()FillFlushToLocalKCaches.visit_FieldAccess()FillFlushToLocalKCaches.visit_HorizontalExecution()FillFlushToLocalKCaches.visit_Stencil()FillFlushToLocalKCaches.visit_VerticalLoop()FillFlushToLocalKCaches.visit_VerticalLoopSection()
IJCacheDetectionKCacheDetectionPruneKCacheFillsPruneKCacheFlushes
- gt4py.cartesian.gtc.passes.oir_optimizations.horizontal_execution_merging module
HorizontalExecutionMergingOnTheFlyMergingOnTheFlyMerging._merge()OnTheFlyMerging._node_visitor_cache_OnTheFlyMerging.allow_expensive_function_duplicationOnTheFlyMerging.max_horizontal_execution_body_sizeOnTheFlyMerging.visit_CartesianOffset()OnTheFlyMerging.visit_FieldAccess()OnTheFlyMerging.visit_ScalarAccess()OnTheFlyMerging.visit_Stencil()OnTheFlyMerging.visit_VerticalLoop()OnTheFlyMerging.visit_VerticalLoopSection()
- gt4py.cartesian.gtc.passes.oir_optimizations.inlining module
- gt4py.cartesian.gtc.passes.oir_optimizations.mask_stmt_merging module
- gt4py.cartesian.gtc.passes.oir_optimizations.pruning module
- gt4py.cartesian.gtc.passes.oir_optimizations.temporaries module
- gt4py.cartesian.gtc.passes.oir_optimizations.utils module
AccessCollectorAccessCollector.CartesianAccessCollectionAccessCollector.GeneralAccessCollectionAccessCollector.GenericAccessCollectionAccessCollector._node_visitor_cache_AccessCollector.apply()AccessCollector.visit_AssignStmt()AccessCollector.visit_FieldAccess()AccessCollector.visit_HorizontalRestriction()AccessCollector.visit_Interval()AccessCollector.visit_MaskStmt()AccessCollector.visit_While()
CartesianAccessGeneralAccessGenericAccessStencilExtentComputercollect_symbol_names()compute_extents()compute_fields_extents()compute_horizontal_block_extents()symbol_name_creator()
- gt4py.cartesian.gtc.passes.oir_optimizations.vertical_loop_merging module
- Module contents
AdjacentLoopMergingFillFlushToLocalKCachesFillFlushToLocalKCaches._fill_limits()FillFlushToLocalKCaches._fill_stmts()FillFlushToLocalKCaches._flush_stmts()FillFlushToLocalKCaches._node_visitor_cache_FillFlushToLocalKCaches._requires_splitting()FillFlushToLocalKCaches._split_entry_level()FillFlushToLocalKCaches._split_section_with_multiple_fills()FillFlushToLocalKCaches.visit_FieldAccess()FillFlushToLocalKCaches.visit_HorizontalExecution()FillFlushToLocalKCaches.visit_Stencil()FillFlushToLocalKCaches.visit_VerticalLoop()FillFlushToLocalKCaches.visit_VerticalLoopSection()
HorizontalExecutionMergingIJCacheDetectionKCacheDetectionLocalTemporariesToScalarsMaskInliningMaskStmtMergingNoFieldAccessPruningOnTheFlyMergingOnTheFlyMerging._merge()OnTheFlyMerging._node_visitor_cache_OnTheFlyMerging.allow_expensive_function_duplicationOnTheFlyMerging.max_horizontal_execution_body_sizeOnTheFlyMerging.visit_CartesianOffset()OnTheFlyMerging.visit_FieldAccess()OnTheFlyMerging.visit_ScalarAccess()OnTheFlyMerging.visit_Stencil()OnTheFlyMerging.visit_VerticalLoop()OnTheFlyMerging.visit_VerticalLoopSection()
PruneKCacheFillsPruneKCacheFlushesUnreachableStmtPruningWriteBeforeReadTemporariesToScalars
Submodules¶
gt4py.cartesian.gtc.passes.gtir_definitive_assignment_analysis module¶
- class gt4py.cartesian.gtc.passes.gtir_definitive_assignment_analysis.DefinitiveAssignmentAnalysis[source]¶
Bases:
NodeVisitorAnalyse gtir stencil expression for access to undefined symbols.
A symbol is said to be defined if it was assigned to in the code-path of its usage. In other words: If a symbol is defined in both branches of an if-statement it may be used outside. If a symbol is only defined in a single branch it may only be used inside that branch unless it was already defined previously (as this is equal to assigning to the previous value again). Note that whether a symbols is defined is independent of the actual result of the condition.
- _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.
- classmethod apply(gtir_stencil_expr: Stencil) List[FieldAccess][source]¶
Execute analysis and return all accesses to undefined symbols.
- visit_FieldAccess(node: FieldAccess, *, alive_vars: Set[str], invalid_accesses: List[FieldAccess], **kwargs) None[source]¶
- gt4py.cartesian.gtc.passes.gtir_definitive_assignment_analysis.analyze(gtir_stencil_expr: Stencil) List[FieldAccess]¶
Execute analysis and return all accesses to undefined symbols.
gt4py.cartesian.gtc.passes.gtir_dtype_resolver module¶
- class gt4py.cartesian.gtc.passes.gtir_dtype_resolver._GTIRPropagateDtypeToAccess[source]¶
Bases:
NodeTranslator,VisitorWithSymbolTableTraitPropagates dtype from Decl to Access.
Precondition: Decls have dtype (not None), can be AUTO or DEFAULT Postcondition: All dtypes of Access are not None
- _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_FieldAccess(node: FieldAccess, **kwargs: Any) FieldAccess[source]¶
- visit_ScalarAccess(node: ScalarAccess, *, symtable: Dict[str, Any], **kwargs: Any) ScalarAccess[source]¶
- class gt4py.cartesian.gtc.passes.gtir_dtype_resolver._GTIRResolveAuto[source]¶
Bases:
NodeTranslator,VisitorWithSymbolTableTraitReplaces AUTO dtype by a concrete dtype.
Note that currently only temporaries (FieldDecl/FieldAccess) can have AUTO type.
Precondition: All dtype are set, but some can be set to AUTO Postcondition: All dtypes are concrete (no AUTO)
- class _GTIRUpdateAutoDecl[source]¶
Bases:
NodeTranslatorUpdates FieldDecls with resolved types.
- _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_FieldAccess(node: FieldAccess, *, symtable: Dict[str, Any], **kwargs: Any) FieldAccess[source]¶
- visit_ParAssignStmt(node: ParAssignStmt, **kwargs: Any) ParAssignStmt[source]¶
gt4py.cartesian.gtc.passes.gtir_k_boundary module¶
- class gt4py.cartesian.gtc.passes.gtir_k_boundary.KBoundaryVisitor[source]¶
Bases:
NodeVisitorFor every field compute the boundary in k, e.g. (2, -1) if [k_origin-2, k_origin+k_domain-1] is accessed.
- _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.
- gt4py.cartesian.gtc.passes.gtir_k_boundary._iter_field_names(node: Stencil | ParAssignStmt) XIterable[FieldAccess][source]¶
gt4py.cartesian.gtc.passes.gtir_pipeline module¶
gt4py.cartesian.gtc.passes.gtir_prune_unused_parameters module¶
- gt4py.cartesian.gtc.passes.gtir_prune_unused_parameters.prune_unused_parameters(node: Stencil) Stencil[source]¶
Remove unused parameters from the gtir signature.
(Maybe this pass should go into a later stage. If you need to touch this pass, e.g. when the definition_ir gets removed, consider moving it to a more appropriate level. Maybe to the backend IR?)
gt4py.cartesian.gtc.passes.gtir_upcaster module¶
- class gt4py.cartesian.gtc.passes.gtir_upcaster._GTIRUpcasting[source]¶
Bases:
NodeTranslatorIntroduces Cast nodes (upcasting) for expr involving different datatypes.
Precondition: all dtypes are resolved (no None, Auto, Default) Postcondition: all dtype transitions are explicit via a Cast node
- _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_NativeFuncCall(node: NativeFuncCall) NativeFuncCall[source]¶
- visit_ParAssignStmt(node: ParAssignStmt) ParAssignStmt[source]¶
- gt4py.cartesian.gtc.passes.gtir_upcaster._common_upcasting_rule(*dtypes)[source]¶
Look up upcasting behavior according to C++ casting rules.
- gt4py.cartesian.gtc.passes.gtir_upcaster._numpy_ufunc_upcasting_rule(*dtypes, ufunc: ufunc)[source]¶
Look up upcasting behavior according to NumPy universal function casting convention.
NumPy specifies that it chooses ufunc implementations based on input types, where the inputs are suitably cast if necessary. Mimicking this results in a behavior that can be reproduced in C++ backends but is also consistent with python in the numpy backend to the extent possible. We choose ufunc implementations according to NumPy rules while implementing C/C++ type promotion rules, restricted to supported types. See https://numpy.org/doc/stable/user/basics.ufuncs.html?highlight=index#type-casting-rules for details.
- gt4py.cartesian.gtc.passes.gtir_upcaster._upcast_node(target_dtype: DataType, node: Expr) Expr[source]¶
- gt4py.cartesian.gtc.passes.gtir_upcaster._upcast_nodes(*exprs: Expr, upcasting_rule: Callable) Iterator[Expr][source]¶
- gt4py.cartesian.gtc.passes.gtir_upcaster._update_node(node: _T, updated_children: Dict[str, NodeT | list[NodeT | bool | bytes | int | float | str | IntEnum | StrEnum] | dict[Any, NodeT | bool | bytes | int | float | str | IntEnum | StrEnum] | set[NodeT | bool | bytes | int | float | str | IntEnum | StrEnum]]) _T[source]¶
gt4py.cartesian.gtc.passes.horizontal_masks module¶
- gt4py.cartesian.gtc.passes.horizontal_masks._compute_relative_interval(extent: Tuple[int, int], interval: HorizontalInterval) Tuple[AxisBound, AxisBound] | None[source]¶
- gt4py.cartesian.gtc.passes.horizontal_masks._overlap_along_axis(extent: Tuple[int, int], interval: HorizontalInterval) Tuple[int, int] | None[source]¶
Return a tuple of the distances to the edge of the compute domain, if overlapping.
- gt4py.cartesian.gtc.passes.horizontal_masks.compute_relative_mask(extent: Extent, mask: HorizontalMask) Tuple[Tuple[AxisBound, AxisBound], Tuple[AxisBound, AxisBound]] | None[source]¶
Output a HorizontalMask that is relative to and always inside the extent instead of the compute domain.
This is used in the numpy backend to compute HorizontalMask bounds relative to the start/end bounds of the horizontal axes.
gt4py.cartesian.gtc.passes.oir_access_kinds module¶
- class gt4py.cartesian.gtc.passes.oir_access_kinds.AccessKindComputer[source]¶
Bases:
NodeVisitor- _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_Access(name, *, access: Dict[str, AccessKind], kind: AccessKind, **kwargs: Any) None[source]¶
- visit_AssignStmt(node: AssignStmt, **kwargs: Any) None[source]¶
- visit_FieldAccess(node: FieldAccess, **kwargs: Any) None[source]¶
- visit_HorizontalExecution(node: HorizontalExecution, **kwargs: Any) None[source]¶
- visit_HorizontalRestriction(node: HorizontalRestriction, *, horizontal_extent: Extent, **kwargs: Any) None[source]¶
- visit_RuntimeAxisBound(axis_bound: RuntimeAxisBound, **kwargs: Any) None[source]¶
- visit_ScalarAccess(node: ScalarAccess, **kwargs: Any) None[source]¶
gt4py.cartesian.gtc.passes.oir_pipeline module¶
- class gt4py.cartesian.gtc.passes.oir_pipeline.DefaultPipeline(*, skip: Sequence[Callable[[Stencil], Stencil] | Type[NodeVisitor]] | None = None, add_steps: Sequence[Callable[[Stencil], Stencil] | Type[NodeVisitor]] | None = None)[source]¶
Bases:
OirPipelineOIR passes pipeline runs passes in order and allows skipping.
May only call existing passes and may not contain any pass logic itself.
- _abc_impl = <_abc._abc_data object>¶
- _is_protocol = False¶
Module contents¶
- class gt4py.cartesian.gtc.passes.DefaultPipeline(*, skip: Sequence[Callable[[Stencil], Stencil] | Type[NodeVisitor]] | None = None, add_steps: Sequence[Callable[[Stencil], Stencil] | Type[NodeVisitor]] | None = None)[source]¶
Bases:
OirPipelineOIR passes pipeline runs passes in order and allows skipping.
May only call existing passes and may not contain any pass logic itself.
- _abc_impl = <_abc._abc_data object>¶
- _is_protocol = False¶
- class gt4py.cartesian.gtc.passes.GtirPipeline(node: Stencil, stencil_id: StencilID)[source]¶
Bases:
objectGTIR passes pipeline runs passes in order and allows skipping.
May only call existing passes and may not contain any pass logic itself.
- class gt4py.cartesian.gtc.passes.OirPipeline(*args, **kwargs)[source]¶
Bases:
Protocol- _abc_impl = <_abc._abc_data object>¶
- _is_protocol = True¶
- gt4py.cartesian.gtc.passes.compute_min_k_size(node: Stencil) int[source]¶
Compute the required number of k levels to run a stencil.
- gt4py.cartesian.gtc.passes.compute_relative_mask(extent: Extent, mask: HorizontalMask) Tuple[Tuple[AxisBound, AxisBound], Tuple[AxisBound, AxisBound]] | None[source]¶
Output a HorizontalMask that is relative to and always inside the extent instead of the compute domain.
This is used in the numpy backend to compute HorizontalMask bounds relative to the start/end bounds of the horizontal axes.
- gt4py.cartesian.gtc.passes.mask_overlap_with_extent(mask: HorizontalMask, horizontal_extent: Extent) Extent | None[source]¶
Compute an overlap extent between a mask and horizontal extent.
- gt4py.cartesian.gtc.passes.prune_unused_parameters(node: Stencil) Stencil[source]¶
Remove unused parameters from the gtir signature.
(Maybe this pass should go into a later stage. If you need to touch this pass, e.g. when the definition_ir gets removed, consider moving it to a more appropriate level. Maybe to the backend IR?)