Histograms
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function Usage
Collects statistics on histogram data and adds the base data of dstReg and the statistics result of srcReg, including the data frequency statistics and accumulated statistics.
- Frequency statistics
As shown in the following figure, in the low-bit mode, dstReg (dst0) counts the frequency of each value in the range of [0-127] (the first half) in srcReg. In the high-bit mode, dstReg (dst1) counts the frequency of each value in the range of [128-255] (the second half). The nth bit in dst0 and dst1 indicates the frequency of value n in srcReg, and the value is accumulated based on the original data in dstReg.
Figure 1 Frequency statistics
- Accumulated statistics
As shown in the following figure, in low-bit mode, dstReg (dst0) collects statistics on the distribution of data whose values fall within the low-bit range [0-127] in srcReg. In high-bit mode, dstReg (dst1) collects statistics on the distribution of data whose values fall within the high-bit range [128-255] in srcReg. In dst0 and dst1, the nth bit indicates the total frequency of all values from 0 to n in srcReg in the corresponding range. Finally, the statistical result is accumulated based on the original data in the destination register.
Figure 2 Accumulated statistics
Prototype
template <typename T = DefaultType, typename U = DefaultType, HistogramsBinType mode, HistogramsType type, typename S, typename V> __simd_callee__ inline void Histograms(V& dstReg, S& srcReg, MaskReg& mask)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Data type of the source operand. For the Atlas 350 Accelerator Card, the supported data type is uint8_t. |
|
U |
Data type of the destination operand. For the Atlas 350 Accelerator Card, the supported data type is uint16_t. |
|
mode |
HistogramsBinType enum type, which is used to control the statistics of the lower-bit range [0-127] (the first half) or the high-bit range [128-255] (the second half) in the src. The VL is 256 bytes, and the dst data type is uint16_t. One dst can store 128 pieces of data. Therefore, two destination registers are required.
|
|
type |
HistogramsType enum type, indicating statistical mode.
|
|
S |
RegTensor type of the destination operand. It is automatically inferred by the compiler and does not need to be specified. |
|
V |
RegTensor type of the source operand. It is automatically inferred by the compiler and does not need to be specified. |
Returns
None
Constraints
None
Example
template <typename T, typename U>
__simd_vf__ inline void HistogramsVF(__ubuf__ U* dstAddr, __ubuf__ T* srcAddr, uint32_t oneRepeatSize, uint16_t repeatTimes, AscendC::Reg::HistogramsBinType mode, AscendC::Reg::HistogramsType type)
{
AscendC::Reg::RegTensor<T> srcReg;
AscendC::Reg::RegTensor<U> dstReg;
AscendC::Reg::MaskReg mask0 = AscendC::Reg::CreateMask<T>();
AscendC::Reg::MaskReg mask1 = AscendC::Reg::CreateMask<T>();
for (uint16_t i = 0; i < repeatTimes; ++i){
AscendC::Reg::LoadAlign(srcReg, srcAddr + oneRepeatSize * i);
AscendC::Reg::Histograms<T, U, mode, type>(dstReg, srcReg, mask0);
AscendC::Reg::StoreAlign(dstAddr, dstReg, mask1);
}
}