昇腾社区首页
中文
注册

快速入门

准备调试环境

  1. 参考环境准备完成配套版本NPU驱动包的安装。
    • 若要使能msdebug工具,安装驱动时需要指定--debug参数,驱动安装请参考CANN 软件安装指南中的“安装驱动和固件”章节。
      ./Ascend-hdk-<chip_type>-npu-driver_<version>_linux-<arch>.run --debug
    • 调试通道权限较大,存在安全风险,请谨慎使用,生产环境不推荐使用,使用本调试工具即代表认可并接受该风险。
  2. 参考环境准备完成CANN相关软件包的安装。

    若安装CANN相关软件包时提示与驱动版本不匹配,可使用“--force”强制安装,该参数需要配合“--install”一起使用。

调试编译

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
    1. kernel_name算子为例,算子编译后可获取NPU侧可执行文件<kernel_name>_npu。

      基于Ascend C算子的kernel侧框架执行一键式编译运行,可生成NPU侧可执行文件<kernel_name>_npu,具体操作可参考Ascend C算子开发指南中的“ 算子开发(基础篇)> 核函数运行验证”章节。

    2. 输入如下命令,使用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脚本
    1. 完成了PyTorch框架的适配插件开发后,即可实现从PyTorch框架调用Ascend C自定义算子,可以通过自定义python脚本test_ops_custom.py调用算子。

      通过PyTorch框架进行单算子调用的场景,详细信息可参考Ascend C算子开发指南中“算子开发(进阶篇)> 网络中算子调用 > PyTorch框架”章节。

    2. 输入如下命令,使用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.