SetLoopModePara
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Enables the loop mode and sets loop mode parameters during the DataCopy and DataCopyPad operations. This API must be used together with ResetLoopModePara. After data movement is complete, call ResetLoopModePara to reset loop mode parameters. The following paths are supported:
- GM -> VECIN/VECOUT
- VECOUT -> GM
Prototype
1 | __aicore__ inline void SetLoopModePara(const LoopModeParams& loopParams, DataCopyMVType type) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
loopParams |
Input |
Loop mode parameters of type LoopModeParams. The definition is as follows. For details about the parameters, see Table 2. struct LoopModeParams {
loop1Size = 0;
loop2Size = 0;
loop1SrcStride = 0;
loop1DstStride = 0;
loop2SrcStride = 0;
loop2DstStride = 0 ;
};
|
type |
Input |
Data movement mode. DataCopyMVType is of the enumerated type and is defined as follows. For details about the parameters, see Table 3. enum class DataCopyMVType : uint8_t {
UB_TO_OUT = 0,
OUT_TO_UB = 1,
};
|
Parameter |
Description |
|---|---|
loop1Size |
Sets the number of iterations for the inner loop. The data type is uint32_t. The value range is [0, 221). |
loop2Size |
Sets the number of iterations for the outer loop. The data type is uint32_t. The value range is [0, 221). |
loop1SrcStride |
Sets the stride between source data chunks in adjacent iterations of the inner loop. The data type is uint64_t. The unit is byte.
|
loop1DstStride |
Sets the stride between destination data chunks in adjacent iterations of the inner loop. The data type is uint64_t. The unit is byte.
|
loop2SrcStride |
Sets the stride between source data chunks in adjacent iterations of the outer loop. The data type is uint64_t. The unit is byte.
|
loop2DstStride |
Sets the stride between destination data chunks in adjacent iterations of the outer loop. The data type is uint64_t. The unit is byte.
|
Parameter |
Description |
|---|---|
UB_TO_OUT |
Path for moving data from the UB to the GM. |
OUT_TO_UB |
Path for moving data from the GM to the UB. |
The following example shows how to use SetLoopModePara.
In the example, the data type is int8_t, the data chunk size is 384, the data movement mode of DataCopyPad is Compact:
blockLen = 48: Each data chunk contains 48 bytes.
blockCount = 2: There are two data chunks.
srcStride = 0 and dstStride = 0: There is no stride between adjacent data chunks of both source and destination operands.
isPad = false: There is no need to pad with user-defined values.
Set the parameters of LoopModeParams in SetLoopModePara:
loop1Size = 2: The inner loop runs 2 iterations.
loop2Size = 2: The outer loop runs 2 iterations.
loop1SrcStride = 96: In the inner loop, the stride between source data chunks of adjacent iterations is 96 bytes.
loop2SrcStride =192: In the outer loop, the stride between source data chunks of adjacent iterations is 192 bytes.
loop1DstStride = 128: In the inner loop, the stride between destination data chunks of adjacent iterations is 128 bytes.
loop2DstStride = 288: In the outer loop, the stride between destination data chunks of adjacent iterations is 288 bytes.
DataCopyMVType = OUT_TO_UB: The data path is from the global memory to Unified Buffer.
- With the preceding configuration, you can call SetLoopModePara and then DataCopyPad to enable the loop mode of DataCopyPad and move data chunks of 384 bytes with the data type of int8_t. The following figures illustrate the details.


Returns
None
Restrictions
- The start addresses of both source and destination operands must be 32-byte aligned.
- The data of destination operands cannot overlap. If there is any overlap, no error or alarm is reported at the hardware layer and the correctness of the overlapped data cannot be ensured. However, different iterations can interleave. For example, in the inner loop, the stride between destination data chunks of adjacent iterations can be smaller than the stride between consecutive destination data chunks.
- You need to reset loop mode parameters by calling ResetLoopModePara each time after the loop mode is enabled and the loop mode parameters are set. Otherwise, the data movement of the corresponding channel in the next operation will be affected, causing exceptions.
Examples
1 2 3 4 5 6 7 8 9 10 11 | AscendC::LocalTensor<int8_t> srcLocal = inQueueSrc.AllocTensor<int8_t>(); AscendC::DataCopyExtParams copyParams{2, 48 * sizeof(int8_t), 0, 0, 0}; // The last parameter of DataCopyExtParams is reserved. AscendC::DataCopyPadExtParams<half> padParams{false, 0, 0, 0}; AscendC::LoopModeParams loopParam2Ub {2, 2, 96, 128, 192, 288}; AscendC::SetLoopModePara(loopParam2Ub, DataCopyMVType::OUT_TO_UB); AscendC::DataCopyPad<int8_t, PaddingMode::Compact>(srcLocal, srcGlobal, copyParams, padParams); // Move 384 bytes (48 × 2 × 2 × 2) from GM to VECIN. AscendC::ResetLoopModePara(DataCopyMVType::OUT_TO_UB); AscendC::LoopModeParams loopParam2Gm {2, 2, 128, 96, 288, 192}; AscendC::SetLoopModePara(loopParams2Gm, DataCopyMVType::UB_TO_OUT); DataCopyPad<T, PaddingMode::Compact>(dstGlobal, srcLocal, copyParams); AscendC::ResetLoopModePara(DataCopyMVType::UB_TO_OUT); |
Result example:
Input (src0Global): [1 2 3 ... 384] Output (dstGlobal):[1 2 3 ... 384]