aclnnAddRmsNormDynamicMxQuantV2
Applicable Products
Ascend 950PR&950DT products : Not 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: This API provides the same function as
aclnnAddRmsNormDynamicMxQuant, with the optional input x3Optional added to support three-way residual addition. When x3Optional is a null pointer, the V2 API behaves exactly the same asaclnnAddRmsNormDynamicMxQuant. This API fuses the Add operator, RmsNorm normalization (which removes the mean subtraction part compared with the LayerNorm operator), and DynamicMxQuant dynamic MX quantization into a single computation, reducing data movement operations: it first adds the inputs, then performs RmsNorm normalization, and finally performs dynamic MX quantization in groups of blocksize=32 along the trailing axis of the input, outputting the quantization result yOut, addition result xOut, quantization scale mxscaleOut, and reciprocal of the standard deviation rstdOut. The algorithm for computing mxscaleOut is specified by scaleAlg (both OCP and cuBLAS implementations are supported when dstType is FP8, and only OCP is supported when dstType is FP4). For the detailed computation process, see the formula below.Formula:
If x3Optional is null:
When x3Optional is not empty (additions are performed in the order within brackets, matching residual addition semantics):
When scaleAlg is 0:
Group the RmsNorm output y along the trailing axis into groups of k = 32 numbers. Each group of k numbers is dynamically quantized to
emax: Exponent bits of the maximum normal number for the corresponding data type.
| DataType | Emax | | :-----------: | :--: | | FLOAT4_E2M1 | 2 | | FLOAT4_E1M2 | 0 | | FLOAT8_E4M3FN | 8 | | FLOAT8_E5M2 | 15 |
When scaleAlg is 1, only FP8 data types are involved:
Divide the long vector into blocks, each of length k. Compute a block scaling factor for each block independently, and then map all elements in the block to the target low-precision type FP8 using the same .
Find the maximum absolute value of the elements in the block:
Map FP32 to the range representable by the target data type FP8:
Convert to the scale value representable in FP8 format:
Extract the unbiased exponent and mantissa from the block floating-point scale factor .
To prevent overflow during quantization, round up the exponent:
Calculate the block scale factor:
Calculate the block conversion factor:
Apply the final step to quantization:
Function Prototype
Each operator uses a two-phase API. Call the aclnnAddRmsNormDynamicMxQuantV2GetWorkspaceSize API first to obtain the workspace size required for computation and the executor containing the operator computation process, and then call the aclnnAddRmsNormDynamicMxQuantV2 API to perform the computation.
aclnnStatus aclnnAddRmsNormDynamicMxQuantV2GetWorkspaceSize(
const aclTensor *x1,
const aclTensor *x2,
const aclTensor *gamma,
const aclTensor *beta,
const aclTensor *x3Optional,
double epsilon,
int64_t scaleAlg,
char *roundMode,
int64_t dstType,
bool outputRstd,
aclTensor *yOut,
aclTensor *xOut,
aclTensor *mxscaleOut,
aclTensor *rstdOut,
uint64_t *workspaceSize,
aclOpExecutor **executor)aclnnStatus aclnnAddRmsNormDynamicMxQuantV2(
void *workspace,
uint64_t workspaceSize,
aclOpExecutor *executor,
aclrtStream stream)aclnnAddRmsNormDynamicMxQuantV2
Parameters
Parameter Input/Output Description Instruction Data Type Data Format Dimension (shape) Non-contiguous Tensor x1 (aclTensor*) Input Indicates the source data tensor in the normalization process. It is x1 in the corresponding formula. - Supports null tensor.
- For details, see Constraints.
FLOAT16, BFLOAT16 ND 1-7 √ x2 (aclTensor*) Input Indicates the source data tensor in the normalization process. It is x2 in the corresponding formula. - Supports null tensors.
- The shape and data type must remain consistent with x1.
FLOAT16, BFLOAT16 ND 1-7 √ gamma (aclTensor*) Input Indicates the weight tensor in the normalization process. It is gamma in the corresponding formula. - Supports null tensors.
- The shape must be one-dimensional and match the last dimension of x1.
- The data type defaults to that of input x1; if not consistent, it must be explicitly set to FLOAT32.
FLOAT16, BFLOAT16, FLOAT32 ND 1 √ beta (aclTensor*) Input Indicates the bias term in the normalization process, which is beta in the corresponding formula. - Supports null tensors.
- Optional parameter; supports passing in a null pointer.
- If provided, the shape and data type must remain consistent with gamma.
FLOAT16, BFLOAT16, FLOAT32 ND 1 √ x3Optional (aclTensor*) Input Indicates the optional input in the addition computation, that is, the residual path. It is x3Optional in the corresponding formula. - Optional parameter, supporting passing in a null pointer.
- When a null pointer is passed in, the V2 API behaves exactly the same as aclnnAddRmsNormDynamicMxQuant.
- When it is not empty, the formula becomes x = (x3Optional + x1) + x2. Its shape and data type must remain consistent with those of x1.
FLOAT16, BFLOAT16 ND 1-7 √ epsilon (double) Input Indicates the value added to the denominator to ensure numerical stability. It is epsilon in the corresponding formula. - It is recommended to pass in a small positive number, such as 1e-6.
- - - - scaleAlg (int64_t) Input Indicates the calculation method of mxscaleOut. It is scaleAlg in the corresponding formula. - Supported values are 0 and 1. The value 0 indicates the Open Compute Project (OCP) implementation, and the value 1 indicates the cuBLAS implementation.
- Only the value 0 is supported when dstType is FLOAT4_E2M1/FLOAT4_E1M2.
- - - - roundMode (char*) Input Indicates the data conversion mode, that is, roundMode in the corresponding formula. - Passing in a null pointer is not supported. You must explicitly pass in a supported string.
- When dstType is 35/36, only {"rint"} is supported.
- When dstType is 40/41, {"rint", "floor", "round"} are supported.
- - - - dstType (int64_t) Input Indicates the type of yOut after data conversion, which is DType in the corresponding formula. - The input range is {35, 36, 40, 41}, corresponding to FLOAT8_E5M2, FLOAT8_E4M3FN, FLOAT4_E2M1, and FLOAT4_E1M2, respectively.
- - - - outputRstd (bool) Input Indicates whether to output a valid rstdOut. - Supports True and False.
- If outputRstd is False, rstdOut is an invalid output.
- - - - yOut (aclTensor*) Output Indicates the result after normalization and quantization, corresponding to Pi and di in the formula. - Supports null tensor.
- The shape must be consistent with that of input x1.
- The data type must remain consistent with dstType.
FLOAT4_E2M1, FLOAT4_E1M2, FLOAT8_E4M3FN, FLOAT8_E5M2 ND 1-7 √ xOut (aclTensor*) Output Indicates the sum of x3Optional+x1+x2 (or x1+x2 when x3Optional is null), corresponding to x in the formula. - Supports null tensors.
- The shape and data type must be consistent with input x1.
FLOAT16, BFLOAT16 ND 1-7 √ mxscaleOut (aclTensor*) Output Indicates the quantization scale corresponding to each group, that is, mxscale and Sb in the corresponding formula. - Supports null tensors.
- The shape on the trailing axis is the corresponding value of x divided by blocksize=32 and rounded up, and then padded to an even number. The pad fill value is 0.
- The remaining dimensions remain consistent with the leading dimensions of the shape of input x1. The leading dimensions refer to the dimensions of x1 minus those of gamma, indicating the dimensions that do not need norm.
- For details about the calculation process, see Constraints.
FLOAT8_E8M0 ND 2-8 √ rstdOut (aclTensor*) Output Indicates the reciprocal of the standard deviation after normalization. It is the reciprocal of Rms(x) in the corresponding formula. - Supports null tensors.
- When outputRstd is True, the number of dimensions remains consistent with input x1. Except for the last dimension, each dimension remains consistent with the corresponding dimension of x1, and the last dimension is 1. Example of the relationship between the rstdOut shape and the x1 shape: if the x1 shape is (2,3,4,8), the rstdOut shape is (2,3,4,1).
- When outputRstd is False, rstdOut is an invalid output.
FLOAT32 ND 1-7 √ workspaceSize(uint64_t*) Output Returns the workspace size to be requested on the Device. - - - - - executor(aclOpExecutor**) Output Returns the op executor, which contains the operator computation flow. - - - - - Return Value
aclnnStatus: returned status code. For details, see aclnn return code.
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 The passed-in x1, x2, gamma, yOut, xOut, and mxscaleOut are null pointers. When outputRstd is True, the passed-in rstdOut is a null pointer. ACLNN_ERR_INNER_NULLPTR 561103 The number of dimensions and data type of input or output parameters are out of range. The data type of dstType does not match that of yOut. The shapes of inputs x1 and x2 and outputs yOut and xOut are not exactly the same. When x3Optional is not a null pointer, the shape or data type of x3Optional is not consistent with x1. The shapes of gamma and beta (if any) are not exactly the same, or the number of dimensions of either is not 1, or the axis length is not equal to the size of the trailing axis of x1, or their data types are different. The dimensions of gamma are not the same as the dimensions of x1 to be normalized, or the dimensions of rstdOut are not the same as the dimensions of x1 not to be normalized, or the axis length of rstdOut corresponding to the normalized dimensions of x1 is not 1. scaleAlg is not 0 or 1, or roundMode is a null pointer, or roundMode is not one of {"rint", "floor", "round"}. If dstType is FP8, roundMode is not "rint". If dstType is fp4, scaleAlg is not 0, or the trailing axis of input x1 is not divisible by 2. The number of dimensions of mxscaleOut is not equal to the number of dimensions of input x1 plus 1, or the axis length does not comply with the Constraints.
aclnnAddRmsNormDynamicMxQuantV2
Parameters
Parameter Input/Output Description workspace Input Workspace memory address allocated on the device. workspaceSize Input Size of the workspace allocated on the device, obtained by calling the first-phase API aclnnAddRmsNormDynamicMxQuantV2GetWorkspaceSize. executor Input Op executor, which contains the operator computation process. stream Input Stream for executing tasks. Return Value
aclnnStatus: return status code. For details, see aclnn Error Codes.
Constraints
Boundary Value Scenario Description
- If the input is Inf: 1. The output yOut is 0; 2. The output xOut is Inf; 3. The output mxscaleOut is 255, and the fill value of even pads is 0; 4. The output rstdOut is 0.
- If the input is NaN: 1. The output yOut is 0; 2. The output xOut is Nan; 3. The output mxscaleOut is 255, and the fill value of even pads is 0; 4. The output rstdOut is NaN.
- The preceding boundary value rules apply to x3Optional, x1, and x2.
Data Format Description
It is recommended to use the ND format for all input and output tensors. Other data formats are converted to the ND format by the framework by default for processing.
Supported Data Types by Product Model
Ascend 950PR&950DT products :
| x1 Data Type | x2 Data Type | gamma Data Type | beta Data Type | x3Optional Data Type | yOut Data Type | xOut Data Type | mxscaleOut Data Type | rstdOut Data Type |
| ----------- | ----------- | -------------- | ------------- | ----------- | -------------- | ------------- | ------------------- | ---------------- |
| FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT4_E2M1 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT4_E1M2 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT8_E4M3FN | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT16 | FLOAT8_E5M2 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | FLOAT4_E2M1 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | FLOAT4_E1M2 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | FLOAT8_E4M3FN | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | BFLOAT16 | FLOAT8_E5M2 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT32 | FLOAT32 | FLOAT16 | FLOAT4_E2M1 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT32 | FLOAT32 | FLOAT16 | FLOAT4_E1M2 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT32 | FLOAT32 | FLOAT16 | FLOAT8_E4M3FN | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| FLOAT16 | FLOAT16 | FLOAT32 | FLOAT32 | FLOAT16 | FLOAT8_E5M2 | FLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | FLOAT32 | FLOAT32 | BFLOAT16 | FLOAT4_E2M1 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | FLOAT32 | FLOAT32 | BFLOAT16 | FLOAT4_E1M2 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | FLOAT32 | FLOAT32 | BFLOAT16 | FLOAT8_E4M3FN | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
| BFLOAT16 | BFLOAT16 | FLOAT32 | FLOAT32 | BFLOAT16 | FLOAT8_E5M2 | BFLOAT16 | FLOAT8_E8M0 | FLOAT32 |
Description: The data type of x3Optional is kept consistent with x1; if a null pointer is passed in for x3Optional, the x3Optional column in the preceding table does not take effect.
The shape constraints of mxscaleOut are as follows:
- rank(mxscaleOut) = rank(x1) + 1.
- mxscaleOut.shape[-2] = ceil(ceil(x1.shape[-1] / 32) / 2), which indicates that the number of blocks after grouping the last axis of x1 by blocksize=32 is rounded up to an even number and then divided by 2.
- mxscaleOut.shape[-1] = 2.
- The other dimensions are the same as those of input x1.
The shape constraints of x1 are as follows:
- If the data type of output yOut is FLOAT4_E2M1 or FLOAT4_E1M2, the value of the last axis of x1 must be an even number.
Constraints on x3Optional are as follows:
- x3Optional is an optional input and supports passing in a null pointer. When a null pointer is passed in, the V2 API is equivalent to
aclnnAddRmsNormDynamicMxQuant. - If x3Optional is not null, the shape and data type of x3Optional must be exactly the same as those of x1.
- x3Optional supports non-contiguous tensors.
- x3Optional is an optional input and supports passing in a null pointer. When a null pointer is passed in, the V2 API is equivalent to
Deterministic computation:
- aclnnAddRmsNormDynamicMxQuantV2 defaults to a deterministic implementation.
Example
The following sample code is for reference only. For details about compilation and execution, see Compile and Run Samples.
#include <iostream>
#include <vector>
#include "acl/acl.h"
#include "aclnnop/aclnn_add_rms_norm_dynamic_mx_quant.h"
#define CHECK_RET(cond, return_expr) \
do { \
if (!(cond)) { \
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 shape_size = 1;
for (auto i : shape) {
shape_size *= i;
}
return shape_size;
}
int Init(int32_t deviceId, aclrtStream* stream)
{
// Boilerplate: 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-side 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-side data to the device-side 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;
}
int main()
{
// 1. (Boilerplate) Initialize the device/stream. For details, see the acl API reference.
// Set deviceId based on the actual device.
int32_t deviceId = 0;
aclrtStream stream;
auto ret = Init(deviceId, &stream);
// Process check as required.
CHECK_RET(ret == 0, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
// 2. Construct inputs and outputs as required by the API.
std::vector<int64_t> xShape = {2, 64};
std::vector<int64_t> gammaShape = {64};
std::vector<int64_t> mxscaleShape = {2, 1, 2};
void* x1DeviceAddr = nullptr;
void* x2DeviceAddr = nullptr;
void* x3OptionalDeviceAddr = nullptr;
void* gammaDeviceAddr = nullptr;
void* yDeviceAddr = nullptr;
void* mxscaleDeviceAddr = nullptr;
void* xDeviceAddr = nullptr;
aclTensor* x1 = nullptr;
aclTensor* x2 = nullptr;
aclTensor* x3Optional = nullptr;
aclTensor* gamma = nullptr;
aclTensor* y = nullptr;
aclTensor* mxscale = nullptr;
aclTensor* x = nullptr;
int64_t xShapeSize = GetShapeSize(xShape);
int64_t gammaShapeSize = GetShapeSize(gammaShape);
int64_t mxscaleShapeSize = GetShapeSize(mxscaleShape);
std::vector<short> x1HostData(xShapeSize, 0x3800);
std::vector<short> x2HostData(xShapeSize, 0x3800);
std::vector<short> x3OptionalHostData(xShapeSize, 0x3c00);
std::vector<short> gammaHostData(gammaShapeSize, 0x3e00);
std::vector<int8_t> yHostData(xShapeSize, 0);
std::vector<int8_t> mxscaleHostData(mxscaleShapeSize, 0);
std::vector<short> xHostData(xShapeSize, 0);
float epsilon = 1e-6;
// Create the x1 aclTensor.
ret = CreateAclTensor(x1HostData, xShape, &x1DeviceAddr, aclDataType::ACL_FLOAT16, &x1);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the x2 aclTensor.
ret = CreateAclTensor(x2HostData, xShape, &x2DeviceAddr, aclDataType::ACL_FLOAT16, &x2);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the x3Optional aclTensor (optional input; a non-null value is passed here to demonstrate the x3Optional path of V2).
ret = CreateAclTensor(x3OptionalHostData, xShape, &x3OptionalDeviceAddr, aclDataType::ACL_FLOAT16, &x3Optional);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the gamma aclTensor.
ret = CreateAclTensor(gammaHostData, gammaShape, &gammaDeviceAddr, aclDataType::ACL_FLOAT16, &gamma);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the y aclTensor (FLOAT8_E4M3FN).
ret = CreateAclTensor(yHostData, xShape, &yDeviceAddr, aclDataType::ACL_FLOAT8_E4M3FN, &y);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the mxscale aclTensor (FLOAT8_E8M0).
ret = CreateAclTensor(mxscaleHostData, mxscaleShape, &mxscaleDeviceAddr, aclDataType::ACL_FLOAT8_E8M0, &mxscale);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// Create the x aclTensor.
ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT16, &x);
CHECK_RET(ret == ACL_SUCCESS, return ret);
// 3. Call the CANN operator library API.
uint64_t workspaceSize = 0;
aclOpExecutor* executor;
// Call the first-phase API of aclnnAddRmsNormDynamicMxQuantV2.
// Passing in nullptr for beta indicates that no bias is used; passing in a non-null pointer for x3Optional enables the x = (x3Optional+x1)+x2 path of V2.
// Passing in "rint" for roundMode (FP8 output supports only "rint"); passing in nullptr for rstdOut (can be omitted when outputRstd=false).
ret = aclnnAddRmsNormDynamicMxQuantV2GetWorkspaceSize(
x1, x2, gamma, nullptr, x3Optional, epsilon, 0, const_cast<char*>("rint"), 36, false, y, x, mxscale, nullptr, &workspaceSize, &executor);
CHECK_RET(ret == ACL_SUCCESS,
LOG_PRINT("aclnnAddRmsNormDynamicMxQuantV2GetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
// Allocate device memory using the workspaceSize computed by the first-phase API.
void* workspaceAddr = nullptr;
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);
}
// Call the second-phase API of aclnnAddRmsNormDynamicMxQuantV2.
ret = aclnnAddRmsNormDynamicMxQuantV2(workspaceAddr, workspaceSize, executor, stream);
CHECK_RET(ret == ACL_SUCCESS,
LOG_PRINT("aclnnAddRmsNormDynamicMxQuantV2 failed. ERROR: %d\n", ret); return ret);
// 4. (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);
// 5. Obtain the output value and copy the result from device memory to the host side.
auto size = GetShapeSize(xShape);
std::vector<int8_t> yRet(size, 0);
ret = aclrtMemcpy(
yRet.data(), yRet.size() * sizeof(yRet[0]), yDeviceAddr, size * sizeof(int8_t), ACL_MEMCPY_DEVICE_TO_HOST);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret);
for (int64_t i = 0; i < size; i++) {
LOG_PRINT("result[%ld] is: %d\n", i, yRet[i]);
}
// 6. Release the aclTensor.
aclDestroyTensor(x1);
aclDestroyTensor(x2);
aclDestroyTensor(x3Optional);
aclDestroyTensor(gamma);
aclDestroyTensor(y);
aclDestroyTensor(mxscale);
aclDestroyTensor(x);
// 7. Release the device resources.
aclrtFree(x1DeviceAddr);
aclrtFree(x2DeviceAddr);
aclrtFree(x3OptionalDeviceAddr);
aclrtFree(gammaDeviceAddr);
aclrtFree(yDeviceAddr);
aclrtFree(mxscaleDeviceAddr);
aclrtFree(xDeviceAddr);
if (workspaceSize > 0) {
aclrtFree(workspaceAddr);
}
aclrtDestroyStream(stream);
aclrtResetDevice(deviceId);
aclFinalize();
return 0;
}