Detecting AscendCL-Called Single Operators

After the custom operator is developed and deployed, use the single-operator API to call the operator, add detection-related compilation options, rebuild and deploy the operator, and use msSanitizer to run the executable file to detect exceptions of the operator.

Prerequisite

Click Link to obtain the sample project for operator check.
  • 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

Procedure

  1. Run the following command to generate a custom operator project and provide the operator implementation on the host and kernel:
    bash install.sh -v Ascendxxxyy    # xxxyy indicates the processor type.
  2. Compile and deploy the operator by referring to Compiling and Deploying Operators.

    In the ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CustomOp directory of the sample project, modify the op_kernel/CMakeLists.txt file and add the detection option -sanitizer to the kernel implementation to support the detection function.

    1
    add_ops_compile_options(ALL OPTIONS -sanitizer)
    
  3. Obtain the sample project for verifying the code by referring to Prerequisite.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    ├──input                                                 // Directory for storing the input data generated by the script
    ├──output                                                // Directory for storing the output data and truth value generated during operator execution
    ├── inc                           // Header file directory
       ├── common.h                 // Common method class declaration file, used to read binary files
       ├── operator_desc.h         // Operator description declaration file, including the operator input and output, operator type, input description, and output description
       ├── op_runner.h             // Operator execution information declaration file, including the numbers and sizes of operator input and output
    ├── src 
       ├── CMakeLists.txt    // Compilation script
       ├── common.cpp         // Common function file, used to read binary files
       ├── main.cpp    // Entry for single-operator execution
       ├── operator_desc.cpp     // File used to construct the input and output description of the operator
       ├── op_runner.cpp   // Main process implementation file for single-operator execution
    ├── scripts
       ├── verify_result.py    // Truth value comparison file
       ├── gen_data.py    // Script file for generating the input data and truth value
       ├── acl.json    // ACL configuration file
    
  4. Use the detection tool to start the operator API to run the script.
    mssanitizer --tool=memcheck bash run.sh  # Specify --tool=memcheck for memory check.
    mssanitizer --tool=racecheck bash run.sh # Specify --tool=racecheck for contention detection.
  5. Analyze abnormal behavior by referring to Memory Exception Report Parsing and Analyzing Contention Check Report.