已合并
【ACLNN】sacle、zeroPoint to contiguous #2714
张喻翔创建于 3月14日
【ACLNN】sacle、zeroPoint to contiguous #2714
已合并
共 4 个文件变更+101-55
Mquant/fake_quant_affine_cachemask/op_host/op_api/aclnn_fake_quant_per_channel_affine_cachemask.cpp+9-27
| @@ -15,20 +15,12 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | - | ||
| 19 | - | ||
| 20 | 18 | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | 19 | ||
| 20 | + | ||
| 30 | 21 | ||
| 31 | using namespace op; | 22 | using namespace op; |
| 23 | +using namespace FakeQuantCommon; | ||
| 32 | 24 | ||
| 33 | extern "C" { | 25 | extern "C" { |
| 34 | 26 | ||
| @@ -195,30 +187,20 @@ aclnnStatus aclnnFakeQuantPerChannelAffineCachemaskGetWorkspaceSize( | |||
| 195 | return ACLNN_SUCCESS; | 187 | return ACLNN_SUCCESS; |
| 196 | } | 188 | } |
| 197 | 189 | ||
| 198 | - auto selfContiguous = l0op::Contiguous(self, uniqueExecutor.get()); | 190 | + const auto& [selfContiguous, scaleContiguous, zeroPointContiguous] = GetContiguousInput(self, scale, zeroPoint, uniqueExecutor.get()); |
| 199 | - CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | 191 | + CHECK_RET(selfContiguous != nullptr && scaleContiguous!= nullptr && zeroPointContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 200 | 192 | ||
| 201 | - auto promoteType = op::PromoteType(self->GetDataType(), scale->GetDataType()); | 193 | + aclTensor* fakeQuantOut = nullptr, *fakeQuantMask = nullptr; |
| 202 | - // 将输入self的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 203 | - auto selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); | ||
| 204 | - CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 205 | - | ||
| 206 | - // 将输入other的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 207 | - auto scaleCasted = l0op::Cast(scale, promoteType, uniqueExecutor.get()); | ||
| 208 | - CHECK_RET(scaleCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 209 | - | ||
| 210 | - aclTensor* fakeQuantOut = nullptr; | ||
| 211 | - aclTensor* fakeQuantMask = nullptr; | ||
| 212 | if (axis != 0) { | 194 | if (axis != 0) { |
| 213 | - aclIntArray* axes = GetTransposeArray(selfCasted, axis, uniqueExecutor.get()); | 195 | + aclIntArray* axes = GetTransposeArray(selfContiguous, axis, uniqueExecutor.get()); |
| 214 | CHECK_RET(axes != nullptr, ACLNN_ERR_INNER_NULLPTR); | 196 | CHECK_RET(axes != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 215 | 197 | ||
| 216 | // 对self进行transpose | 198 | // 对self进行transpose |
| 217 | - auto selfTranspose = const_cast<aclTensor*>(l0op::Transpose(selfCasted, axes, uniqueExecutor.get())); | 199 | + auto selfTranspose = const_cast<aclTensor*>(l0op::Transpose(selfContiguous, axes, uniqueExecutor.get())); |
| 218 | CHECK_RET(selfTranspose != nullptr, ACLNN_ERR_INNER_NULLPTR); | 200 | CHECK_RET(selfTranspose != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 219 | 201 | ||
| 220 | auto result = l0op::FakeQuantAffineCachemask( | 202 | auto result = l0op::FakeQuantAffineCachemask( |
| 221 | - selfTranspose, scaleCasted, zeroPoint, quantMin, quantMax, uniqueExecutor.get()); | 203 | + selfTranspose, scaleContiguous, zeroPointContiguous, quantMin, quantMax, uniqueExecutor.get()); |
| 222 | auto fakeOut = std::get<0>(result); | 204 | auto fakeOut = std::get<0>(result); |
| 223 | auto maskOut = std::get<1>(result); | 205 | auto maskOut = std::get<1>(result); |
| 224 | CHECK_RET(fakeOut != nullptr && maskOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | 206 | CHECK_RET(fakeOut != nullptr && maskOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| @@ -230,7 +212,7 @@ aclnnStatus aclnnFakeQuantPerChannelAffineCachemaskGetWorkspaceSize( | |||
| 230 | fakeQuantMask = const_cast<aclTensor*>(l0op::Transpose(maskOut, axes, uniqueExecutor.get())); | 212 | fakeQuantMask = const_cast<aclTensor*>(l0op::Transpose(maskOut, axes, uniqueExecutor.get())); |
| 231 | } else { | 213 | } else { |
| 232 | auto result = l0op::FakeQuantAffineCachemask( | 214 | auto result = l0op::FakeQuantAffineCachemask( |
| 233 | - selfCasted, scaleCasted, zeroPoint, quantMin, quantMax, uniqueExecutor.get()); | 215 | + selfContiguous, scaleContiguous, zeroPointContiguous, quantMin, quantMax, uniqueExecutor.get()); |
| 234 | fakeQuantOut = std::get<0>(result); | 216 | fakeQuantOut = std::get<0>(result); |
| 235 | fakeQuantMask = std::get<1>(result); | 217 | fakeQuantMask = std::get<1>(result); |
| 236 | } | 218 | } |
Mquant/fake_quant_affine_cachemask/op_host/op_api/aclnn_fake_quant_per_tensor_affine_cachemask.cpp+10-28
| @@ -15,21 +15,13 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | - | ||
| 19 | - | ||
| 20 | 18 | ||
| 21 | 19 | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | 20 | ||
| 21 | + | ||
| 31 | 22 | ||
| 32 | using namespace op; | 23 | using namespace op; |
| 24 | +using namespace FakeQuantCommon; | ||
| 33 | 25 | ||
| 34 | extern "C" { | 26 | extern "C" { |
| 35 | 27 | ||
| @@ -169,38 +161,28 @@ aclnnStatus aclnnFakeQuantPerTensorAffineCachemaskGetWorkspaceSize( | |||
| 169 | return ACLNN_SUCCESS; | 161 | return ACLNN_SUCCESS; |
| 170 | } | 162 | } |
| 171 | 163 | ||
| 172 | - auto selfContiguous = l0op::Contiguous(self, uniqueExecutor.get()); | 164 | + const auto& [selfContiguous, scaleContiguous, zeroPointContiguous] = GetContiguousInput(self, scale, zeroPoint, uniqueExecutor.get()); |
| 173 | - CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | 165 | + CHECK_RET(selfContiguous != nullptr && scaleContiguous!= nullptr && zeroPointContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 174 | 166 | ||
| 175 | - auto promoteType = op::PromoteType(self->GetDataType(), scale->GetDataType()); | 167 | + aclTensor* fakeQuantOut = nullptr, *fakeQuantMask = nullptr; |
| 176 | - // 将输入self的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 177 | - auto selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); | ||
| 178 | - CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 179 | - | ||
| 180 | - // 将输入other的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 181 | - auto scaleCasted = l0op::Cast(scale, promoteType, uniqueExecutor.get()); | ||
| 182 | - CHECK_RET(scaleCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 183 | - | ||
| 184 | - aclTensor* fakeQuantOut = nullptr; | ||
| 185 | - aclTensor* fakeQuantMask = nullptr; | ||
| 186 | if (fakeQuantEnbled < 1.0) { | 168 | if (fakeQuantEnbled < 1.0) { |
| 187 | // 将结果values_transpose进行transpose,转换成正确的shape | 169 | // 将结果values_transpose进行transpose,转换成正确的shape |
| 188 | - fakeQuantOut = const_cast<aclTensor*>(selfCasted); | 170 | + fakeQuantOut = const_cast<aclTensor*>(selfContiguous); |
| 189 | fakeQuantMask = const_cast<aclTensor*>(GetOutputTensorWithValueTrue(out, uniqueExecutor.get())); | 171 | fakeQuantMask = const_cast<aclTensor*>(GetOutputTensorWithValueTrue(out, uniqueExecutor.get())); |
| 190 | } else { | 172 | } else { |
| 191 | - int64_t tensorSize = (int64_t)(selfCasted->GetViewShape().GetDim(0)); | 173 | + int64_t tensorSize = (int64_t)(selfContiguous->GetViewShape().GetDim(0)); |
| 192 | int64_t tensorShape[1] = {tensorSize}; | 174 | int64_t tensorShape[1] = {tensorSize}; |
| 193 | auto expectShape = uniqueExecutor.get()->AllocIntArray(tensorShape, 1); | 175 | auto expectShape = uniqueExecutor.get()->AllocIntArray(tensorShape, 1); |
| 194 | CHECK_RET(expectShape != nullptr, ACLNN_ERR_INNER_NULLPTR); | 176 | CHECK_RET(expectShape != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 195 | 177 | ||
| 196 | - auto scaleBroadcast = l0op::BroadcastTo(scaleCasted, expectShape, uniqueExecutor.get()); | 178 | + auto scaleBroadcast = l0op::BroadcastTo(scaleContiguous, expectShape, uniqueExecutor.get()); |
| 197 | CHECK_RET(scaleBroadcast != nullptr, ACLNN_ERR_INNER_NULLPTR); | 179 | CHECK_RET(scaleBroadcast != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 198 | 180 | ||
| 199 | - auto zeroPointBroadcast = l0op::BroadcastTo(zeroPoint, expectShape, uniqueExecutor.get()); | 181 | + auto zeroPointBroadcast = l0op::BroadcastTo(zeroPointContiguous, expectShape, uniqueExecutor.get()); |
| 200 | CHECK_RET(zeroPointBroadcast != nullptr, ACLNN_ERR_INNER_NULLPTR); | 182 | CHECK_RET(zeroPointBroadcast != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 201 | 183 | ||
| 202 | auto result = l0op::FakeQuantAffineCachemask( | 184 | auto result = l0op::FakeQuantAffineCachemask( |
| 203 | - selfCasted, scaleBroadcast, zeroPointBroadcast, quantMin, quantMax, uniqueExecutor.get()); | 185 | + selfContiguous, scaleBroadcast, zeroPointBroadcast, quantMin, quantMax, uniqueExecutor.get()); |
| 204 | fakeQuantOut = std::get<0>(result); | 186 | fakeQuantOut = std::get<0>(result); |
| 205 | fakeQuantMask = std::get<1>(result); | 187 | fakeQuantMask = std::get<1>(result); |
| 206 | } | 188 | } |
| @@ -0,0 +1,46 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file fake_quant_common.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +namespace FakeQuantCommon { | ||
| 19 | + | ||
| 20 | +auto nullptrInner = std::tuple<aclTensor*, aclTensor*, aclTensor*>(nullptr, nullptr, nullptr); | ||
| 21 | + | ||
| 22 | +std::tuple<const aclTensor*, const aclTensor*, const aclTensor*> GetContiguousInput(const aclTensor* self, const aclTensor* scale, | ||
| 23 | + const aclTensor* zeroPoint, aclOpExecutor* executor) | ||
| 24 | +{ | ||
| 25 | + auto selfContiguous = l0op::Contiguous(self, executor); | ||
| 26 | + OP_CHECK_NULL(selfContiguous, return nullptrInner); | ||
| 27 | + | ||
| 28 | + auto promoteType = op::PromoteType(self->GetDataType(), scale->GetDataType()); | ||
| 29 | + // 将输入self的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 30 | + auto selfCasted = l0op::Cast(selfContiguous, promoteType, executor); | ||
| 31 | + OP_CHECK_NULL(selfCasted, return nullptrInner); | ||
| 32 | + | ||
| 33 | + auto scaleContiguous = l0op::Contiguous(scale, executor); | ||
| 34 | + OP_CHECK_NULL(scaleContiguous, return nullptrInner); | ||
| 35 | + | ||
| 36 | + // 将输入other的数据类型转换成隐式数据类型,根据具体算子语义按需调用 | ||
| 37 | + auto scaleCasted = l0op::Cast(scaleContiguous, promoteType, executor); | ||
| 38 | + OP_CHECK_NULL(scaleCasted, return nullptrInner); | ||
| 39 | + | ||
| 40 | + auto zeroPointContiguous = l0op::Contiguous(zeroPoint, executor); | ||
| 41 | + OP_CHECK_NULL(zeroPointContiguous, return nullptrInner); | ||
| 42 | + | ||
| 43 | + return std::tuple<const aclTensor*, const aclTensor*, const aclTensor*>(selfCasted, scaleCasted, zeroPointContiguous); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +} | ||
| @@ -0,0 +1,36 @@ | |||
| 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 | +/*! | ||
代码文档不一致: 文件头注释中声明的文件名与实际文件名不一致。注释中写的是'fake_quant_common.cpp',但实际文件是头文件'fake_quant_common.h'。这种不一致可能导致开发者在查找或理解代码时产生混淆。 问题类型: 代码文档不一致 文件路径: quant/fake_quant_affine_cachemask/op_host/op_api/fake_quant_common.h行号: 11 问题代码: /*! * \file fake_quant_common.cpp * \brief */ 修改建议: 将文件头注释中的文件名修改为实际的文件名'fake_quant_common.h',确保文档与实际代码保持一致。 --- 此评论由代码审查工具自动生成 ![]() ![]() | |||
| 12 | + * \file fake_quant_common.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +namespace FakeQuantCommon { | ||
| 31 | + | ||
| 32 | +std::tuple<const aclTensor*, const aclTensor*, const aclTensor*> GetContiguousInput(const aclTensor* self, const aclTensor* scale, | ||
| 33 | + const aclTensor* zeroPoint, aclOpExecutor* executor); | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | + | ||
代码结构与可维护性: 文件末尾缺少换行符(No newline at end of file)。虽然这不是功能性问题,但违反了许多代码规范(如POSIX标准),可能导致某些工具(如编译器、版本控制系统)处理时出现问题。 问题类型: 代码结构与可维护性 文件路径: quant/fake_quant_affine_cachemask/op_host/op_api/fake_quant_common.h行号: 36 问题代码: #endif 修改建议: 在#endif后添加一个换行符,确保文件以换行符结束。 --- 此评论由代码审查工具自动生成 ![]() ![]() | |||


quant/fake_quant_affine_cachemask/op_host/op_api/fake_quant_common.h此评论由代码审查工具自动生成