当前位置:网站首页>[cann document express issue 06] first knowledge of tbe DSL operator development
[cann document express issue 06] first knowledge of tbe DSL operator development
2022-06-24 19:58:00 【Hua Weiyun】

Shengteng developers can be based on TBE(Tensor Boost Engine) Provided python Interface for user-defined operator development ,TBE Operator development has DSL ( Domain-Specific Language ) and TIK ( Tensor Iterator Kernel ) Two ways , The applicable scenarios, advantages and disadvantages of the two methods are as follows :

In this issue, we mainly introduce the easy to use DSL Operator development mode .
DSL Functional framework

- Developers call DSL Interface to describe the computing logic , Indicate the calculation method and steps of the operator .
- After the development of computing logic , Developers can call Auto Schedule Interface starts automatic scheduling , During automatic dispatching TBE Automatically select the appropriate scheduling template according to the calculation type , Complete data segmentation and data flow division , Ensure optimal hardware execution . After the dispatch , Will generate something similar to TVM Of IR(Intermediate Representation) In the middle .
- IR After generation ,Pass The generated IR Compile and optimize , The optimized way is double buffering (Double Buffer)、 Assembly line (Pipeline) Sync 、 Memory allocation management 、 Instruction mapping, etc .
- Operator longitude Pass After processing , Will be automatically by CodeGen Generating classes C Temporary files of code , This temporary file generates the binary file of the operator through the compiler , It can be directly loaded and called by the network model .
DSL Operator code implementation
Before implementing the operator code, you need to analyze the mathematical expression of the operator , Input 、 Output , Specify what needs to be called DSL Interface , Then the operator implementation code is developed . be based on DSL The code implementation process of is shown in the following figure :

The code structure of the operator implementation is as follows :

Let's implement two inputs shape identical 、 The data type is “float32” Of Add For example, operators , about DSL Operator implementation of the code flow .
1. First, introduce the development time dependency Python modular
frequently-used Python The modules are as follows :
- “tbe.dsl”: contain TBE DSL Computing interface of 、 Scheduling interface and compilation interface
- “tbe.tvm”:TBE Is based on TVM Framework extension , Developers can use when implementing operators TVM Interface
- “tbe.common.utils.para_check”:TBE Operator parameter verification interface provided
- “tbe.common.utils.shape_util”:TBE Operator provided shape Processing interface
2. Declare operator interface
The operator interface definition function contains the input and output information of the operator and the kernel name .
Here is Add The definition of operator :

In the above example ,add Of the operator type,input_x、input_y Is the input and output of the operator tensor, Define in the form of a dictionary , contain shape、ori_shape、format、ori_format And dtype Information ,kernel_name Is the name of the operator in the kernel , And operator type Keep consistent .
Developers can use when defining operator interface functions TBE Provided parameter verification interface check_input_type Check whether the parameter type of the operator is legal ,check_input_type For decorator function , The usage method is shown below :

Of course , You can also customize the verification function of related parameters , Basic parameter checking helps to find problems ahead of time in the operator compilation phase .
3. For input tensor To carry on the placeholder

Get the input data shape、dtype( This example is float32 Fixed data type of ), Use TVM Of placeholder Interface pair input tensor To carry on the placeholder , Return to one tensor object , The data in this location is specified only when the program is running .
4. Implementation of computing logic
The computational logic of an operator can be obtained by TBE Of DSL Computing interface implementation , for example Add Operators can be passed through DSL Of vadd Interface implementation input_x And input_y The addition operation of .

5. Scheduling and compiling
After the implementation of computing logic , Need to call auto_schedule Interface , Automatically generate corresponding scheduling ; And then call build Interface to compile operators , Compile the operator specific kernel .

among config Configured for compilation parameters map, The configuration information includes whether to print IR、 Operator kernel name and input 、 Output tensor .
Congratulations , So far, you have completed Add Operator implementation code development .
More about
The above is only for DSL The key code of operator development is briefly introduced , For more details and skills of operator implementation, please log in to shengteng community , Read the relevant documents :https://www.hiascend.com/

Rise CANN The document center is dedicated to providing developers with better content and more convenient development experience , help CANN Developers co build AI ecology . Any comments and suggestions can be fed back in shengteng community , Your every attention is our driving force .
边栏推荐
- Install the custom module into the system and use find in the independent project_ Package found
- 试驾 Citus 11.0 beta(官方博客)
- Nodered has no return value after successfully inserting into the database (the request cannot be ended)
- 数字孪生行业案例:智慧港口数字化
- Why is the executor thread pool framework introduced
- How to deal with the problem that the Flink CDC reads MySQL in full and always reports this error
- redis数据结构之压缩列表
- gateway
- Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
- Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi
猜你喜欢

Programmers spend most of their time not writing code, but...

Q1: error in JMeter filename must not be null or empty

微信小程序轮播图怎么自定义光标位置

Power supply noise analysis

Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/3a/db240deb4c66b219ef86f40d4c7b7d.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial

一次 MySQL 误操作导致的事故,高可用都不顶不住!

Capacitive inching touch switch module control (stm32f103c8t6)

SaltStack State状态文件配置实例
随机推荐
Volcano成Spark默认batch调度器
Mq-2 smoke concentration sensor (STM32F103)
Based on STM32F103 0.96 inch OLED LCD driver (IIC communication)
Q1: error in JMeter filename must not be null or empty
Hutool reads large excel (over 10m) files
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!
试驾 Citus 11.0 beta(官方博客)
Geoscience remote sensing data collection online
Kubernetes cluster deployment
假如,程序员面试的时候说真话
Data backup and recovery of PgSQL
Redis error: -bash: redis cli: command not found
LCD12864 (ST7565P) Chinese character display (STM32F103)
Does version 2.2.0 support dynamic addition of MySQL synchronization tables
Test drive citus 11.0 beta (official blog)
Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
Power supply noise analysis
Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"
Oracle create tablespaces and tables