From b688fbbcf5b524dd4e29a3b1b27e12e46e0786a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B4=B2=E6=9D=B0?= Date: Wed, 24 Sep 2025 09:38:39 +0800 Subject: [PATCH] topk and __NPU_HOST/DEVICE__ --- lib/matmul/matmul_tiling_base.h | 6 +++--- lib/sort/topk_tiling.h | 7 +------ lib/sort/topk_utils.h | 8 +------- lib/sort/topk_utils_constants.h | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 lib/sort/topk_utils_constants.h diff --git a/lib/matmul/matmul_tiling_base.h b/lib/matmul/matmul_tiling_base.h index b0c6666a..87fd8491 100644 --- a/lib/matmul/matmul_tiling_base.h +++ b/lib/matmul/matmul_tiling_base.h @@ -21,7 +21,7 @@ #include "tiling/platform/platform_ascendc.h" namespace matmul_tiling { -#if !defined(__ASCC_DEVICE__) && !defined(__ASCC_HOST__) +#if !defined(__NPU_DEVICE__) && !defined(__NPU_HOST__) using half = double; #endif constexpr int32_t UINT8_BYTES = 1; @@ -74,7 +74,7 @@ enum class DataType : int32_t { DT_MAX = 40 // Mark the boundaries of data types }; -#ifndef __ASCC_DEVICE__ +#ifndef __NPU_DEVICE__ const std::map DTYPE_BYTE_TAB = { {DataType::DT_FLOAT, 4}, {DataType::DT_FLOAT16, 2}, {DataType::DT_INT8, 1}, {DataType::DT_INT16, 2}, {DataType::DT_UINT16, 2}, {DataType::DT_UINT8, 1}, {DataType::DT_INT32, 4}, {DataType::DT_INT64, 8}, @@ -90,7 +90,7 @@ const std::map DTYPE_BIT_TAB = { {DataType::DT_INT4, 4}, {DataType::DT_FLOAT4_E2M1, 4}, {DataType::DT_FLOAT4_E1M2, 4}, {DataType::DT_HIFLOAT8, 8}, {DataType::DT_FLOAT8_E4M3FN, 8}, {DataType::DT_FLOAT8_E5M2, 8}, {DataType::DT_FLOAT8_E8M0, 8} }; -#endif // __ASCC_DEVICE__ +#endif // __NPU_DEVICE__ enum class TPosition : int32_t { GM, A1, diff --git a/lib/sort/topk_tiling.h b/lib/sort/topk_tiling.h index e08d1af4..9b4a4d72 100644 --- a/lib/sort/topk_tiling.h +++ b/lib/sort/topk_tiling.h @@ -12,14 +12,9 @@ #include "topk_tilingdata.h" #include "tiling/platform/platform_ascendc.h" #include "graph/types.h" +#include "topk_utils_constants.h" namespace AscendC { - -enum class TopKMode { - TOPK_NORMAL, - TOPK_NSMALL, -}; - /* * @ingroup GetTopKMaxMinTmpSize * @brief Get TopK api calculate need max and min temporary local space size. diff --git a/lib/sort/topk_utils.h b/lib/sort/topk_utils.h index 8dd20767..58baa5fe 100644 --- a/lib/sort/topk_utils.h +++ b/lib/sort/topk_utils.h @@ -14,6 +14,7 @@ */ #ifndef LIB_SORT_TOPK_UTILS_H #define LIB_SORT_TOPK_UTILS_H +#include "topk_utils_constants.h" namespace AscendC { struct TopKInfo { @@ -21,13 +22,6 @@ struct TopKInfo { 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 diff --git a/lib/sort/topk_utils_constants.h b/lib/sort/topk_utils_constants.h new file mode 100644 index 00000000..0948cbb8 --- /dev/null +++ b/lib/sort/topk_utils_constants.h @@ -0,0 +1,24 @@ +/* + * 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_constants.h + * \brief + */ +#ifndef LIB_SORT_TOPK_UTILS_CONSTANTS_H +#define LIB_SORT_TOPK_UTILS_CONSTANTS_H + +namespace AscendC { +enum class TopKMode { + TOPK_NORMAL, + TOPK_NSMALL, +}; +}; // namespace AscendC +#endif // LIB_SORT_TOPK_UTILS_CONSTANTS_H \ No newline at end of file -- Gitee