aclnnSwigluGroupQuant
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
The SwigluGroupQuant operator implements the fused computation of the SwiGLU activation function and group quantization. Four quantization modes are supported:
- quant_mode=0: Block Quant (FP8 block quantization, fixed group of 128 elements)
- quant_mode=1: MX Quant (FP8 MX quantization, fixed group of 32 elements)
- quant_mode=2: HiFp8 Static Quant (HiFp8 static quantization)
- quant_mode=3: HiFp8 Dynamic Quant (HiFp8 dynamic quantization)
Formula
Basic Computation Process
Step 1: GroupIndex processing (optional) → Compute real_bs
Step 2: Input splitting (only the first real_bs rows are processed)
Step 3: Clamp processing (optional, only the first real_bs rows are processed)
Step 4: SwiGLU activation (only the first real_bs rows are processed)
Step 5: Weight multiplication (optional, only the first real_bs rows are processed)
Step 6: Quantization computation (only the first real_bs rows are processed)Step 1: GroupIndex Processing (Optional)
When group_index is provided, it is used to dynamically compute the quantity of tokens actually processed:
Where:
- is the number of MoE expert groupings
- is the first dimension of the input tensor (preset batch size)
- All subsequent steps process only the first rows of data
MoE Scenario Description: In MoE inference, different experts may process different quantities of tokens. group_index allows dynamically adjusting the processing range to avoid processing empty data.
Step 2: Input Splitting
The input tensor is split into two parts along the last dimension:
Step 3: Clamp Processing (Optional)
When clamp_limit > 0, the input is clamped:
Where is clamp_limit.
Purpose of Clamp:
- (gating branch) is limited to the positive range to prevent sigmoid gradient vanishing
- (linear branch) is limited to the symmetric range to prevent numerical overflow
Step 4: SwiGLU Activation
Definition of the SwiGLU activation function (element-wise computation):
where the Swish function is:
Complete computation step breakdown:
yOrigin output:
When outputOrigin is set to True, yOrigin outputs the SwiGLU result .
Step 5: Weight Application (Optional)
When weight is provided, the SwiGLU output is weighted:
where is the weight value of the -th token.
MoE use case: The weight comes from the softmax output of the expert router and indicates the weight of the token for the current expert.
Step 6: Quantization Computation
quant_mode=0 (Block Quant)
Group division: Divide the output along the last dimension into groups of 128 elements:
Each group .
Non-finite value masking and absolute value computation:
Masking principle: The property of NaN is NaN != NaN; meanwhile, Inf * 0 also produces NaN. Therefore, this step masks NaN and Inf when computing amax.
Scale computation:
For the -th group (containing 128 consecutive elements):
where takes the following values:
- FP8 E4M3FN:
- FP8 E5M2:
Scale Output and InvScale Computation:
When round_scale=false:
When round_scale=true, the scale is rounded up to the nearest power of 2:
where is written to the FLOAT32 scale output.
Quantization calculation:
If is NaN or Inf, the implementation uses the original as the FP8 cast input:
Where cast_fp8_rint indicates the type conversion from FP32 to FP8, using the RINT (round to nearest) mode.
quant_mode=1 (MX Quant)
MX Quantization Principle: Uses the combination of E8M0 Scale + FP8 Data.
Grouping: Every 32 elements form a group:
Amax Computation:
Raw Scale Computation:
where takes the following values:
- FP8 E4M3FN:
- FP8 E5M2:
quant_mode=1 only supports round_scale=true, which rounds the original scale up to a power of 2:
This is equivalent to the computation based on the FP32 bit pattern:
E8M0 Scale Encoding:
where is written to the scale output of the FLOAT8_E8M0 type, indicating that the actual scale value is .
InvScale Computation:
Quantization computation:
quant_mode=2 (HiFp8 Static Quant)
Static Quantization Description: The weighted SwiGLU output is scaled and quantized using the pre-provided invScale.
Case 1: No GroupIndex (groupIndex is empty):
Where hif8_cast is the HiFloat8 type conversion function.
Case 2: With GroupIndex (groupIndex is not empty):
Let be the number of MoE expert groups. indicates the quantity of tokens processed by the -th expert.
Compute the start and end indices of each group:
For the -th group, quantization is performed using the corresponding scale factor :
MoE Scenario Description: In MoE inference, different experts process different quantities of tokens. groupIndex identifies the token range processed by each expert, and invScale is the pre-computed static scale factor for each expert.
quant_mode=3 (HiFp8 Dynamic Quant)
Dynamic Quantization Description: The scale factor is dynamically computed based on the weighted SwiGLU output for quantization.
Case 1: No GroupIndex (groupIndex is empty):
The global maximum absolute value is computed:
Where is a numerical stability constant.
Compute the scaling factor:
Where is dstTypeMax, indicating the maximum finite value of the HiFloat8 data type.
Quantization computation:
Where hif8_cast is the HiFloat8 type conversion function.
Case 2: With GroupIndex (groupIndex is not empty):
Let be the number of MoE expert groups. indicates the quantity of tokens processed by the -th expert.
Compute the start and end indices of each group:
For the -th group, extract the corresponding data:
Compute the maximum absolute value of this group:
Compute the scaling factor for the group:
Quantize the group:
MoE Scenario Description: In MoE inference, different experts process different quantities of tokens. groupIndex indicates the token range processed by each expert. Each group independently computes the scaling factor to adapt to different data distributions.
Function Prototype
Each operator uses a two-phase API. Call the "aclnnSwigluGroupQuantGetWorkspaceSize" API first to obtain the workspace size required for computation and the executor that contains the operator computation process, and then call the "aclnnSwigluGroupQuant" API to perform the computation.
aclnnStatus aclnnSwigluGroupQuantGetWorkspaceSize(
const aclTensor *x,
const aclTensor *weightOptional,
const aclTensor *groupIndexOptional,
const aclTensor *scaleOptional,
int64_t dstType,
int64_t quantMode,
int64_t blockSize,
bool roundScale,
double clampLimit,
double dstTypeMax,
bool outputOrigin,
const aclTensor *yOut,
const aclTensor *yScaleOut,
const aclTensor *yOriginOut,
uint64_t *workspaceSize,
aclOpExecutor **executor)aclnnStatus aclnnSwigluGroupQuant(
void *workspace,
uint64_t workspaceSize,
aclOpExecutor *executor,
aclrtStream stream)aclnnSwigluGroupQuantGetWorkspaceSize
Parameters:
Parameter Input/Output Description Instruction Data Type Data Format Dimension (shape) Non-Contiguous Tensor x (aclTensor*) Input SwiGLU input. - Shape: [...,D].
- D must be divisible by 256.
- Dimensions: 2-8, among which 2-7 when quantMode is 1.
- When quantMode is 0 or 1, only FLOAT16 and BFLOAT16 are supported; when quantMode is 2 or 3, FLOAT, FLOAT16, and BFLOAT16 are supported.
- Empty tensors are supported when quantMode is 0 or 1; empty tensors are not supported when quantMode is 2 or 3.
FLOAT, FLOAT16, BFLOAT16 ND 2-8 × weightOptional (aclTensor*) Input (optional) MoE weight tensor used for the weighted computation of the SwiGLU output. - Optional parameter. Empty tensors are supported when quantMode is 0 or 1, and not supported when quantMode is 2 or 3.
- When not empty, the data type is FLOAT32, and the number of elements must equal the total number of elements of x excluding the last dimension.
FLOAT32 ND 1-8 × groupIndexOptional (aclTensor*) Input (optional) Group token count in count mode. - Optional parameter. When quantMode is 0 or 1, the tensor cannot be empty alone; when quantMode is 2 or 3, empty tensors are not supported.
- When not empty, the data type is INT64 and the shape is [G].
INT64 ND 1 × scaleOptional(aclTensor*) Input (optional) invScale tensor used for static quantization when quantMode=2. - Optional parameter, used only when quant_mode is 2.
- If groupIndex exists, shape=[G]; otherwise, shape=[1].
FLOAT32 ND 1 × dstType (int64_t) Input Target quantization type. - This parameter takes effect only when quantMode is 0 or 1.
- Supported values are 35 and 36, which indicate FLOAT8_E5M2 and FLOAT8_E4M3FN respectively.
- - - - quantMode (int64_t) Input Quantization mode. - Supported values: 0, 1, 2, and 3.
- 0 indicates the Block FP8 mode.
- 1 indicates the MX mode.
- 2 indicates the HIFP8 static quantization mode.
- 3 indicates the HIFP8 dynamic quantization mode.
- - - - blockSize (int64_t) Input Quantization block size. - 0 indicates that the default block size of the current quantization mode is used.
- If quantMode is 0, 0 or 128 is supported.
- If quantMode is 1, 0 or 32 is supported.
- If quantMode is 2 or 3, this parameter does not take effect and defaults to 0.
- - - - roundScale (bool) Input Whether to round scale to a power of 2. - If quantMode is 1, roundScale must be true.
- If quantMode is 2 or 3, this parameter does not take effect.
- - - - clampLimit (double) Input Clamp threshold before the SwiGLU computation. - -1.0 indicates that clamp is disabled.
- If clamp is enabled, clampLimit must be greater than 0.
- - - - dstTypeMax (double) Input Maximum finite value of the target quantization type. - This parameter takes effect only when quantMode is 3.
- Default value: 15.0
- - - - outputOrigin (bool) Input Whether to output the SwiGLU result before weight weighting. - true indicates that yOrigin is output. When false, the yOrigin output is invalid.
- - - - yOut(aclTensor*) Output Quantization output. - When quantMode is 0 or 1, the data type must be consistent with dstType; when quantMode is 2 or 3, the data type defaults to HIFLOAT8.
- All shapes are [...,D/2].
- Empty tensors are supported when quantMode is 0 or 1, and not supported when quantMode is 2 or 3.
HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN ND 2-8 × yScaleOut (aclTensor*) Output Quantization scale output. - When quantMode is 0, the shape is [...,ceil((D/2)/128)] and the data type is FLOAT32.
- When quantMode is 1, the shape is [...,ceil(ceil((D/2)/32)/2),2] and the data type is FLOAT8_E8M0.
- When quantMode is 3, the shape is [1] without groupIndex and [G] with groupIndex; the data type is FLOAT32.
- Empty tensors are supported when quantMode is 0 or 1, and not supported when quantMode is 2 or 3.
FLOAT32, FLOAT8_E8M0 ND 1-8 × yOriginOut (aclTensor*) Output SwiGLU result before weight multiplication. - The shape is [...,D/2].
- The data type must be the same as that of x.
- Null pointers are not supported.
- Empty tensors are supported when quantMode is 0 or 1; empty tensors are not supported when quantMode is 2 or 3.
FLOAT, FLOAT16, BFLOAT16 ND 2-8 × workspaceSize (uint64_t*) Output Returns the size of the workspace to be requested on the device. - - - - - executor (aclOpExecutor**) Output Returns the op executor that contains the operator computation process. - - - - - 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, yOut, yScaleOut, yOriginOut, workspaceSize, or executor is a null pointer. ACLNN_ERR_PARAM_INVALID 161002 The data type of the input or output is out of the supported range. The shape of the input or output does not meet the constraints. dstType, quantMode, blockSize, roundScale, or clampLimit is not a supported value. The combination of dstType, quantMode, blockSize, roundScale, and the data type of yScaleOut does not match. weightOptional or groupIndexOptional does not meet the optional input constraints. ACLNN_ERR_INNER_TILING_ERROR 561002 The shape information among multiple input tensors is mismatched, or the input attributes are out of the value range (see Parameters for details).
aclnnSwigluGroupQuant
Parameters:
Parameter Input/Output Description workspace Input Workspace memory address requested on the Device. workspaceSize Input Workspace memory size requested on the Device, obtained by calling the first-phase API aclnnSwigluGroupQuantGetWorkspaceSize. executor Input Op executor that contains the operator computation process. stream Input Stream for task execution. Return value
aclnnStatus: return status code. For details, see aclnn Error Codes.
Constraints
Deterministic computation: aclnnSwigluGroupQuant defaults to a deterministic implementation.
When quantMode is 0, only FP8 output is supported, and blockSize can be 0 or 128.
When quantMode is 1, FP8 output is supported, blockSize can be 0 or 32, and roundScale must be true.
When quantMode is 2 or 3, HIFP8 quantization output is supported, and dstType, blockSize, and roundScale do not take effect. The dimensions of input x are [T, D] or [B, S, D], which must meet the following specification constraints:
Specification Item Specification Specification Description B 1~31 - S 0~128K - D/2 512, 768, 1024, 1536, 1792, 2048, 2560, 4096 - dstTypeMax 15, 56, 224, 32768 - The data type of yScale must match quantMode: when quantMode is 0 or 3, the data type is FLOAT32; when quantMode is 1, the data type is FLOAT8_E8M0.
Each element in groupIndex must be greater than or equal to 0.
Example
The following sample code is for reference only. For details about compilation and execution, see Compile and Run Samples.
#include <cstdint>
#include <cstring>
#include <iostream>
#include <vector>
#include "acl/acl.h"
#include "aclnnop/aclnn_swiglu_group_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 shapeSize = 1;
for (auto dim : shape) {
shapeSize *= dim;
}
return shapeSize;
}
int Init(int32_t deviceId, aclrtStream* stream)
{
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 ACL_SUCCESS;
}
bool CheckHardwareSupport()
{
const char* socName = aclrtGetSocName();
if (socName == nullptr) {
LOG_PRINT("Warning: Cannot get SOC name, skip hardware check\n");
return true;
}
LOG_PRINT("Current SOC: %s\n", socName);
if (strstr(socName, "Ascend950") != nullptr || strstr(socName, "ascend950") != nullptr) {
return true;
}
LOG_PRINT("Warning: SwigluGroupQuant only supports Ascend950, current SOC '%s' is not supported. Skip test.\n",
socName);
return false;
}
void Finalize(int32_t deviceId, aclrtStream stream)
{
(void)aclrtDestroyStream(stream);
(void)aclrtResetDevice(deviceId);
(void)aclFinalize();
}
struct AclTensorResource {
void* deviceAddr = nullptr;
aclTensor* tensor = nullptr;
};
void DestroyAclTensorResource(AclTensorResource& resource)
{
if (resource.tensor != nullptr) {
aclDestroyTensor(resource.tensor);
resource.tensor = nullptr;
}
if (resource.deviceAddr != nullptr) {
aclrtFree(resource.deviceAddr);
resource.deviceAddr = nullptr;
}
}
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);
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);
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);
std::vector<int64_t> strides(shape.size(), 1);
for (int64_t i = static_cast<int64_t>(shape.size()) - 2; i >= 0; --i) {
strides[i] = shape[i + 1] * strides[i + 1];
}
*tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, ACL_FORMAT_ND, shape.data(),
shape.size(), *deviceAddr);
return ACL_SUCCESS;
}
struct SwigluGroupQuantCase {
const char* name;
int64_t quantMode;
int64_t blockSize;
bool roundScale;
std::vector<int64_t> yScaleShape;
aclDataType yScaleDataType;
bool yScaleIsE8M0;
int64_t dstType;
double dstTypeMax;
aclDataType yDataType;
int64_t yElementSize;
bool outputOrigin;
bool hasScaleInput;
std::vector<int64_t> scaleShape;
};
int RunSwigluGroupQuantCase(const SwigluGroupQuantCase& testCase, aclrtStream stream)
{
std::vector<int64_t> xShape = {2, 256};
std::vector<int64_t> yShape = {2, 128};
std::vector<int64_t> yOriginShape = {2, 128};
std::vector<uint16_t> xHostData(GetShapeSize(xShape), 0);
for (size_t i = 0; i < xHostData.size(); ++i) {
xHostData[i] = static_cast<uint16_t>(i % 23);
}
std::vector<uint8_t> yHostData(GetShapeSize(yShape) * testCase.yElementSize, 0);
std::vector<uint8_t> yScaleE8M0HostData(GetShapeSize(testCase.yScaleShape), 0);
std::vector<float> yScaleFp32HostData(GetShapeSize(testCase.yScaleShape), 0.0f);
std::vector<uint16_t> yOriginHostData(GetShapeSize(yOriginShape), 0);
std::vector<float> scaleHostData;
if (testCase.hasScaleInput) {
scaleHostData.resize(GetShapeSize(testCase.scaleShape), 1.0f);
}
AclTensorResource xResource;
AclTensorResource yResource;
AclTensorResource yScaleResource;
AclTensorResource yOriginResource;
AclTensorResource scaleResource;
auto ret = CreateAclTensor(xHostData, xShape, &xResource.deviceAddr, ACL_FLOAT16, &xResource.tensor);
CHECK_RET(ret == ACL_SUCCESS, return ret);
ret = CreateAclTensor(yHostData, yShape, &yResource.deviceAddr, testCase.yDataType, &yResource.tensor);
CHECK_RET(ret == ACL_SUCCESS, DestroyAclTensorResource(xResource); return ret);
if (testCase.yScaleIsE8M0) {
ret = CreateAclTensor(yScaleE8M0HostData, testCase.yScaleShape, &yScaleResource.deviceAddr,
testCase.yScaleDataType, &yScaleResource.tensor);
} else {
ret = CreateAclTensor(yScaleFp32HostData, testCase.yScaleShape, &yScaleResource.deviceAddr,
testCase.yScaleDataType, &yScaleResource.tensor);
}
CHECK_RET(ret == ACL_SUCCESS, DestroyAclTensorResource(xResource); DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource); return ret);
ret = CreateAclTensor(yOriginHostData, yOriginShape, &yOriginResource.deviceAddr, ACL_FLOAT16,
&yOriginResource.tensor);
CHECK_RET(ret == ACL_SUCCESS, DestroyAclTensorResource(xResource); DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource); DestroyAclTensorResource(yOriginResource); return ret);
if (testCase.hasScaleInput) {
ret = CreateAclTensor(scaleHostData, testCase.scaleShape, &scaleResource.deviceAddr,
ACL_FLOAT, &scaleResource.tensor);
CHECK_RET(ret == ACL_SUCCESS, DestroyAclTensorResource(xResource); DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource); DestroyAclTensorResource(yOriginResource);
DestroyAclTensorResource(scaleResource); return ret);
}
double clampLimit = -1.0;
bool outputOrigin = testCase.outputOrigin;
const aclTensor* scaleTensor = testCase.hasScaleInput ? scaleResource.tensor : nullptr;
LOG_PRINT("Run %s: quant_mode=%ld\n", testCase.name, testCase.quantMode);
uint64_t workspaceSize = 0;
aclOpExecutor* executor = nullptr;
ret = aclnnSwigluGroupQuantGetWorkspaceSize(xResource.tensor, nullptr, nullptr, scaleTensor, testCase.dstType,
testCase.quantMode, testCase.blockSize, testCase.roundScale, clampLimit,
testCase.dstTypeMax, outputOrigin, yResource.tensor,
yScaleResource.tensor, yOriginResource.tensor, &workspaceSize,
&executor);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnSwigluGroupQuantGetWorkspaceSize failed. ERROR: %d\n", ret);
DestroyAclTensorResource(xResource); DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource); DestroyAclTensorResource(yOriginResource);
DestroyAclTensorResource(scaleResource); return ret);
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);
DestroyAclTensorResource(xResource); DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource); DestroyAclTensorResource(yOriginResource);
DestroyAclTensorResource(scaleResource); return ret);
}
ret = aclnnSwigluGroupQuant(workspaceAddr, workspaceSize, executor, stream);
CHECK_RET(
ret == ACL_SUCCESS, LOG_PRINT("aclnnSwigluGroupQuant failed. ERROR: %d\n", ret);
if (workspaceAddr != nullptr) { aclrtFree(workspaceAddr); } DestroyAclTensorResource(xResource);
DestroyAclTensorResource(yResource); DestroyAclTensorResource(yScaleResource);
DestroyAclTensorResource(yOriginResource); DestroyAclTensorResource(scaleResource); return ret);
ret = aclrtSynchronizeStream(stream);
CHECK_RET(
ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret);
if (workspaceAddr != nullptr) { aclrtFree(workspaceAddr); } DestroyAclTensorResource(xResource);
DestroyAclTensorResource(yResource); DestroyAclTensorResource(yScaleResource);
DestroyAclTensorResource(yOriginResource); DestroyAclTensorResource(scaleResource); return ret);
std::vector<uint8_t> resultData(GetShapeSize(yShape) * testCase.yElementSize, 0);
ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), yResource.deviceAddr,
resultData.size() * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
CHECK_RET(
ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret);
if (workspaceAddr != nullptr) { aclrtFree(workspaceAddr); } DestroyAclTensorResource(xResource);
DestroyAclTensorResource(yResource); DestroyAclTensorResource(yScaleResource);
DestroyAclTensorResource(yOriginResource); DestroyAclTensorResource(scaleResource); return ret);
LOG_PRINT("%s result[0] is: %d\n", testCase.name, resultData[0]);
DestroyAclTensorResource(xResource);
DestroyAclTensorResource(yResource);
DestroyAclTensorResource(yScaleResource);
DestroyAclTensorResource(yOriginResource);
DestroyAclTensorResource(scaleResource);
if (workspaceAddr != nullptr) {
aclrtFree(workspaceAddr);
}
return ACL_SUCCESS;
}
int main()
{
int32_t deviceId = 0;
aclrtStream stream;
auto ret = Init(deviceId, &stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
if (!CheckHardwareSupport()) {
LOG_PRINT("\n=== Test SKIPPED (hardware not supported) ===\n");
Finalize(deviceId, stream);
return ACL_SUCCESS;
}
std::vector<SwigluGroupQuantCase> testCases = {
{"block_fp8", 0, 0, false, {2, 1}, ACL_FLOAT, false, 36, 448.0, ACL_FLOAT8_E4M3FN, 1, false, false, {}},
{"block_fp8_y_origin", 0, 0, false, {2, 1}, ACL_FLOAT, false, 36, 448.0, ACL_FLOAT8_E4M3FN, 1, true, false, {}},
{"mx_fp8", 1, 0, true, {2, 2, 2}, ACL_FLOAT8_E8M0, true, 36, 448.0, ACL_FLOAT8_E4M3FN, 1, false, false, {}},
{"mx_fp8_y_origin", 1, 0, true, {2, 2, 2}, ACL_FLOAT8_E8M0, true, 36, 448.0, ACL_FLOAT8_E4M3FN, 1, true,
false, {}},
{"hifp8_static", 2, 0, false, {1}, ACL_FLOAT, false, 27, 448.0, ACL_HIFLOAT8, 1, false, true, {1}},
{"hifp8_dynamic", 3, 0, false, {1}, ACL_FLOAT, false, 27, 15.0, ACL_HIFLOAT8, 1, false, false, {}},
};
for (const auto& testCase : testCases) {
ret = RunSwigluGroupQuantCase(testCase, stream);
CHECK_RET(ret == ACL_SUCCESS, Finalize(deviceId, stream); return ret);
}
Finalize(deviceId, stream);
return ACL_SUCCESS;
}