mojo
mojo copied to clipboard
[Feature Request] `XBuffer` with static stride
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
The current NDBuffer specifies a static size, why doesn't it allow for a statically defined stride as well? This would enable us to easily create a column-major array or a padded array. We could have XBuffer[rank, shape, stride, type]
.
For example, a column-major matrix is just:
shape: (3,5)
stride: (1,3)
Padding a column to a row-major matrix is simply
shape: (3,5)
stride: (6,1)
And a lazy array filled with a single element could be defined as:
shape: (3,5)
stride: (0, 0)
What is your motivation for this change?
- Naturally create a lazily filled array, saving memory.
- Allow for the creation of column-major tensors and other things like "batched transposed tensor".
- In CUDA programming, it is often necessary to pad a tensor (without changing the logical shape) to avoid bank conflicts.
Any other details?
NVIDIA's CuTe provides an excellent abstraction for data layout, where they make extensive use of compile-time constants. Mojo seems inherently suited to implement a similar product.
Seems quite reasonable, and I think it's something NDBuffer might just get. FYI @abduld
yes, this is planned. We do not have an explicit timeline thought atm