triton-lang / triton

Development repository for the Triton language and compiler
https://triton-lang.org/
MIT License
11.86k stars 1.4k forks source link

Question regarding stride #4087

Open wookjeHan opened 3 weeks ago

wookjeHan commented 3 weeks ago

Dear team,

I was wondering how the stride(e.g., x.stride(0)) is decided. I thought if the shape and dtype of two tensors are same, the stride would also be the same.

However, I noted that in some cases, strides are different even with the same shape and dtype.

What makes the difference of stride in such cases and how the strides can be calculated?

Thanks in advance,

lancerts commented 3 weeks ago

https://martinlwx.github.io/en/how-to-reprensent-a-tensor-or-ndarray/ contains a detailed discussion. stride is related to memory layout. if shape and type are same, stride can still be different. Sride can be derived from shape if the tensor is contiguous (but not in general).