Operator Implementation Flow
During operator development based on the TBE DSL, the operator scheduling depends on the auto schedule mechanism and cannot be directly controlled at the operator development layer. Therefore, you only need to focus on the implementation of the operator computation process during the development based on the TBE DSL. During the computation, you can improve the operator accuracy and performance using various methods.
Figure 5-2 shows the flow of implementing operators in TBE DSL mode.
- Operator implementation analysis: Before developing the operator code, analyze the mathematical expression, input, output, and computation logic implementation of the operator, and specify the TBE DSL API to be called.
If a third-party open-source network is used and some operators are not supported by the Ascend AI processor, you can analyze the operator implementation on the third-party open-source website to obtain the mathematical expression of the operator.
If the TBE DSL APIs cannot meet the operator implementation requirements, use the TIK development mode.
- Computation implementation: Implement the operator computation logic, including the import of the Python module, API declaration, parameter initialization and verification, and computation process description.
The operator implementation file contains two modules: operator API function and compute function. The operator API function is used to initialize the input tensor and verify parameters. The compute function is used to describe the operator computation process and is called in the operator API function.
Computing implementation is the most important phase in TBE DSL development. How to implement the functions of operators and how to further optimize the accuracy and performance of operators must be fully considered in this phase.
- Operator scheduling: Call the generic.auto_schedule API to automatically schedule the operator.
- Operator compilation: Call the te.lang.cce.cce_build_code API to compile the operator and generate the operator binary file (.o) and operator description file (.json).