Using Operator Samples

On the command line interface (CLI), you can choose a custom operator sample project from the Ascend open-source community, make slight tweaking, and append your own custom operator to the sample project.

Sample Obtaining

Go to the Ascend samples repository on Gitee or GitHub and download the sample package that matches the required version. For the version mapping, see "Release Notes" in the README file. Find the sample in the cplusplus/level1_single_api/4_op_dev/1_custom_op directory.

If you do not have enough permission to obtain the code, contact technical support to join the Ascend community.

Directory Structure

The directory structure of the operator project is as follows. Develop the operator deliverables in the corresponding directory accordingly.

├── custom.proto    // Original .proto definition file of a Caffe operator
├── build.sh       // Entry script for building a project
├── cpukernel      // Directory of AI CPU operator implementation and information library files
│   ├── impl                  // Directory of the operator implementation files (.h and .cc)
│   ├── op_info_cfg
│       ├── aicpu_kernel
│           ├── xx.ini  // Operator information library files
├── framework      // Directory of the operator plugin implementation files. Ignore this directory for a PyTorch operator.
│   ├── CMakeLists.txt
│   ├── caffe_plugin    // Directory of the Caffe operator plugin implementation code and the CMakeLists build script
│       ├── CMakeLists.txt 
│       ├── xx_plugin.cc 
│   ├── tf_plugin    // Directory of the TensorFlow operator plugin implementation code and the CMakeLists build script
│       ├── CMakeLists.txt 
│       ├── xx_plugin.cc 
│   ├── onnx_plugin    // Directory of the ONNX operator plugin implementation code and the CMakeLists build script
│       ├── CMakeLists.txt 
│       ├── xx_plugin.cc 
│   ├── tf_scope_fusion_pass    // Directory of the implementation code for parser scope fusion patterns and the CMakeLists build script
│       └── xx_pass.h
│       └── xx_pass.cc
│       └── CMakeLists.txt
├── op_proto     // Directory of the operator prototype definition files and the CMakeLists file
│   ├── xx.h
│   ├── xx.cc
│   ├── CMakeLists.txt   // Build script of the operator IR definition file, called by CMakeLists.txt of the operator project
├── tbe 
│   ├── CMakeLists.txt   
│   ├── impl    // Directory of operator implementation files
│   │      ├── xx.py
│   │      ├── __init__.py      // Python package identifier
│   ├── op_info_cfg   // Directory of the operator information library files
│       └── ai_core
│           ├── {Soc Version}           // Directory named after Ascend AI Processor version
│               ├── xx.ini
│   ├── testcase   
│       ├── tf1.15_test  // Directory of the TensorFlow 1.15 operator test files
│           ├── op_name                      // Directory of code for verifying single-operators on network
│              ├── tf_xx.py
│       ├── tf2.6_test  // Directory of the TensorFlow 2.6 operator test files
│           ├── op_name                      // Directory of code for verifying single-operators on network
│              ├── tf_xx.py
├── cmake 
│   ├── config.cmake
│   ├── util                // Directory of build-related common files
│       ├── makeself       // Directory of build-related common files
├── scripts     // Directory of scripts used for custom operator project packing
├── tools

The PyTorch adaptation code is not included in the preceding operator project. To develop adaptation code from the PyTorch source code, please refer to Plugin Development (PyTorch).

  • Operator Project Building demonstrates the build procedure.
  • The sample project contains the TBE operator and AI CPU operator samples whose original frameworks are TensorFlow and Caffe. During operator project building and deployment, the operators in all sample projects are deployed to the operator library. If the sample operator conflicts with your own operator, delete the sample operator from the corresponding directory.
  • For details about the TensorFlow parser scope fusion patterns, see TensorFlow Parser Scope Fusion Pattern Developer Guide.