Matmul模板参数

产品支持情况

产品

是否支持

Ascend 950PR/Ascend 950DT

√

Atlas A3 训练系列产品/Atlas A3 推理系列产品

√

Atlas A2 训练系列产品/Atlas A2 推理系列产品

√

Atlas 200I/500 A2 推理产品

√

Atlas 推理系列产品AI Core

√

Atlas 推理系列产品Vector Core

x

Atlas 训练系列产品

x

功能说明

创建Matmul对象时需要传入:

函数原型

1
2
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE = C_TYPE, const auto& MM_CFG = CFG_NORM, class MM_CB = MatmulCallBackFunc<nullptr, nullptr, nullptr>, MATMUL_POLICY_DEFAULT_OF(MatmulPolicy)>
using Matmul = AscendC::MatmulImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, MM_CB, MATMUL_POLICY>;

参数说明

表1 MatmulApiStaticTiling常量化Tiling参数说明

参数

数据类型

说明

M, N, Ka, Kb,

singleCoreM, singleCoreN, singleCoreK,

baseM, baseN, baseK,

depthA1, depthB1,

stepM, stepN,stepKa,stepKb,

isBias,

transLength,

iterateOrder,

dbL0A, dbL0B,

dbL0C,

shareMode,

shareL1Size,

shareL0CSize,

shareUbSize,

batchM,

batchN,

singleBatchM,

singleBatchN,

mxTypePara

int32_t

与TCubeTiling结构体中各同名参数含义一致。本结构体中的参数是常量化后的常数值。

cfg

MatmulConfig

Matmul模板的参数配置。

返回值说明

无

约束说明

无

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// 用户自定义回调函数
void DataCopyOut(const __gm__ void *gm, const LocalTensor<int8_t> &co1Local, const void *dataCopyOutParams, const uint64_t tilingPtr, const uint64_t dataPtr);
void CopyA1(const AscendC::LocalTensor<int8_t> &aMatrix, const __gm__ void *gm, int row, int col, int useM, int useK, const uint64_t tilingPtr, const uint64_t dataPtr);
void CopyB1(const AscendC::LocalTensor<int8_t> &bMatrix, const __gm__ void *gm, int row, int col, int useK, int useN, const uint64_t tilingPtr, const uint64_t dataPtr);

// 定义创建对象时需要传入的A、B、C、Bias参数类型信息
typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> aType; 
typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> bType; 
typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> cType; 
typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> biasType; 

// 使用MDL模板,创建Matmul实例
AscendC::Matmul<aType, bType, cType, biasType, CFG_MDL> mm1; 

AscendC::MatmulConfig mmConfig{false/*不使用Norm模板*/, true/*开启BasicBlock模板*/, false/*不开启MDL模板*/, 128/*Matmul计算时base块M轴长度*/, 128/*Matmul计算时base块N轴长度*/, 64/*Matmul计算时base块K轴长度*/};
mmConfig.enUnitFlag = false; // 不开启UnitFlag功能
// 使用自定义的mmConfig,创建Matmul实例
AscendC::Matmul<aType, bType, cType, biasType, mmConfig> mm2;

// 使用NORM模板、自定义的mmConfig和自定义的回调函数,创建Matmul实例
AscendC::Matmul<aType, bType, cType, biasType, CFG_NORM, AscendC::MatmulCallBackFunc<DataCopyOut, CopyA1, CopyB1>> mm3;