Moving Data from MaskReg

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Indicates the Reg vector computation data movement interface, and is used to move data from MaskReg to UB.

Prototype

// Use AddrReg to store the offset when data is moved from MaskReg.
template <typename T, MaskDist dist = MaskDist::DIST_NORM>
__simd_callee__ inline void StoreAlign(__ubuf__ T* dstAddr, MaskReg& mask, AddrReg offset);

// Move data from MaskReg in the POST_MODE_NORMAL scenario.
template <typename T, MaskDist dist = MaskDist::DIST_NORM>
__simd_callee__ inline void StoreAlign(__ubuf__ T* dstAddr, MaskReg& mask);

// Move data from MaskReg in the POST_MODE_UPDATE scenario.
template <typename T, PostLiteral postMode, MaskDist dist = MaskDist::DIST_NORM>
__simd_callee__ inline void StoreAlign(__ubuf__ T*& dstAddr, MaskReg& mask, int32_t offset);

// Move data from MaskReg in non-aligned mode.
template <typename T>
__simd_callee__ inline void StoreUnAlign(__ubuf__ T*& dstAddr, MaskReg& mask, UnalignRegForStore& ureg);

Parameters

Table 1 Parameters for using AddrReg to store the offset when data is moved from MaskReg

Parameter

Input/Output

Description

T

Input

The supported data types are b8, b16, and b32.

dist

Input

Movement mode. Use the MaskDist type. The values are as follows:

  • DIST_NORM: The normal mode is used. The alignment constraint is VL/8 bytes. VL/8 bytes of data are moved.
  • DIST_PACK: The downsampling mode is used. The alignment constraint is VL/16 bytes. VL/16 bytes of data are moved, and every other bit is discarded.

mask

Input

Source operand, which is of the MaskTensor type.

dstAddr

Output

Start address of the destination operand in the UB.

offset

Input

The actual UB start address for the movement is computed as: dstAddr + offset.

Table 2 Parameters in the POST_MODE_NORMAL scenario for moving data from MaskReg

Parameter

Input/Output

Description

T

Input

The supported data types are b8, b16, b32, or b64.

dist

Input

Movement mode. Use the MaskDist type. The values are as follows:

  • DIST_NORM: The normal mode is used. The alignment constraint is VL/8 bytes. VL/8 bytes of data are moved.
  • DIST_PACK: The downsampling mode is used. The alignment constraint is VL/16 bytes. VL/16 bytes of data are moved, and every other bit is discarded.

mask

Input

Source operand, which is of the MaskReg type.

dstAddr

Output

Start address of the destination operand in the UB.

Table 3 Parameters in the POST_MODE_UPDATE scenario for moving data from MaskReg

Parameter

Input/Output

Description

T

Input

The supported data types are b8, b16, b32, or b64.

dist

Input

Movement mode. Use the MaskDist type. The values are as follows:

  • DIST_NORM: The normal mode is used. The alignment constraint is VL/8 bytes. VL/8 bytes of data are moved.
  • DIST_PACK: The downsampling mode is used. The alignment constraint is VL/16 bytes. VL/16 bytes of data are moved, and every other bit is discarded.

postMode

Input

This parameter controls whether to enable post update.

  • POST_MODE_NORMAL: In normal scenarios, the UB operand address is not updated.
  • POST_MODE_UPDATE: This is used in the POST_MODE_UPDATE scenario. The UB address is used as both the input and output and is updated each time it is called.

mask

Input

Source operand, which is of the MaskTensor type.

dstAddr

Output

Start address of the destination operand in the UB.

offset

Input

When the offset is of the int32_t type, the meanings of POST_MODE_NORMAL and POST_MODE_UPDATE are different.
  • POST_MODE_NORMAL scenario: The actual UB start address for the movement is computed as: dstAddr + offset.
  • POST_MODE_UPDATE scenario: The actual UB start address for the movement is dstAddr. After the movement, the address is updated as follows: dstAddr += offset.
Table 4 Parameters for moving data from MaskReg in non-aligned mode

Parameter

Input/Output

Description

T

Input

The supported data types are b16 and b32.

mask

Input

Source operand, which is of the MaskTensor type.

dstAddr

Output

Start address of the destination operand in the UB.

ureg

Output

UnalignRegForStore: non-aligned register, which is used to store non-aligned data. The length is 32 bytes. After StoreUnAlign (MaskReg non-aligned store interface) is called, the StoreUnAlignPost API needs to be called to pass the non-aligned register and write the remaining data to the destination address.

Returns

None

Restrictions

None

Examples

template <typename T>
__simd_vf__ inline void StoreAlignVF(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
    AscendC::Reg::MaskReg mask;
    for (uint16_t i = 0; i < repeatTimes; ++i) {
        mask = AscendC::Reg::UpdateMask<T>(count);        
        AscendC::Reg::AddrReg offset = AscendC::Reg::CreateAddrReg<T>(i, oneRepeatSize);
        AscendC::Reg::LoadAlign(mask, srcAddr, offset);
        AscendC::Reg::StoreAlign(dstAddr, mask, offset);
    }
}