| @@ -96,8 +96,8 @@ aclnnStatus aclnnDequantSituQuantGetWorkspaceSize( | |||
| 96 | const aclTensor* quantScaleOptional, | 96 | const aclTensor* quantScaleOptional, |
| 97 | const aclTensor* quantOffsetOptional, | 97 | const aclTensor* quantOffsetOptional, |
| 98 | const aclTensor* groupIndexOptional, | 98 | const aclTensor* groupIndexOptional, |
| 99 | - float beta, | 99 | + double beta, |
| 100 | - float linearBeta, | 100 | + double linearBeta, |
| 101 | bool activateLeft, | 101 | bool activateLeft, |
| 102 | char* quantTypeOptional, | 102 | char* quantTypeOptional, |
| 103 | const aclTensor* yOut, | 103 | const aclTensor* yOut, |
| @@ -194,7 +194,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 194 | <td>quantOffsetOptional(aclTensor*)</td> | 194 | <td>quantOffsetOptional(aclTensor*)</td> |
| 195 | <td>输入</td> | 195 | <td>输入</td> |
| 196 | <td>量化的offset。</td> | 196 | <td>量化的offset。</td> |
| 197 | - <td><ul><li>不支持空Tensor。</li><li>当`quantTypeOptional`为static时必选,shape同`quantScaleOptional`。</li><li>当`quantTypeOptional`为dynamic时可选。</li></ul></td> | 197 | + <td><ul><li>不支持空Tensor。</li><li>当`quantTypeOptional`为static时可选(缺省按0处理),shape同`quantScaleOptional`。</li><li>当`quantTypeOptional`为dynamic时不使用,须为空。</li></ul></td> |
| 198 | <td>FLOAT</td> | 198 | <td>FLOAT</td> |
| 199 | <td>ND</td> | 199 | <td>ND</td> |
| 200 | <td>1</td> | 200 | <td>1</td> |
| @@ -211,7 +211,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 211 | <td>x</td> | 211 | <td>x</td> |
| 212 | </tr> | 212 | </tr> |
| 213 | <tr> | 213 | <tr> |
| 214 | - <td>beta(float)</td> | 214 | + <td>beta(double)</td> |
| 215 | <td>输入</td> | 215 | <td>输入</td> |
| 216 | <td>Situ激活的beta参数。</td> | 216 | <td>Situ激活的beta参数。</td> |
| 217 | <td>不能为0。默认4.0。</td> | 217 | <td>不能为0。默认4.0。</td> |
| @@ -221,7 +221,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 221 | <td>-</td> | 221 | <td>-</td> |
| 222 | </tr> | 222 | </tr> |
| 223 | <tr> | 223 | <tr> |
| 224 | - <td>linearBeta(float)</td> | 224 | + <td>linearBeta(double)</td> |
| 225 | <td>输入</td> | 225 | <td>输入</td> |
| 226 | <td>Situ激活的linear_beta参数。</td> | 226 | <td>Situ激活的linear_beta参数。</td> |
| 227 | <td>当值≤0时不启用。默认25.0。</td> | 227 | <td>当值≤0时不启用。默认25.0。</td> |
| @@ -408,6 +408,8 @@ aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/co | |||
| 408 | - BF16/FLOAT16:除`groupIndexOptional`外其余可选输入均不使用(预反量化模式);`groupIndexOptional`可选, | 408 | - BF16/FLOAT16:除`groupIndexOptional`外其余可选输入均不使用(预反量化模式);`groupIndexOptional`可选, |
| 409 | 为各专家连续排布的行计数(INT64段长),计数总和不超过x行数,超出计数总和的尾行不参与计算、输出保持0。 | 409 | 为各专家连续排布的行计数(INT64段长),计数总和不超过x行数,超出计数总和的尾行不参与计算、输出保持0。 |
| 410 | - 当`quantTypeOptional`为static时,`quantScaleOptional`必须提供。 | 410 | - 当`quantTypeOptional`为static时,`quantScaleOptional`必须提供。 |
| 411 | +- 当`quantTypeOptional`为static时,`quantOffsetOptional`可选,缺省按0处理;当`quantTypeOptional`为dynamic时, | ||
| 412 | + `quantOffsetOptional`须为空(不使用)。 | ||
| 411 | - 当`quantTypeOptional`为dynamic时,`quantScaleOptional`可选(作为smoothScale使用)。 | 413 | - 当`quantTypeOptional`为dynamic时,`quantScaleOptional`可选(作为smoothScale使用)。 |
| 412 | 414 | ||
| 413 | ## 调用示例 | 415 | ## 调用示例 |
| @@ -514,8 +516,8 @@ int main() | |||
| 514 | ret = CreateAclTensor(yScaleHostData, yScaleShape, &yScaleDeviceAddr, aclDataType::ACL_FLOAT, &yScale); | 516 | ret = CreateAclTensor(yScaleHostData, yScaleShape, &yScaleDeviceAddr, aclDataType::ACL_FLOAT, &yScale); |
| 515 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 517 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 516 | 518 | ||
| 517 | - float beta = 4.0; | 519 | + double beta = 4.0; |
| 518 | - float linearBeta = 25.0; | 520 | + double linearBeta = 25.0; |
| 519 | bool activateLeft = true; | 521 | bool activateLeft = true; |
| 520 | 522 | ||
| 521 | // 3. 调用CANN算子库API,需要修改为具体的API名称 | 523 | // 3. 调用CANN算子库API,需要修改为具体的API名称 |
| @@ -98,8 +98,8 @@ aclnnStatus aclnnDequantSituQuantGetWorkspaceSize( | |||
| 98 | const aclTensor* quantScaleOptional, | 98 | const aclTensor* quantScaleOptional, |
| 99 | const aclTensor* quantOffsetOptional, | 99 | const aclTensor* quantOffsetOptional, |
| 100 | const aclTensor* groupIndexOptional, | 100 | const aclTensor* groupIndexOptional, |
| 101 | - float beta, | 101 | + double beta, |
| 102 | - float linearBeta, | 102 | + double linearBeta, |
| 103 | bool activateLeft, | 103 | bool activateLeft, |
| 104 | char* quantTypeOptional, | 104 | char* quantTypeOptional, |
| 105 | const aclTensor* yOut, | 105 | const aclTensor* yOut, |
| @@ -196,7 +196,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 196 | <td>quantOffsetOptional (aclTensor*)</td> | 196 | <td>quantOffsetOptional (aclTensor*)</td> |
| 197 | <td>Input</td> | 197 | <td>Input</td> |
| 198 | <td>Quantized offset.</td> | 198 | <td>Quantized offset.</td> |
| 199 | - <td><ul><li>Does not support null tensor.</li><li>Required when `quantTypeOptional` is static, with the same shape as `quantScaleOptional`.</li><li>Optional when `quantTypeOptional` is dynamic.</li></ul></td> | 199 | + <td><ul><li>Does not support null tensor.</li><li>Optional when `quantTypeOptional` is static (treated as 0 if absent), with the same shape as `quantScaleOptional`.</li><li>Not used when `quantTypeOptional` is dynamic; must be empty.</li></ul></td> |
| 200 | <td>FLOAT</td> | 200 | <td>FLOAT</td> |
| 201 | <td>ND</td> | 201 | <td>ND</td> |
| 202 | <td>1</td> | 202 | <td>1</td> |
| @@ -213,7 +213,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 213 | <td>x</td> | 213 | <td>x</td> |
| 214 | </tr> | 214 | </tr> |
| 215 | <tr> | 215 | <tr> |
| 216 | - <td>beta (float)</td> | 216 | + <td>beta (double)</td> |
| 217 | <td>Input</td> | 217 | <td>Input</td> |
| 218 | <td>Beta parameter for Situ activation.</td> | 218 | <td>Beta parameter for Situ activation.</td> |
| 219 | <td>Cannot be 0. Defaults to 4.0.</td> | 219 | <td>Cannot be 0. Defaults to 4.0.</td> |
| @@ -223,7 +223,7 @@ aclnnStatus aclnnDequantSituQuant( | |||
| 223 | <td>-</td> | 223 | <td>-</td> |
| 224 | </tr> | 224 | </tr> |
| 225 | <tr> | 225 | <tr> |
| 226 | - <td>linearBeta (float)</td> | 226 | + <td>linearBeta (double)</td> |
| 227 | <td>Input</td> | 227 | <td>Input</td> |
| 228 | <td>The linear_beta parameter of the Situ activation.</td> | 228 | <td>The linear_beta parameter of the Situ activation.</td> |
| 229 | <td>Not enabled when the value is ≤ 0. The default value is 25.0.</td> | 229 | <td>Not enabled when the value is ≤ 0. The default value is 25.0.</td> |
| @@ -409,6 +409,8 @@ The first-phase API performs input parameter validation and returns an error in | |||
| 409 | - INT32: `weightScaleOptional` and `activationScaleOptional` are required, while `quantScaleOptional` and `quantOffsetOptional` are forbidden. | 409 | - INT32: `weightScaleOptional` and `activationScaleOptional` are required, while `quantScaleOptional` and `quantOffsetOptional` are forbidden. |
| 410 | - BF16/FLOAT16: None of the optional inputs is used (pre-dequantization mode). | 410 | - BF16/FLOAT16: None of the optional inputs is used (pre-dequantization mode). |
| 411 | - When `quantTypeOptional` is static, `quantScaleOptional` is required. | 411 | - When `quantTypeOptional` is static, `quantScaleOptional` is required. |
| 412 | +- When `quantTypeOptional` is static, `quantOffsetOptional` is optional and treated as 0 when absent; when | ||
| 413 | + `quantTypeOptional` is dynamic, `quantOffsetOptional` must be empty (not used). | ||
| 412 | - When `quantTypeOptional` is dynamic, `quantScaleOptional` is optional (used as smoothScale). | 414 | - When `quantTypeOptional` is dynamic, `quantScaleOptional` is optional (used as smoothScale). |
| 413 | 415 | ||
| 414 | ## Example | 416 | ## Example |
| @@ -515,8 +517,8 @@ int main() | |||
| 515 | ret = CreateAclTensor(yScaleHostData, yScaleShape, &yScaleDeviceAddr, aclDataType::ACL_FLOAT, &yScale); | 517 | ret = CreateAclTensor(yScaleHostData, yScaleShape, &yScaleDeviceAddr, aclDataType::ACL_FLOAT, &yScale); |
| 516 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 518 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 517 | 519 | ||
| 518 | - float beta = 4.0; | 520 | + double beta = 4.0; |
| 519 | - float linearBeta = 25.0; | 521 | + double linearBeta = 25.0; |
| 520 | bool activateLeft = true; | 522 | bool activateLeft = true; |
| 521 | 523 | ||
| 522 | // 3. Call the CANN operator library API. Replace it with the specific API name. | 524 | // 3. Call the CANN operator library API. Replace it with the specific API name. |
| @@ -8,4 +8,4 @@ | |||
| 8 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE dequant_situ_quant ACLNNTYPE aclnn) | 11 | +add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE dequant_situ_quant ACLNNTYPE aclnn_inner) |
| @@ -0,0 +1,335 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include "aclnn_dequant_situ_quant.h" | ||
| 12 | + | ||
| 13 | +#include <string> | ||
| 14 | +#include <vector> | ||
| 15 | +#include "aclnnInner_dequant_situ_quant.h" | ||
| 16 | +#include "aclnn/aclnn_base.h" | ||
| 17 | +#include "aclnn_kernels/common/op_error_check.h" | ||
| 18 | +#include "base/err_msg.h" | ||
| 19 | +#include "op_api/aclnn_util.h" | ||
| 20 | +#include "opdev/common_types.h" | ||
| 21 | +#include "opdev/data_type_utils.h" | ||
| 22 | +#include "opdev/format_utils.h" | ||
| 23 | +#include "opdev/op_dfx.h" | ||
| 24 | +#include "opdev/op_executor.h" | ||
| 25 | +#include "opdev/op_log.h" | ||
| 26 | +#include "opdev/shape_utils.h" | ||
| 27 | + | ||
| 28 | +using namespace op; | ||
| 29 | +#ifdef __cplusplus | ||
| 30 | +extern "C" { | ||
| 31 | +#endif | ||
| 32 | + | ||
| 33 | +namespace { | ||
| 34 | +constexpr size_t MIN_DIM_NUM_INT8 = 2; | ||
| 35 | +constexpr size_t MAX_DIM_NUM = 8; | ||
| 36 | +constexpr size_t DIM_NUM_NOT_INT8 = 2; | ||
| 37 | +constexpr int64_t NUM_TWO = 2; | ||
| 38 | +constexpr double BETA_ZERO = 0.0; | ||
| 39 | +const char* const ACLNN_OP_NAME = "aclnnDequantSituQuant"; | ||
| 40 | + | ||
| 41 | +static const std::initializer_list<op::DataType> X_DTYPE_SUPPORT_LIST = { | ||
| 42 | + op::DataType::DT_INT8, op::DataType::DT_INT32, op::DataType::DT_BF16, op::DataType::DT_FLOAT16}; | ||
| 43 | +static const std::initializer_list<op::DataType> FLOAT_DTYPE_SUPPORT_LIST = {op::DataType::DT_FLOAT}; | ||
| 44 | +static const std::initializer_list<op::DataType> Y_DTYPE_SUPPORT_LIST = {op::DataType::DT_INT8}; | ||
| 45 | +static const std::initializer_list<op::DataType> GROUP_INDEX_DTYPE_SUPPORT_LIST = {op::DataType::DT_INT64}; | ||
| 46 | + | ||
| 47 | +enum class QuantType : int32_t { STATIC = 0, DYNAMIC = 1 }; | ||
| 48 | + | ||
| 49 | +static void ReportInvalidValue(const char* paramName, const std::string& incorrectValue, const std::string& reason) | ||
| 50 | +{ | ||
| 51 | + OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str()); | ||
| 52 | + REPORT_PREDEFINED_ERR_MSG( | ||
| 53 | + "EZ0026", (std::vector<const char*>{"param_name", "op_name", "incorrect_value", "reason"}), | ||
| 54 | + (std::vector<const char*>{paramName, ACLNN_OP_NAME, incorrectValue.c_str(), reason.c_str()})); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +static void ReportInvalidShape(const char* paramNames, const std::string& incorrectShapes, const std::string& reason) | ||
| 58 | +{ | ||
| 59 | + OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str()); | ||
| 60 | + REPORT_PREDEFINED_ERR_MSG( | ||
| 61 | + "EZ0010", (std::vector<const char*>{"param_names", "op_name", "incorrect_shapes", "reason"}), | ||
| 62 | + (std::vector<const char*>{paramNames, ACLNN_OP_NAME, incorrectShapes.c_str(), reason.c_str()})); | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +static bool HasUnknownDim(const op::Shape& shape) | ||
| 66 | +{ | ||
| 67 | + for (size_t i = 0; i < shape.GetDimNum(); i++) { | ||
| 68 | + if (shape.GetDim(i) < 0) { | ||
| 69 | + return true; | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + return false; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +// 1. 检查必选输入/输出是否为空指针 | ||
| 76 | +static bool CheckNotNull(const aclTensor* x, const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 77 | +{ | ||
| 78 | + OP_CHECK_NULL(x, return false); | ||
| 79 | + OP_CHECK_NULL(yOut, return false); | ||
| 80 | + OP_CHECK_NULL(yScaleOut, return false); | ||
| 81 | + return true; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +// 2. 检查条件必选输入是否为空指针:INT8/INT32必选weightScaleOptional,INT32必选activationScaleOptional, | ||
| 85 | +// static量化必选quantScaleOptional | ||
| 86 | +static bool CheckConditionalInputNotNull(const aclTensor* x, const aclTensor* weightScaleOptional, | ||
| 87 | + const aclTensor* activationScaleOptional, const aclTensor* quantScaleOptional, | ||
| 88 | + QuantType quantType) | ||
| 89 | +{ | ||
| 90 | + const op::DataType xDtype = x->GetDataType(); | ||
| 91 | + if (xDtype == op::DataType::DT_INT8 || xDtype == op::DataType::DT_INT32) { | ||
| 92 | + OP_CHECK_NULL(weightScaleOptional, return false); | ||
| 93 | + } | ||
| 94 | + if (xDtype == op::DataType::DT_INT32) { | ||
| 95 | + OP_CHECK_NULL(activationScaleOptional, return false); | ||
| 96 | + } | ||
| 97 | + if (quantType == QuantType::STATIC) { | ||
| 98 | + OP_CHECK_NULL(quantScaleOptional, return false); | ||
| 99 | + } | ||
| 100 | + return true; | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +// 3. 检查quantTypeOptional取值,nullptr按默认值dynamic处理,取值大小写不敏感 | ||
| 104 | +static bool CheckQuantType(char* quantTypeOptional, QuantType& quantType) | ||
| 105 | +{ | ||
| 106 | + quantType = QuantType::DYNAMIC; | ||
| 107 | + if (quantTypeOptional == nullptr) { | ||
| 108 | + return true; | ||
| 109 | + } | ||
| 110 | + std::string quantTypeStr{quantTypeOptional}; | ||
| 111 | + for (size_t i = 0; i < quantTypeStr.size(); i++) { | ||
| 112 | + if (quantTypeStr[i] >= 'A' && quantTypeStr[i] <= 'Z') { | ||
| 113 | + quantTypeStr[i] = static_cast<char>(quantTypeStr[i] - 'A' + 'a'); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + if (quantTypeStr == "static") { | ||
| 117 | + quantType = QuantType::STATIC; | ||
| 118 | + return true; | ||
| 119 | + } | ||
| 120 | + if (quantTypeStr == "dynamic") { | ||
| 121 | + quantType = QuantType::DYNAMIC; | ||
| 122 | + return true; | ||
| 123 | + } | ||
| 124 | + const std::string reason = (("quantTypeOptional only supports \"static\" or \"dynamic\", but got " + | ||
| 125 | + std::string(quantTypeOptional) + ".")); | ||
| 126 | + ReportInvalidValue("quantTypeOptional", std::string(quantTypeOptional), reason); | ||
| 127 | + return false; | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +// 4. 检查x、yOut、yScaleOut是否为空tensor | ||
| 131 | +static bool CheckEmptyTensor(const aclTensor* x, const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 132 | +{ | ||
| 133 | + if (x->IsEmpty() || yOut->IsEmpty() || yScaleOut->IsEmpty()) { | ||
| 134 | + const std::string reason = (("x, yOut and yScaleOut do not support empty tensor, x: " + | ||
| 135 | + std::string(op::ToString(x->GetViewShape()).GetString()) + ", yOut: " + | ||
| 136 | + std::string(op::ToString(yOut->GetViewShape()).GetString()) + ", yScaleOut: " + | ||
| 137 | + std::string(op::ToString(yScaleOut->GetViewShape()).GetString()) + ".")); | ||
| 138 | + ReportInvalidShape("x,yOut,yScaleOut", | ||
| 139 | + (std::string(op::ToString(x->GetViewShape()).GetString()) + "," + | ||
| 140 | + op::ToString(yOut->GetViewShape()).GetString() + "," + | ||
| 141 | + op::ToString(yScaleOut->GetViewShape()).GetString()), | ||
| 142 | + reason); | ||
| 143 | + return false; | ||
| 144 | + } | ||
| 145 | + return true; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +// 5. 检查beta是否为0 | ||
| 149 | +static bool CheckBeta(double beta) | ||
| 150 | +{ | ||
| 151 | + if (beta == BETA_ZERO) { | ||
| 152 | + const std::string reason = "beta must not be 0."; | ||
| 153 | + ReportInvalidValue("beta", std::to_string(beta), reason); | ||
| 154 | + return false; | ||
| 155 | + } | ||
| 156 | + return true; | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +// 6. 检查输入/输出数据类型是否在支持范围内 | ||
| 160 | +static bool CheckDtypeValid(const aclTensor* x, const aclTensor* weightScaleOptional, | ||
| 161 | + const aclTensor* activationScaleOptional, const aclTensor* biasOptional, | ||
| 162 | + const aclTensor* quantScaleOptional, const aclTensor* quantOffsetOptional, | ||
| 163 | + const aclTensor* groupIndexOptional, const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 164 | +{ | ||
| 165 | + OP_CHECK_DTYPE_NOT_SUPPORT(x, X_DTYPE_SUPPORT_LIST, return false); | ||
| 166 | + OP_CHECK_DTYPE_NOT_SUPPORT(yOut, Y_DTYPE_SUPPORT_LIST, return false); | ||
| 167 | + OP_CHECK_DTYPE_NOT_SUPPORT(yScaleOut, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 168 | + if (weightScaleOptional != nullptr) { | ||
| 169 | + OP_CHECK_DTYPE_NOT_SUPPORT(weightScaleOptional, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 170 | + } | ||
| 171 | + if (activationScaleOptional != nullptr) { | ||
| 172 | + OP_CHECK_DTYPE_NOT_SUPPORT(activationScaleOptional, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 173 | + } | ||
| 174 | + if (biasOptional != nullptr) { | ||
| 175 | + OP_CHECK_DTYPE_NOT_SUPPORT(biasOptional, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 176 | + } | ||
| 177 | + if (quantScaleOptional != nullptr) { | ||
| 178 | + OP_CHECK_DTYPE_NOT_SUPPORT(quantScaleOptional, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 179 | + } | ||
| 180 | + if (quantOffsetOptional != nullptr) { | ||
| 181 | + OP_CHECK_DTYPE_NOT_SUPPORT(quantOffsetOptional, FLOAT_DTYPE_SUPPORT_LIST, return false); | ||
| 182 | + } | ||
| 183 | + if (groupIndexOptional != nullptr) { | ||
| 184 | + OP_CHECK_DTYPE_NOT_SUPPORT(groupIndexOptional, GROUP_INDEX_DTYPE_SUPPORT_LIST, return false); | ||
| 185 | + } | ||
| 186 | + return true; | ||
| 187 | +} | ||
| 188 | + | ||
| 189 | +// 7. 检查数据格式是否为线性格式(ND/NCL/NCHW/NCDHW),分形等非线性存储格式拦截 | ||
| 190 | +static bool IsLinearFormat(op::Format format) | ||
| 191 | +{ | ||
| 192 | + return format == op::Format::FORMAT_ND || format == op::Format::FORMAT_NCL || format == op::Format::FORMAT_NCHW || | ||
| 193 | + format == op::Format::FORMAT_NCDHW; | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +static bool CheckFormat(const aclTensor* x, const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 197 | +{ | ||
| 198 | + if (!IsLinearFormat(x->GetStorageFormat()) || !IsLinearFormat(yOut->GetStorageFormat()) || | ||
| 199 | + !IsLinearFormat(yScaleOut->GetStorageFormat())) { | ||
| 200 | + const std::string reason = (( | ||
| 201 | + "x, yOut and yScaleOut only support linear formats (ND/NCL/NCHW/NCDHW), but got x: " + | ||
| 202 | + std::string(op::ToString(x->GetStorageFormat()).GetString()) + | ||
| 203 | + ", yOut: " + std::string(op::ToString(yOut->GetStorageFormat()).GetString()) + | ||
| 204 | + ", yScaleOut: " + std::string(op::ToString(yScaleOut->GetStorageFormat()).GetString()) + ".")); | ||
| 205 | + OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str()); | ||
| 206 | + REPORT_PREDEFINED_ERR_MSG( | ||
| 207 | + "EZ0018", (std::vector<const char*>{"param_names", "op_name", "incorrect_formats", "reason"}), | ||
| 208 | + (std::vector<const char*>{"x,yOut,yScaleOut", ACLNN_OP_NAME, | ||
| 209 | + (std::string(op::ToString(x->GetStorageFormat()).GetString()) + "," + | ||
| 210 | + op::ToString(yOut->GetStorageFormat()).GetString() + "," + | ||
| 211 | + op::ToString(yScaleOut->GetStorageFormat()).GetString()) | ||
| 212 | + .c_str(), | ||
| 213 | + reason.c_str()})); | ||
| 214 | + return false; | ||
| 215 | + } | ||
| 216 | + return true; | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +// 8. 检查x的维度和最后一维是否为2的倍数 | ||
| 220 | +static bool CheckXShape(const aclTensor* x) | ||
| 221 | +{ | ||
| 222 | + const op::Shape& xShape = x->GetViewShape(); | ||
| 223 | + const size_t dimNum = xShape.GetDimNum(); | ||
| 224 | + if (x->GetDataType() == op::DataType::DT_INT8) { | ||
| 225 | + OP_CHECK_MIN_DIM(x, MIN_DIM_NUM_INT8, return false); | ||
| 226 | + OP_CHECK_MAX_DIM(x, MAX_DIM_NUM, return false); | ||
| 227 | + } else if (dimNum != DIM_NUM_NOT_INT8) { | ||
| 228 | + const std::string reason = (("x shape rank must be 2 for int32/bfloat16/float16, but got " + | ||
| 229 | + std::to_string(dimNum) + ".")); | ||
| 230 | + ReportInvalidShape("x", op::ToString(xShape).GetString(), reason); | ||
| 231 | + return false; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + // 含未知维(-1)的动态shape无法在host侧确定最后一维,交由执行阶段校验 | ||
| 235 | + if (HasUnknownDim(xShape)) { | ||
| 236 | + return true; | ||
| 237 | + } | ||
| 238 | + const int64_t lastDim = xShape.GetDim(dimNum - 1); | ||
| 239 | + if (lastDim % NUM_TWO != 0) { | ||
| 240 | + const std::string reason = (("The last dimension of x must be divisible by 2, but got " + | ||
| 241 | + std::to_string(lastDim) + ".")); | ||
| 242 | + OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str()); | ||
| 243 | + REPORT_PREDEFINED_ERR_MSG( | ||
| 244 | + "EZ0015", (std::vector<const char*>{"param_name", "op_name", "incorrect_size", "reason"}), | ||
| 245 | + (std::vector<const char*>{("x"), ACLNN_OP_NAME, (std::to_string(lastDim)).c_str(), reason.c_str()})); | ||
| 246 | + return false; | ||
| 247 | + } | ||
| 248 | + return true; | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +// 9. 检查输出shape的维度与x匹配 | ||
| 252 | +static bool CheckOutShape(const aclTensor* x, const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 253 | +{ | ||
| 254 | + const size_t xDimNum = x->GetViewShape().GetDimNum(); | ||
| 255 | + const size_t expectedYDimNum = (x->GetDataType() == op::DataType::DT_INT8) ? xDimNum : DIM_NUM_NOT_INT8; | ||
| 256 | + const size_t expectedYScaleDimNum = (x->GetDataType() == op::DataType::DT_INT8) ? (xDimNum - 1) : | ||
| 257 | + (DIM_NUM_NOT_INT8 - 1); | ||
| 258 | + if (yOut->GetViewShape().GetDimNum() != expectedYDimNum) { | ||
| 259 | + const std::string reason = (("yOut shape rank must be " + std::to_string(expectedYDimNum) + ", but got " + | ||
| 260 | + std::to_string(yOut->GetViewShape().GetDimNum()) + ".")); | ||
| 261 | + ReportInvalidShape("yOut", op::ToString(yOut->GetViewShape()).GetString(), reason); | ||
| 262 | + return false; | ||
| 263 | + } | ||
| 264 | + if (yScaleOut->GetViewShape().GetDimNum() != expectedYScaleDimNum) { | ||
| 265 | + const std::string reason = (("yScaleOut shape rank must be " + std::to_string(expectedYScaleDimNum) + | ||
| 266 | + ", but got " + std::to_string(yScaleOut->GetViewShape().GetDimNum()) + ".")); | ||
| 267 | + ReportInvalidShape("yScaleOut", op::ToString(yScaleOut->GetViewShape()).GetString(), reason); | ||
| 268 | + return false; | ||
| 269 | + } | ||
| 270 | + return true; | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +static aclnnStatus CheckParams(const aclTensor* x, const aclTensor* weightScaleOptional, | ||
| 274 | + const aclTensor* activationScaleOptional, const aclTensor* biasOptional, | ||
| 275 | + const aclTensor* quantScaleOptional, const aclTensor* quantOffsetOptional, | ||
| 276 | + const aclTensor* groupIndexOptional, double beta, char* quantTypeOptional, | ||
| 277 | + const aclTensor* yOut, const aclTensor* yScaleOut) | ||
| 278 | +{ | ||
| 279 | + // 1. 检查必选输入/输出是否为空指针 | ||
| 280 | + CHECK_RET(CheckNotNull(x, yOut, yScaleOut), ACLNN_ERR_PARAM_NULLPTR); | ||
| 281 | + | ||
| 282 | + // 2. 检查quantTypeOptional取值 | ||
| 283 | + QuantType quantType = QuantType::DYNAMIC; | ||
| 284 | + CHECK_RET(CheckQuantType(quantTypeOptional, quantType), ACLNN_ERR_PARAM_INVALID); | ||
| 285 | + | ||
| 286 | + // 3. 检查条件必选输入是否为空指针 | ||
| 287 | + CHECK_RET( | ||
| 288 | + CheckConditionalInputNotNull(x, weightScaleOptional, activationScaleOptional, quantScaleOptional, quantType), | ||
| 289 | + ACLNN_ERR_PARAM_NULLPTR); | ||
| 290 | + | ||
| 291 | + // 4. 检查x、yOut、yScaleOut是否为空tensor | ||
| 292 | + CHECK_RET(CheckEmptyTensor(x, yOut, yScaleOut), ACLNN_ERR_PARAM_INVALID); | ||
| 293 | + | ||
| 294 | + // 5. 检查host侧标量参数beta | ||
| 295 | + CHECK_RET(CheckBeta(beta), ACLNN_ERR_PARAM_INVALID); | ||
| 296 | + | ||
| 297 | + // 6. 检查输入/输出数据类型是否在API支持的数据类型范围之内 | ||
| 298 | + CHECK_RET(CheckDtypeValid(x, weightScaleOptional, activationScaleOptional, biasOptional, quantScaleOptional, | ||
| 299 | + quantOffsetOptional, groupIndexOptional, yOut, yScaleOut), | ||
| 300 | + ACLNN_ERR_PARAM_INVALID); | ||
| 301 | + | ||
| 302 | + // 7. 检查format是否符合要求 | ||
| 303 | + CHECK_RET(CheckFormat(x, yOut, yScaleOut), ACLNN_ERR_PARAM_INVALID); | ||
| 304 | + | ||
| 305 | + // 8. 检查x和输出的shape维度是否符合约束 | ||
| 306 | + CHECK_RET(CheckXShape(x), ACLNN_ERR_PARAM_INVALID); | ||
| 307 | + CHECK_RET(CheckOutShape(x, yOut, yScaleOut), ACLNN_ERR_PARAM_INVALID); | ||
| 308 | + return ACLNN_SUCCESS; | ||
| 309 | +} | ||
| 310 | +} // namespace | ||
| 311 | + | ||
| 312 | +aclnnStatus aclnnDequantSituQuantGetWorkspaceSize( | ||
| 313 | + const aclTensor* x, const aclTensor* weightScaleOptional, const aclTensor* activationScaleOptional, | ||
| 314 | + const aclTensor* biasOptional, const aclTensor* quantScaleOptional, const aclTensor* quantOffsetOptional, | ||
| 315 | + const aclTensor* groupIndexOptional, double beta, double linearBeta, bool activateLeft, char* quantTypeOptional, | ||
| 316 | + const aclTensor* yOut, const aclTensor* yScaleOut, uint64_t* workspaceSize, aclOpExecutor** executor) | ||
| 317 | +{ | ||
| 318 | + OP_CHECK_COMM_INPUT(workspaceSize, executor); | ||
| 319 | + auto ret = CheckParams(x, weightScaleOptional, activationScaleOptional, biasOptional, quantScaleOptional, | ||
| 320 | + quantOffsetOptional, groupIndexOptional, beta, quantTypeOptional, yOut, yScaleOut); | ||
| 321 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 322 | + return aclnnInnerDequantSituQuantGetWorkspaceSize(x, weightScaleOptional, activationScaleOptional, biasOptional, | ||
| 323 | + quantScaleOptional, quantOffsetOptional, groupIndexOptional, beta, | ||
| 324 | + linearBeta, activateLeft, quantTypeOptional, yOut, yScaleOut, | ||
| 325 | + workspaceSize, executor); | ||
| 326 | +} | ||
| 327 | + | ||
| 328 | +aclnnStatus aclnnDequantSituQuant(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream) | ||
| 329 | +{ | ||
| 330 | + return aclnnInnerDequantSituQuant(workspace, workspaceSize, executor, stream); | ||
| 331 | +} | ||
| 332 | + | ||
| 333 | +#ifdef __cplusplus | ||
| 334 | +} | ||
| 335 | +#endif | ||
| @@ -0,0 +1,77 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#ifndef OP_API_INC_DEQUANT_SITU_QUANT_H_ | ||
| 12 | +#define OP_API_INC_DEQUANT_SITU_QUANT_H_ | ||
| 13 | + | ||
| 14 | +#include "aclnn/aclnn_base.h" | ||
| 15 | +#include "aclnn_util.h" | ||
| 16 | + | ||
| 17 | +#ifdef __cplusplus | ||
| 18 | +extern "C" { | ||
| 19 | +#endif | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @brief aclnnDequantSituQuant的第一段接口,根据具体的计算流程,计算workspace大小。 | ||
| 23 | + * @domain aclnn_ops_infer | ||
| 24 | + * | ||
| 25 | + * 算子功能:在Situ激活函数前后添加dequant和quant操作,实现x的DequantSituQuant计算。 | ||
| 26 | + * 计算流程为:反量化 -> Situ激活 -> 量化。 | ||
| 27 | + * | ||
| 28 | + * @param [in] x: npu device侧的aclTensor,数据类型支持INT8、INT32、BFLOAT16、FLOAT16,数据格式支持ND, | ||
| 29 | + * 不支持空Tensor。x为INT8时维度为2-8维,为INT32/BFLOAT16/FLOAT16时维度为2维,最后一维需要是2的倍数。 | ||
| 30 | + * @param [in] weightScaleOptional: npu device侧的aclTensor,反量化的weight scale,数据类型FLOAT,数据格式ND, | ||
| 31 | + * shape为(2H,)或(1,)。INT8和INT32必选,BFLOAT16/FLOAT16不使用。 | ||
【review】 问题分类:可读性 位置:quant/dequant_situ_quant/op_host/op_api/aclnn_dequant_situ_quant.h:31,代码:* shape为(2H,)或(1,)。INT8和INT32必选,BFLOAT16/FLOAT16不使用。 问题:新头文件把 weightScaleOptional 的 (2H,) 或 (1,) 也写成 INT32 分组模式的合法 shape。当传入 groupIndex 时,INT32 tiling 的检查要求权重 scale 和已提供的 bias 为 [专家数,2H],一维 [2H] 会被拒绝。另外,第 33 行把 INT32 activationScale 限为 [1],现有 tiling 和 kernel 还支持每行一个值。 可能导致的结果:例如 x 为 INT32 [4,64]、groupIndex 有 2 个元素时,调用方按头文件给 weightScale=[64] 会在 tiling 失败,实际需要 [2,64]。每行不同的 activationScale 也无法从头文件中得知。 建议的修改方法:在头文件和中英文参数表补齐 INT32 的分组分支。传 groupIndex 时明确 weightScale 和可选 bias 为 [专家数,2H],并列出 activationScale 可用的标量和逐行形状。 ![]() ![]() | |||
| 32 | + * @param [in] activationScaleOptional: npu device侧的aclTensor,反量化的activation scale,数据类型FLOAT, | ||
| 33 | + * 数据格式ND,shape为(1,)。仅INT32必选,其他数据类型不使用。 | ||
| 34 | + * @param [in] biasOptional: npu device侧的aclTensor,反量化的bias,数据类型FLOAT,数据格式ND, | ||
| 35 | + * shape为(2H,)或(1,)。INT8和INT32可选,BFLOAT16/FLOAT16不使用。 | ||
| 36 | + * @param [in] quantScaleOptional: npu device侧的aclTensor,量化的scale,数据类型FLOAT,数据格式ND, | ||
| 37 | + * shape为(H,)或(1,)。quantTypeOptional为static时必选;为dynamic时可选,作为smooth scale使用。仅INT8使用。 | ||
| 38 | + * @param [in] quantOffsetOptional: npu device侧的aclTensor,量化的offset,数据类型FLOAT,数据格式ND, | ||
| 39 | + * shape同quantScaleOptional。仅static量化使用且为可选输入,缺省时按0处理;dynamic时不使用,须为空。 | ||
| 40 | + * @param [in] groupIndexOptional: npu device侧的aclTensor,MoE分组的group index,数据类型INT64,数据格式ND, | ||
| 41 | + * 1维tensor。INT32/BFLOAT16/FLOAT16可选,INT8不使用。 | ||
| 42 | + * @param [in] beta: host侧的double类型,Situ激活的beta参数,不能为0,默认4.0。 | ||
| 43 | + * @param [in] linearBeta: host侧的double类型,Situ激活的linear_beta参数,当值<=0时不启用,默认25.0。 | ||
| 44 | + * @param [in] activateLeft: host侧的bool类型,是否对输入的左半部分做Situ激活,默认true。 | ||
| 45 | + * @param [in] quantTypeOptional: host侧的char*类型,量化模式,仅支持{"static", "dynamic"},传入nullptr时按默认值 | ||
| 46 | + * "dynamic"处理。 | ||
| 47 | + * @param [out] yOut: npu device侧的aclTensor,量化后的输出,数据类型INT8,数据格式ND,不支持空Tensor。 | ||
| 48 | + * INT8时shape为x.shape[:-1]+[H];其他数据类型时shape为[M, H]。其中H=x.shape[-1]/2。 | ||
| 49 | + * @param [out] yScaleOut: npu device侧的aclTensor,动态量化的scale,数据类型FLOAT,数据格式ND,不支持空Tensor。 | ||
| 50 | + * INT8时shape为x.shape[:-1];其他数据类型时shape为[M]。quantTypeOptional为static时输出无意义值。 | ||
| 51 | + * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。 | ||
| 52 | + * @param [out] executor: 返回op执行器,包含了算子计算流程。 | ||
| 53 | + * @return aclnnStatus: 返回状态码 | ||
| 54 | + */ | ||
| 55 | +ACLNN_API aclnnStatus aclnnDequantSituQuantGetWorkspaceSize( | ||
| 56 | + const aclTensor* x, const aclTensor* weightScaleOptional, const aclTensor* activationScaleOptional, | ||
| 57 | + const aclTensor* biasOptional, const aclTensor* quantScaleOptional, const aclTensor* quantOffsetOptional, | ||
| 58 | + const aclTensor* groupIndexOptional, double beta, double linearBeta, bool activateLeft, char* quantTypeOptional, | ||
🟡 Medium Priority 变更行:新头文件 line 58 声明 受影响契约:这是对既有公开 aclnn 导出符号 失败模式:若原先生成头(或已安装的 toolkit 建议:核对 opbuild 生成的/官方 toolkit 的 aclnn 头中 beta、linearBeta 的实际类型:若原为 float,则本头必须保持 float(保持既有 ABI);若确为 double,则把 docs/aclnnDequantSituQuant.md 与 _en.md 的函数原型同步改为 double,使头文件与文档一致。 ![]() ![]() Incorrect? | |||
| 59 | + const aclTensor* yOut, const aclTensor* yScaleOut, uint64_t* workspaceSize, aclOpExecutor** executor); | ||
| 60 | + | ||
| 61 | +/** | ||
| 62 | + * @brief aclnnDequantSituQuant的第二段接口,用于执行计算。 | ||
| 63 | + * | ||
| 64 | + * @param [in] workspace: 在npu device侧申请的workspace内存起址。 | ||
| 65 | + * @param [in] workspaceSize: 在npu device侧申请的workspace大小,由第一段接口获取。 | ||
| 66 | + * @param [in] executor: op执行器,包含了算子计算流程。 | ||
| 67 | + * @param [in] stream: acl stream流。 | ||
| 68 | + * @return aclnnStatus: 返回状态码 | ||
| 69 | + */ | ||
| 70 | +ACLNN_API aclnnStatus aclnnDequantSituQuant(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, | ||
| 71 | + aclrtStream stream); | ||
| 72 | + | ||
| 73 | +#ifdef __cplusplus | ||
| 74 | +} | ||
| 75 | +#endif | ||
| 76 | + | ||
| 77 | +#endif // OP_API_INC_DEQUANT_SITU_QUANT_H_ | ||
| @@ -0,0 +1,531 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | +#include <vector> | ||
| 11 | + | ||
| 12 | +#include "gtest/gtest.h" | ||
| 13 | +#include "../../../op_host/op_api/aclnn_dequant_situ_quant.h" | ||
| 14 | +#include "op_api_ut_common/op_api_ut.h" | ||
| 15 | +#include "op_api_ut_common/tensor_desc.h" | ||
| 16 | + | ||
| 17 | +using namespace std; | ||
| 18 | + | ||
| 19 | +class l2_dequant_situ_quant_test : public testing::Test { | ||
| 20 | +protected: | ||
| 21 | + static void SetUpTestCase() { cout << "l2_dequant_situ_quant_test SetUp" << endl; } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() { cout << "l2_dequant_situ_quant_test TearDown" << endl; } | ||
| 24 | +}; | ||
| 25 | + | ||
| 26 | +// issue 8380: x为空指针 | ||
| 27 | +TEST_F(l2_dequant_situ_quant_test, x_nullptr) | ||
| 28 | +{ | ||
| 29 | + auto weight_scale_desc = TensorDesc({64}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 30 | + auto quant_scale_desc = TensorDesc({1}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 31 | + auto y_desc = TensorDesc({16, 32}, ACL_INT8, ACL_FORMAT_ND); | ||
| 32 | + auto y_scale_desc = TensorDesc({16}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 33 | + const float beta = 4.0f; | ||
| 34 | + const float linear_beta = 25.0f; | ||
| 35 | + const bool activate_left = true; | ||
| 36 | + char* quant_type = const_cast<char*>("static"); | ||
| 37 | + | ||
| 38 | + auto ut = OP_API_UT( | ||
| 39 | + aclnnDequantSituQuant, | ||
| 40 | + INPUT((aclTensor*)nullptr, weight_scale_desc, (aclTensor*)nullptr, (aclTensor*)nullptr, quant_scale_desc, | ||
| 41 | + (aclTensor*)nullptr, (aclTensor*)nullptr, beta, linear_beta, activate_left, quant_type), | ||
| 42 | + OUTPUT(y_desc, y_scale_desc)); | ||
| 43 | + uint64_t workspace_size = 0; | ||
| 44 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 45 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +// issue 8380: yOut为空指针 | ||
| 49 | +TEST_F(l2_dequant_situ_quant_test, y_nullptr) | ||
| 50 | +{ | ||
| 51 | + auto x_desc = TensorDesc({16, 64}, ACL_INT8, ACL_FORMAT_ND); | ||
| 52 | + auto weight_scale_desc = TensorDesc({64}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 53 | + auto quant_scale_desc = TensorDesc({1}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 54 | + auto y_scale_desc = TensorDesc({16}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 55 | + const float beta = 4.0f; | ||
| 56 | + const float linear_beta = 25.0f; | ||
| 57 | + const bool activate_left = true; | ||
| 58 | + char* quant_type = const_cast<char*>("static"); | ||
| 59 | + | ||
| 60 | + auto ut = OP_API_UT(aclnnDequantSituQuant, | ||
| 61 | + INPUT(x_desc, weight_scale_desc, (aclTensor*)nullptr, (aclTensor*)nullptr, quant_scale_desc, | ||
| 62 | + (aclTensor*)nullptr, (aclTensor*)nullptr, beta, linear_beta, activate_left, quant_type), | ||
| 63 | + OUTPUT((aclTensor*)nullptr, y_scale_desc)); | ||
| 64 | + uint64_t workspace_size = 0; | ||
| 65 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 66 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +// issue 8380: yScaleOut为空指针 | ||
| 70 | +TEST_F(l2_dequant_situ_quant_test, y_scale_nullptr) | ||
| 71 | +{ | ||
| 72 | + auto x_desc = TensorDesc({16, 64}, ACL_INT8, ACL_FORMAT_ND); | ||
| 73 | + auto weight_scale_desc = TensorDesc({64}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 74 | + auto quant_scale_desc = TensorDesc({1}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 75 | + auto y_desc = TensorDesc({16, 32}, ACL_INT8, ACL_FORMAT_ND); | ||
| 76 | + const float beta = 4.0f; | ||
| 77 | + const float linear_beta = 25.0f; | ||
| 78 | + const bool activate_left = true; | ||
| 79 | + char* quant_type = const_cast<char*>("static"); | ||
| 80 | + | ||
| 81 | + auto ut = OP_API_UT(aclnnDequantSituQuant, | ||
| 82 | + INPUT(x_desc, weight_scale_desc, (aclTensor*)nullptr, (aclTensor*)nullptr, quant_scale_desc, | ||
| 83 | + (aclTensor*)nullptr, (aclTensor*)nullptr, beta, linear_beta, activate_left, quant_type), | ||
| 84 | + OUTPUT(y_desc, (aclTensor*)nullptr)); | ||
| 85 | + uint64_t workspace_size = 0; | ||
| 86 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 87 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +// issue 8380: INT8时weightScaleOptional为空指针 | ||
| 91 | +TEST_F(l2_dequant_situ_quant_test, int8_weight_scale_nullptr) | ||
| 92 | +{ | ||
| 93 | + auto x_desc = TensorDesc({16, 64}, ACL_INT8, ACL_FORMAT_ND); | ||
| 94 | + auto quant_scale_desc = TensorDesc({1}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 95 | + auto y_desc = TensorDesc({16, 32}, ACL_INT8, ACL_FORMAT_ND); | ||
| 96 | + auto y_scale_desc = TensorDesc({16}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 97 | + const float beta = 4.0f; | ||
| 98 | + const float linear_beta = 25.0f; | ||
| 99 | + const bool activate_left = true; | ||
| 100 | + char* quant_type = const_cast<char*>("static"); | ||


readme是否同步修改