From fb32195562b5d3b801381ab65c563404642711ca Mon Sep 17 00:00:00 2001 From: PengC Date: Wed, 23 Apr 2025 11:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E9=83=A8=E5=88=86API?= =?UTF-8?q?=E7=9A=84struct=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softmax_common/softmax_common_utils.h | 16 --------- impl/math/cumsum/cumsum_common_impl.h | 5 --- .../layernorm/layernorm_common_basic_impl.h | 13 -------- .../layernormgrad/layernormgrad_common_impl.h | 5 +-- .../normalize/normalize_common_impl.h | 15 --------- .../welfordfinalize_common_impl.h | 13 +------- .../antiquant/ascend_antiquant_common.h | 9 ++--- .../dequant/ascend_dequant_common_impl.h | 7 +--- impl/reduce/mean/mean_common_impl.h | 6 +--- impl/reduce/sum/sum_common_impl.h | 6 +--- impl/sort/topk/topk_common_utils.h | 14 ++------ lib/activation/softmax_utils.h | 17 ++++++++++ lib/math/cumsum_utils.h | 5 +++ lib/normalization/layernorm_utils.h | 13 ++++++++ lib/normalization/layernormgrad.h | 1 + lib/normalization/layernormgrad_utils.h | 27 +++++++++++++++ lib/normalization/normalize_utils.h | 15 +++++++++ lib/normalization/welfordfinalize.h | 1 + lib/normalization/welfordfinalize_utils.h | 33 +++++++++++++++++++ lib/quantization/ascend_antiquant.h | 1 + lib/quantization/ascend_antiquant_utils.h | 27 +++++++++++++++ lib/quantization/ascend_dequant.h | 1 + lib/quantization/ascend_dequant_utils.h | 26 +++++++++++++++ lib/reduce/mean.h | 1 + lib/reduce/mean_utils.h | 26 +++++++++++++++ lib/reduce/sum.h | 1 + lib/reduce/sum_utils.h | 26 +++++++++++++++ lib/sort/topk.h | 1 + lib/sort/topk_utils.h | 33 +++++++++++++++++++ 29 files changed, 264 insertions(+), 100 deletions(-) create mode 100644 lib/normalization/layernormgrad_utils.h create mode 100644 lib/normalization/welfordfinalize_utils.h create mode 100644 lib/quantization/ascend_antiquant_utils.h create mode 100644 lib/quantization/ascend_dequant_utils.h create mode 100644 lib/reduce/mean_utils.h create mode 100644 lib/reduce/sum_utils.h create mode 100644 lib/sort/topk_utils.h diff --git a/impl/activation/softmax/softmax_common/softmax_common_utils.h b/impl/activation/softmax/softmax_common/softmax_common_utils.h index 8237582e..3314a646 100644 --- a/impl/activation/softmax/softmax_common/softmax_common_utils.h +++ b/impl/activation/softmax/softmax_common/softmax_common_utils.h @@ -37,15 +37,6 @@ constexpr uint32_t SOFTMAX_SPECIAL_BASICBLOCK_LEN = FLOAT_REPEAT_SIZE * SOFTMAX_ constexpr uint32_t SOFTMAX_SUB_DIV_ROW_COLUMN_SIZE = 192; constexpr uint32_t SOFTMAX_FLOAT_SPECIAL_BLOCKREDUCE_LEN = DEFAULT_BLOCK_SIZE * HALF_FACTOR; -struct SoftMaxParams { - uint32_t srcM{ 0 }; - uint32_t srcK{ 0 }; - uint32_t oriSrcM{ 0 }; - uint32_t oriSrcK{ 0 }; - uint32_t loopCnt{ 1 }; - uint32_t splitMeanCnt{ 8 }; - float alpha{ 0.9375 }; -}; struct LastAxisShapeND { uint32_t m; uint32_t k; @@ -67,12 +58,5 @@ struct BroadCastLastND { uint32_t srcK; }; -struct SoftMaxShapeInfo { - uint32_t srcM{ 0 }; - uint32_t srcK{ 0 }; - uint32_t oriSrcM{ 0 }; - uint32_t oriSrcK{ 0 }; -}; - }; // namespace AscendC #endif // IMPL_ACTIVATION_SOFTMAX_SOFTMAX_COMMON_UTILS_H \ No newline at end of file diff --git a/impl/math/cumsum/cumsum_common_impl.h b/impl/math/cumsum/cumsum_common_impl.h index 63547831..106c1385 100644 --- a/impl/math/cumsum/cumsum_common_impl.h +++ b/impl/math/cumsum/cumsum_common_impl.h @@ -22,11 +22,6 @@ #include "lib/math/cumsum_utils.h" namespace AscendC { -struct CumSumInfo { - uint32_t outter{0}; - uint32_t inner{0}; // 32-byte aligned -}; - __aicore__ inline TransDataTo5HDParams ExtractTransDataParam(uint8_t repeatTimes, uint32_t inner, uint16_t alignOutter, uint32_t oneBlockElementNum, uint16_t dstRepStride, uint32_t srcRepStride) { diff --git a/impl/normalization/layernorm/layernorm_common_basic_impl.h b/impl/normalization/layernorm/layernorm_common_basic_impl.h index 1a76027e..b8bb9b14 100644 --- a/impl/normalization/layernorm/layernorm_common_basic_impl.h +++ b/impl/normalization/layernorm/layernorm_common_basic_impl.h @@ -25,19 +25,6 @@ struct LayerNormRstdTmpTensorParams { LocalTensor varianceTmpTensor; }; -struct LayerNormPara { - uint32_t aLength; - uint32_t rLength; - uint32_t rLengthWithPadding; -}; - -struct WelfordUpdateParam { - uint32_t rnLength; - uint32_t abLength; - uint32_t abComputeLength; - float nRec; -}; - template __aicore__ inline void LayerNormReduceSumImpl(const LocalTensor& dstMVTmp, const LocalTensor& dst, const LocalTensor& src, const uint32_t bsLength, const uint32_t hLength) diff --git a/impl/normalization/layernormgrad/layernormgrad_common_impl.h b/impl/normalization/layernormgrad/layernormgrad_common_impl.h index 57b7d47a..1460d91c 100644 --- a/impl/normalization/layernormgrad/layernormgrad_common_impl.h +++ b/impl/normalization/layernormgrad/layernormgrad_common_impl.h @@ -17,15 +17,12 @@ #include "kernel_tensor.h" #include "kernel_tiling/kernel_tiling.h" +#include "lib/normalization/layernormgrad_utils.h" const uint32_t LAYERNORM_GRAD_B32_BYTE_SIZE = 4; const uint32_t LAYERNORM_GRAD_B16_BYTE_SIZE = 2; namespace AscendC { -struct LayerNormGradShapeInfo { - DataFormat dataFormat = DataFormat::ND; -}; - struct LayerNormGradParams { __aicore__ LayerNormGradParams(LayerNormGradTiling &tiling, LocalTensor &stackBuffer) : bLength(tiling.bLength), diff --git a/impl/normalization/normalize/normalize_common_impl.h b/impl/normalization/normalize/normalize_common_impl.h index f61ffd2f..0d4177e0 100644 --- a/impl/normalization/normalize/normalize_common_impl.h +++ b/impl/normalization/normalize/normalize_common_impl.h @@ -22,21 +22,6 @@ namespace AscendC { const float DEFAULT_EPSILON = 1e-5; -struct NormalizePara { - uint32_t aLength; - uint32_t rLength; - uint32_t rLengthWithPadding; -}; - -template -struct NormalizeTmpTensor { - __aicore__ NormalizeTmpTensor(){}; - LocalTensor tempTensorA; - LocalTensor tempTensorB; - LocalTensor gammaTmpTensor; - LocalTensor betaTmpTensor; -}; - template __aicore__ inline constexpr bool IsDtypeValid() { diff --git a/impl/normalization/welfordfinalize/welfordfinalize_common_impl.h b/impl/normalization/welfordfinalize/welfordfinalize_common_impl.h index 9a8b62dd..08d405a3 100644 --- a/impl/normalization/welfordfinalize/welfordfinalize_common_impl.h +++ b/impl/normalization/welfordfinalize/welfordfinalize_common_impl.h @@ -18,6 +18,7 @@ #include "kernel_tensor.h" #include "kernel_pop_stack_buffer.h" #include "kernel_tiling/kernel_tiling.h" +#include "lib/normalization/welfordfinalize_utils.h" namespace AscendC { @@ -25,18 +26,6 @@ constexpr uint32_t OUTPUT_SIZE = 8; constexpr uint32_t B32_LEN = 256 / sizeof(float); constexpr uint32_t OUTPUT_MASK_B32 = 254; -struct WelfordFinalizePara -{ - uint32_t rnLength; - uint32_t abLength; - uint32_t headCount; - uint32_t headCountLength; - uint32_t tailCount; - uint32_t tailCountLength; - float abRec; - float rRec; -}; - struct WelfordFinalizeTilingData { uint32_t computeLength; diff --git a/impl/quantization/antiquant/ascend_antiquant_common.h b/impl/quantization/antiquant/ascend_antiquant_common.h index ee60d037..4bf123ce 100644 --- a/impl/quantization/antiquant/ascend_antiquant_common.h +++ b/impl/quantization/antiquant/ascend_antiquant_common.h @@ -15,6 +15,8 @@ #ifndef IMPL_QUANTIZATION_ANTIQUANT_ASCEND_ANTIQUANT_COMMON_H #define IMPL_QUANTIZATION_ANTIQUANT_ASCEND_ANTIQUANT_COMMON_H +#include "lib/quantization/ascend_antiquant_utils.h" + namespace AscendC { constexpr uint32_t ANTIQUANT_TWO = 2; constexpr uint32_t ANTIQUANT_FOUR = 4; @@ -26,12 +28,5 @@ constexpr uint32_t ANTIQUANT_SINGLE_N_SIZE_FP16 = 128; constexpr uint32_t ANTIQUANT_MAX_K = 255; constexpr uint32_t MAX_K_FOR_FP16_BRCB = 4096; -struct AntiQuantShapeInfo { - uint32_t offsetHeight{0}; - uint32_t offsetWidth{0}; - uint32_t scaleHeight{0}; - uint32_t scaleWidth{0}; -}; - } // namespace AscendC #endif // IMPL_QUANTIZATION_ANTIQUANT_ASCEND_ANTIQUANT_COMMON_H diff --git a/impl/quantization/dequant/ascend_dequant_common_impl.h b/impl/quantization/dequant/ascend_dequant_common_impl.h index 782977dd..235ba2b7 100644 --- a/impl/quantization/dequant/ascend_dequant_common_impl.h +++ b/impl/quantization/dequant/ascend_dequant_common_impl.h @@ -17,17 +17,12 @@ #include "kernel_tensor.h" #include "kernel_pop_stack_buffer.h" +#include "lib/quantization/ascend_dequant_utils.h" namespace AscendC { constexpr uint32_t FLOAT_PER_BLOCK = 8; // 32B = FP32(4B) * 8 constexpr uint32_t FLOAT_PER_REPEAT = 64; // 256B = FP32(4B) * 64 -struct DequantParams { - uint32_t m; // outer axis length (do not need 32B align) in unit of element num - uint32_t n; // inner axis length (must be 32B align) in unit of element num - uint32_t calCount; // in one inner line, calCount elements do dequant calculation in unit of element num -}; - __aicore__ inline bool IsCalCountValid(const LocalTensor& srcTensor, uint32_t calCount) { // calCount must be in range (0, srcTensor element num] diff --git a/impl/reduce/mean/mean_common_impl.h b/impl/reduce/mean/mean_common_impl.h index 4215ca78..92835d4c 100644 --- a/impl/reduce/mean/mean_common_impl.h +++ b/impl/reduce/mean/mean_common_impl.h @@ -17,6 +17,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/mean_utils.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" #include @@ -25,11 +26,6 @@ namespace AscendC { constexpr uint32_t HALF_NUM_PER = 128; constexpr uint32_t FLOAT_NUM_PER = 64; -struct MeanParams { - uint32_t outter = 1; - uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) - uint32_t n; // actual length of the tensor -}; template __aicore__ inline void CheckParamsIsValid(const LocalTensor& dstTensor, const LocalTensor& srcTensor, diff --git a/impl/reduce/sum/sum_common_impl.h b/impl/reduce/sum/sum_common_impl.h index 0f920551..7f4dcd29 100644 --- a/impl/reduce/sum/sum_common_impl.h +++ b/impl/reduce/sum/sum_common_impl.h @@ -17,16 +17,12 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/sum_utils.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" #include #endif namespace AscendC { -struct SumParams { - uint32_t outter = 1; - uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) - uint32_t n; // actual length of the tensor -}; template __aicore__ inline void CheckParamsIsValid(const LocalTensor &dstTensor, const LocalTensor &srcTensor, diff --git a/impl/sort/topk/topk_common_utils.h b/impl/sort/topk/topk_common_utils.h index e999ed41..61db22b4 100644 --- a/impl/sort/topk/topk_common_utils.h +++ b/impl/sort/topk/topk_common_utils.h @@ -15,6 +15,8 @@ #ifndef IMPL_SORT_TOPK_TOPK_COMMON_UTILS_H #define IMPL_SORT_TOPK_TOPK_COMMON_UTILS_H +#include "lib/sort/topk_utils.h" + #if __CCE_AICORE__ >= 200 namespace { constexpr uint16_t MIN_SORT32_SIZE = 32; @@ -46,18 +48,6 @@ constexpr uint32_t TOPK_NSMALL_INNER_LEN = 32; constexpr uint32_t TOPK_NORMAL_INNER_MAX_LEN = 4096; } // namespace -namespace AscendC { -struct TopKInfo { - int32_t outter = 1; - int32_t inner; // inner = 32-byte alignment of n - int32_t n; // actual length of the tensor -}; - -enum class TopKMode { - TOPK_NORMAL, - TOPK_NSMALL, -}; -} #endif #endif // IMPL_SORT_TOPK_TOPK_COMMON_UTILS_H \ No newline at end of file diff --git a/lib/activation/softmax_utils.h b/lib/activation/softmax_utils.h index 49cd6b34..afb6ebd1 100644 --- a/lib/activation/softmax_utils.h +++ b/lib/activation/softmax_utils.h @@ -49,5 +49,22 @@ struct SoftmaxConfig { constexpr SoftmaxConfig SOFTMAX_DEFAULT_CFG = { true, 0, 0 , SoftmaxMode::SOFTMAX_NORMAL}; +struct SoftMaxParams { + uint32_t srcM{ 0 }; + uint32_t srcK{ 0 }; + uint32_t oriSrcM{ 0 }; + uint32_t oriSrcK{ 0 }; + uint32_t loopCnt{ 1 }; + uint32_t splitMeanCnt{ 8 }; + float alpha{ 0.9375 }; +}; + +struct SoftMaxShapeInfo { + uint32_t srcM{ 0 }; + uint32_t srcK{ 0 }; + uint32_t oriSrcM{ 0 }; + uint32_t oriSrcK{ 0 }; +}; + }; // namespace AscendC #endif // LIB_ACTIVATION_SOFTMAX_UTILS_H \ No newline at end of file diff --git a/lib/math/cumsum_utils.h b/lib/math/cumsum_utils.h index 39272ab2..9a19f8fa 100644 --- a/lib/math/cumsum_utils.h +++ b/lib/math/cumsum_utils.h @@ -23,5 +23,10 @@ struct CumSumConfig { bool outputLastRow{false}; }; +struct CumSumInfo { + uint32_t outter{0}; + uint32_t inner{0}; // 32-byte aligned +}; + }; // namespace AscendC #endif // LIB_MATH_CUMSUM_UTILS_H \ No newline at end of file diff --git a/lib/normalization/layernorm_utils.h b/lib/normalization/layernorm_utils.h index 471a0e09..a9c608f2 100644 --- a/lib/normalization/layernorm_utils.h +++ b/lib/normalization/layernorm_utils.h @@ -37,5 +37,18 @@ struct WelfordUpdateConfig { constexpr WelfordUpdateConfig WFUPDATE_DEFAULT_CFG = {false}; +struct LayerNormPara { + uint32_t aLength; + uint32_t rLength; + uint32_t rLengthWithPadding; +}; + +struct WelfordUpdateParam { + uint32_t rnLength; + uint32_t abLength; + uint32_t abComputeLength; + float nRec; +}; + }; // namespace AscendC #endif // LIB_NORMALIZATION_LAYERNORM_UTILS_H \ No newline at end of file diff --git a/lib/normalization/layernormgrad.h b/lib/normalization/layernormgrad.h index 06c572be..13f06e9e 100644 --- a/lib/normalization/layernormgrad.h +++ b/lib/normalization/layernormgrad.h @@ -16,6 +16,7 @@ #define LIB_NORMALIZATION_LAYERNORMGRAD_H #include "kernel_tensor.h" +#include "lib/normalization/layernormgrad_utils.h" #include "../../impl/normalization/layernormgrad/layernormgrad_common_impl.h" #include "kernel_tiling/kernel_tiling.h" diff --git a/lib/normalization/layernormgrad_utils.h b/lib/normalization/layernormgrad_utils.h new file mode 100644 index 00000000..b148343b --- /dev/null +++ b/lib/normalization/layernormgrad_utils.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file layernormgrad_utils.h + * \brief + */ +#ifndef LIB_NORMALIZATION_LAYERNORMGRAD_UTILS_H +#define LIB_NORMALIZATION_LAYERNORMGRAD_UTILS_H + +#include "kernel_tensor.h" + +namespace AscendC { + +struct LayerNormGradShapeInfo { + DataFormat dataFormat = DataFormat::ND; +}; + +}; // namespace AscendC +#endif // LIB_NORMALIZATION_LAYERNORMGRAD_UTILS_H \ No newline at end of file diff --git a/lib/normalization/normalize_utils.h b/lib/normalization/normalize_utils.h index 15bd1bf4..86e1710e 100644 --- a/lib/normalization/normalize_utils.h +++ b/lib/normalization/normalize_utils.h @@ -47,5 +47,20 @@ constexpr NormalizeConfig NLCFG_NOGAMMA = GetNormalizeConfig(false, true); constexpr NormalizeConfig NLCFG_NOOPT = GetNormalizeConfig(true, true); +struct NormalizePara { + uint32_t aLength; + uint32_t rLength; + uint32_t rLengthWithPadding; +}; + +template +struct NormalizeTmpTensor { + __aicore__ NormalizeTmpTensor(){}; + LocalTensor tempTensorA; + LocalTensor tempTensorB; + LocalTensor gammaTmpTensor; + LocalTensor betaTmpTensor; +}; + }; // namespace AscendC #endif // LIB_NORMALIZATION_NORMALIZE_UTILS_H \ No newline at end of file diff --git a/lib/normalization/welfordfinalize.h b/lib/normalization/welfordfinalize.h index 84e05646..d4d5c8be 100644 --- a/lib/normalization/welfordfinalize.h +++ b/lib/normalization/welfordfinalize.h @@ -17,6 +17,7 @@ #ifndef LIB_NORMALIZATION_WELFORDFINALIZE_H #define LIB_NORMALIZATION_WELFORDFINALIZE_H #if __CCE_AICORE__ == 200 || __CCE_AICORE__ == 220 +#include "lib/normalization/welfordfinalize_utils.h" #include "../../impl/normalization/welfordfinalize/welfordfinalize_common_impl.h" #include "kernel_tensor.h" #include "kernel_tiling/kernel_tiling.h" diff --git a/lib/normalization/welfordfinalize_utils.h b/lib/normalization/welfordfinalize_utils.h new file mode 100644 index 00000000..61f80a83 --- /dev/null +++ b/lib/normalization/welfordfinalize_utils.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file welfordfinalize_utils.h + * \brief + */ +#ifndef LIB_NORMALIZATION_WELFORDFINALIZE_UTILS_H +#define LIB_NORMALIZATION_WELFORDFINALIZE_UTILS_H + +namespace AscendC { + +struct WelfordFinalizePara +{ + uint32_t rnLength; + uint32_t abLength; + uint32_t headCount; + uint32_t headCountLength; + uint32_t tailCount; + uint32_t tailCountLength; + float abRec; + float rRec; +}; + +}; // namespace AscendC +#endif // LIB_NORMALIZATION_WELFORDFINALIZE_UTILS_H \ No newline at end of file diff --git a/lib/quantization/ascend_antiquant.h b/lib/quantization/ascend_antiquant.h index 435367a8..0275ae1e 100644 --- a/lib/quantization/ascend_antiquant.h +++ b/lib/quantization/ascend_antiquant.h @@ -15,6 +15,7 @@ #ifndef LIB_QUANTIZATION_ASCEND_ANTIQUANT_H #define LIB_QUANTIZATION_ASCEND_ANTIQUANT_H #include "kernel_tensor.h" +#include "lib/quantization/ascend_antiquant_utils.h" #include "../../impl/quantization/antiquant/ascend_antiquant_impl.h" namespace AscendC { #pragma begin_pipe(V) diff --git a/lib/quantization/ascend_antiquant_utils.h b/lib/quantization/ascend_antiquant_utils.h new file mode 100644 index 00000000..ce21cc8f --- /dev/null +++ b/lib/quantization/ascend_antiquant_utils.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file ascend_antiquant_utils.h + * \brief + */ +#ifndef LIB_QUANTIZATION_ASCEND_ANTIQUANT_UTILS_H +#define LIB_QUANTIZATION_ASCEND_ANTIQUANT_UTILS_H + +namespace AscendC { +struct AntiQuantShapeInfo { + uint32_t offsetHeight{0}; + uint32_t offsetWidth{0}; + uint32_t scaleHeight{0}; + uint32_t scaleWidth{0}; +}; + +}; // namespace AscendC +#endif // LIB_QUANTIZATION_ASCEND_ANTIQUANT_UTILS_H \ No newline at end of file diff --git a/lib/quantization/ascend_dequant.h b/lib/quantization/ascend_dequant.h index 11f7790d..1340a51e 100644 --- a/lib/quantization/ascend_dequant.h +++ b/lib/quantization/ascend_dequant.h @@ -14,6 +14,7 @@ */ #ifndef LIB_QUANTIZATION_ASCEND_DEQUANT_H #define LIB_QUANTIZATION_ASCEND_DEQUANT_H +#include "lib/quantization/ascend_dequant_utils.h" #if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 220 || __CCE_AICORE__ == 200) #include "kernel_tensor.h" #include "../../impl/quantization/dequant/ascend_dequant_common_impl.h" diff --git a/lib/quantization/ascend_dequant_utils.h b/lib/quantization/ascend_dequant_utils.h new file mode 100644 index 00000000..2147be7b --- /dev/null +++ b/lib/quantization/ascend_dequant_utils.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file ascend_dequant_utils.h + * \brief + */ +#ifndef LIB_QUANTIZATION_ASCEND_DEQUANT_UTILS_H +#define LIB_QUANTIZATION_ASCEND_DEQUANT_UTILS_H + +namespace AscendC { +struct DequantParams { + uint32_t m; // outer axis length (do not need to be 32B aligned) in unit of element num + uint32_t n; // inner axis length (must be 32B aligned) in unit of element num + uint32_t calCount; // in one inner line, calCount elements do dequant calculation in unit of element num +}; + +}; // namespace AscendC +#endif // LIB_QUANTIZATION_ASCEND_DEQUANT_UTILS_H \ No newline at end of file diff --git a/lib/reduce/mean.h b/lib/reduce/mean.h index 914ce783..dbc87a13 100644 --- a/lib/reduce/mean.h +++ b/lib/reduce/mean.h @@ -17,6 +17,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/mean_utils.h" #include "../../impl/reduce/mean/mean_common_impl.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" diff --git a/lib/reduce/mean_utils.h b/lib/reduce/mean_utils.h new file mode 100644 index 00000000..925d7b6c --- /dev/null +++ b/lib/reduce/mean_utils.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file mean_utils.h + * \brief + */ +#ifndef LIB_REDUCE_MEAN_UTILS_H +#define LIB_REDUCE_MEAN_UTILS_H + +namespace AscendC { +struct MeanParams { + uint32_t outter = 1; + uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) + uint32_t n; // actual length of the tensor +}; + +}; // namespace AscendC +#endif // LIB_REDUCE_MEAN_UTILS_H \ No newline at end of file diff --git a/lib/reduce/sum.h b/lib/reduce/sum.h index 840ba3ff..a9f877b1 100644 --- a/lib/reduce/sum.h +++ b/lib/reduce/sum.h @@ -17,6 +17,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/sum_utils.h" #include "../../impl/reduce/sum/sum_common_impl.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" diff --git a/lib/reduce/sum_utils.h b/lib/reduce/sum_utils.h new file mode 100644 index 00000000..61561799 --- /dev/null +++ b/lib/reduce/sum_utils.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file sum_utils.h + * \brief + */ +#ifndef LIB_REDUCE_SUM_UTILS_H +#define LIB_REDUCE_SUM_UTILS_H + +namespace AscendC { +struct SumParams { + uint32_t outter = 1; + uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) + uint32_t n; // actual length of the tensor +}; + +}; // namespace AscendC +#endif // LIB_REDUCE_SUM_UTILS_H \ No newline at end of file diff --git a/lib/sort/topk.h b/lib/sort/topk.h index d07e7c7c..11e8532d 100644 --- a/lib/sort/topk.h +++ b/lib/sort/topk.h @@ -15,6 +15,7 @@ #ifndef LIB_SORT_TOPK_H #define LIB_SORT_TOPK_H +#include "lib/sort/topk_utils.h" #if __CCE_AICORE__ >= 200 #include "kernel_tensor.h" diff --git a/lib/sort/topk_utils.h b/lib/sort/topk_utils.h new file mode 100644 index 00000000..8dd20767 --- /dev/null +++ b/lib/sort/topk_utils.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * This file is a part of the CANN Open Software. + * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + */ + +/* ! + * \file topk_utils.h + * \brief + */ +#ifndef LIB_SORT_TOPK_UTILS_H +#define LIB_SORT_TOPK_UTILS_H + +namespace AscendC { +struct TopKInfo { + int32_t outter = 1; + int32_t inner; // inner = 32-byte alignment of n + int32_t n; // actual length of the tensor +}; +#ifndef ASCC_ENUM_TOPKMODE +#define ASCC_ENUM_TOPKMODE +enum class TopKMode { + TOPK_NORMAL, + TOPK_NSMALL, +}; +#endif + +}; // namespace AscendC +#endif // LIB_SORT_TOPK_UTILS_H \ No newline at end of file -- Gitee