IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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 nested RuntimeTuple into a single-level RuntimeTuple, by multiplying all the values together.
  • ​concat: Concatenates two IntTuple instances into a single IntTuple.
  • ​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 a RuntimeTuple represents a scalar integer value.
  • ​is_tuple: Determines if a RuntimeTuple represents a tuple rather than a scalar value.
  • ​prefix_product: Computes the prefix products of elements in the RuntimeTuple.
  • ​product: Computes the product of all elements in the RuntimeTuple.
  • ​shape_div: Performs specialized shape division between RuntimeTuples.
  • ​signum: Returns the sign of an integer value.
  • ​to_index_list: Converts a RuntimeTuple to an IndexList with the same values.

Was this page helpful?