Integrating custom operators into a graph
If you encounter operators that are not supported by the operator acceleration library when executing the PyTorch/TensorFlow network model or constructing an Ascend graph based on the operator prototype, you need to develop custom operators and then integrate them to a graph.
This section describes the overall process of developing custom operators and integrating them to a graph.
Custom Operator Development for PyTorch
The following figure shows the process of developing custom Ascend C operators, adapting them to PyTorch, and integrate them into a graph.

- Custom operator development
Before integrating custom operators into a graph, you need to develop custom operators based on Ascend C.
- Create an operator project.
- Implement the operators, including operator prototype definition, operator implementation on the kernel, and tiling implementation on the host.
- Implement functions such as shape derivation and data type derivation to import operators to the GE graph.
- Build and deploy the operator project. Build and generate the custom operator installation package, install the operator package, and deploy the custom operators to the operator acceleration library.
For details about the preceding process, see Integrating Operators into a GE Graph in Ascend C Operator Development Guide .
- Adaptation to PyTorch
After a custom operator is developed, you need to perform adaptation on the PyTorch side to import the custom operator to the graph. The operations are as follows:
For details about how to import a custom operator into a PyTorch graph, see "Importing a Custom Operator into a Graph Using a Plugin" in PyTorch Graph Mode Instructions (TorchAir) .
Custom Operator Development for TensorFlow
The following figure shows the process of developing a custom Ascend C operator, adapting the TensorFlow framework, and executing the operator into the graph.

- Custom operator development
Before integrating custom operators into a graph, you need to develop custom operators based on Ascend C.
- Create an operator project.
- Implement the operators, including operator prototype definition, operator implementation on the kernel, and tiling implementation on the host.
- Implement functions such as shape derivation and data type derivation to import operators to the GE graph.
For details about the preceding process, see Integrating Operators into a GE Graph in Ascend C Operator Development Guide .
- Develop the TensorFlow adaptation plugin. Register a custom operator and map the TensorFlow operator to the CANN operator by using REGISTER_CUSTOM_OP. In the scenario where a TensorFlow custom operator is mapped to a CANN operator, you also need to develop the TensorFlow custom operator. For details, see " AI Framework Operator Adaptation > TensorFlow Framework" in " Ascend C Operator Development Guide ."
- Build and deploy the operator project. Build and generate the custom operator installation package, install the operator package, and deploy the custom operators to the operator acceleration library.
- Call operators in the TensorFlow framework.
Constructing an Ascend graph
The following figure shows the development process of developing custom Ascend C operators and integrating them into an Ascend graph.

- Custom operator development
Before integrating custom operators into a graph, you need to develop custom operators based on Ascend C.
- Create an operator project and perform operator prototype definition, operator implementation on the kernel, and tiling implementation on the host.
- Implement the shape derivation and data type derivation functions to support the operator in graph mode.
- Build and deploy the operator project. Build and generate the custom operator installation package, install the operator package, and deploy the custom operators to the operator acceleration library.
For details about the preceding process, see Integrating Operators into a GE Graph in Ascend C Operator Development Guide .
- Ascend graph construction
The method of constructing an Ascend graph based on a custom operator is the same as that of constructing an Ascend graph based on other built-in CANN operators. You can call the operator prototype. For details about the typical process, see Constructing an Ascend graph.