Before You Start

Setting Up the Environment

Configure environment variables by referring to Environment Setup.

Adding Compilation Options

The locations of the compilation options to be added vary depending on the operator project. The following uses the Kernel Launch Symbol and msOpGen Operator Project Compilation as examples.

  • Kernel launch symbol
    • Add -g --cce-enable-sanitizer to the compilation options of the operator code.
      Add the following code to the cmake/npu/CMakeLists.txt file in the sample project directory and click Link to see the complete sample for kernel function development and running verification.
      target_compile_options(${smoke_testcase}_npu PRIVATE
                           -O2
                           -std=c++17
                           --cce-enable-sanitizer
                           -g
      )

      The --cce-enable-sanitizer option is added to enable exception detection.

      The -g option is added to enable the compiler to generate location information. The specific location of the exception (file name, line number, and call stack) is displayed in the exception report.

      • When downloading the code sample, run the following command to specify the branch version:
        git clone https://gitee.com/ascend/samples.git -b 8.0.RC2
      • If both --cce-enable-sanitizer and -O0 are enabled, the --cce-ignore-always-inline=false compilation option needs to be added.
      • If the -g compilation option is added, the generated binary file contains debugging information. You are advised to restrict the access permission of user programs with debugging information to ensure that only authorized personnel can access the binary file.
      • Due to the restrictions of the llvm-symbolizer open source software, the call stack may fail to be obtained. In this case, you can run the detection command again to obtain the exception information about the call stack.
    • The target_link_options option needs to be added in the link phase.
      • Add the following code to the cmake/npu/CMakeLists.txt file in the sample project directory:
        target_link_options(${smoke_testcase}_npu PRIVATE
            --cce-fatobj-link
            --cce-enable-sanitizer
        )
      • Edit the cmake/Modules/CMakeCCEInformation.cmake file in the sample project directory.
        if(NOT CMAKE_CCE_LINK_EXECUTABLE)
          set(CMAKE_CCE_LINK_EXECUTABLE
            "<CMAKE_CCE_COMPILER> ${CMAKE_LIBRARY_CREATE_CCE_FLAGS} ${_CMAKE_COMPILE_AS_CCE_FLAG} <FLAGS> <CMAKE_CCE_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICIT_LINKS}")
        endif()
    • When msSanitizer is enabled, the NPU-side executable file <kernel_name>_npu needs to be loaded. For details about how to obtain this file, see Kernel Launch.
  • msOpGen operator project compilation
    1. Click Link and run the install.sh script in the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch directory to generate a custom operator project.
      When downloading the code sample, run the following command to specify the branch version:
      git clone https://gitee.com/ascend/samples.git -b v0.2-8.0.0.beta1
      bash install.sh -v Ascendxxxyy    # xxxyy indicates the processor type.
    2. Switch to the custom operator project directory.
      1
      cd CustomOp
      
    3. Edit the op_kernel/CMakeLists.txt file in the sample project directory and add the -sanitizer option to the compilation options. For details, see custom compilation options.
      1
      add_ops_compile_options(ALL OPTIONS -sanitizer)
      

Starting the Tool

After the environment setup and compilation option adding are complete, enable msSanitizer functions by referring to Enabling Memory Detection and Enabling Contention Detection.