Development Modes
Developers can use TBE to develop operators in the following modes: DSL development and TIK development. These development modes improve the TBE-based operator development efficiency from different abstraction and encapsulation degrees to meet different requirements.
You can select an operator development policy as follows.
Before developing an operator, you need to preliminarily analyze the operator and select an operator development mode. The procedure is as follows:
- Analyze the principle of the operator algorithm and extract the mathematical expression of the operator.
For example, for the Atanh operator, the inverse hyperbolic tangent function atanh is an inverse function of the hyperbolic tangent function tanh, and is equivalent to tanh-1x. A mathematical expression is as follows:
The value range is (–∞, +∞). Specifically, the value range of x is (–1, 1). As for origin symmetry, is a singular function.
- Extract basic operations to be used based on the mathematical expression of the operator.
According to the mathematical expression of the Atanh operator, the following basic operations are used:
+, –, *, /, ln()
- Analyze whether the APIs provided by the TBE DSL can meet the requirements of the compute logic description. If yes, the DSL mode is preferred for development.
The main feature of the DSL development mode is that the Ascend AI Software Stack has encapsulated several operation APIs on the TVM mechanism in advance and configured common operation templates. During development, you only need to focus on the operation logic of operators without the need to care about the data adaptation and instruction operation process required by the Ascend AI Processor to implement the operation logic. The DSL development mode is the most convenient and fastest, which can meet the implementation of basic mathematical operations such as Pow, Sqrt, and ReduceSum. Currently, the DSL provides computation APIs for addition, subtraction, multiplication, and division, logarithm, and exponent operations. Developers can combine required logic based on these APIs.
For example, the basic operations used by the Atanh operator include +, –, *, /, and ln(). Analyze whether the APIs provided by the TBE DSL can meet these operation requirements.
- +: implemented using the te.lang.cce.vadds API
- –: multiplies a parameter value by –1 using the te.lang.cce.vmuls API to obtain a negative value, and then add the negative value to the minuend.
- *: multiplies a tensor by a scalar 0.5 using the te.lang.cce.vmuls API.
- /: divides two tensors element-wise using the te.lang.cce.vdiv API.
- ln(): performs a logarithm operation using the te.lang.cce.vlog API.
Based on the preceding analysis, it can be seen that the TBE DSL API meets the implementation requirements of the Atanh operator. Therefore, the TBE DSL mode can be preferentially used to implement the Atanh operator.
- If the TBE DSL API cannot meet the compute logic description or the performance cannot meet your requirements, use the TIK for development.
- The TIK-based custom operator development provides the buffer management and automatic data synchronization mechanism. However, developers need to manually calculate the elements and indexes. Therefore, developers need to be familiar with the Da Vinci Architecture, presenting higher requirements. Theoretically, all operators can be developed in TIK mode. If the DSL development cannot meet requirements, you can use TIK development.