Optimization Suggestions

Function or Restriction

Involved AscendCL API

Implementation on Ascend 310

Implementation on Ascend 310P

What You Need to Do

Setting the resizing algorithm in the VPC function

acldvppSetResizeConfigInterpolation

The following algorithms are supported:

  • 0 (default): high-order filtering algorithm developed by Huawei.
  • 1: conventional bilinear algorithm, whose compute process is close to that of OpenCV.
  • 2: conventional nearest neighbor algorithm, whose compute process is close to that of OpenCV.
  • 3: conventional bilinear algorithm, whose compute process is close to that of TensorFlow.
  • 4: conventional nearest neighbor algorithm, whose compute process is close to that of TensorFlow.

The following algorithms are supported:

  • 0 (default): The system automatically uses the value 1.
  • 1: conventional bilinear algorithm, whose compute process is close to that of OpenCV.
  • 2: conventional nearest neighbor algorithm, whose compute process is close to that of OpenCV.

If you do not explicitly call this API, you can directly use the default resizing algorithm on Ascend 310P without modifying the code after migration. This achieves higher precision.

If you explicitly call this API to set the resizing algorithm to 1 or 2, you do not need to modify the code.

If you explicitly call this API to set the resizing algorithm to 3 or 4, modify the code to set the resizing algorithm supported by Ascend 310P. After modifying the code, recompile it.

YUV400 image processing in the VPC function

acldvppSetPicDescSize

Ascend 310 supports processing YUV420 images (data of the Y component) rather than YUV400 images. Therefore, you need to set the format of the input image to YUV420 and the memory size to at least widthStride x heightStride x 3/2. VPC verifies the memory size based on the YUV420 image format.

Ascend 310P supports YUV400 image processing. Therefore, you can set the input image format to YUV400 and set the memory size to at least widthStride x heightStride. VPC verifies the memory size based on the YUV400 image format.

After migration to Ascend 310P, you can obtain the Y component from YUV420 to support YUV400, which does not require code modification and recompilation.

In addition, Ascend 310P supports the YUV400 format. Therefore, if you directly use the YUV400 format, you need to modify the code to set the output format to YUV400 and set the memory size to at least widthStride x heightStride, in order to save memory. After modifying the code, recompile it.

Setting the maximum width and height of streams to be decoded in the VDEC function

aclvdecSetChannelDescOutPicWidth

aclvdecSetChannelDescOutPicHeight

  • Frame buffer size for the decoded images: When a channel is created, frame buffer for internal use is not allocated based on the maximum width and height of a decoded stream. Instead, the frame buffer is allocated based on the actual width and height obtained from the stream information during decoding.
  • Buffer size for the input streams: 6 MB when resolution ≤ 1080p; 9 MB when resolution > 1080p.
  • Frame buffer size for the decoded images: When a channel is created, frame buffer for internal use is not allocated based on the maximum width and height of a decoded stream. Instead, the frame buffer is allocated based on the actual width and height obtained from the stream information during decoding.
  • Buffer size for the input streams: Maximum width of the decoded stream x Maximum height of the decoded stream x 2.

After the migration to Ascend 310P, you do not need to modify the code. The system automatically allocates frame buffers based on the decoding stream information.

In addition, on the Ascend 310P, the size of the frame buffer allocated by the system must not exceed the maximum value, which is related to the maximum width and height of the decoded stream, number of reference frames, and stream bit width. The maximum value of the frame buffer is roughly as follows: (Maximum width x Maximum height x 3/2) x Stream bit width/8 x (Number of reference frames + 3).

You are advised to properly plan the VDEC memory during user migration. For details, see Performance Specifications (Ascend 310P AI Processor).

Configuring the number of reference frames in the VDEC function

aclvdecSetChannelDescRefFrameNum

Unsupported.

Supported. If the number of reference frames is not set, the default value 8 is used.

When a channel is created, the frame buffer is allocated based on the default values. However, during decoding, the actual reference frame information of the stream is obtained based on the stream information to adapt to the frame buffer.

Specifying the output bit rate in the VENC function

aclvencSetChannelDescMaxBitRate

aclvencSetChannelDescParam

The default output bit rate is 300.

The default output bit rate is 2000.

If you do not explicitly call the API to set the output bit rate, you do not need to modify the code after the migration to Ascend 310P. The default output bit rate 2000 on Ascend 310P is used. This achieves better image quality.

If you want to adjust the image quality, set the output bit rate as required. After modifying the code, recompile it.

Note that the size of the encoded stream varies according to the output bit rate.

Setting of the channel mode

(Note: Specify the function to be implemented. Currently, the VPC, JPEGD, JPEGE, and PNGD functions are supported. If this API is not called, VPC channels are first created by default, which may occupy channel resources. You are advised to specify the channel mode based on the function you use.)

acldvppSetChannelDescMode

Unsupported.

Set the channel mode. Otherwise, VPC channels are first created by default to reduce the waste of channel and memory resources, though a certain number of VPC channels are occupied.

After the migration to Ascend 310P, you do not need to call this API to set the channel mode. That is, you do not need to modify the code or recompile it. In this case, VPC channels are first created by default. When a JPEGD, JPEGE, or PNGD API is called, the system automatically creates a JPEGD, JPEGE, or PNGD channel.

You are advised to call this API based on your service needs.