cycle 5
Temporaries are currently always 3D, which complicates the implementation of some computations. For example, 2D temporaries are useful for vertical reduction/scan patterns, and high-dimensional temporaries are useful in operations involving vector/matrix/tensor fields, like FEM methods.
Ideally, to avoid the declaration of pseudo-temporary fields outside stencils, it could be possible to explicitly create lower and higher dimensional temporary fields, which requires some sort of typing for temporaries.
Already shaped some aspects of this in a previous sprint at https://hackmd.io/7XI0eNXSTlWnXnHIx5o-Bw.
Typed Temporary Variables: https://hackmd.io/qz976j3XTuWR6aLYCdXz4w
Temporary fields should be 3D by default, unless a explicit type hint is provided (which also ensures backward compatibility). This means that there is no type inference and all data dimensions and lower-dimensional fields should be explicitly declared.
One important problem addressed by this proposed solution is that a temporary field might be initialized with different expressions in different intervals of the same computation, which would complicate any type inference mechanism with complex rules not so easy to understand for users.
Example:
In the proposed solution, temporaries can be optionally declared in the function scope to define their dimensionality before their first use:
Here is a summary of the main changes required to implement this proposal:
ValueInliner
pass replaces external
symbols with their actual values inside of the type hints used for temporary declaration.Assign
nodes in CONTROL_FLOW
context for the declaration of temporaries with type hints-only.IRMaker.visit_Assign
add a new if
branch if current context is CONTROL_FLOW
If the assignment has no target, then parse type hint and save this information for the future declaration of the temporary (first time is used).
If the assignment target is a scalar value, additionally create a new computation block with the assignment/initialization using the scalar value. Example:
The implementation of this feature could introduce a new full parallel with computation
block with the initial assignment:
FieldDecl
for temporaries:
axes
data_dims
Passes and optimizations: only a few of them should be affected and should not be hard to fix
GTC backends should be supported
GT_DECLARE_TMP
(docs). The only difference is that the type of the temporary is not a single scalar but a fixed-sized array (for CUDA compatibility use gridtools::array
instead of std::array
)make_cached_allocator
) for performance.DaCe backends should be supported and most likely it will work out of the box, since the entry point is the OIR, which is barely affected by the changes. Verify that it works, add tests and fix any minor issue that may appear.
Classic backends are out of scope and don't need to be supported.
The implementation of type hints in the function arguments or in symbols declared inside functions should be straightforward, because there are not several interval/computation contexts.
The CallInliner
pass in the frontend inlines all function calls and creates unique names for each argument or temporary symbol declared. If the declarations contain type hints, they should be parsed and used in the FieldDecl
node.
_constant
, _global
, _sc
, โฆ suffixes).