快速入门
准备调试环境
调试编译
Ascend C算子的kernel侧源码通过毕昇编译器进行编译,编译后生成NPU域的可执行文件。编译选项添加 -g -O0,使算子编译时包含了所需的调试信息,以便于使用msDebug工具进行调试,具体方法可参考使用示例。
工具启动
msdebug工具安装在Ascend-cann-toolkit开发套件包中,工具路径为${INSTALL_DIR}/tools/msdebug/bin/msdebug。

- ${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。例如,若安装的Ascend-cann-toolkit软件包,则安装后文件存储路径为:$HOME/Ascend/ascend-toolkit/latest。
- 若完成了环境准备章节中的环境变量配置,则无需切换目录直接执行msdebug命令。
msdebug工具支持以下两种启动方式:

若工具弹出Cannot read termcap database; using dumb terminal settings. 的提示信息,可以通过配置export TERMINFO=xx消除提示,xx为本地TERMINFO路径:
export TERMINFO=xx //xx信息可通过infocmp -D命令查询,可以选择符合当前终端配置的路径做为TERMINFO值
- 加载可执行文件<kernel_name>_npu
- 以kernel_name算子为例,算子编译后可获取NPU侧可执行文件<kernel_name>_npu。
- 输入如下命令,使用msdebug工具加载可执行文件。
$ msdebug ./add_custom_npu (msdebug) target create "./<kernel_name>_npu" Current executable set to '${INSTALL_DIR}/projects/add_ascendc_sample/<kernel_name>_npu' (aarch64). (msdebug)
若可执行文件有其他入参,则按照如下形式传入入参:msdebug ./<kernel_name>_npu parameter1 parameter2 ...
- 加载调用算子的python脚本
- 完成了PyTorch框架的适配插件开发后,即可实现从PyTorch框架调用Ascend C自定义算子,可以通过自定义python脚本test_ops_custom.py调用算子。
- 输入如下命令,使用msdebug工具加载python脚本。
$ msdebug python3 test_ops_custom.py msdebug(MindStudio Debugger) is part of MindStudio Operator-dev Tools. The tool provides developers with a mechanism for debugging Ascend kernels running on actual hardware. This enables developers to debug Ascend kernels without being affected by potential changes brought by simulation and emulation environments. (msdebug) target create "./add_custom_npu" Current executable set to ''${INSTALL_DIR}/projects/add_ascendc_sample/add_custom_npu' (aarch64). (msdebug) settings set -- target.run-args "test_ops_custom.py" (msdebug)
调试退出
输入以下命令,退出调试器。
(msdebug) q [localhost add_ascendc_sample]$

该调试通道无法单独关闭,若要关闭调试通道,需要通过覆盖安装方式,具体请参见对应的NPU驱动和固件安装文档。
获取帮助
可以使用help命令输出工具命令的帮助信息,格式为“help msdebug_command”。
打印信息将会展示该命令的功能描述、使用语法以及参数选项。
如核切换命令的帮助信息如下所示:
(msdebug) help ascend aic change the id of the focused ascend aicore. Syntax: ascend aic <id>
如ascend info blocks命令的帮助信息如下所示:
(msdebug) help ascend info blocks show blocks overall info. Syntax: ascend info blocks Command Options Usage: ascend info blocks [-d] -d ( --details ) Show stopped states for all blocks.
父主题: 使用msdebug上板调试算子