aclnnDynamicMxQuantV3

📄 View Source Code

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Not supported
  • Atlas A2 products: Not supported
  • Atlas 200I/500 A2 inference products: Not supported
  • Atlas inference products: Not supported
  • Atlas training products: Not supported

Function

  • Description: MX quantization with destination data types in the FLOAT4 and FLOAT8 classes. On the given axis, for each blocksize count of numbers, calculate the quantization scale mxscale corresponding to the group as the corresponding part of the output mxscaleOut. Then divide each number in the group by mxscale, convert it to the corresponding dstType according to round_mode, and obtain the quantized result y as the corresponding part of the output yOut. When dstType is FLOAT8_E4M3FN or FLOAT8_E5M2, the value of scaleAlg specifies different algorithms for calculating mxscale. Compared with aclnnDynamicMxQuantV2, this API adds the maxLowBound parameter, which can be used to set the lower clamp value of the maximum absolute value calculated for each block.

  • Formula:

    • Scenario 1, when scaleAlg is 0:
      • Group the input x along the axis dimension by k = blocksize elements. Each group of k elements {{Vi}i=1k}\{\{V_i\}_{i=1}^{k}\} is dynamically quantized into {mxscale1,{Pi}i=1k}\{mxscale1, \{P_i\}_{i=1}^{k}\}, where k = blocksize.
      shared_exp=floor(log2(maxi(∣Vi∣)))−emaxmxscale=2shared_expPi=cast_to_dst_type(Vi/mxscale,round_mode), i from 1 to blocksizeshared\_exp = floor(log_2(max_i(|V_i|))) - emax \\ mxscale = 2^{shared\_exp}\\ P_i = cast\_to\_dst\_type(V_i/mxscale, round\_mode), \space i\space from\space 1\space to\space blocksize\\
      • The quantized PiP_{i} form the output yOut at the positions of corresponding ViV_{i}, and mxscale forms the output mxscaleOut according to the group composition on the corresponding axis dimension.

      • emax: The exponent of the maximum normal number of the corresponding data type.

