Operator APIs (aclnn)
How to Use
To make it easier to call operators, a set of C-based APIs (with the aclnn prefix) are provided. You do not need to provide the Intermediate Representation (IR) definition to facilitate efficient model and application development. This method is called single-operator API calling, or aclnn calling for short.
Header File/Library File
When calling operator APIs, you need to reference the dependency header file and library file. Generally, the header file is stored in
${INSTALL_DIR}/include/aclnnopand the library file is stored in${INSTALL_DIR}/lib64. The specific files are as follows:- Header file: Method 1 (recommended): Reference the general header file
aclnn_ops_{ops_project}.hof the operator repository. Method 2: Reference the header file aclnn_*.h of a single operator API. - Library file: Reference the library file libopapi_${ops_project}.so corresponding to the operator repository. Note that the original master library file libopapi.so for all operator repositories will be deprecated in the future. It is not recommended for use, nor is it supported for simultaneous use with individual operator repository files.
${INSTALL_DIR} indicates the file path after CANN installation. ${ops_project} indicates the operator repository name (such as math, nn, cv, and transformer). Change it to the actual operator repository name.
- Header file: Method 1 (recommended): Reference the general header file
Version Evolution
Note that some APIs have multiple versions. Select the latest version. (APIs of a later version are compatible with all capabilities of an earlier version.)
API List
- Operator feature introduction: Before calling APIs, learn the basics of operators, including deterministic algorithms, Batch consistency, and common quantization modes. For details, see Basic Operator Concepts.
- Symbol notation: "-" in the table indicates that the API is not yet supported by the products in the current column.
The following table lists the operator APIs.
| API Name | Description | Deterministic Computation (A2/A3) | Deterministic Computation (Ascend 950) |
|---|---|---|---|
| aclnnMrgbaCustom | Performs transparency multiplication on the tensor rgb and tensor alpha. | - | - |
| aclnnBackgroundReplace | Fuses the input new background image with the existing image, and replaces the background with the new background via a mask. | - | - |
| aclnnBlendImagesCustom | Performs transparency multiplication on the tensor rgb, frame, and alpha. | - | - |
| aclnnGridSampler2D | Samples pixel values from the input tensor according to grid-defined coordinates and remaps them to the output space. | Default deterministic implementation | Default deterministic implementation |
| aclnnGridSampler3D | Samples pixel values from the input tensor according to grid-defined coordinates and remaps them to the output space. | Default deterministic implementation | Default deterministic implementation |
| aclnnGridSampler2DBackward | Backpropagation of aclnnGridSampler2D. Computes the gradients of tensor input and tensor grid. | Disabled by default. Can be enabled. | Disabled by default. Can be enabled. |
| aclnnGridSampler3DBackward | Backpropagation of aclnnGridSampler3D. Computes the gradients of tensor input and tensor grid. | Disabled by default. Can be enabled. | Disabled by default. Can be enabled. |
| aclnnRasterizer | Performs rasterization. Based on the given points and faces in 3D space, obtains the minimum depth of each pixel on the screen and its corresponding face index, and computes the perspective-corrected barycentric coordinate interpolation of that face. | Default deterministic implementation | - |
| aclnnResize | Resizes the input tensor according to scales. | Default deterministic implementation | Default deterministic implementation |
| aclnnThreeInterpolateBackward | Computes the gradient grad_y via three-point interpolation based on grad_x, idx, and weight. | Non-deterministic implementation by default, which cannot be enabled | - |
| aclnnUpsampleNearest1d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest2d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleTrilinear3d | Applies the trilinear interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleBicubic2d | Applies 2D bicubic upsampling to an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleBicubic2dAA | Applies the bicubic anti-aliasing algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleBicubic2dAAGrad | Backpropagation of aclnnUpsampleBicubic2dAA. | Default deterministic implementation | Disabled by default. Can be enabled. |
| aclnnUpsampleBicubic2dBackward | Backpropagation of aclnnUpsampleBicubic2d. | Disabled by default. Can be enabled. | Disabled by default. Can be enabled. |
| aclnnUpsampleBilinear2d | Applies 2D bilinear upsampling to an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleBilinear2dAA | Applies 2D bilinear anti-aliasing sampling to an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleBilinear2dAABackward | Backpropagation of aclnnUpsampleBilinear2dAA. | Default deterministic implementation | Disabled by default. Can be enabled. |
| aclnnUpsampleBilinear2dBackward | Backpropagation of aclnnUpsampleBilinear2d. | Default deterministic implementation | Disabled by default. Can be enabled. |
| aclnnUpsampleBilinear2dBackwardV2 | Backpropagation of aclnnUpsampleBilinear2d. | Default deterministic implementation | Disabled by default. Can be enabled. |
| aclnnUpsampleLinear1d | Applies the linear interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleLinear1dBackward | Backpropagation of aclnnUpsampleLinear1d. | Default deterministic implementation | Disabled by default. Can be enabled. |
| aclnnUpsampleNearestExact1d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearestExact2d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest1dBackward | Backpropagation of aclnnUpsampleNearest1dV2. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest2dBackward | Backpropagation of aclnnUpsampleNearest2dV2. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest1dV2 | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest2dV2 | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest3d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearest3dBackward | Backpropagation of aclnnUpsampleNearest3d. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearestExact1dBackward | Backpropagation of aclnnUpsampleNearestExact1d. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearestExact2dBackward | Backpropagation of aclnnUpsampleNearestExact2d. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearestExact3d | Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleNearestExact3dBackward | Backpropagation of aclnnUpsampleNearestExact3d. | Default deterministic implementation | Default deterministic implementation |
| aclnnUpsampleTrilinear3dBackward | Backpropagation of aclnnUpsampleTrilinear3d. | Default deterministic implementation | - |
| aclnnCIoU | A loss function for bounding box regression. Based on IoU, it simultaneously considers center point distance, aspect ratio, and overlap area to more comprehensively measure the difference between the predicted box and the ground truth box. | - | Default deterministic implementation |
| aclnnIou | Computes the intersection over union (IOU) or intersection over foreground (IOF) of two sets of rectangular boxes (predicted boxes bBox and ground truth boxes gtBox) to evaluate their overlap degree. | Default deterministic implementation | Default deterministic implementation |
| aclnnNonMaxSuppression | Removes bounding boxes with scores lower than scoreThreshold, and filters out boxes that have high overlap (high IOU) with previously selected ones. | - | - |
| aclnnRoiAlign | RoIAlign is a pooling layer used for feature maps with non-uniform input sizes, and outputs feature maps of a fixed size. | Default deterministic implementation | - |
| aclnnRoiAlignV2 | RoIAlign is a pooling layer used for feature maps with non-uniform input sizes, and outputs feature maps of a fixed size. | Default deterministic implementation | - |
| aclnnRoiAlignV2Backward | Backpropagation of aclnnRoiAlignV2. | Disabled by default. Can be enabled. | - |
| aclnnRoiPoolingWithArgMax | Pools the input feature map by ROI (region of interest), divides each ROI into pooled_h × pooled_w cells, performs max pooling on each cell, and outputs the pooling result and the 1D index (argmax) of the maximum value within the channel. | - | Default deterministic implementation |
| aclnnRoiPoolingGradWithArgMax | Backpropagation of aclnnRoiPoolingWithArgMax. | - | Non-deterministic implementation by default, which cannot be enabled |
| aclnnIm2colBackward | Restores the gradient tensor to the gradient distribution of the original input tensor to complete backward propagation. | Default deterministic implementation | Default deterministic implementation |