Operator Information Library Definition

Overview

You need to register the operator information to the operator information library by configuring the operator information file. The operator information library mainly describes the implementation specifications of an operator on the Ascend AI Processor.

For TBE operators, the operator information library includes the input and output data types, formats, and input shapes supported by the operators. For AI CPU operators, the operator information library includes the input and output names, and supported data types and formats.

During network execution, Graph Compiler performs basic verification and operator matching based on the operator information in the operator information library.

TBE Operator Information Library

Go to the tbe/op_info_cfg/ai_core/soc_version directory and configure the operator information library file add.ini.

soc_version indicates the Ascend AI Processor version.

You need to modify the add.ini file automatically generated by MindStudio. The following shows the modified operator information library definition of the Add operator.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[Add]
input0.name=x1
input0.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32
input0.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND
input0.shape=all
input0.paramType=required
input1.name=x2
input1.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32
input1.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND
input1.shape=all
input1.paramType=required
output0.name=y
output0.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32
output0.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND
output0.shape=all
output0.paramType=required
opFile.value=add
opInterface.value=add

Table 1 describes the configuration options. The following table lists only the common configuration options of the operator information library. For details about other configuration options, see "Operator Development > Operator Information Library Definition > TBE Operator Information Library" in the TBE & AI CPU Operator Development Guide.

Table 1 Operator information library definition of the Add operator

Information

Add Operator Configuration

Description

[OpType]

[Add]

Operator type, which is included in square brackets to mark the start of operator information. The operator type is Add according to Operator Analysis.

input0.name

x1

Name of the first input tensor of the Add operator. According to Operator Analysis, the name of the first input tensor is x1. Therefore, set this parameter to x1, which must be the same as the name in Operator Prototype Definition.

input0.dtype

input0.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32

input0.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND

Data type and data layout format supported by the input tensor.

According to Operator Analysis, the Add operator supports input types float16, float32 and int32 and data layout formats NCHW, NC1HWC0, NHWC, and ND.

NOTE:

If the input tensor supports multiple dtype and format combinations, dtype and format must be configured in pairs and in sequence. List all the combinations supported by the operator and separate them with commas (,).

input0.format

input0.shape

all

Shape of the input tensor.

input0.paramType

required

Type of the input tensor.

  • dynamic: indicates that the number of inputs is subject to change, which can be one or more.
  • optional: indicates that there could be one input or no input at all.
  • required: indicates that there is one and only one input.

Set input0 of the Add operator to required.

input1.name

x2

The Add operator has two inputs, while the generated configuration template has only one input. Therefore, you need to add the configuration of input1.

Name of the second input tensor of the Add operator. According to Operator Analysis, the name of the second input tensor is x2. Therefore, set this parameter to x2, which must be the same as the name in Operator Prototype Definition.

input1.dtype

input1.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32

input1.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND

Data type and data layout format supported by the input tensor.

According to Operator Analysis, the Add operator supports input types float16, float32, and int32 and data layout formats NCHW, NC1HWC0, NHWC, and ND.

NOTE:

If the input tensor supports multiple dtype and format combinations, dtype and format must be configured in pairs and in sequence. List all the combinations supported by the operator and separate them with commas (,).

input1.format

input1.shape

all

Shape of the input tensor.

input1.paramType

required

Type of the input tensor.

  • dynamic: indicates that the number of inputs is subject to change, which can be one or more.
  • optional: indicates that there could be one input or no input at all.
  • required: indicates that there is only one input.

Set input1 of the Add operator to required.

output0.name

y

Name of the output tensor of the Add operator. According to Operator Analysis, the output name of the operator is y. Therefore, set this parameter to y, which must be the same as the name in Operator Prototype Definition.

output0.dtype

output0.dtype=float16,float16,float16,float16,float,float,float,float,int32,int32,int32,int32

output0.format=NCHW,NC1HWC0,NHWC,ND,NCHW,NC1HWC0,NHWC,ND

Data type and data layout format supported by the output tensor.

According to Operator Analysis, the Add operator supports output types float16, float32, and int32 and data layout formats NCHW, NC1HWC0, NHWC, and ND.

NOTE:

If the input tensor supports multiple dtype and format combinations, dtype and format must be configured in pairs and in sequence. List all the combinations supported by the operator and separate them with commas (,).

output0.format

output0.shape

all

Shape of the output tensor.

output0.paramType

required

Type of the output tensor:

  • dynamic: indicates that the number of outputs is subject to change, which can be one or more.
  • optional: indicates that there could be one output or no output at all.
  • required: indicates that there is one and only one output.

Set output0 of the Add operator to required.

opFile.value

add

Name of the operator implementation file.

According to Step 4, the name of the operator implementation code complies with the rules of converting OpType to the code implementation name. Therefore, this parameter does not need to be specified.

opInterface.value

add

Name of the definition function in the operator implementation file.

The name of the operator definition function complies with the rules of converting OpType to the operator definition function name. See Step 4. Therefore, this parameter does not need to be specified.

AI CPU Operator Information Library

Go to the cpukernel/op_info_cfg/aicpu_kernel directory and configure the operator information library file reshape_cust.ini.

You need to modify the reshape_cust.ini file automatically generated by MindStudio. The following shows the operator information library definition of the modified ReshapeCust operator.

[ReshapeCust]
opInfo.engine=DNN_VM_AICPU
opInfo.flagPartial=False
opInfo.computeCost=100
opInfo.flagAsync=False
opInfo.opKernelLib=CUSTAICPUKernel
opInfo.kernelSo=libcust_aicpu_kernels.so
opInfo.functionName=RunCpuKernel
opInfo.workspaceSize=1024

Table 2 describes the configuration options. The following table lists only the common configuration options of the operator information library. For details about other configuration options, see "Operator Development > Operator Information Library Definition > AI CPU Operator Information Library" in the TBE & AI CPU Operator Development Guide.

Table 2 Operator information library definition of the ReshapeCust operator

Information

ReshapeCust Operator Configuration

Description

[OpType]

[ReshapeCust]

Operator type, which is included in brackets to mark the start of operator information. The operator type is ReshapeCust according to Operator Analysis.

opInfo.engine

DNN_VM_AICPU

Operator engine.

Fixed to DNN_VM_AICPU for AI CPU custom operators.

opInfo.flagPartial

False

Reserved, fixed to False.

opInfo.computeCost

100

Reserved, fixed to 100.

opInfo.flagAsync

False

Reserved, fixed to False.

opInfo.opKernelLib

CUSTAICPUKernel

kernelLib called by the operator.

Fixed to CUSTAICPUKernel for AI CPU custom operators.

opInfo.kernelSo

libcust_aicpu_kernels.so

Name of the .so file generated after the AI CPU operator is built.

opInfo.functionName

RunCpuKernel

Name of the kernel function called by the custom operator.

Fixed to RunCpuKernel for AI CPU custom operators.

opInfo.workspaceSize

1024

Reserved.

Memory space used for temporary operator computation.

The unit is KB, and the value range is 0–1048576 (1 GB).

Recommended value: 1024