Checking the Single-Operator via APIs
After the custom operator is developed and deployed, use the single-operator API to call the operator, add check-related compilation options, rebuild and deploy the operator, and use msSanitizer to run the executable file to check exceptions of the operator.
Prerequisite
You have obtained the sample project by visiting link to prepare for the operator check.
- This example project does not support
Atlas A3 Training Series Product . - When downloading the code sample, run the following command to specify the branch version:
git clone https://gitee.com/ascend/samples.git -b master
Procedure
- Run the following command 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.
- 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.
add_ops_compile_options(ALL OPTIONS -sanitizer)
- Click Prerequisite to obtain the sample project for verifying the code.
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
- 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 # --tool=racecheck must be specified for contention check.
- Analyze abnormal behaviors by referring to Analyzing a Memory Exception Report, Analyzing a Contention Check Report, and Analyzing a Uninitialization Exception Report.
Parent topic: Typical Cases