Non-Alignment Scenario

This section describes more methods for processing data that is not 32-byte aligned, including moving in, computing, and moving out the data. During operator development, you can flexibly handle the non-alignment scenario by referring to the following schemes and operator examples.

Alignment Requirements for Data Movement and Vector Computation

During data movement and vector computation, the length of the moved data and the start address of the operand must meet the following alignment requirements:

  • When the DataCopy API is used to move data, the length of the moved data and the start address of the operand (on UB) must be 32-byte aligned.
  • Generally, during vector computation, the start address of the operand must be 32-byte aligned. For details about the alignment requirements, see the corresponding API reference.

In the following description, Global refers to the tensor on the global memory (GlobalTensor), and Local refers to the tensor on the local memory (LocalTensor).

The following are some examples of non-aligned movement and computation.

Non-Alignment Scheme

The DataCopyPad API provides the function of non-aligned movement. If an operator is developed based on the supported products (see product support), this API can be directly used to solve the movement problem in the non-alignment scenario. For details about how to use DataCopyPad, see DataCopyPad sample.

Some models do not support the DataCopyPad API. In this case, refer to the following scheme.

Figure 4 Non-alignment scheme

The length of the moved data must be 32-byte aligned. If the data length is not aligned, when tensor data is moved from Global to Local row by row, each row in Local has redundant data.

After data is moved in, redundant data is processed in the following manners during vector computation:
The length of the moved data and the start address of the operand (on UB) must be 32-byte aligned. Therefore, you can remove redundant data or move out data along with redundant data.
The following separately describes the foregoing several processing schemes in detail.

Examples