make_tiled_copy
创建tiled_copy策略。CopyAtom Ops转置矩阵大小与atom_shape相应m和n相乘所得乘积表示实际转置矩阵大小。
当前atom_shape中m/n不支持任意扩展,对于不同的CopyAtom Ops存在不同的限制,具体见下表2参数定义中描述。
接口定义
template<typename CopyAtom, typename Shape>
TiledCopy<CopyAtom, Shape> make_tiled_copy( CopyAtom copy_atom, Shape atom_shape);
模板参数
参数名 |
类型 |
描述 |
|---|---|---|
CopyAtom |
typename |
copy原子策略类型。 |
Shape |
typename |
形状类型。 |
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
copy_atom |
CopyAtom,Ops<枚举copy_atom_t> |
copy原子策略,当前store_atom_t可设置为:
|
输入 |
atom_shape |
Shape |
原子策略在各维度执行次数,包含m和n两个数值。 |
输入 |
返回值
返回TiledCopy<StoreCopy, Shape>对象
示例
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<COPY_32x1_F64_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; } |
上述示例演示了基于32*512_F64矩阵形状从行主序到列主序的copy流程,其中通过make_tiled_copy创建copy tile策略,具体选择的原子方法为COPY_32x1_F64_RM2CM,atom_shape为shape<1, 512>。
父主题: 矩阵编程接口函数