For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
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β
- β
coalesce_nested_tuple: Coalesces a nestedRuntimeTupleinto a single-levelRuntimeTuple, by multiplying all the values together. - β
concat: Concatenates twoIntTupleinstances 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 aRuntimeTuplerepresents a scalar integer value. - β
is_tuple: Determines if aRuntimeTuplerepresents 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 betweenRuntimeTuples. - β
signum: Returns the sign of an integer value. - β
to_index_list: Converts a RuntimeTuple to an IndexList with the same values.