SetDeqScale

Function Usage

Sets the value of the DEQSCALE register.

Prototype

  • Used in the s322f16 scenario of the AddDeqRelu and Cast instructions
    1
    __aicore__ inline void SetDeqScale(half scale)
    
  • Used in the CastDeq (isVecDeq=false) scenario
    1
    __aicore__ inline void SetDeqScale(float scale, int16_t offset, bool signMode)
    
  • Used in the CastDeq (isVecDeq=true) scenario.
    1
    2
    template <typename T>
    __aicore__ inline void SetDeqScale(const LocalTensor<T>& vdeqTensor, const VdeqInfo& vdeqInfo)
    

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

scale (half)

Input

Data of the half type.

scale (float)

Input

Data of the float type.

Used by the CastDeq (isVecDeq=false) instruction to set the value of the DEQSCALE register.

offset

Input

Data of the int16_t type, indicating an offset of the s9 type. Only the first nine bits of the input parameter are valid.

Used in the CastDeq (isVecDeq=false) scenario.

signMode

Input

Whether the quantization result contains a sign. The value is of the Boolean type.

Used in the CastDeq (isVecDeq=false) scenario.

vdeqTensor

Input

Used in the CastDeq (isVecDeq=true) scenario. A 128-byte quantized tensor is input.

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of the LocalTensor must be 32-byte aligned.

The supported data type is uint64_t.

vdeqInfo

Input

Data structure for storing the quantized tensor information. The structure contains 16 groups of quantization parameters of the quantized tensor.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
const uint8_t VDEQ_TENSOR_SIZE = 16;

struct VdeqInfo {
    __aicore__ VdeqInfo() {}
    __aicore__ VdeqInfo(const float vdeqScaleIn[VDEQ_TENSOR_SIZE], const int16_t vdeqOffsetIn[VDEQ_TENSOR_SIZE],
        const bool vdeqSignModeIn[VDEQ_TENSOR_SIZE])
    {
        for (int32_t i = 0; i < VDEQ_TENSOR_SIZE; ++i) {
            vdeqScale[i] = vdeqScaleIn[i];
            vdeqOffset[i] = vdeqOffsetIn[i];
            vdeqSignMode[i] = vdeqSignModeIn[i];
        }
    }

    float vdeqScale[VDEQ_TENSOR_SIZE] = { 0 };
    int16_t vdeqOffset[VDEQ_TENSOR_SIZE] = { 0 };
    bool vdeqSignMode[VDEQ_TENSOR_SIZE] = { 0 };
};
  • vdeqScale: array of the float type, used to store the scale parameter scale0 - scale15 of the quantized tensor.
  • vdeqOffset: array of the int16_t type, used to store the offset parameter offset0 - offset15 of the quantized tensor.
  • vdeqSignMode: array of the Boolean type, used to store the signMode parameter signMode0 - signMode15 of the quantized tensor.

Returns

None

Availability

Constraints

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
AscendC::LocalTensor<int8_t> dstLocal;
AscendC::LocalTensor<int16_t> srcLocal;
AscendC::LocalTensor<uint64_t> tmpBuffer;
uint32_t srcSize = 256;
// Cast
AscendC::LocalTensor<half> castDstLocal;
AscendC::LocalTensor<int32_t> castSrcLocal;
half scale = 1.0;
AscendC::SetDeqScale(scale);
AscendC::Cast(castDstLocal, castSrcLocal, AscendC::RoundMode::CAST_NONE, srcSize);
// CastDeq
float scale = 1.0;
int16_t offset = 0;
bool signMode = true;
AscendC::SetDeqScale(scale, offset, signMode);
AscendC::CastDeq<int8_t, int16_t, false, false>(dstLocal, srcLocal, srcSize);
// CastVdeq
float vdeqScale[16] = { 0 };
int16_t vdeqOffset[16] = { 0 };
bool vdeqSignMode[16] = { 0 };
for (int i = 0; i < 16; i++) {
    vdeqScale[i] = 1.0;
    vdeqOffset[i] = 0;
    vdeqSignMode[i] = true;
}
AscendC::VdeqInfo vdeqInfo(vdeqScale, vdeqOffset, vdeqSignMode);
AscendC::SetDeqScale<uint64_t>(tmpBuffer, vdeqInfo);
AscendC::CastDeq<int8_t, int16_t, true, false>(dstLocal, srcLocal, srcSize);