The source operand is GlobalTensor, and the destination operand is LocalTensor.
// Continuous and discontinuous data movements template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dstLocal, const GlobalTensor<T>& srcGlobal, const DataCopyParams& repeatParams); // Continuous data movements template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dstLocal, const GlobalTensor<T>& srcGlobal, const uint32_t calCount);
The prototype supports the following data paths and types:
Table 1 Data paths and types (GlobalTensor as the source operand and LocalTensor as the destination operand)
| Supported Model | Data Path (Expressed Using Table 1 in TPosition) | Data Types of the Source and Destination Operands (Same) |
|---|---|---|
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | GM->L1 | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | GM->UB | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
Both the source operand and destination operand are LocalTensor.
// Continuous and discontinuous data movements template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcGlobal, const DataCopyParams& repeatParams); // Continuous data movements template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcGlobal, const uint32_t calCount);
The prototype supports the following data paths and types:
Table 2 Data paths and types (LocalTensor as the source operand and destination operand)
| Supported Model | Data Path (Expressed Using Table 1 in TPosition) | Data Types of the Source and Destination Operands (Same) |
|---|---|---|
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | L1->UB | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | L1->BT | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | L1->PT | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | L1->FB | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | UB->L1 | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
The source operand is LocalTensor, and the destination operand is GlobalTensor.
// Continuous and discontinuous data movements template <typename T> __aicore__ inline void DataCopy(const GlobalTensor <T>& dstGlobal, const LocalTensor <T>& srcLocal, const DataCopyParams& repeatParams); // Continuous data movements template <typename T> __aicore__ inline void DataCopy(const GlobalTensor <T>& dstGlobal, const LocalTensor <T>& srcLocal, const uint32_t calCount);
The prototype supports the following data paths and types:
Table 3 Data paths and types (LocalTensor as the source operand and GlobalTensor as the destination operand)
| Supported Model | Data Path (Expressed Using Table 1 in TPosition) | Data Types of the Source and Destination Operands (Same) |
|---|---|---|
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | L1->GM | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
| Kirin 9020, Kirin 9030, and Kirin X90 series processors | UB->GM | int8_t/uint8_t/int16_t/uint16_t/int32_t/uint32_t/half/float |
Both the source operand and destination operand are LocalTensor. The types of the source operand and destination operand can be different.
template <typename dst_T, typename src_T> __aicore__ inline void DataCopy(const LocalTensor<dst_T>& dstLocal, const LocalTensor<src_T>& srcLocal, const DataCopyParams& repeatParams);
Table 4 Parameters of common data movement APIs
| Parameter | Input/Output | Description |
|---|---|---|
| dstLocal and dstGlobal | Output | Destination operand, which is of the LocalTensor or GlobalTensor type. When dstLocal is located in C2, the start address must be 64-byte aligned. When dstLocal is located in C2PIPE2GM, the start address must be 128-byte aligned. In other cases, the start address must be 32-byte aligned. |
| srcLocal and srcGlobal | Input | Source operand, which is of the LocalTensor or GlobalTensor type. |
| repeatParams | Input | Movement parameter, DataCopyParams type. The definition is described below and the parameter details are provided in Table 5. |
| calCount | Input | Number of elements involved in the movement. Note: The size of data moved by DataCopy must be a multiple of 32 bytes. Therefore, when the common data movement API (continuous data movement, including the calCount parameter) is used, calCount x sizeof(T) must be 32-byte aligned. Otherwise, the size of moved data is rounded down to the nearest multiple of 32 bytes. |
Table 5 Parameters in the DataCopyParams structure
| Parameter | Description |
|---|---|
| blockCount | Number of data chunks in the command. Value range: blockCount ∈ [1, 4095]. |
| blockLen | Length of each data chunk. The unit is data block (32 bytes). Value range: blockLen ∈ [1, 65535]. Particularly, when dstLocal is located in C2PIPE2GM, the unit is 128 bytes; when dstLocal is located in C2, the unit is 64 bytes. |
| srcStride | Interval between adjacent data chunks of the source operand (the interval between the tail of one data chunk and the head of the next). The unit is a data block (32 bytes). The data type is uint16_t. The value of srcStride cannot exceed the value range of this data type. |
| dstStride | Interval between adjacent data chunks of the destination operand (the interval between the tail of the previous data chunk and the head of the next data chunk). The unit is data block (32 bytes). The data type is uint16_t. The value of dstStride cannot exceed the value range of this data type. Particularly, when dstLocal is located in C2PIPE2GM, the unit is 128 bytes; when dstLocal is located in C2, the unit is 64 bytes. |
The following example shows how to use the DataCopyParams structure. In the example, two consecutive data chunks are moved, and each data chunk contains eight data blocks. There is no stride between adjacent data chunks of the source operand, while there is a stride of one data block between the tail and head of the adjacent data chunks of the destination operand.

