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/aclnnop and 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}.h of 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.

  • 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 NameDescriptionDeterministic Computation (A2/A3)Deterministic Computation (Ascend 950)
aclnnMrgbaCustomPerforms transparency multiplication on the tensor rgb and tensor alpha.--
aclnnBackgroundReplaceFuses the input new background image with the existing image, and replaces the background with the new background via a mask.--
aclnnBlendImagesCustomPerforms transparency multiplication on the tensor rgb, frame, and alpha.--
aclnnGridSampler2DSamples pixel values from the input tensor according to grid-defined coordinates and remaps them to the output space.Default deterministic implementationDefault deterministic implementation
aclnnGridSampler3DSamples pixel values from the input tensor according to grid-defined coordinates and remaps them to the output space.Default deterministic implementationDefault deterministic implementation
aclnnGridSampler2DBackwardBackpropagation of aclnnGridSampler2D. Computes the gradients of tensor input and tensor grid.Disabled by default. Can be enabled.Disabled by default. Can be enabled.
aclnnGridSampler3DBackwardBackpropagation of aclnnGridSampler3D. Computes the gradients of tensor input and tensor grid.Disabled by default. Can be enabled.Disabled by default. Can be enabled.
aclnnRasterizerPerforms 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-
aclnnResizeResizes the input tensor according to scales.Default deterministic implementationDefault deterministic implementation
aclnnThreeInterpolateBackwardComputes the gradient grad_y via three-point interpolation based on grad_x, idx, and weight.Non-deterministic implementation by default, which cannot be enabled-
aclnnUpsampleNearest1dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest2dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleTrilinear3dApplies the trilinear interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleBicubic2dApplies 2D bicubic upsampling to an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleBicubic2dAAApplies the bicubic anti-aliasing algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleBicubic2dAAGradBackpropagation of aclnnUpsampleBicubic2dAA.Default deterministic implementationDisabled by default. Can be enabled.
aclnnUpsampleBicubic2dBackwardBackpropagation of aclnnUpsampleBicubic2d.Disabled by default. Can be enabled.Disabled by default. Can be enabled.
aclnnUpsampleBilinear2dApplies 2D bilinear upsampling to an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleBilinear2dAAApplies 2D bilinear anti-aliasing sampling to an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleBilinear2dAABackwardBackpropagation of aclnnUpsampleBilinear2dAA.Default deterministic implementationDisabled by default. Can be enabled.
aclnnUpsampleBilinear2dBackwardBackpropagation of aclnnUpsampleBilinear2d.Default deterministic implementationDisabled by default. Can be enabled.
aclnnUpsampleBilinear2dBackwardV2Backpropagation of aclnnUpsampleBilinear2d.Default deterministic implementationDisabled by default. Can be enabled.
aclnnUpsampleLinear1dApplies the linear interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleLinear1dBackwardBackpropagation of aclnnUpsampleLinear1d.Default deterministic implementationDisabled by default. Can be enabled.
aclnnUpsampleNearestExact1dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearestExact2dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest1dBackwardBackpropagation of aclnnUpsampleNearest1dV2.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest2dBackwardBackpropagation of aclnnUpsampleNearest2dV2.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest1dV2Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest2dV2Applies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest3dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearest3dBackwardBackpropagation of aclnnUpsampleNearest3d.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearestExact1dBackwardBackpropagation of aclnnUpsampleNearestExact1d.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearestExact2dBackwardBackpropagation of aclnnUpsampleNearestExact2d.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearestExact3dApplies the nearest neighbor interpolation algorithm to upsample an input signal consisting of multiple input channels.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleNearestExact3dBackwardBackpropagation of aclnnUpsampleNearestExact3d.Default deterministic implementationDefault deterministic implementation
aclnnUpsampleTrilinear3dBackwardBackpropagation of aclnnUpsampleTrilinear3d.Default deterministic implementation-
aclnnCIoUA 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
aclnnIouComputes 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 implementationDefault deterministic implementation
aclnnNonMaxSuppressionRemoves bounding boxes with scores lower than scoreThreshold, and filters out boxes that have high overlap (high IOU) with previously selected ones.--
aclnnRoiAlignRoIAlign is a pooling layer used for feature maps with non-uniform input sizes, and outputs feature maps of a fixed size.Default deterministic implementation-
aclnnRoiAlignV2RoIAlign is a pooling layer used for feature maps with non-uniform input sizes, and outputs feature maps of a fixed size.Default deterministic implementation-
aclnnRoiAlignV2BackwardBackpropagation of aclnnRoiAlignV2.Disabled by default. Can be enabled.-
aclnnRoiPoolingWithArgMaxPools 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
aclnnRoiPoolingGradWithArgMaxBackpropagation of aclnnRoiPoolingWithArgMax.-Non-deterministic implementation by default, which cannot be enabled
aclnnIm2colBackwardRestores the gradient tensor to the gradient distribution of the original input tensor to complete backward propagation.Default deterministic implementationDefault deterministic implementation