Unsqueeze
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Decompresses data in dstReg based on the mask. The decompression method is as follows: Sets the 0th element of dstReg to 0, and the ith element of dstReg equals the number of 1s from the 0th element to the (i-1)th element in the mask. The most significant bit of the mask is ignored and not counted. The following uses the uint8_t type as an example to describe the algorithm logic:
dstReg[0] = 0;
for(int i = 1; i < AscendC::GetVecLen() / sizeof(uint8_t); i++){
dstReg[i] = mask[i - 1] ? (dstReg[i - 1] + 1) : dstReg[i - 1];
}
AscendC::GetVecLen() / sizeof(uint8_t) indicates the number of elements contained in dstReg.
Prototype
template <typename T = DefaultType, typename U> __simd_callee__ inline void Unsqueeze(U& dstReg, MaskReg& mask)
Parameters
Parameter |
Description |
|---|---|
T |
Data type of the destination operand. For the Atlas 350 Accelerator Card, the supported data types are int8_t, uint8_t, int16_t, uint16_t, int32_t, and uint32_t. |
U |
RegTensor type of the destination operand. It is automatically inferred by the compiler and does not need to be specified. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstReg |
Output |
Destination operand and source operand. The type is RegTensor. |
mask |
Input |
mask is used to provide dstReg decompression information. The type is MaskReg. |
Constraints
None
Example
template<typename T>
__simd_vf__ inline void UnsqueezeVF(__ubuf__ T* dstAddr, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> dstReg;
AscendC::Reg::MaskReg mask;
mask = AscendC::Reg::CreateMask<T>();
for (uint16_t i = 0; i < repeatTimes; i++) {
AscendC::Reg::Unsqueeze(dstReg, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}