TIK Function Debugging

Overview

MindStudio IDE supports visualized debugging of TIK operators. You can set breakpoints, perform single-step debugging, continuously run to the end or next breakpoint, view variable information, and exit debugging.

Prerequisites

  • You have configured the user-level environment variable. If it is not configured, perform the following operations:
    1. Modify the ~/.bashrc file. Add the following content to the file:
      # Ascend-CANN-Toolkit environment variable. Change it to the actual path.
      source $HOME/Ascend/ascend-toolkit/set_env.sh
    2. Run the following command:
      source ~/.bashrc
  • The implementation code of TIK operators has been developed.

Procedure

This section uses the Add operator as an example to describe the TIK operator debugging function.

  1. Write the Add operator debugging code file (a .py file).
    A complete code example is as follows (the file is named simple_add.py in this example).
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    import numpy as np
    
    from tbe import tik
    from tbe.common.platform import set_current_compile_soc_info
    
    def simple_add():
        tik_instance = tik.Tik(disable_debug=False)
        kernel_name = "tik_vec_add_128_float32"
        dst_ub = tik_instance.Tensor("float32", [128], tik.scope_ubuf, "dst_ub")
        dst_gm = tik_instance.Tensor("float32", (128,), tik.scope_gm,  "dst_gm")
        src0_gm = tik_instance.Tensor("float32", (128,), tik.scope_gm, "src0_gm")
        src0_ub = tik_instance.Tensor("float32", (128,), tik.scope_ubuf, "src0_ub")
        src1_gm = tik_instance.Tensor("float32", (128,), tik.scope_gm, "src1_gm")
        src1_ub = tik_instance.Tensor("float32", (128,), tik.scope_ubuf, "src1_ub")
    
        tik_instance.data_move(src0_ub, src0_gm, 0, 1, 16, 0, 0)
        tik_instance.data_move(src1_ub, src1_gm, 0, 1, 16, 0, 0)
        tik_instance.vec_add(64, dst_ub, src0_ub, src1_ub, 2, 8, 8, 8)
        tik_instance.data_move(dst_gm, dst_ub, 0, 1, 16, 0, 0)
        tik_instance.BuildCCE(kernel_name, [src0_gm, src1_gm], [dst_gm])
    
        return tik_instance
    
    if __name__=='__main__':
        set_current_compile_soc_info("Ascendxxx")   # Set the SoC as needed. For details, see the parameter description of set_current_compile_soc_info.
        tik_instance = simple_add()
        data_x = np.ones((128,)).astype("float32")
        data_y = np.ones((128,)).astype("float32")
        feed_dict = {'src0_gm': data_x, 'src1_gm': data_y}
        model_data, = tik_instance.tikdb.start_debug(feed_dict=feed_dict,interactive=True) # Add TIK debugging code.
        print(model_data)
    

    During TIK debugging, you need to change the description of tik_instance to tik.Tik(disable_debug=False) as follows:

    Add the following information in bold to the .py file of the Add operator debugging code:

    self.tik_instance = tik.Tik(disable_debug=False)
  2. Set breakpoints.
    • Add a breakpoint.

      Click the row where the TIK breakpoint needs to be set and select Tik Operator Breakpoint in the dialog box displayed. See Figure 1.

      Figure 1 Setting a breakpoint
      • A TIK breakpoint must be added to the TIK statement.
      • If a row of code is divided into multiple rows, set the breakpoint in the last row.
    • Delete a breakpoint.

      To delete a breakpoint, click the icon on the left.

    • Disable a breakpoint. To use only some of the breakpoints without deleting the unneeded ones during debugging, disable the unneeded breakpoints as follows:

      Right-click and deselect Enabled in the displayed dialog box. You can see that changes to . In this case, the disabled breakpoint does not take effect during debugging next time.

      Figure 2 Disabling a breakpoint
    • Enable a breakpoint. To enable a disabled breakpoint during debugging, perform the following steps:

      Right-click and select Enabled in the displayed dialog box. You can see that changes to . In this case, the newly enabled breakpoint takes effect in next debugging.

      Figure 3 Enabling a breakpoint
    • View breakpoints. View the set breakpoints as follows:

      Click More(Ctrl+Shift+F8). The dialog box for viewing breakpoints is displayed, as shown in Figure 4.

      Figure 4 Viewing the TIK breakpoints

      In the preceding figure, area 1 is a breakpoint list that contains all breakpoints set in the current code. Area 2 contains the breakpoint Enabled and Suspend execution functions. Area 3 is the code preview.

      • In the breakpoint list, if you select the check box on the left of a breakpoint, the Enabled option is selected in area 2 and the icon is displayed next to the corresponding code line in the code review area. If you deselect the check box, the Enabled option is deselected in area 2, and the icon is displayed next to the corresponding code line in the code review area.
      • To delete a breakpoint, select the breakpoint in the breakpoint list and click . In the code preview area, the breakpoint icon at the corresponding code line is deleted accordingly.
      • To add a breakpoint, directly click a code line number in the code preview area. Then, information about this breakpoint is automatically added to the breakpoint list.
  3. Start debugging.
    • For the first debugging, right-click the simple_add.py file and choose Tik Operator Debug from the shortcut menu.
    • If this is not the first debugging, click on the toolbar or press Shift+F9 to start debugging.
  4. Perform debugging.

    For details about the debugging procedure, see Debugging.