Deeploy.TilingExtension.TilingCodegen.calculateFlatOffset

Deeploy.TilingExtension.TilingCodegen.calculateFlatOffset(offsets: Sequence[int], strides: Sequence[int]) int

Calculate the flat memory offset from multi-dimensional coordinates.

Converts multi-dimensional tensor coordinates (offsets) to a single flat memory offset using the provided stride information. This is essential for translating tensor indices to memory addresses.

Parameters:
  • offsets (Sequence[int]) – The multi-dimensional coordinates/offsets in each dimension.

  • strides (Sequence[int]) – The stride values for each dimension.

Returns:

The flat memory offset corresponding to the multi-dimensional position.

Return type:

int

Raises:

AssertionError – If offsets and strides have different numbers of dimensions.

Notes

The flat offset is computed as the sum of (offset[i] * stride[i]) for all dimensions i.

Examples

>>> calculateFlatOffset([1, 2, 3], [12, 4, 1])
23
>>> calculateFlatOffset([0, 1], [6, 1])
1