Developing Custom Operators

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.

The sample package provides sample code for developing TBE custom operators, AI CPU custom operators, and TensorFlow scope fusion patterns, as well as the operator build scripts. You can build your own custom OPP based on the sample or add your own custom operator implementation code to the sample.

You can obtain more samples from the tools/msopgen/template/custom_operator_sample directory in the CANN component directory. For details, see Custom Operator Template.

Sample Description

Build and deploy the sample operator project. For details, see the README.md file of each sample operator.

Do not modify the sample project or the build configuration file that is automatically generated to avoid operator execution failures.

Table 1 TBE DSL sample operators

Operator

Description

Add

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/Add_EN.md directory.

LeakyRelu

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/LeakyRelu_EN.md directory.

Table 2 TBE TIK sample operators

Operator

Description

Conv2d

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/Conv2d_EN.md directory.

Matmul

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/Matmul_EN.md directory.

Permute

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/Permute_EN.md directory.

ScatterNdAdd

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/ScatterNdAdd_EN.md directory.

Upsample

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/Upsample_EN.md directory.

Table 3 AI CPU sample operators

Operator

Description

addblockcust

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/addblockcust_EN.md directory.

ReshapeCust

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/ReshapeCust_EN.md directory.

UniqueCust

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 description in the cplusplus/level1_single_api/4_op_dev/1_custom_op/doc/UniqueCust_EN.md directory.