thunder.clang.stride_order¶
- thunder.clang.stride_order(a, order=None)[source]¶
Creates a dense, non-overlapping and strided tensor with the same data and metadata as a.
- Return type:
- Parameters:
a (TensorProxy) –
order (None | collections.abc.Sequence[int]) –
- A dense, non-overlapping and strided tensor has three properties:
Dense. Its data is stored contiguously in memory in an array
Non-overlapping. Each array element has a unique index in the tensor
Strided. The array position of an element x with index index_x is <index_x, strides>, the dot product of its index and the tensor’s strides
Intuitively, dense and non-overlapping tensors are distinguished from arbitrarily strided tensors because they are neither “overlapped”, where multiple indices refer to the same elements, nor do they have “gaps” where memory addresses between the first and last array elements do not point to the tensor’s data.
If a permutation is provided the strides will be ordered (least to greatest) like the permutation. If no permutation is provided the strides will be ordered from outermost to innermost (…, 2, 1, 0). For example, if a is a 4D tensor with dimensions labeled NCHW, then strided(a, (3, 0, 2, 1)) produces a dense, non-overlapping and strided tensor where the C dimension has a corresponding stride of one.
Note
No other thunder.jit operations specify how their outputs are represented in memory, and thunder.jit does not model strides. This operation is an explicit directive to construct a dense, non-overlapping and strided tensor, but operations on that tensor do not have to preserve those properties.