Before You Start
Set up the environment.
Configure environment variables by referring to Environment Setup.
Restrictions
- To enable the msDebug tool, specify the --debug parameter when installing the driver. For details, see Environment Setup.
- For a single device, only one msDebug tool can be used for debugging. You are not advised to run other operator programs at the same time.
- During operator debugging, the overflow/underflow detection function is disabled.
Importing Debugging Information
Before debugging an operator, enable the debug -g -O0 compilation option and recompile the operator to bring the debugging information to the operator binary. For details, see Building an Operator Based on the Sample Project.
The behavior of the operator program in the -O0 compile option scenario is different from that in the -O2 compile scenario. Therefore, you are advised to use the Contention Check function of the mssanitizer tool instead of the O0 compilation option to locate the internal competition problem of the operator.
Only the debugging information of a single operator can be imported.
- Method 1: Before debugging, configure the following environment variable, specify the operator loading path, and import the debugging information.
export LAUNCH_KERNEL_PATH={path_to_kernel} /my_kernel.o //{path_to_kernel} is the directory where the .o file on the kernel side is located. - Method 2: Before executing the run command, run the image add command to specify the operator loading path and import the debugging information.
(msdebug) image add {path_to_kernel} /my_kernel.o //{path_to_kernel} is the directory where the .o file on the kernel side is located.
- image add is tailor-made only for PyTorch.
- If you want to import the debugging information after the program runs, run the image load command to load the operator debugging information.
(msdebug) image load -f {path_to_kernel}/my_kernel.o -s 0
Starting the Tool
The msDebug tool can be started in either of the following ways.
export TERMINFO= xx //xx can be queried by running the infocmp -D command. You can select a path that meets the current terminal configuration as the value of TERMINFO.
- Load the executable file application.
- After the operator is built, the executable file application on the NPU can be obtained.
- Use msDebug to load the executable file.
$ msdebug ./application
If the executable file has other input parameters, pass them as follows:msdebug -- ./application --flag1 arg1 --flag2 args2 ...
- By loading the Python script for operator call
- After plugins of the PyTorch framework are developed, you can directly call Ascend C custom operators from PyTorch through the custom Python script test_ops_custom.py.
For details about how to use the PyTorch framework to call a single-operator, see .
- Use msDebug to load the Python script.
$ 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 "application" Current executable set to ''${INSTALL_DIR}/projects/application' (aarch64). (msdebug) settings set -- target.run-args "test_ops_custom.py" (msdebug)
- After plugins of the PyTorch framework are developed, you can directly call Ascend C custom operators from PyTorch through the custom Python script test_ops_custom.py.
Exiting Debugging
(msdebug) q [localhost add_ascendc_sample]$
The debugging channel cannot be disabled independently. To disable the debugging channel, you need to enable the overwrite mode. For details, see the NPU driver and firmware installation documents.