Merged
fix MatmulImpl in docs and examples #4142
ruanyyAdd on Jul 7
fix MatmulImpl in docs and examples #4142
Merged
Merged fromruanyy/asc-devkit9.1.0intocann/asc-devkit9.1.0
Total: 7 files changed+18-14
| @@ -24,7 +24,7 @@ CubeResGroupHandle用于在分离模式下对AI Core计算资源分组。分组 | |||
| 24 | 24 | ||
| 25 | ``` | 25 | ``` |
| 26 | // A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_NORM根据实际需求场景构造 | 26 | // A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_NORM根据实际需求场景构造 |
| 27 | - using MatmulApiType = MatmulImpl<A_TYPE, B_TYPE, C_TYPE, C_TYPE, CFG_NORM>; | 27 | + using MatmulApiType = Matmul<A_TYPE, B_TYPE, C_TYPE, C_TYPE, CFG_NORM>; |
| 28 | ``` | 28 | ``` |
| 29 | 29 | ||
| 30 | 2. 创建KfcWorkspace。 | 30 | 2. 创建KfcWorkspace。 |
| @@ -41,9 +41,9 @@ | |||
| 41 | 41 | ||
| 42 | ## 函数原型 | 42 | ## 函数原型 |
| 43 | 43 | ||
| 44 | +Matmul模板参数如下: | ||
| 44 | ``` | 45 | ``` |
| 45 | 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)> | 46 | 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)> |
| 46 | -using Matmul = AscendC::MatmulImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, MM_CB, MATMUL_POLICY>; | ||
| 47 | ``` | 47 | ``` |
| 48 | 48 | ||
| 49 | - A\_TYPE、B\_TYPE、C\_TYPE类型信息通过[MatmulType](Matmul使用说明.md#table1188045714378)来定义。 | 49 | - A\_TYPE、B\_TYPE、C\_TYPE类型信息通过[MatmulType](Matmul使用说明.md#table1188045714378)来定义。 |
| @@ -40,11 +40,14 @@ __aicore__ inline void SetSubBlockIdx(uint8_t subBlockIdx) | |||
| 40 | ## 调用示例 | 40 | ## 调用示例 |
| 41 | 41 | ||
| 42 | ``` | 42 | ``` |
| 43 | +#define ASCENDC_CUBE_ONLY | ||
| 44 | +#include "lib/matmul_intf.h" | ||
| 45 | + | ||
| 43 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> aType; | 46 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> aType; |
| 44 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> bType; | 47 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, half> bType; |
| 45 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> cType; | 48 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> cType; |
| 46 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> biasType; | 49 | typedef AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, float> biasType; |
| 47 | 50 | ||
| 48 | -MatmulImpl<aType, bType, cType, biasType, CFG_NORM> mm; | 51 | +Matmul<aType, bType, cType, biasType, CFG_NORM> mm; |
| 49 | mm.SetSubBlockIdx(0); // 子核ID设置为0 | 52 | mm.SetSubBlockIdx(0); // 子核ID设置为0 |
| 50 | ``` | 53 | ``` |
| @@ -95,13 +95,13 @@ | |||
| 95 | 设置模板参数MatmulPolicy为NBuffer33模板策略,创建Matmul对象。 | 95 | 设置模板参数MatmulPolicy为NBuffer33模板策略,创建Matmul对象。 |
| 96 | 96 | ||
| 97 | ``` | 97 | ``` |
| 98 | - AscendC::MatmulImpl< | 98 | + AscendC::Matmul<AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, AType, IS_TRANS_A>, |
| 99 | - AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, aType>, | 99 | + AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, BType, IS_TRANS_B>, |
| 100 | - AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, bType>, | 100 | + AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, CType>, |
| 101 | - AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, cType>, | 101 | + AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, BiasType>, CFG_MDL, |
| 102 | - AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, biasType>, CFG_MDL, | 102 | + AscendC::MatmulCallBackFunc<nullptr, nullptr, nullptr>, |
| 103 | - AscendC::MatmulCallBackFunc<nullptr, nullptr, nullptr>, | 103 | + AscendC::Impl::Detail::NBuffer33MatmulPolicy> |
| 104 | - AscendC::Impl::Detail::NBuffer33MatmulPolicy> matmulObj; | 104 | + matmulObj; |
| 105 | ``` | 105 | ``` |
| 106 | 106 | ||
| 107 | ## 验证优化方案性能收益<a name="section19022397498"></a> | 107 | ## 验证优化方案性能收益<a name="section19022397498"></a> |
| @@ -309,7 +309,7 @@ | |||
| 309 | auto gmB = bGlobal[offsetB]; | 309 | auto gmB = bGlobal[offsetB]; |
| 310 | auto gmC = cGlobal[offsetC]; | 310 | auto gmC = cGlobal[offsetC]; |
| 311 | 311 | ||
| 312 | - AscendC::MatmulImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_MDL> mm; | 312 | + AscendC::Matmul<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_MDL> mm; |
| 313 | mm.SetSubBlockIdx(0); | 313 | mm.SetSubBlockIdx(0); |
| 314 | mm.Init(&tiling, pipe); | 314 | mm.Init(&tiling, pipe); |
| 315 | mm.SetTensorA(gmA, false); | 315 | mm.SetTensorA(gmA, false); |
Mexamples/01_simd_cpp_api/05_best_practices/01_matrix_compute/matmul_mxfp4_high_performance/README.md+1-1
| @@ -75,7 +75,7 @@ $$ | |||
| 75 | 75 | ||
| 76 | ### 实现要点 | 76 | ### 实现要点 |
| 77 | 77 | ||
| 78 | -本样例将 tiling 参数统一在 `matmul_mx.h` 中编译期确定,通过模板常量 `CONSTANT_CFG` 传给 `MatmulImpl`: | 78 | +本样例将 tiling 参数统一在 `matmul_mx.h` 中编译期确定,通过模板常量 `CONSTANT_CFG` 传给 `Matmul`: |
| 79 | 79 | ||
| 80 | ```cpp | 80 | ```cpp |
| 81 | constexpr static auto CONSTANT_CFG = GetMxConstantCFG<aType, bType, cType, EnableScaleCache>(); | 81 | constexpr static auto CONSTANT_CFG = GetMxConstantCFG<aType, bType, cType, EnableScaleCache>(); |
| @@ -16,7 +16,8 @@ | |||
| 16 | #include "acl/acl.h" | 16 | #include "acl/acl.h" |
| 17 | #include "kernel_operator.h" | 17 | #include "kernel_operator.h" |
| 18 | #include "data_utils.h" | 18 | #include "data_utils.h" |
| 19 | -#include "lib/matrix/matmul/matmul.h" | 19 | +#define ASCENDC_CUBE_ONLY |
| 20 | +#include "lib/matmul_intf.h" | ||
| 20 | 21 | ||
| 21 | #ifdef ASCENDC_CPU_DEBUG | 22 | #ifdef ASCENDC_CPU_DEBUG |
| 22 | #include "cpu_debug_launch.h" | 23 | #include "cpu_debug_launch.h" |
| @@ -126,7 +127,7 @@ private: | |||
| 126 | auto gmB = bGlobal[offsetB]; | 127 | auto gmB = bGlobal[offsetB]; |
| 127 | auto gmC = cGlobal[offsetC]; | 128 | auto gmC = cGlobal[offsetC]; |
| 128 | 129 | ||
| 129 | - AscendC::MatmulImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_MDL> mm; | 130 | + AscendC::Matmul<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, CFG_MDL> mm; |
| 130 | mm.SetSubBlockIdx(0); | 131 | mm.SetSubBlockIdx(0); |
| 131 | mm.Init(&tiling, pipe); | 132 | mm.Init(&tiling, pipe); |
| 132 | mm.SetTensorA(gmA, false); | 133 | mm.SetTensorA(gmA, false); |