├── aclnn_Xxx.cpp // 自动生成的单算子API执行接口实现文件 ├── aclnn_Xxx.h // 自动生成的单算子API执行接口头文件
add_ops_compile_options(ALL OPTIONS -g -O0)
add_compile_options(-O0 -g)
├──input // 存放脚本生成的输入数据目录 ├──output // 存放算子运行输出数据和真值数据的目录 ├── inc // 头文件目录 │ ├── common.h // 声明公共方法类,用于读取二进制文件 │ ├── operator_desc.h // 算子描述声明文件,包含算子输入/输出,算子类型以及输入描述与输出描述 │ ├── op_runner.h // 算子运行相关信息声明文件,包含算子输入/输出个数,输入/输出大小等 ├── src │ ├── CMakeLists.txt // 编译规则文件 │ ├── common.cpp // 公共函数,读取二进制文件函数的实现文件 │ ├── main.cpp // 单算子调用应用的入口 │ ├── operator_desc.cpp // 构造算子的输入与输出描述 │ ├── op_runner.cpp // 单算子调用主体流程实现文件 ├── scripts │ ├── verify_result.py // 真值对比文件 │ ├── gen_data.py // 输入数据和真值数据生成脚本文件 │ ├── acl.json // acl配置文件
如果需要在算子调用程序中添加断点(如main.cpp),则需要编辑算子工程目录下的CMakeLists文件,如样例工程中的AclNNInvocation/src/CMakeLists.txt。
# 添加编译选项 add_compile_options(-O0 -g)
如在AclNNInvocation/src/op_runner.cpp文件中使用了具有超时参数的同步接口aclrtSynchronizeStreamWithTimeout,则需要适当调整或取消超时参数,否则在调试过程中,程序在断点停止时间过长,调用程序会认为执行失败并中断执行。
# 在op_runner.cpp中进行接口同步时,假如原定的超时时间为5000毫秒 aclrtSynchronizeStreamWithTimeout(stream, 5000)
aclrtSynchronizeStreamWithTimeout(stream, 5000000)
aclrtSynchronizeStream(stream)
将自定义算子工程编译后输出在build_out目录下kernel侧的.o文件路径导入环境变量。
export LAUNCH_KERNEL_PATH=/{path_to_kernel}/kernel_name.o
{path_to_kernel}表示对算子kernel侧实现编译后生成的算子二进制文件*.o所在路径,请根据实际情况进行替换。
kernel侧对算子的多个dtype可能会编译出多个.o文件,任选一个文件导入即可,原则上都会包含源码路径信息。
cd AclNNInvocation/output msdebug execute_add_op (msdebug) target create "execute_add_op" Current executable set to '/home/AclNNInvocation/output/execute_add_op' (aarch64). (msdebug)
b /home/xx/op_host/add_custom.cpp:24
(msdebug) b /home/xx/op_host/add_custom.cpp:24 Breakpoint 1: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (msdebug)
在算子运行后,会自动找到实际位置,并自动设置断点。
(msdebug) run Process 3248297 launched: '/home/AclNNInvocation/output/execute_add_op' (aarch64) 1 location added to breakpoint 1 1 location added to breakpoint 1 ... # 省略部分输出 [INFO] Create stream success Process 3248297 stopped * thread #1, name = 'execute_add_', stop reason = breakpoint 1.1 frame #0: 0x0000ffffd529062c liboptiling.so`optiling::TilingFunc(context=0x0000000008ea4820) at add_custom.cpp:24 21 const uint32_t totalNum = context->GetInputTensor(0)->GetShapeSize(); 22 23 auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo()); -> 24 const uint32_t actCoreNum = ascendcPlatform.GetCoreNumAiv(); 25 uint64_t ubSize; 26 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); 27 (msdebug)