Non-Contiguous Tensors
Currently, the input aclTensors of most operator APIs support non-contiguous tensors. That is, a tensor can be represented by (shape, strides, offset).
Note: You can create an aclTensor by calling the aclCreateTensor API in "Common APIs" in Operator Library API Reference.
Example 1
For a tensor with shape=(6, 5), strides=(10, 1), and offset=22, its memory layout is as follows:
a0,0 , a0,1 , a0,2 , a0,3 , a0,4 , a0,5 , a0,6 , a0,7 , a0,8 , a0,9
a1,0 , a1,1 , a1,2 , a1,3 , a1,4 , a1,5 , a1,6 , a1,7 , a1,8 , a1,9
a2,0 , a2,1 , a2,2 , a2,3 , a2,4 , a2,5 , a2,6 , a2,7 , a2,8 , a2,9
a3,0 , a3,1 , a3,2 , a3,3 , a3,4 , a3,5 , a3,6 , a3,7 , a3,8 , a3,9
a4,0 , a4,1 , a4,2 , a4,3 , a4,4 , a4,5 , a4,6 , a4,7 , a4,8 , a4,9
a5,0 , a5,1 , a5,2 , a5,3 , a5,4 , a5,5 , a5,6 , a5,7 , a5,8 , a5,9
a6,0 , a6,1 , a6,2 , a6,3 , a6,4 , a6,5 , a6,6 , a6,7 , a6,8 , a6,9
a7,0 , a7,1 , a7,2 , a7,3 , a7,4 , a7,5 , a7,6 , a7,7 , a7,8 , a7,9
a8,0 , a8,1 , a8,2 , a8,3 , a8,4 , a8,5 , a8,6 , a8,7 , a8,8 , a8,9
a9,0 , a9,1 , a9,2 , a9,3 , a9,4 , a9,5 , a9,6 , a9,7 , a9,8 , a9,9
The boldfaced values represent the memory layout of the tensor. The complete tensor is discontiguous in memory layout. strides indicates the interval between two adjacent elements on a tensor dimension. If the stride on dimension 1 is 1, the dimension is contiguous. If the stride on dimension 0 is 10, adjacent elements are separated by 10 elements, that is, they are discontiguous elements. offset indicates the offset of the first element of the tensor relative to the address.
Example 2
For a tensor with shape=(4, 3), strides=(20, 2), and offset=22, its memory layout is as follows:
a0,0 , a0,1 , a0,2 , a0,3 , a0,4 , a0,5 , a0,6 , a0,7 , a0,8 , a0,9
a1,0 , a1,1 , a1,2 , a1,3 , a1,4 , a1,5 , a1,6 , a1,7 , a1,8 , a1,9
a2,0 , a2,1 , a2,2 , a2,3 , a2,4 , a2,5 , a2,6 , a2,7 , a2,8 , a2,9
a3,0 , a3,1 , a3,2 , a3,3 , a3,4 , a3,5 , a3,6 , a3,7 , a3,8 , a3,9
a4,0 , a4,1 , a4,2 , a4,3 , a4,4 , a4,5 , a4,6 , a4,7 , a4,8 , a4,9
a5,0 , a5,1 , a5,2 , a5,3 , a5,4 , a5,5 , a5,6 , a5,7 , a5,8 , a5,9
a6,0 , a6,1 , a6,2 , a6,3 , a6,4 , a6,5 , a6,6 , a6,7 , a6,8 , a6,9
a7,0 , a7,1 , a7,2 , a7,3 , a7,4 , a7,5 , a7,6 , a7,7 , a7,8 , a7,9
a8,0 , a8,1 , a8,2 , a8,3 , a8,4 , a8,5 , a8,6 , a8,7 , a8,8 , a8,9
a9,0 , a9,1 , a9,2 , a9,3 , a9,4 , a9,5 , a9,6 , a9,7 , a9,8 , a9,9
The boldfaced values represent the memory layout of the tensor. The whole tensor is not contiguous in memory. strides indicates the interval between two adjacent elements on a tensor dimension. If the stride on dimension 1 is 2, there is an interval of 1 element on this dimension. If the stride on dimension 0 is 20, adjacent elements are separated by 20 elements, that is, they are discontiguous elements. offset indicates the offset of the first element of the tensor relative to the address.