展示如何使用msOpGen工具进行Ascend C自定义算子的工程创建、编译和部署,并使用msOpST工具对Ascend C自定义算子进行功能测试。
已参考使用前准备,完成msOpGen工具的使用准备。
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 39 40 41 42 43 44 45 46 47 48 49 50 | [ { "op": "MatmulCustom", "language": "cpp", "input_desc": [ { "name": "a", "param_type": "required", "format": [ "ND" ], "type": [ "float16" ] }, { "name": "b", "param_type": "required", "format": [ "ND" ], "type": [ "float16" ] }, { "name": "bias", "param_type": "required", "format": [ "ND" ], "type": [ "float" ] } ], "output_desc": [ { "name": "c", "param_type": "required", "format": [ "ND" ], "type": [ "float" ] } ] } ] |
msopgen gen -i MatMulCustom.json -f tf -c ai_core-Ascendxxxyy -lan cpp -out MatmulCustom
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | MatmulCustom/ ├── build.sh // 编译入口脚本 ├── cmake │ ├── xx.cmake │ ├── .... │ ├── util // 算子工程编译所需脚本及公共编译文件存放目录 ├── CMakeLists.txt // 算子工程的CMakeLists.txt ├── CMakePresets.json // 编译配置项 ├── framework // 算子插件实现文件目录,单算子模型文件的生成不依赖算子适配插件,无需关注 ├── op_host // host侧实现文件 │ ├── matmul_custom_tiling.h // 算子tiling定义文件 │ ├── matmul_custom.cpp // 算子原型注册、shape推导、信息库、tiling实现等内容文件 │ ├── CMakeLists.txt ├── op_kernel // kernel侧实现文件 │ ├── CMakeLists.txt │ ├── matmul_custom.cpp // 算子代码实现文件 ├── scripts // 自定义算子工程打包相关脚本所在目录 |
./build.sh
./build_out/custom_opp_<target os>_<target architecture>.run
./build_out/custom_opp_<target os>_<target architecture>.run --install-path="xxx/MatmulCustom/installed"
msopst create -i "xxx/MatmulCustom/op_host/matmul_custom.cpp" -out ./st // xxx需要修改为用户实际工程路径
export DDK_PATH=${INSTALL_DIR} export NPU_HOST_LIB=${INSTALL_DIR}/{arch-os}/devlib
msopst run -i ./st/xxx.json -soc Ascendxxxyy -out ./st/out //xxx.json为步骤6获得的测试用例