| @@ -96,7 +96,7 @@ aclnnStatus aclnnDequantBias( | |||
| 96 | <td>INT32</td> | 96 | <td>INT32</td> |
| 97 | <td>ND</td> | 97 | <td>ND</td> |
| 98 | <td>2</td> | 98 | <td>2</td> |
| 99 | - <td>×</td> | 99 | + <td>√</td> |
| 100 | </tr> | 100 | </tr> |
| 101 | <tr> | 101 | <tr> |
| 102 | <td>weightScale(aclTensor*)</td> | 102 | <td>weightScale(aclTensor*)</td> |
| @@ -106,7 +106,7 @@ aclnnStatus aclnnDequantBias( | |||
| 106 | <td>FLOAT,BFLOAT16</td> | 106 | <td>FLOAT,BFLOAT16</td> |
| 107 | <td>ND</td> | 107 | <td>ND</td> |
| 108 | <td>1</td> | 108 | <td>1</td> |
| 109 | - <td>×</td> | 109 | + <td>√</td> |
| 110 | </tr> | 110 | </tr> |
| 111 | <tr> | 111 | <tr> |
| 112 | <td>activateScaleOptional(aclTensor*)</td> | 112 | <td>activateScaleOptional(aclTensor*)</td> |
| @@ -116,7 +116,7 @@ aclnnStatus aclnnDequantBias( | |||
| 116 | <td>FLOAT</td> | 116 | <td>FLOAT</td> |
| 117 | <td>ND</td> | 117 | <td>ND</td> |
| 118 | <td>1</td> | 118 | <td>1</td> |
| 119 | - <td>×</td> | 119 | + <td>√</td> |
| 120 | </tr> | 120 | </tr> |
| 121 | <tr> | 121 | <tr> |
| 122 | <td>biasOptional(aclTensor*)</td> | 122 | <td>biasOptional(aclTensor*)</td> |
| @@ -126,7 +126,7 @@ aclnnStatus aclnnDequantBias( | |||
| 126 | <td>FLOAT,BFLOAT16,FLOAT16,INT32</td> | 126 | <td>FLOAT,BFLOAT16,FLOAT16,INT32</td> |
| 127 | <td>ND</td> | 127 | <td>ND</td> |
| 128 | <td>1</td> | 128 | <td>1</td> |
| 129 | - <td>×</td> | 129 | + <td>√</td> |
| 130 | </tr> | 130 | </tr> |
| 131 | <tr> | 131 | <tr> |
| 132 | <td>outputDtype(int64_t)</td> | 132 | <td>outputDtype(int64_t)</td> |
| @@ -146,7 +146,7 @@ aclnnStatus aclnnDequantBias( | |||
| 146 | <td>FLOAT16、BFLOAT16</td> | 146 | <td>FLOAT16、BFLOAT16</td> |
| 147 | <td>ND</td> | 147 | <td>ND</td> |
| 148 | <td>2</td> | 148 | <td>2</td> |
| 149 | - <td>×</td> | 149 | + <td>√</td> |
| 150 | </tr> | 150 | </tr> |
| 151 | <tr> | 151 | <tr> |
| 152 | <td>workspaceSize(uint64_t*)</td> | 152 | <td>workspaceSize(uint64_t*)</td> |
| @@ -98,7 +98,7 @@ aclnnStatus aclnnDequantBias( | |||
| 98 | <td>INT32</td> | 98 | <td>INT32</td> |
| 99 | <td>ND</td> | 99 | <td>ND</td> |
| 100 | <td>2</td> | 100 | <td>2</td> |
| 101 | - <td>×</td> | 101 | + <td>√</td> |
| 102 | </tr> | 102 | </tr> |
| 103 | <tr> | 103 | <tr> |
| 104 | <td>weightScale (aclTensor*)</td> | 104 | <td>weightScale (aclTensor*)</td> |
| @@ -108,7 +108,7 @@ aclnnStatus aclnnDequantBias( | |||
| 108 | <td>FLOAT, BFLOAT16</td> | 108 | <td>FLOAT, BFLOAT16</td> |
| 109 | <td>ND</td> | 109 | <td>ND</td> |
| 110 | <td>1</td> | 110 | <td>1</td> |
| 111 | - <td>×</td> | 111 | + <td>√</td> |
| 112 | </tr> | 112 | </tr> |
| 113 | <tr> | 113 | <tr> |
| 114 | <td>activateScaleOptional (aclTensor*)</td> | 114 | <td>activateScaleOptional (aclTensor*)</td> |
| @@ -118,7 +118,7 @@ aclnnStatus aclnnDequantBias( | |||
| 118 | <td>FLOAT</td> | 118 | <td>FLOAT</td> |
| 119 | <td>ND</td> | 119 | <td>ND</td> |
| 120 | <td>1</td> | 120 | <td>1</td> |
| 121 | - <td>×</td> | 121 | + <td>√</td> |
| 122 | </tr> | 122 | </tr> |
| 123 | <tr> | 123 | <tr> |
| 124 | <td>biasOptional (aclTensor*)</td> | 124 | <td>biasOptional (aclTensor*)</td> |
| @@ -128,7 +128,7 @@ aclnnStatus aclnnDequantBias( | |||
| 128 | <td>FLOAT, BFLOAT16, FLOAT16, INT32</td> | 128 | <td>FLOAT, BFLOAT16, FLOAT16, INT32</td> |
| 129 | <td>ND</td> | 129 | <td>ND</td> |
| 130 | <td>1</td> | 130 | <td>1</td> |
| 131 | - <td>×</td> | 131 | + <td>√</td> |
| 132 | </tr> | 132 | </tr> |
| 133 | <tr> | 133 | <tr> |
| 134 | <td>outputDtype (int64_t)</td> | 134 | <td>outputDtype (int64_t)</td> |
| @@ -148,7 +148,7 @@ aclnnStatus aclnnDequantBias( | |||
| 148 | <td>FLOAT16, BFLOAT16</td> | 148 | <td>FLOAT16, BFLOAT16</td> |
| 149 | <td>ND</td> | 149 | <td>ND</td> |
| 150 | <td>2</td> | 150 | <td>2</td> |
| 151 | - <td>×</td> | 151 | + <td>√</td> |
| 152 | </tr> | 152 | </tr> |
| 153 | <tr> | 153 | <tr> |
| 154 | <td>workspaceSize (uint64_t*)</td> | 154 | <td>workspaceSize (uint64_t*)</td> |
| @@ -9,4 +9,4 @@ | |||
| 9 | 9 | ||
| 10 | message(STATUS "=== Debug: start dequant.bias.op_host.CMakeLists.txt ") | 10 | message(STATUS "=== Debug: start dequant.bias.op_host.CMakeLists.txt ") |
| 11 | 11 | ||
| 12 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE dequant_bias ACLNNTYPE aclnn) | 12 | +add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE dequant_bias ACLNNTYPE aclnn_exclude) |
| @@ -28,7 +28,8 @@ public: | |||
| 28 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 28 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 29 | ge::FORMAT_ND, ge::FORMAT_ND}) | 29 | ge::FORMAT_ND, ge::FORMAT_ND}) |
| 30 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 30 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 31 | - ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 31 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) |
| 32 | + .AutoContiguous(); | ||
| 32 | this->Input("weight_scale") | 33 | this->Input("weight_scale") |
| 33 | .ParamType(REQUIRED) | 34 | .ParamType(REQUIRED) |
| 34 | .DataType({ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, | 35 | .DataType({ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, |
| @@ -36,7 +37,8 @@ public: | |||
| 36 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 37 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 37 | ge::FORMAT_ND, ge::FORMAT_ND}) | 38 | ge::FORMAT_ND, ge::FORMAT_ND}) |
| 38 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 39 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 39 | - ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 40 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) |
| 41 | + .AutoContiguous(); | ||
| 40 | this->Input("activate_scale") | 42 | this->Input("activate_scale") |
| 41 | .ParamType(OPTIONAL) | 43 | .ParamType(OPTIONAL) |
| 42 | .DataType({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, | 44 | .DataType({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, |
| @@ -44,7 +46,8 @@ public: | |||
| 44 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 46 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 45 | ge::FORMAT_ND, ge::FORMAT_ND}) | 47 | ge::FORMAT_ND, ge::FORMAT_ND}) |
| 46 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 48 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 47 | - ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 49 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) |
| 50 | + .AutoContiguous(); | ||
| 48 | this->Input("bias") | 51 | this->Input("bias") |
| 49 | .ParamType(OPTIONAL) | 52 | .ParamType(OPTIONAL) |
| 50 | .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32, ge::DT_BF16, ge::DT_FLOAT16, | 53 | .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32, ge::DT_BF16, ge::DT_FLOAT16, |
| @@ -52,7 +55,8 @@ public: | |||
| 52 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 55 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 53 | ge::FORMAT_ND, ge::FORMAT_ND}) | 56 | ge::FORMAT_ND, ge::FORMAT_ND}) |
| 54 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 57 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 55 | - ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 58 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) |
| 59 | + .AutoContiguous(); | ||
| 56 | this->Output("y") | 60 | this->Output("y") |
| 57 | .ParamType(REQUIRED) | 61 | .ParamType(REQUIRED) |
| 58 | .DataType({ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT16, | 62 | .DataType({ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT16, |
| @@ -60,7 +64,8 @@ public: | |||
| 60 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 64 | .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 61 | ge::FORMAT_ND, ge::FORMAT_ND}) | 65 | ge::FORMAT_ND, ge::FORMAT_ND}) |
| 62 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | 66 | .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, |
| 63 | - ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | 67 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) |
| 68 | + .AutoContiguous(); | ||
🟡 Medium Priority 改动:
建议:合入前用 #8693 复现脚本在 ascend910b 与 ascend950 验证非连续出参按 stride 读回与基线逐元素一致;若自动生成层不做出参 view 回写,则改为 host 侧显式返回 161002 并保留资料 ×,或补手写 op_host/op_api 实现连续化后回写。 ![]() ![]() Incorrect? | |||
| 64 | this->Attr("output_dtype").AttrType(REQUIRED).Int(); // 输出类型,传入 | 69 | this->Attr("output_dtype").AttrType(REQUIRED).Int(); // 输出类型,传入 |
| 65 | this->AICore().AddConfig("ascend910b"); | 70 | this->AICore().AddConfig("ascend910b"); |
| 66 | this->AICore().AddConfig("ascend910_93"); | 71 | this->AICore().AddConfig("ascend910_93"); |
| @@ -0,0 +1,151 @@ | |||
| 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 "aclnn_dequant_bias.h" | ||
| 11 | +#include "dequant_bias.h" | ||
| 12 | +#include "aclnn_kernels/contiguous.h" | ||
| 13 | +#include "aclnn_kernels/common/op_error_check.h" | ||
| 14 | +#include "aclnn/aclnn_base.h" | ||
| 15 | +#include "opdev/common_types.h" | ||
| 16 | +#include "opdev/format_utils.h" | ||
| 17 | +#include "opdev/shape_utils.h" | ||
| 18 | +#include "opdev/op_dfx.h" | ||
| 19 | +#include "opdev/op_executor.h" | ||
| 20 | +#include "opdev/op_log.h" | ||
| 21 | +#include "opdev/data_type_utils.h" | ||
| 22 | +#include "opdev/tensor_view_utils.h" | ||
| 23 | +#include "opdev/make_op_executor.h" | ||
| 24 | + | ||
| 25 | +using namespace op; | ||
| 26 | +#ifdef __cplusplus | ||
| 27 | +extern "C" { | ||
| 28 | +#endif | ||
| 29 | + | ||
| 30 | +static const std::initializer_list<op::DataType> DTYPE_SUPPORT_X_LIST = {op::DataType::DT_INT32}; | ||
| 31 | +static const std::initializer_list<op::DataType> DTYPE_SUPPORT_WS_LIST = {op::DataType::DT_FLOAT, | ||
| 32 | + op::DataType::DT_BF16}; | ||
| 33 | +static const std::initializer_list<op::DataType> DTYPE_SUPPORT_AS_LIST = {op::DataType::DT_FLOAT}; | ||
| 34 | +static const std::initializer_list<op::DataType> DTYPE_SUPPORT_BIAS_LIST = { | ||
| 35 | + op::DataType::DT_FLOAT, op::DataType::DT_BF16, op::DataType::DT_FLOAT16, op::DataType::DT_INT32}; | ||
| 36 | +static const std::initializer_list<op::DataType> DTYPE_SUPPORT_OUT_LIST = {op::DataType::DT_FLOAT16, | ||
| 37 | + op::DataType::DT_BF16}; | ||
| 38 | + | ||
| 39 | +static bool CheckNotNull(const aclTensor* x, const aclTensor* weightScale, const aclTensor* activateScale, | ||
| 40 | + const aclTensor* bias, const aclTensor* out) | ||
| 41 | +{ | ||
| 42 | + OP_CHECK_NULL(x, return false); | ||
| 43 | + OP_CHECK_NULL(weightScale, return false); | ||
| 44 | + OP_CHECK_NULL(out, return false); | ||
| 45 | + return true; | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +static bool CheckDtypeValid(const aclTensor* x, const aclTensor* weightScale, const aclTensor* activateScale, | ||
| 49 | + const aclTensor* bias, const aclTensor* out) | ||
| 50 | +{ | ||
| 51 | + OP_CHECK_DTYPE_NOT_SUPPORT(x, DTYPE_SUPPORT_X_LIST, return false); | ||
| 52 | + OP_CHECK_DTYPE_NOT_SUPPORT(weightScale, DTYPE_SUPPORT_WS_LIST, return false); | ||
| 53 | + if (activateScale != nullptr) { | ||
| 54 | + OP_CHECK_DTYPE_NOT_SUPPORT(activateScale, DTYPE_SUPPORT_AS_LIST, return false); | ||
| 55 | + } | ||
| 56 | + if (bias != nullptr) { | ||
| 57 | + OP_CHECK_DTYPE_NOT_SUPPORT(bias, DTYPE_SUPPORT_BIAS_LIST, return false); | ||
| 58 | + } | ||
| 59 | + OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_OUT_LIST, return false); | ||
| 60 | + return true; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +static bool CheckOutputDtypeValid(int64_t outputDtype) | ||
| 64 | +{ | ||
| 65 | + OP_CHECK( | ||
| 66 | + outputDtype == 1 || outputDtype == 27, | ||
| 67 | + OP_LOGE(ACLNN_ERR_PARAM_INVALID, "outputDtype should be 1 (FLOAT16) or 27 (BFLOAT16), got %ld.", outputDtype), | ||
| 68 | + return false); | ||
| 69 | + return true; | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +static bool CheckShape(const aclTensor* x, const aclTensor* out) | ||
| 73 | +{ | ||
| 74 | + // out 的 view shape 必须与 x 一致(kernel 按 x 的 [M, N] 生成输出) | ||
| 75 | + OP_CHECK_SHAPE_NOT_EQUAL(x, out, return false); | ||
| 76 | + return true; | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +static aclnnStatus CheckParams(const aclTensor* x, const aclTensor* weightScale, const aclTensor* activateScale, | ||
| 80 | + const aclTensor* bias, int64_t outputDtype, const aclTensor* out) | ||
| 81 | +{ | ||
| 82 | + CHECK_RET(CheckNotNull(x, weightScale, activateScale, bias, out), ACLNN_ERR_PARAM_NULLPTR); | ||
| 83 | + CHECK_RET(CheckDtypeValid(x, weightScale, activateScale, bias, out), ACLNN_ERR_PARAM_INVALID); | ||
| 84 | + CHECK_RET(CheckOutputDtypeValid(outputDtype), ACLNN_ERR_PARAM_INVALID); | ||
| 85 | + CHECK_RET(CheckShape(x, out), ACLNN_ERR_PARAM_INVALID); | ||
| 86 | + return ACLNN_SUCCESS; | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +aclnnStatus aclnnDequantBiasGetWorkspaceSize(const aclTensor* x, const aclTensor* weightScale, | ||
| 90 | + const aclTensor* activateScaleOptional, const aclTensor* biasOptional, | ||
| 91 | + int64_t outputDtype, const aclTensor* out, uint64_t* workspaceSize, | ||
| 92 | + aclOpExecutor** executor) | ||
| 93 | +{ | ||
| 94 | + OP_CHECK_COMM_INPUT(workspaceSize, executor); | ||
| 95 | + | ||
| 96 | + L2_DFX_PHASE_1(aclnnDequantBias, DFX_IN(x, weightScale, activateScaleOptional, biasOptional), DFX_OUT(out)); | ||
| 97 | + | ||
| 98 | + auto uniqueExecutor = CREATE_EXECUTOR(); | ||
| 99 | + CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR); | ||
| 100 | + | ||
| 101 | + auto ret = CheckParams(x, weightScale, activateScaleOptional, biasOptional, outputDtype, out); | ||
| 102 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 103 | + | ||
| 104 | + auto xContiguous = l0op::Contiguous(x, uniqueExecutor.get()); | ||
| 105 | + CHECK_RET(xContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 106 | + auto weightScaleContiguous = l0op::Contiguous(weightScale, uniqueExecutor.get()); | ||
| 107 | + CHECK_RET(weightScaleContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 108 | + const aclTensor* activateScaleContiguous = nullptr; | ||
| 109 | + if (activateScaleOptional != nullptr) { | ||
| 110 | + activateScaleContiguous = l0op::Contiguous(activateScaleOptional, uniqueExecutor.get()); | ||
| 111 | + CHECK_RET(activateScaleContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 112 | + } | ||
| 113 | + const aclTensor* biasContiguous = nullptr; | ||
| 114 | + if (biasOptional != nullptr) { | ||
| 115 | + biasContiguous = l0op::Contiguous(biasOptional, uniqueExecutor.get()); | ||
| 116 | + CHECK_RET(biasContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + // 输出out连续且 storage 与 view 一致、dtype 与 outputDtype 推导一致时, | ||
| 120 | + // 直接绑定 out 作为 kernel 输出(kernel 直接写入调用方内存); | ||
| 121 | + // 非连续时先算到连续张量,再按 out 的 stride 回写 | ||
| 122 | + const bool directOut = IsContiguous(out) && out->GetStorageShape() == out->GetViewShape() && | ||
[Major] 新增的 agent检视,通过wangzitao_leo提交 ![]() ![]() | |||
| 123 | + ((outputDtype == 1 && out->GetDataType() == op::DataType::DT_FLOAT16) || | ||
| 124 | + (outputDtype == 27 && out->GetDataType() == op::DataType::DT_BF16)); | ||
| 125 | + const aclTensor* dequantBiasOut = nullptr; | ||
| 126 | + if (directOut) { | ||
| 127 | + dequantBiasOut = l0op::DequantBias(xContiguous, weightScaleContiguous, activateScaleContiguous, biasContiguous, | ||
| 128 | + outputDtype, uniqueExecutor.get(), out); | ||
| 129 | + CHECK_RET(dequantBiasOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 130 | + } else { | ||
| 131 | + dequantBiasOut = l0op::DequantBias(xContiguous, weightScaleContiguous, activateScaleContiguous, biasContiguous, | ||
| 132 | + outputDtype, uniqueExecutor.get()); | ||
| 133 | + CHECK_RET(dequantBiasOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 134 | + auto viewCopyResult = l0op::ViewCopy(dequantBiasOut, out, uniqueExecutor.get()); | ||
| 135 | + CHECK_RET(viewCopyResult != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + *workspaceSize = uniqueExecutor->GetWorkspaceSize(); | ||
| 139 | + uniqueExecutor.ReleaseTo(executor); | ||
| 140 | + return ACLNN_SUCCESS; | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +aclnnStatus aclnnDequantBias(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, const aclrtStream stream) | ||
| 144 | +{ | ||
| 145 | + L2_DFX_PHASE_2(aclnnDequantBias); | ||
| 146 | + return CommonOpExecutorRun(workspace, workspaceSize, executor, stream); | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +#ifdef __cplusplus | ||
| 150 | +} | ||
| 151 | +#endif | ||
| @@ -0,0 +1,85 @@ | |||
| 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 | +#ifndef OP_API_INC_ACLNN_DEQUANT_BIAS_H_ | ||
| 11 | +#define OP_API_INC_ACLNN_DEQUANT_BIAS_H_ | ||
| 12 | + | ||
| 13 | +#include "aclnn/aclnn_base.h" | ||
| 14 | +#include "aclnn_util.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @brief aclnnDequantBias的第一段接口,根据具体的计算流程,计算workspace大小。 | ||
| 22 | + * @domain aclnn_ops_infer | ||
| 23 | + * | ||
| 24 | + * 算子功能:反量化偏置叠加: | ||
| 25 | + * $$ | ||
| 26 | + * y = A \times weightScale \times activateScale | ||
| 27 | + * $$ | ||
| 28 | + * (无 bias) | ||
| 29 | + * $$ | ||
| 30 | + * y = (A + bias) \times weightScale \times activateScale | ||
【review】
问题分类:正确性
位置:quant/dequant_bias/op_host/op_api/aclnn_dequant_bias.h:26,代码:* y = (A + bias) \times weightScale \times activateScale
问题:新头文件把 bias 一律写成反量化前加。实际 INT32 bias 在乘缩放因子前加,FLOAT、FLOAT16 和 BFLOAT16 bias 在两次缩放后加。arch22 的 ![]() ![]() | |||
| 31 | + * $$ | ||
| 32 | + * (bias 为 INT32 时,先加 bias 再缩放) | ||
| 33 | + * $$ | ||
| 34 | + * y = A \times weightScale \times activateScale + bias | ||
| 35 | + * $$ | ||
| 36 | + * (bias 为 FLOAT、FLOAT16、BFLOAT16 时,先缩放再加 bias; | ||
| 37 | + * activateScale 缺省时按 1 处理) | ||
| 38 | + * | ||
| 39 | + * 实现说明: | ||
| 40 | + * api计算的基本路径: | ||
| 41 | + * ```mermaid | ||
| 42 | + * graph LR | ||
| 43 | + * A[(x, weightScale, activateScale, bias)] -->B([L0::Contiguous]) | ||
| 44 | + * B --> C([L0::DequantBias]) | ||
| 45 | + * C --> D([L0::ViewCopy]) | ||
| 46 | + * D --> E[(out)] | ||
| 47 | + * ``` | ||
| 48 | + * | ||
| 49 | + * @param [in] x: device侧的aclTensor,shape为[M, N],数据类型支持INT32,支持非连续的Tensor。 | ||
| 50 | + * @param [in] weightScale: device侧的aclTensor,shape为[N],长度与x的N维长度一致, | ||
| 51 | + * 数据类型支持FLOAT、BFLOAT16,支持非连续的Tensor。 | ||
| 52 | + * @param [in] activateScaleOptional: device侧的aclTensor,shape为[M],长度与x的M维长度一致, | ||
| 53 | + * 数据类型支持FLOAT,支持非连续的Tensor。可选输入,传入nullptr时视为不参与计算。 | ||
| 54 | + * @param [in] biasOptional: device侧的aclTensor,shape为[N],长度与x的N维长度一致, | ||
| 55 | + * 数据类型支持FLOAT、BFLOAT16、FLOAT16、INT32,支持非连续的Tensor。可选输入,传入nullptr时视为不参与计算。 | ||
| 56 | + * @param [in] outputDtype: 表示输出out的数据类型,值为1表示FLOAT16,值为27表示BFLOAT16。 | ||
| 57 | + * 当weightScale数据类型为FLOAT时该参数配置为1,为BFLOAT16时配置为27。 | ||
| 58 | + * @param [in] out: device侧的aclTensor,shape为[M, N],数据类型支持FLOAT16、BFLOAT16,支持非连续的Tensor。 | ||
| 59 | + * @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。 | ||
| 60 | + * @param [out] executor: 返回op执行器,包含算子计算流程。 | ||
| 61 | + * @return aclnnStatus: 返回状态码。 | ||
| 62 | + */ | ||
| 63 | +ACLNN_API aclnnStatus aclnnDequantBiasGetWorkspaceSize(const aclTensor* x, const aclTensor* weightScale, | ||
| 64 | + const aclTensor* activateScaleOptional, | ||
| 65 | + const aclTensor* biasOptional, int64_t outputDtype, | ||
| 66 | + const aclTensor* out, uint64_t* workspaceSize, | ||
| 67 | + aclOpExecutor** executor); | ||
| 68 | + | ||
| 69 | +/** | ||
| 70 | + * @brief aclnnDequantBias的第二段接口,用于执行计算。 | ||
| 71 | + * | ||
| 72 | + * @param [in] workspace: 在npu device侧申请的workspace内存起址。 | ||
| 73 | + * @param [in] workspaceSize: 在npu device侧申请的workspace大小,由第一段接口获取。 | ||
| 74 | + * @param [in] executor: op执行器,包含了算子计算流程。 | ||
| 75 | + * @param [in] stream: acl stream流。 | ||
| 76 | + * @return aclnnStatus: 返回状态码。 | ||
| 77 | + */ | ||
| 78 | +ACLNN_API aclnnStatus aclnnDequantBias(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, | ||
| 79 | + const aclrtStream stream); | ||
| 80 | + | ||
| 81 | +#ifdef __cplusplus | ||
| 82 | +} | ||
| 83 | +#endif | ||
| 84 | + | ||
| 85 | +#endif // OP_API_INC_ACLNN_DEQUANT_BIAS_H_ | ||
| @@ -0,0 +1,44 @@ | |||
| 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 "dequant_bias.h" | ||
| 11 | +#include "opdev/make_op_executor.h" | ||
| 12 | +#include "opdev/op_def.h" | ||
| 13 | +#include "opdev/op_dfx.h" | ||
| 14 | +#include "opdev/op_log.h" | ||
| 15 | + | ||
| 16 | +using namespace op; | ||
| 17 | + | ||
| 18 | +namespace l0op { | ||
| 19 | + | ||
| 20 | +OP_TYPE_REGISTER(DequantBias); | ||
| 21 | + | ||
| 22 | +const aclTensor* DequantBias(const aclTensor* x, const aclTensor* weightScale, const aclTensor* activateScale, | ||
| 23 | + const aclTensor* bias, int64_t outputDtype, aclOpExecutor* executor, const aclTensor* out) | ||
| 24 | +{ | ||
| 25 | + L0_DFX(DequantBias, x, weightScale, activateScale, bias, outputDtype); | ||
| 26 | + DataType outputDataType = (outputDtype == 1) ? DataType::DT_FLOAT16 : DataType::DT_BF16; | ||
| 27 | + const aclTensor* outTensor = out; | ||
| 28 | + if (outTensor == nullptr) { | ||
| 29 | + auto outputShape = x->GetViewShape(); | ||
| 30 | + outTensor = executor->AllocTensor(outputShape, outputDataType, Format::FORMAT_ND); | ||
| 31 | + if (outTensor == nullptr) { | ||
| 32 | + return nullptr; | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + auto ret = ADD_TO_LAUNCHER_LIST_AICORE(DequantBias, OP_INPUT(x, weightScale, activateScale, bias), | ||
| 36 | + OP_OUTPUT(outTensor), OP_ATTR(outputDtype)); | ||
| 37 | + if (ret != ACLNN_SUCCESS) { | ||
| 38 | + OP_LOGE(ACLNN_ERR_INNER_STATIC_WORKSPACE_INVALID, "DequantBias launch failed."); | ||
| 39 | + return nullptr; | ||
| 40 | + } | ||
| 41 | + return outTensor; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +} // namespace l0op | ||
| @@ -0,0 +1,23 @@ | |||
| 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 | +#ifndef OP_API_DEQUANT_BIAS_H_ | ||
| 11 | +#define OP_API_DEQUANT_BIAS_H_ | ||
| 12 | + | ||
| 13 | +#include "opdev/op_executor.h" | ||
| 14 | + | ||
| 15 | +namespace l0op { | ||
| 16 | + | ||
| 17 | +const aclTensor* DequantBias(const aclTensor* x, const aclTensor* weightScale, const aclTensor* activateScale, | ||
| 18 | + const aclTensor* bias, int64_t outputDtype, aclOpExecutor* executor, | ||
| 19 | + const aclTensor* out = nullptr); | ||
| 20 | + | ||
| 21 | +} // namespace l0op | ||
| 22 | + | ||
| 23 | +#endif // OP_API_DEQUANT_BIAS_H_ | ||


🟡 Medium Priority
改动:
dequant_bias_def.cpp:32/41/50/59/68为 x、weight_scale、activate_scale、bias、y 全部加上.AutoContiguous(),即 aclnn 生成层不再拒绝非连续 Tensor,行为契约由「不支持」变为「支持」。 证据链:本仓quant/dequant_bias/docs/aclnnDequantBias.md、docs/aclnnDequantBias_en.md存在,而关联 issue #8693 明确记载该参数表五个参数的「非连续Tensor」列全部为 ×;本次 diff 只包含op_host/dequant_bias_def.cpp一个文件,PR 描述中却声称「文档更新:docs/aclnnDequantBias.md、aclnnDequantBias_en.md(非连续Tensor 列 ×→√,5 行×2)」——该文档改动未出现在本次变更中。 失败模式:合入后代码接受非连续输入/出参,资料仍声明 ×(不支持)。用户与下游 ST 依据资料构造用例时会认为该路径应返回 161002,而实际返回 0;反向地,若后续有人依据资料 × 再补「拒绝」校验,会与本次 AutoContiguous 直接冲突。这是本次单侧改动(只改代码不改契约文档)新引入的不一致。 修复方向:把 docs 两个文件的「非连续Tensor」列 5 行 ×→√ 一并纳入本 PR(或拆单时在描述中明确拆出并标注依赖),确保代码与资料同一提交内一致。建议:将 quant/dequant_bias/docs/aclnnDequantBias.md 与 aclnnDequantBias_en.md 中 5 个参数的「非连续Tensor」列由 × 改为 √,与本 def.cpp 改动放在同一次提交中。