Histograms

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

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

Table 1 Template 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.

  • BIN0 indicates the lower-bit mode. The data in the range of [0, 127] in the src is written to dst0.
  • BIN1 indicates the high-order mode. The data in the range of [128, 255] in the src is written to dst1.

type

HistogramsType enum type, indicating statistical mode.
  • FREQUENCY: frequency statistics mode, which counts the frequency of each number in the range of [0, 255] in the src. Each dst has 128 elements. Each element in dst0 corresponds to the accumulated number of elements in the range of [0, 127] in the src, and each element in dst1 corresponds to the accumulated number of elements in the range of [128, 255] in the src.
  • ACCUMULATE: accumulation statistics mode, which counts the number of elements in each range of x ≤ 0, x ≤ 1, x ≤ 2, x ≤ 3, ..., x ≤ 254, and x ≤ 255 in the src. Each dst has 128 elements. Each element in dst0 corresponds to the accumulated number of elements in the range of [0, 127] in the src, and each element in dst1 corresponds to the accumulated number of elements in the range of [128, 255] in the src.

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.

Table 2 Parameters

Parameter

Input/Output

Description

dstReg

Output

Destination operand.

The type is RegTensor.

srcReg

Input

Source operand.

The type is RegTensor.

mask

Input

Valid indication of the source operand element operation. For details, see MaskReg.

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);
    }
}