Introduction¶
Nomenclature¶
The term tensor refers to an order-n (a.k.a., n-dimensional) array. One can think of tensors as a generalization of matrices to higher orders. For example, scalars, vectors, and matrices are order-0, order-1, and order-2 tensors, respectively.
An order-n tensor has \(n\) modes. Each mode has an extent (a.k.a. size). For each mode you can specify a stride \(s > 0\). This stride describes how two logically consecutive elements along that mode are laid out in physical memory. This is similar to the leading-dimension in BLAS.
cuTENSOR, by default, adheres to a generalized column-major data layout. For example: \(A_{a,b,c} \in {R}^{4\times 8 \times 12}\) is an order-3 tensor with the extent of the a-mode, b-mode, and c-mode respectively being 4, 8, and 12. If not explicitly specified, the strides are assumed to be:
\(stride(a) = 1\)
\(stride(b) = size(a)\)
\(stride(c) = size(a) * size(b)\).
For a general order-n tensor \(A_{i_1,i_2,...,i_n}\) we require that the strides do not lead to overlapping memory accesses; for instance, \(stride(i_1) >= 1\), and \(stride(i_{l-1}) >=stride(i_l) * extent(i_l)\).
We say that a tensor is packed if it is contiguously stored in memory along all modes. That is, \(stride(i_1) = 1\) and \(stride(i_l) = stride(i_{l-1}) * extent(i_{l-1})\).
Furthermore, we say that a tensor is x-way vectorized along mode y if the x consecutive elements along the y-mode are consecutively stored in memory (i.e., have a stride of one).
Einstein Notation¶
We adhere to the “Einstein notation”: modes that appear in the input tensors, and that do not appear in the output tensor, are implicitly contracted.
Compute And Scalar Types¶
cuTENSOR uses its own compute type to guarantee the minimal accuracy across computations. See Accuracy Guarantees for details.
The scalar type used for element-wise operations is a function of the output type and the compute type:
Output type |
Scalar type |
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|