msDebug (Operator Debugging)
msDebug can debug all Ascend operators. You can use different functions as required. For example, you can set breakpoints, print variables and memory, perform single-step debugging, stop running, and switch cores.
- Install the NPU driver and firmware. For details, see Overview.
- Run the following command in the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch directory to generate a custom operator project and implement the operator on the host and kernel:
bash install.sh -v Ascendxxxyy # xxxyy indicates the processor type used by the user.
- In the CMakePresets.json file under the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CustomOp directory, set the cacheVariables configuration item from Release to Debug.
"cacheVariables": { "CMAKE_BUILD_TYPE": { "type": "STRING", "value": "Debug" }, ... } - Run the following commands to build and deploy the operator again:
- Run the following command in the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CustomOp directory to build and deploy the operator again:
bash build.sh ./build_out/custom_opp_<target_os>_<target_architecture>.run // Name of the .run package in the current directory
- Switch to the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/AclNNInvocation directory and run the following command to generate the executable file execute_add_op in the ./output directory:
bash run.sh cd ./output
- Run the following command in the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CustomOp directory to build and deploy the operator again:
- Before debugging, configure the following environment variables, specify the operator loading path, and import the debugging information. An example is provided as follows:
export LAUNCH_KERNEL_PATH=${INSTALL_DIR}/opp/vendors/customize/op_impl/ai_core/tbe/kernel/${soc_version}/add_custom/AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b.o //soc_version is the chip name of the Ascend AI Processor and must be in lowercase.
- Specify the path of the dynamic library on which the operator depends and load the .so file of the dynamic library.
export LD_LIBRARY_PATH=${INSTALL_DIR}/opp/vendors/customize/op_api/lib:$LD_LIBRARY_PATH - Run the msdebug execute_add_op command in the executable file directory to access msDebug.
msdebug execute_add_op
- Set a breakpoint.
- Set a breakpoint.
(msdebug) b add_custom.cpp:55
- The following command output indicates that the breakpoint is successfully added:
Breakpoint 1: where = AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b.o`KernelAdd::Compute(int) (.vector) + 68 at add_custom.cpp:55:9, address = 0x00000000000014f4
- Set a breakpoint.
- Enter the r command to run the operator program and wait until the breakpoint is hit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
(msdebug) r Process 1454802 launched: '${INSTALL_DIR}/add_cus/AclNNInvocation/output/execute_add_op' (aarch64) [INFO] Set device[0] success [INFO] Get RunMode[1] success [INFO] Init resource success [INFO] Set input success [INFO] Copy input[0] success [INFO] Copy input[1] success [INFO] Create stream success [INFO] Execute aclnnAddCustomGetWorkspaceSize success, workspace size 0 [Launch of Kernel AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b on Device 0] [INFO] Execute aclnnAddCustom success Process 1454802 stopped [Switching to focus on Kernel AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b, CoreId 39, Type aiv] * thread #1, name = 'execute_add_op', stop reason = breakpoint 1.1 frame #0: 0x00000000000014f4 AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b.o`KernelAdd::Compute(this=0x00000000003078a8, progress=0) (.vector) at add_custom.cpp:55:9 52 __aicore__ inline void Compute(int32_t progress) 53 { 54 LocalTensor<DTYPE_X> xLocal = inQueueX.DeQue<DTYPE_X>(); -> 55 LocalTensor<DTYPE_Y> yLocal = inQueueY.DeQue<DTYPE_Y>(); //The line number at the breakpoint is correct. Other information is subject to the actual situation. 56 LocalTensor<DTYPE_Z> zLocal = outQueueZ.AllocTensor<DTYPE_Z>(); 57 Add(zLocal, xLocal, yLocal, this->tileLength); 58 outQueueZ.EnQue<DTYPE_Z>(zLocal);
- Keep running.
- Enter the following command to continue the running:
(msdebug) c
- The following shows that the program hits the breakpoint again:
1 2 3 4 5 6 7 8 9 10 11 12
Process 1454802 resuming Process 1454802 stopped [Switching to focus on Kernel AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b, CoreId 39, Type aiv] * thread #1, name = 'execute_add_op', stop reason = breakpoint 1.1 frame #0: 0x00000000000014f4 AddCustom_1e04ee05ab491cc5ae9c3d5c9ee8950b.o`KernelAdd::Compute(this=0x00000000003078a8, progress=0) (.vector) at add_custom.cpp:55:9 52 __aicore__ inline void Compute(int32_t progress) 53 { 54 LocalTensor<DTYPE_X> xLocal = inQueueX.DeQue<DTYPE_X>(); -> 55 LocalTensor<DTYPE_Y> yLocal = inQueueY.DeQue<DTYPE_Y>(); //The line number at the breakpoint is correct. Other information is subject to the actual situation. 56 LocalTensor<DTYPE_Z> zLocal = outQueueZ.AllocTensor<DTYPE_Z>(); 57 Add(zLocal, xLocal, yLocal, this->tileLength); 58 outQueueZ.EnQue<DTYPE_Z>(zLocal);
- Enter the following command to continue the running:
- Stop debugging.
(msdebug) q
Parent topic: Operator Development Tools Quick Start