Scatter
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function Usage
Scatters the source operand by element to Unified Buffer based on the index positions after the register tensor and index tensor of the source operand and the base address of the result operand in Unified Buffer are given. The following figure shows the scatter process.

Prototype
template <typename T = DefaultType, typename U = DefaultType, typename S, typename V> __simd_callee__ inline void Scatter(__ubuf__ T* baseAddr, S& srcReg, V& index, MaskReg& mask)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Data type of the destination and source operands. |
|
U |
Data type of the index. |
|
S |
RegTensor type of the source operand, for example, RegTensor<half>. It is automatically inferred by the compiler and does not need to be specified. |
|
V |
RegTensor type of the index value, for example, RegTensor<uint16_t>. It is automatically inferred by the compiler and does not need to be specified. |
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
baseAddr |
Output |
Base address of the destination operand in Unified Buffer. The type is Unified Buffer pointer. Atlas 350 Accelerator Card: For details about the supported data types, see Table 3. |
|
srcReg |
Input |
Source operand. The type is RegTensor. Atlas 350 Accelerator Card: For details about the supported data types, see Table 3. |
|
index |
Input |
Index of each element in srcReg relative to baseAddr in Unified Buffer. The index value must be greater than or equal to 0. The type is RegTensor. The IndexT data type must be used together with the data type T of the destination and source operands. For details about the type mapping table, see the constraints. Atlas 350 Accelerator Card: For details about the supported data types, see Table 3. |
|
mask |
Input |
Validity indicator for the src element. For details, see MaskReg. |
Constraints
- The data types T and U of the destination and source operands must be used together. The type mapping table is as follows:
- When T is of the b64 data type, the data types of T, U, and V can only be one of the following combinations:
T
IndexT
RegT
RegIndexT
Remarks
b64
uint32_t
RegTensor<uint64_t, RegTraitNumOne>
RegTensor<uint32_t>
The first 32 index values are valid.
RegTensor<int64_t, RegTraitNumOne>
RegTensor<uint64_t, RegTraitNumTwo>
RegTensor<uint32_t>
-
RegTensor<int64_t, RegTraitNumTwo>
b64
uint64_t
RegTensor<uint64_t, RegTraitNumOne>
RegTensor<uint64_t, RegTraitNumOne>
-
RegTensor<int64_t, RegTraitNumOne>
RegTensor<uint64_t, RegTraitNumOne>
RegTensor<uint64_t, RegTraitNumTwo>
The first 32 index values are valid.
RegTensor<int64_t, RegTraitNumOne>
RegTensor<uint64_t,RegTraitNumTwo>
RegTensor<uint64_t, RegTraitNumTwo>
-
RegTensor<int64_t,RegTraitNumTwo>
- When T is of the int8 or uint8 data type, only the even bytes in the source operand tensor are valid. Only the even bytes in the source operand tensor are stored in the result address of Unified Buffer. This means the data at positions 0, 2, 4, ..., 252, and 254 in srcReg is scattered and stored in the destination operand.
- The index cannot contain duplicate values. If two or more indexes contain the same data, only the data corresponding to one of the indexes is valid, and it is unknown which data is valid.
- The index position must be aligned based on dtype_size (number of bytes of a single element). Otherwise, the data scattering result may be disordered.
Example
template<typename T, typename U>
__simd_vf__ inline void ScatterVF(__ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ U* src1Addr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg0;
AscendC::Reg::RegTensor<U> srcReg1;
AscendC::Reg::MaskReg mask;
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::LoadAlign(srcReg1, src1Addr + i * oneRepeatSize);
AscendC::Reg::Scatter(dstAddr, srcReg0, srcReg1, mask);
}
}