| DataType | Emax | | :-----------: | :--: | | FLOAT4_E2M1 | 2 | | FLOAT4_E1M2 | 0 | | FLOAT8_E4M3FN | 8 | | FLOAT8_E5M2 | 15 |

  • Scenario 2: When scaleAlg is 1, only FP8 types are involved:
    • Divide the long vector into blocks, each with a length of k. Compute a block scale factor Sfp32bS_{fp32}^b for each block individually, and then map all elements within the block to the target low-precision type FP8 using the same Sfp32bS_{fp32}^b. If the last block has fewer than k elements, treat the missing values as 0 and process it as a complete block.
    • Find the maximum absolute value of the elements in the block:Amax(Dfp32b)=max({∣di∣}i=1k)Amax(D_{fp32}^b)=max(\{|d_{i}|\}_{i=1}^{k})
    • When maxLowBound > 0, apply lower-bound clamping to the maximum absolute value:Amax(Dfp32b)=max(Amax(Dfp32b),maxLowBound)Amax(D_{fp32}^b)=max(Amax(D_{fp32}^b), maxLowBound)
    • Map FP32 to the representable range of the target data type FP8, where Amax(DType)Amax(DType) is the maximum value that the target precision can represent.Sfp32b=Amax(Dfp32b)Amax(DType)S_{fp32}^b = \frac{Amax(D_{fp32}^b)}{Amax(DType)}
    • Convert the block scale factor Sfp32bS_{fp32}^b to the representable scale value Sue8m0bS_{ue8m0}^b in FP8 format.
    • Extract the unbiased exponent EintbE_{int}^b and mantissa MfixpbM_{fixp}^b from the block floating-point scale factor Sfp32bS_{fp32}^b.
    • To ensure no overflow during quantization, round up the exponent and keep it within the representable range of FP8:Eintb={Eintb+1,if Sfp32b is a normal number, and Eintb<254 and Mfixpb>0Eintb+1,if Sfp32b is a subnormal number, and Mfixpb>0.5Eintb,otherwiseE_{int}^b = \begin{cases} E_{int}^b + 1, & \text{if } S_{fp32}^b \text{ is a normal number, and } E_{int}^b < 254 \text{ and } M_{fixp}^b > 0 \\ E_{int}^b + 1, & \text{if } S_{fp32}^b \text{ is a subnormal number, and } M_{fixp}^b > 0.5 \\ E_{int}^b, & \text{otherwise} \end{cases}
    • Calculate the block scale factor: Sue8m0b=2EintbS_{ue8m0}^b=2^{E_{int}^b}
    • Calculate the block conversion factor: Rfp32b=1fp32(Sue8m0b)R_{fp32}^b=\frac{1}{fp32(S_{ue8m0}^b)}
    • Apply to the final quantization step. For each element within a block, di=DType(dfp32i⋅Rfp32n)d^i = DType(d_{fp32}^i \cdot R_{fp32}^n). The final quantized output is (Sb,[di]i=1k)\left(S^b, [d^i]_{i=1}^k\right), where SbS^b represents the block scale factor, i.e., Sue8m0bS_{ue8m0}^b, and [di]i=1k[d^i]_{i=1}^k represents the quantized data within the block.
  • Use case 3: when scaleAlg is 2, only the FP4_E2M1 type is involved:
    • When dstTypeMax = 0.0/6.0/7.0:
      • The input x is grouped along the axis dimension in groups of k = blocksize elements, and each group of k numbers {{Vi}i=1k}\{\{V_i\}_{i=1}^{k}\} is dynamically quantized to {mxscale1,{Pi}i=1k}\{mxscale1, \{P_i\}_{i=1}^{k}\}, k = blocksize:shared_exp={ceil(log2(maxi(∣Vi∣)))−emax, iftheone/twobitsbeforethehighbitsofthemantissa are 1, and the mantissa is not all zerosfloor(log2(maxi(∣Vi∣)))−emax, otherwiseshared\_exp = \begin{cases} ceil(log_2(max_i(|V_i|))) - emax, & \text{ if} the one/two bits before the high bits of the mantissa \text{ are 1, and the mantissa is not all zeros} \\ floor(log_2(max_i(|V_i|))) - emax, & \text{ otherwise} \end{cases} \\ Pi=cast_to_dst_type(Vi/mxscale,round_mode), i from 1 to blocksizeP_i = cast\_to\_dst\_type(V_i/mxscale, round\_mode), \space i\space from\space 1\space to\space blocksize\\
      • The quantized PiP_{i} form the output yOut at the positions of corresponding ViV_{i}, and mxscale forms the output mxscaleOut according to the group composition on the corresponding axis dimension.
    • When dstTypeMax != 0.0/6.0/7.0:
      • The long vector is divided into blocks, each with a length of k. A block scale factor Sfp32bS_{fp32}^b is computed separately for each block, and then all elements in the block are mapped to the target low-precision type using the same Sfp32bS_{fp32}^b. If the last block has fewer than k elements, the missing values are treated as 0, and the block is processed as a complete one.
      • Find the maximum absolute value in the block:Amax(Dfp32b)=max({∣di∣}i=1k)Amax(D_{fp32}^b)=max(\{|d_{i}|\}_{i=1}^{k})
      • Map FP32 to within the range representable by the target data type, where if dst_max_value=0, Amax(DType)Amax(DType) is the maximum value representable by the target precision; if dst_max_value!=0, Amax(DType)Amax(DType) is the value passed in for dst_max_value.Sfp32b=Amax(Dfp32b)Amax(DType)S_{fp32}^b = \frac{Amax(D_{fp32}^b)}{Amax(DType)}
      • Convert the block quantization scale factor Sfp32bS_{fp32}^b to a scale value Sue8m0bS_{ue8m0}^b representable in the FP8 format.
      • Extract the unbiased exponent EintbE_{int}^b and the mantissa MfixpbM_{fixp}^b from the floating-point quantization scale factor Sfp32bS_{fp32}^b of the block.
      • To ensure no overflow during quantization, round up the exponent and keep it within the representable range of FP8:Eintb={Eintb+1, ifSfp32b is a normal number, andEintb<254 andMfixpb>0Eintb, otherwiseE_{int}^b = \begin{cases} E_{int}^b + 1, & \text{ if} S_{fp32}^b \text{ is a normal number, and} E_{int}^b < 254 \text{ and} M_{fixp}^b > 0 \\ E_{int}^b, & \text{ otherwise} \end{cases}
      • Calculate the block scale factor: Sue8m0b=2EintbS_{ue8m0}^b=2^{E_{int}^b}
      • Calculate the block conversion factor: Rfp32b=1fp32(Sue8m0b)R_{fp32}^b=\frac{1}{fp32(S_{ue8m0}^b)}
      • Apply to the final quantization step. For each element within a block, di=DType(dfp32i⋅Rfp32n)d^i = DType(d_{fp32}^i \cdot R_{fp32}^n). The final quantized output is (Sb,[di]i=1k)\left(S^b, [d^i]_{i=1}^k\right), where SbS^b represents the block scale factor, i.e., Sue8m0bS_{ue8m0}^b, and [di]i=1k[d^i]_{i=1}^k represents the quantized data within the block.
      • The quantized PiP_{i} form the output yOut at the positions of corresponding ViV_{i}, and mxscale forms the output mxscaleOut according to the group composition on the corresponding axis dimension.

Function Prototype

Each operator uses a two-phase API. You must first call the "aclnnDynamicMxQuantV3GetWorkspaceSize" API to obtain the workspace size required for computation and the executor that contains the computation flow, and then call the "aclnnDynamicMxQuantV3" API to perform computation.

aclnnStatus aclnnDynamicMxQuantV3GetWorkspaceSize(
  const aclTensor *x,
  int64_t          axis,
  char            *roundModeOptional,
  int64_t          dstType,
  int64_t          blocksize,
  int64_t          scaleAlg,
  double           dstTypeMax,
  double           maxLowBound,
  const aclTensor *yOut,
  const aclTensor *mxscaleOut,
  uint64_t        *workspaceSize,
  aclOpExecutor   **executor)
aclnnStatus aclnnDynamicMxQuantV3(
  void          *workspace,
  uint64_t       workspaceSize,
  aclOpExecutor *executor,
  aclrtStream    stream)

aclnnDynamicMxQuantV3GetWorkspaceSize

  • Parameters

    Parameter Input/Output Description Instruction Data Type Data Format Dimension (shape) Non-contiguous Tensor
    x (aclTensor*) Input Represents input x, corresponding to Vi and di in the formula.
    • If the destination type is FLOAT4_E2M1 or FLOAT4_E1M2, the last dimension of x must be an even number.
    • If x is of type FLOAT, only blocksize=32 is supported, and the dimension of the quantization axis cannot be less than 32.
    FLOAT16, BFLOAT16, FLOAT ND 1-7 √
    axis (int64_t) Input Represents the axis on which quantization is performed, corresponding to axis in the formula.
    • The value range is [-D, D-1], where D is the number of dimensions of the shape of x.
    INT64 ND - -
    roundModeOptional(char*) Input Indicates the data conversion mode, corresponding to round_mode in the formula.
    • If dstType is 40/41, {"rint", "floor", "round"} are supported.
    • If dstType is 36/35, only {"rint"} is supported.
    • If a null pointer is passed in, the "rint" mode is used.
    STRING ND - -
    dstType (int64_t) Input Indicates the type of yOut after the specified data conversion, corresponding to DType in the formula.
    • The value range is {35, 36, 40, 41}, corresponding respectively to the data types of output yOut {35:FLOAT8_E5M2, 36:FLOAT8_E4M3FN, 40:FLOAT4_E2M1, 41:FLOAT4_E1M2}.
    INT64 ND - -
    blocksize (int64_t) Input Indicates the number of elements to quantize each time, corresponding to blocksize in the formula.
    • Only multiples of 32 are supported. The value cannot be 0 and cannot exceed 1024.
    • If scaleAlg is 2, blocksize must be 32.
    • If the type of x is FLOAT, blocksize must be 32.
    INT64 ND - -
    scaleAlg (int64_t) Input Specifies the calculation method of mxscaleOut, corresponding to scaleAlg in the formula.
    • Supports values 0, 1, and 2. Value 0 indicates scenario 1, value 1 indicates scenario 2, and value 2 indicates scenario 3.
    • If dstType is FLOAT4_E1M2, only value 0 is supported; if dstType is FLOAT4_E2M1, only values 0 and 2 are supported; if dstType is FLOAT8, only values 0 and 1 are supported.
    INT64 ND - -
    dstTypeMax (double) Input Specifies the value of maxType, corresponding to Amax(DType) in the formula.
    • Supported values are 0.0 and 6.0-12.0. A value of 0.0 indicates that Amax(DType) is the maximum value of the quantized result data type; a value of 6.0-12.0 indicates that Amax(DType) is the passed-in value. Setting this value is only supported for FP4E2M1 when blocksize is 32
    DOUBLE ND - -
    maxLowBound(double) Input Represents the lower-bound clamp value of the calculated maximum absolute value in each block, corresponding to maxLowBound in the formula.
    • Takes effect only when scaleAlg=1. Must be 0.0 when scaleAlg is not equal to 1.
    • Value is a non-negative number. When maxLowBound > 0, the maximum absolute value of each block takes the larger value between it and maxLowBound, that is, $Amax = max(Amax, maxLowBound)$.
    DOUBLE ND - -
    yOut (aclTensor*) Output Represents the quantized result of input x, corresponding to Pi and di in the formula.
    • shape is the same as that of input x.
    FLOAT4_E2M1, FLOAT4_E1M2, FLOAT8_E4M3FN, FLOAT8_E5M2 ND 1-7 ×
    mxscaleOut (aclTensor*) Output Indicates the quantization scale of each group, corresponding to mxscale and Sb in the formula.
    • On the axis dimension, shape is the value of the corresponding axis of x divided by blocksize and rounded up, then padded to an even number with 0.
    • If axis is a non-tail axis, every two rows of the mxscaleOut output need to be interleaved.
    FLOAT8_E8M0 ND 1-8 ×
    workspaceSize (uint64_t) Output Returns the workspace size that needs to be requested on the Device side. - - - - -
    executor (aclOpExecutor**) Output Returns the op executor, which contains the computation flow of the operator. - - - - -
  • Return Value

    aclnnStatus: return status code. For details, see aclnn Error Codes.

    The first-phase API performs input parameter validation and returns an error in the following scenarios:

    Error Code Error Code Description
    ACLNN_ERR_PARAM_NULLPTR 161001 x is a null pointer.
    ACLNN_ERR_PARAM_INVALID 161002 The data types and data formats of x, axis, roundModeOptional, dstType, blocksize, scaleAlg, dstTypeMax, maxLowBound, yOut, and mxscaleOut are not within the supported range.
    The shape of x, yOut, or mxscaleOut does not meet the validation conditions.
    The values of axis, roundModeOptional, dstType, blocksize, scaleAlg, and dstTypeMax are not the currently supported values.
    maxLowBound is not equal to 0.0 but scaleAlg is not equal to 1, or maxLowBound is a negative value.
    ACLNN_ERR_RUNTIME_ERROR 361001 The current platform is not in the range of supported platforms.

aclnnDynamicMxQuantV3

  • Parameters

    Parameter Input/Output Description
    workspace Input Pointer to the workspace memory applied on the Device side.
    workspaceSize Input Size of the workspace applied on the Device side, obtained by the first-phase API aclnnDynamicMxQuantV3GetWorkspaceSize.
    executor Input Op executor, contains the computation flow of the operator.
    stream Input Specifies the stream for task execution.
  • Return Value

    aclnnStatus: return status code. For details, see aclnn Error Code.

Constraints

  • Deterministic computation:
    • aclnnDynamicMxQuantV3 defaults to a deterministic implementation.
  • The shape constraints for x and mxscaleOut are as follows:
    • rank(mxscaleOut) = rank(x) + 1.
    • axis_change = axis if axis >= 0 else axis + rank(x).
    • mxscaleOut.shape[axis_change] = (ceil(x.shape[axis] / blocksize) + 2 - 1) / 2.
    • mxscaleOut.shape[-1] = 2.
    • Other dimensions are consistent with input x.
  • When the data type of x is FLOAT:
    • blocksize must be 32.
    • The dimension of the quantization axis cannot be less than 32.
  • The constraints on maxLowBound are as follows:
    • Takes effect only when scaleAlg=1. If scaleAlg is not 1, maxLowBound must be 0.0.
    • maxLowBound must be non-negative.
    • When maxLowBound > 0, the maximum absolute value calculated for each block is compared with maxLowBound, and the larger value is used for scale calculation.

Example

The following sample code is for reference only. For details about compilation and execution, see Compile and Run Samples.

#include <iostream>
#include <memory>
#include <vector>

#include "acl/acl.h"
#include "aclnnop/aclnn_dynamic_mx_quant_v3.h"

#define CHECK_RET(cond, return_expr) \
    do {                             \
        if (!(cond)) {               \
            return_expr;             \
        }                            \
    } while (0)

#define CHECK_FREE_RET(cond, return_expr) \
    do {                                  \
        if (!(cond)) {                    \
            Finalize(deviceId, stream);   \
            return_expr;                  \
        }                                 \
    } while (0)

#define LOG_PRINT(message, ...)         \
    do {                                \
        printf(message, ##__VA_ARGS__); \
    } while (0)

    int64_t
    GetShapeSize(const std::vector<int64_t>& shape)
{
    int64_t shapeSize = 1;
    for (auto i : shape) {
        shapeSize *= i;
    }
    return shapeSize;
}

int Init(int32_t deviceId, aclrtStream* stream)
{
    // Boilerplate code for resource initialization
    auto ret = aclInit(nullptr);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
    ret = aclrtSetDevice(deviceId);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
    ret = aclrtCreateStream(stream);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
    return 0;
}

template <typename T>
int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
                    aclDataType dataType, aclTensor** tensor)
{
    auto size = GetShapeSize(shape) * sizeof(T);
    // Call aclrtMalloc to allocate device memory.
    auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
    // Call aclrtMemcpy to copy host data to device memory.
    ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);

    // Calculate the strides of the contiguous tensor.
    std::vector<int64_t> strides(shape.size(), 1);
    for (int64_t i = shape.size() - 2; i >= 0; i--) {
        strides[i] = shape[i + 1] * strides[i + 1];
    }

    // Call aclCreateTensor to create an aclTensor.
    *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
                              shape.data(), shape.size(), *deviceAddr);
    return 0;
}

void Finalize(int32_t deviceId, aclrtStream stream)
{
    aclrtDestroyStream(stream);
    aclrtResetDevice(deviceId);
    aclFinalize();
}

int aclnnDynamicMxQuantV3Test(int32_t deviceId, aclrtStream& stream)
{
    auto ret = Init(deviceId, &stream);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);

    // 2. Construct the input and output. Customize the construction based on the API.
    std::vector<int64_t> xShape = {1, 4};
    std::vector<int64_t> yOutShape = {1, 4};
    std::vector<int64_t> mxscaleOutShape = {1, 1, 2};
    void* xDeviceAddr = nullptr;
    void* yOutDeviceAddr = nullptr;
    void* mxscaleOutDeviceAddr = nullptr;
    aclTensor* x = nullptr;
    aclTensor* yOut = nullptr;
    aclTensor* mxscaleOut = nullptr;
    // Values corresponding to BF16 (0, 8, 64, 512)
    std::vector<uint16_t> xHostData = {0, 16640, 17024, 17408};
    // Values corresponding to float8_e4m3 (0, 4, 32, 256)
    std::vector<uint8_t> yOutHostData = {0, 72, 96, 120};
    // Values corresponding to float8_e8m0 (2)
    std::vector<uint8_t> mxscaleOutHostData = {128, 0};
    int64_t axis = -1;
    char* roundModeOptional = const_cast<char*>("rint");
    int64_t dstType = 36;
    int64_t blocksize = 32;
    int64_t scaleAlg = 1;
    double dstTypeMax = 0.0;
    double maxLowBound = 0.5;
    // Create the x aclTensor.
    ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_BF16, &x);
    std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor*)> xTensorPtr(x, aclDestroyTensor);
    std::unique_ptr<void, aclError (*)(void*)> xDeviceAddrPtr(xDeviceAddr, aclrtFree);
    CHECK_RET(ret == ACL_SUCCESS, return ret);
    // Create the yOut aclTensor.
    ret = CreateAclTensor(yOutHostData, yOutShape, &yOutDeviceAddr, aclDataType::ACL_FLOAT8_E4M3FN, &yOut);
    std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor*)> yOutTensorPtr(yOut, aclDestroyTensor);
    std::unique_ptr<void, aclError (*)(void*)> yOutDeviceAddrPtr(yOutDeviceAddr, aclrtFree);
    CHECK_RET(ret == ACL_SUCCESS, return ret);
    // Create the mxscaleOut aclTensor.
    ret = CreateAclTensor(mxscaleOutHostData, mxscaleOutShape, &mxscaleOutDeviceAddr, aclDataType::ACL_FLOAT8_E8M0, &mxscaleOut);
    std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor*)> mxscaleOutTensorPtr(mxscaleOut, aclDestroyTensor);
    std::unique_ptr<void, aclError (*)(void*)> mxscaleOutDeviceAddrPtr(mxscaleOutDeviceAddr, aclrtFree);
    CHECK_RET(ret == ACL_SUCCESS, return ret);

    // Call the CANN operator library API. Replace it with the actual API name.
    uint64_t workspaceSize = 0;
    aclOpExecutor* executor;

    // Call the first-phase API of aclnnDynamicMxQuantV3.
    ret = aclnnDynamicMxQuantV3GetWorkspaceSize(x, axis, roundModeOptional, dstType, blocksize, scaleAlg, dstTypeMax, maxLowBound, yOut, mxscaleOut, &workspaceSize, &executor);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDynamicMxQuantV3GetWorkspaceSize failed. ERROR: %d\n", ret);
              return ret);
    // Allocate device memory based on the workspaceSize calculated by the first-phase API.
    void* workspaceAddr = nullptr;
    std::unique_ptr<void, aclError (*)(void*)> workspaceAddrPtr(nullptr, aclrtFree);
    if (workspaceSize > 0) {
        ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
        CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
        workspaceAddrPtr.reset(workspaceAddr);
    }
    // Call the second-phase API of aclnnDynamicMxQuantV3.
    ret = aclnnDynamicMxQuantV3(workspaceAddr, workspaceSize, executor, stream);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDynamicMxQuantV3 failed. ERROR: %d\n", ret); return ret);

    // (boilerplate) Synchronize and wait for the task execution to complete.
    ret = aclrtSynchronizeStream(stream);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);

    // Obtain the output value, copy the result on the device-side memory to the host side, and modify as required by the specific API definition.
    auto size = GetShapeSize(yOutShape);
    std::vector<uint8_t> yOutData(
        size, 0);  // fp8 data cannot be directly printed in C. Read it as uint8 and convert it to fp8 through binary conversion.
    ret = aclrtMemcpy(yOutData.data(), yOutData.size() * sizeof(yOutData[0]), yOutDeviceAddr,
                      size * sizeof(yOutData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy yOut from device to host failed. ERROR: %d\n", ret);
              return ret);
    for (int64_t i = 0; i < size; i++) {
        LOG_PRINT("yOut[%ld] is: %d\n", i, yOutData[i]);
    }
    size = GetShapeSize(mxscaleOutShape);
    std::vector<uint8_t> mxscaleOutData(
        size, 0);  // fp8 data cannot be directly printed in C. Read it as uint8 and convert it to fp8 through binary conversion.
    ret = aclrtMemcpy(mxscaleOutData.data(), mxscaleOutData.size() * sizeof(mxscaleOutData[0]), mxscaleOutDeviceAddr,
                      size * sizeof(mxscaleOutData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy mxscaleOut from device to host failed. ERROR: %d\n", ret);
              return ret);
    for (int64_t i = 0; i < size; i++) {
        LOG_PRINT("mxscaleOut[%ld] is: %d\n", i, mxscaleOutData[i]);
    }
    return ACL_SUCCESS;
}

int main()
{
    // 1. (Boilerplate) Initialize device/stream. For details, see the acl API manual.
    // Set deviceId based on the actual device.
    int32_t deviceId = 0;
    aclrtStream stream;
    auto ret = aclnnDynamicMxQuantV3Test(deviceId, stream);
    CHECK_FREE_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDynamicMxQuantV3Test failed. ERROR: %d\n", ret); return ret);

    Finalize(deviceId, stream);
    return 0;
}