Kirin 9020 series processors
Kirin 9030 series processors
Kirin X90 series processors
Hardware uses data blocks as the basic unit during data movements (1 data block = 32 bytes). Therefore, you can process data whose size is an integer multiple of 32 bytes each time to improve the instruction execution efficiency.
When executing multiple DataCopy instructions, ensure that the destination addresses of the DataCopy instructions do not overlap.
#include "kernel_operator.h"
class KernelDataCopy {
public:
__aicore__ inline KernelDataCopy() {}
__aicore__ inline void Init(__gm__ uint8_t* src0Gm, __gm__ uint8_t* src1Gm, __gm__ uint8_t* dstGm)
{
src0Global.SetGlobalBuffer((__gm__ half*)src0Gm);
src1Global.SetGlobalBuffer((__gm__ half*)src1Gm);
dstGlobal.SetGlobalBuffer((__gm__ half*)dstGm);
pipe.InitBuffer(inQueueSrc0, 1, 512 * sizeof(half));
pipe.InitBuffer(inQueueSrc1, 1, 512 * sizeof(half));
pipe.InitBuffer(outQueueDst, 1, 512 * sizeof(half));
}
__aicore__ inline void Process()
{
CopyIn();
Compute();
CopyOut();
}
private:
__aicore__ inline void CopyIn()
{
AscendC::LocalTensor<half> src0Local = inQueueSrc0.AllocTensor<half>();
AscendC::LocalTensor<half> src1Local = inQueueSrc1.AllocTensor<half>();
AscendC::DataCopy(src0Local, src0Global, 512);
AscendC::DataCopy(src1Local, src1Global, 512);
inQueueSrc0.EnQue(src0Local);
inQueueSrc1.EnQue(src1Local);
}
__aicore__ inline void Compute()
{
AscendC::LocalTensor<half> src0Local = inQueueSrc0.DeQue<half>();
AscendC::LocalTensor<half> src1Local = inQueueSrc1.DeQue<half>();
AscendC::LocalTensor<half> dstLocal = outQueueDst.AllocTensor<half>();
AscendC::Add(dstLocal, src0Local, src1Local, 512);
outQueueDst.EnQue<half>(dstLocal);
inQueueSrc0.FreeTensor(src0Local);
inQueueSrc1.FreeTensor(src1Local);
}
__aicore__ inline void CopyOut()
{
AscendC::LocalTensor<half> dstLocal = outQueueDst.DeQue<half>();
AscendC::DataCopy(dstGlobal, dstLocal, 512);
outQueueDst.FreeTensor(dstLocal);
}
private:
AscendC::TPipe pipe;
AscendC::TQue<AscendC::QuePosition::VECIN, 1> inQueueSrc0, inQueueSrc1;
AscendC::TQue<AscendC::QuePosition::VECOUT, 1> outQueueDst;
AscendC::GlobalTensor<half> src0Global, src1Global, dstGlobal;
};
extern "C" __global__ __aicore__ void data_copy_kernel(__gm__ uint8_t* src0Gm, __gm__ uint8_t* src1Gm, __gm__ uint8_t* dstGm)
{
KernelDataCopy op;
op.Init(src0Gm, src1Gm, dstGm);
op.Process();
} Result example:
Input (src0Global): [1 2 3 ... 512] Input (src1Global): [1 2 3 ... 512] Output (dstGlobal):[2 4 6 ... 1024]