tensor_tiled_copy(Trans)
Specify the transpose copy operation between matrices with different layouts.
The TiledCopy policy and tensor dst/src matrix input are involved. The shape and stride of the tensor dst/src matrix must be consistent with those defined in the TiledCopy policy.
Interface Definition
template<typename TiledCopy,
typename dtypeD, typename LayoutD,
typename dtypeS, typename LayoutS>
void tensor_tiled_copy(TiledCopy copy, Tensor<dtypeD, LayoutD> dst, Tensor<dtypeS, LayoutS> src);
Template Parameters
Parameter |
Type |
Description |
|---|---|---|
TiledCopy |
typename |
Copy tiling policy type. |
dtypeD, dtypeS |
typename |
Dst/Src precision type. |
LayoutD, LayoutS |
typename |
Dst/Src layout type. |
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
copy |
TiledCopy |
Copy tiling policy. |
Input |
dst |
Tensor<dtypeD, LayoutD> |
Destination matrix for transposition. |
Output |
src |
Tensor<dtypeS, LayoutS> |
Source matrix for transposition. |
Input |
Return Value
void
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <stdio.h> #include <stdlib.h> #include "kupl_mma.h" using namespace kupl::tensor; int main() { constexpr int MATRIX_M = 32; constexpr int MATRIX_N = 512; double *dst = (double*)malloc(sizeof(double) * MATRIX_M * MATRIX_N); double *src = (double*)malloc(sizeof(double) * MATRIX_M * MATRIX_N); for (int i = 0; i < MATRIX_M; i++) { for (int j = 0; j < MATRIX_N; j++) { dst[i * MATRIX_N + j] = 0.0; src[i * MATRIX_N + j] = i * MATRIX_N + j; } } auto shape_d = make_shape(Int<MATRIX_M>{}, Int<MATRIX_N>{}); auto shape_s = make_shape(Int<MATRIX_M>{}, Int<MATRIX_N>{}); auto stride_d = make_stride(Int<1>{}, Int<MATRIX_M>{}); auto stride_s = make_stride(Int<MATRIX_N>{}, Int<1>{}); auto layout_d = make_layout(shape_d, stride_d); auto layout_s = make_layout(shape_s, stride_s); auto atom_copy_shape = make_shape(Int<1>{}, Int<MATRIX_N>{}); auto tiled_copy = make_tiled_copy(Ops<KP36_32x1_F64_TRANS_RM2CM>{}, atom_copy_shape); auto tensor_d = make_tensor(dst, layout_d); auto tensor_s = make_tensor(src, layout_s); tensor_tiled_copy(tiled_copy, tensor_d, tensor_s); free(src); free(dst); return 0; } |
The preceding example demonstrates the copy process from row-major to column-major based on the 32 × 512_F64 matrix shape. The tensor_tiled_copy function is used to perform the copy and transpose operations based on the created copy tiling policy.