Mojo module
runtime_tuple
Provides the RuntimeTuple
data structure and related utility functions for handling tuple-like data with both compile-time and runtime elements. RuntimeTuple
is designed for high-performance tensor operations, supporting efficient manipulation of multi-dimensional data structures like shapes, indices, and coordinates.
Key features:
- Hybrid compile-time/runtime value handling
- Optimized for parallel execution and hardware acceleration
- Support for nested tuple structures
- Efficient conversion between linear indices and multi-dimensional coordinates
- Specialized operations for tensor shape calculations
The module includes functions for tuple manipulation (concatenation, flattening),
coordinate transformations (idx2crd
, crd2idx
), and specialized tensor operations
like shape division and prefix products.
Structs
-
RuntimeTuple
: A struct representing tuple-like data with compile-time and runtime elements. RuntimeTuple combines static (compile-time) and dynamic (runtime) handling of tuple-like data structures, typically used for tensor shapes, indices, and coordinates in high-performance computing contexts. This struct is optimized for parallel execution and hardware acceleration, allowing efficient manipulation of multi-dimensional data. It supports both known compile-time values and runtime-determined values.
Functions
-
concat
: Concatenates twoIntTuple
instances into a singleIntTuple
. -
crd2idx
: Converts multi-dimensional coordinates to a linear index. -
idx2crd
: Converts a linear index to multi-dimensional coordinates. This function transforms a flat index into coordinate values based on the provided shape and stride information. This is essential for mapping linear memory accesses to multi-dimensional tensor elements. -
is_int
: Determines if aRuntimeTuple
represents a scalar integer value. -
is_tuple
: Determines if aRuntimeTuple
represents a tuple rather than a scalar value. -
prefix_product
: Computes the prefix products of elements in theRuntimeTuple
. -
product
: Computes the product of all elements in theRuntimeTuple
. -
shape_div
: Performs specialized shape division betweenRuntimeTuple
s. -
signum
: Returns the sign of an integer value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!