已合并
修复mie_ops和atb-models配套CANN 9.0版本的编译失败问题 #844
hw-zhoutianyang创建于 4月13日
修复mie_ops和atb-models配套CANN 9.0版本的编译失败问题 #844
已合并
hw-zhoutianyang创建于 4月13日
8 个文件变更+191-228
@@ -53,7 +53,9 @@ set(CMAKE_SKIP_RPATH TRUE)
53set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")53set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
54set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion-null")54set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion-null")
55set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")55set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
56-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-dangling-reference")56+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0")
57+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-dangling-reference")
58+endif()
57set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")59set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
58set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong")60set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong")
59set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")61set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
@@ -105,4 +107,4 @@ add_subdirectory(atb_framework/pytorch)
105add_subdirectory(atb_framework/operations)107add_subdirectory(atb_framework/operations)
106add_subdirectory(${PROJECT_SOURCE_DIR}/../../src/utils/log ${CMAKE_BINARY_DIR}/build_log)108add_subdirectory(${PROJECT_SOURCE_DIR}/../../src/utils/log ${CMAKE_BINARY_DIR}/build_log)
107 109 
108-install(FILES ${PROJECT_SOURCE_DIR}/scripts/set_env.sh DESTINATION ./)110+install(FILES ${PROJECT_SOURCE_DIR}/scripts/set_env.sh DESTINATION ./)
@@ -3,5 +3,11 @@ add_library(atb_speed_operations SHARED ${SOURCE_FILES})
3link_directories(3link_directories(
4 ${CMAKE_CURRENT_LIST_DIR}/../../../../src/utils/log/lib4 ${CMAKE_CURRENT_LIST_DIR}/../../../../src/utils/log/lib
5)5)
6+set_source_files_properties(
7+ ${CMAKE_CURRENT_LIST_DIR}/aclnn/ops/attn_operation.cpp
8+ ${CMAKE_CURRENT_LIST_DIR}/aclnn/ops/attn_v3_operation.cpp
9+ PROPERTIES
10+ COMPILE_FLAGS "-Wno-error=cpp"
11+)
6target_link_libraries(atb_speed_operations PRIVATE atb_log atb opapi stdc++fs)12target_link_libraries(atb_speed_operations PRIVATE atb_log atb opapi stdc++fs)
7-install(TARGETS atb_speed_operations DESTINATION lib)13+install(TARGETS atb_speed_operations DESTINATION lib)
@@ -15,22 +15,22 @@
15 15 
16set -e16set -e
17 17 
18-startswith() {18+contains() {
19 local str="$1"19 local str="$1"
20- local prefix="$2"20+ local substr="$2"
21- [[ $str == "$prefix"* ]]21+ [[ "$str" == *"$substr"* ]]
22}22}
23 23 
24soc_name=$(python3 -c "\24soc_name=$(python3 -c "\
25import torch;\25import torch;\
26import torch_npu;\26import torch_npu;\
27soc_name = torch.npu.get_device_properties().name;\27soc_name = torch.npu.get_device_properties().name;\
28-print(soc_name);\28+print(f'mie_ops_version:{soc_name}');\
29" 2>/dev/null) || soc_name="unknown"29" 2>/dev/null) || soc_name="unknown"
30 30 
31-if startswith "$soc_name" "Ascend910B" ]; then31+if contains "$soc_name" "mie_ops_version:Ascend910B" ]; then
32 ops="ascend910b"32 ops="ascend910b"
33-elif startswith "$soc_name" "Ascend910_93" ]; then33+elif contains "$soc_name" "mie_ops_version:Ascend910_93" ]; then
34 ops="ascend910_93"34 ops="ascend910_93"
35else35else
36 if [ $# -eq 1 ]; then36 if [ $# -eq 1 ]; then
@@ -5,8 +5,7 @@ SOC_VERSION=$2
5 5 
6if [[ "$SOC_VERSION" =~ ^ascend910b ]]; then6if [[ "$SOC_VERSION" =~ ^ascend910b ]]; then
7 # ASCEND910B (A2) series7 # ASCEND910B (A2) series
8- # depdendency: catlass8+ # dependency: catlass
9- git config --global --add safe.directory "$ROOT_DIR"
10 CATLASS_PATH=${ROOT_DIR}/../../../third_party/catlass/include9 CATLASS_PATH=${ROOT_DIR}/../../../third_party/catlass/include
11 ABSOLUTE_CATLASS_PATH=$(cd "${CATLASS_PATH}" && pwd)10 ABSOLUTE_CATLASS_PATH=$(cd "${CATLASS_PATH}" && pwd)
12 export CPATH=${ABSOLUTE_CATLASS_PATH}:${CPATH}11 export CPATH=${ABSOLUTE_CATLASS_PATH}:${CPATH}
@@ -19,30 +18,9 @@ if [[ "$SOC_VERSION" =~ ^ascend910b ]]; then
19 SOC_ARG="ascend910b"18 SOC_ARG="ascend910b"
20elif [[ "$SOC_VERSION" =~ ^ascend910_93 ]]; then19elif [[ "$SOC_VERSION" =~ ^ascend910_93 ]]; then
21 # ASCEND910C (A3) series20 # ASCEND910C (A3) series
22- # depdendency: catlass21+ # dependency: catlass
23- git config --global --add safe.directory "$ROOT_DIR"
24 CATLASS_PATH=${ROOT_DIR}/../../../third_party/catlass/include22 CATLASS_PATH=${ROOT_DIR}/../../../third_party/catlass/include
25- # depdendency: cann-toolkit file moe_distribute_base.h
26- HCCL_STRUCT_FILE_PATH=$(find -L "${ASCEND_TOOLKIT_HOME}" -name "moe_distribute_base.h" 2>/dev/null | head -n1)
27- if [ -z "$HCCL_STRUCT_FILE_PATH" ]; then
28- echo "cannot find moe_distribute_base.h file in CANN env"
29- exit 1
30- fi
31- # for dispatch_gmm_combine_decode
32- yes | cp "${HCCL_STRUCT_FILE_PATH}" "${ROOT_DIR}/csrc/utils/inc/kernel"
33- # for dispatch_ffn_combine
34- SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
35- TARGET_DIR="$SCRIPT_DIR/mc2/dispatch_ffn_combine/op_kernel/utils/"
36- TARGET_FILE="$TARGET_DIR/$(basename "$HCCL_STRUCT_FILE_PATH")"
37 23 
38- echo "*************************************"
39- echo $HCCL_STRUCT_FILE_PATH
40- echo "$TARGET_DIR"
41- cp "$HCCL_STRUCT_FILE_PATH" "$TARGET_DIR"
42- 
43- sed -i 's/struct HcclOpResParam {/struct HcclOpResParamCustom {/g' "$TARGET_FILE"
44- sed -i 's/struct HcclRankRelationResV2 {/struct HcclRankRelationResV2Custom {/g' "$TARGET_FILE"
45-
46 CUSTOM_OPS_ARRAY=(24 CUSTOM_OPS_ARRAY=(
47 "dispatch_ffn_combine"25 "dispatch_ffn_combine"
48 "dispatch_gmm_combine_decode"26 "dispatch_gmm_combine_decode"
@@ -18,6 +18,7 @@ if ((NOT Python3_FOUND) OR (${Python3_EXECUTABLE} STREQUAL ""))
18 message(FATAL_ERROR "Can't find python3.")18 message(FATAL_ERROR "Can't find python3.")
19endif ()19endif ()
20set(HI_PYTHON "${Python3_EXECUTABLE}" CACHE STRING "python executor")20set(HI_PYTHON "${Python3_EXECUTABLE}" CACHE STRING "python executor")
21+include(CheckCXXSourceCompiles)
21 22 
22# 获取基础 CANN 路径23# 获取基础 CANN 路径
23if (CUSTOM_ASCEND_CANN_PACKAGE_PATH)24if (CUSTOM_ASCEND_CANN_PACKAGE_PATH)
@@ -50,6 +51,48 @@ get_filename_component(OPS_ADV_DIR "${CMAKE_CURRENT_SOURCE_DIR}
50get_filename_component(OPS_ADV_CMAKE_DIR "${OPS_ADV_DIR}/cmake" REALPATH)51get_filename_component(OPS_ADV_CMAKE_DIR "${OPS_ADV_DIR}/cmake" REALPATH)
51get_filename_component(OPS_ADV_UTILS_KERNEL_INC "${OPS_ADV_DIR}/common/include/kernel" REALPATH)52get_filename_component(OPS_ADV_UTILS_KERNEL_INC "${OPS_ADV_DIR}/common/include/kernel" REALPATH)
52 53 
54+# Detect A5-compatible SoC enum support from the CANN headers we are compiling against.
55+set(_saved_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
56+set(CMAKE_REQUIRED_INCLUDES
57+ ${ASCEND_CANN_PACKAGE_PATH}/include
58+ ${ASCEND_CANN_PACKAGE_PATH}/include/external
59+ ${ASCEND_CANN_PACKAGE_PATH}/include/experiment/platform
60+ ${ASCEND_CANN_PACKAGE_PATH}/include/experiment/runtime
61+)
62+ 
63+check_cxx_source_compiles([[
64+ #include "tiling/platform/platform_ascendc.h"
65+ int main()
66+ {
67+ auto soc = platform_ascendc::SocVersion::ASCEND950;
68+ (void)soc;
69+ return 0;
70+ }
71+]] MINDIE_LLM_HAS_SOC_ASCEND950)
72+ 
73+check_cxx_source_compiles([[
74+ #include "tiling/platform/platform_ascendc.h"
75+ int main()
76+ {
77+ auto soc = platform_ascendc::SocVersion::ASCEND910_95;
78+ (void)soc;
79+ return 0;
80+ }
81+]] MINDIE_LLM_HAS_SOC_ASCEND910_95)
82+ 
83+if (MINDIE_LLM_HAS_SOC_ASCEND950)
84+ set(MINDIE_LLM_950_SOC_ENUM "ASCEND950")
85+elseif (MINDIE_LLM_HAS_SOC_ASCEND910_95)
86+ set(MINDIE_LLM_950_SOC_ENUM "ASCEND910_95")
87+else ()
88+ message(FATAL_ERROR
89+ "Neither platform_ascendc::SocVersion::ASCEND950 nor ASCEND910_95 is available in CANN headers.")
90+endif ()
91+ 
92+set(CMAKE_REQUIRED_INCLUDES "${_saved_CMAKE_REQUIRED_INCLUDES}")
93+unset(_saved_CMAKE_REQUIRED_INCLUDES)
94+ 
95+message(STATUS "MINDIE_LLM_950_SOC_ENUM=${MINDIE_LLM_950_SOC_ENUM}")
53 96 
54# 构建树相关路径97# 构建树相关路径
55set(ASCEND_IMPL_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/impl CACHE STRING "ascend impl output directories")98set(ASCEND_IMPL_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/impl CACHE STRING "ascend impl output directories")
@@ -101,7 +101,7 @@ target_link_options(intf_pub_cxx14 INTERFACE
101 -Wl,-z,noexecstack101 -Wl,-z,noexecstack
102 $<$<CONFIG:Release>:-s>102 $<$<CONFIG:Release>:-s>
103 $<$<CONFIG:Release>:-Wl,--build-id=none>103 $<$<CONFIG:Release>:-Wl,--build-id=none>
104- $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage> 104+ $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage>
105)105)
106target_link_directories(intf_pub_cxx14 INTERFACE)106target_link_directories(intf_pub_cxx14 INTERFACE)
107target_link_libraries(intf_pub_cxx14 INTERFACE107target_link_libraries(intf_pub_cxx14 INTERFACE
@@ -116,21 +116,22 @@ target_compile_options(intf_pub_cxx17 INTERFACE
116 $<IF:$<VERSION_GREATER:${CMAKE_C_COMPILER_VERSION},4.8.5>,-fstack-protector-strong,-fstack-protector-all>116 $<IF:$<VERSION_GREATER:${CMAKE_C_COMPILER_VERSION},4.8.5>,-fstack-protector-strong,-fstack-protector-all>
117 $<$<CONFIG:Debug>:-g>117 $<$<CONFIG:Debug>:-g>
118 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>118 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
119- $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage> 119+ $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage>
120 )120 )
121target_compile_definitions(intf_pub_cxx17 INTERFACE121target_compile_definitions(intf_pub_cxx17 INTERFACE
122 _GLIBCXX_USE_CXX11_ABI=0122 _GLIBCXX_USE_CXX11_ABI=0
123 $<$<CONFIG:Release>:CFG_BUILD_NDEBUG>123 $<$<CONFIG:Release>:CFG_BUILD_NDEBUG>
124 $<$<CONFIG:Debug>:CFG_BUILD_DEBUG>124 $<$<CONFIG:Debug>:CFG_BUILD_DEBUG>
125 WIN64=1125 WIN64=1
126- LINUX=0)126+ LINUX=0
127+ $<$<COMPILE_LANGUAGE:CXX>:MINDIE_LLM_950_SOC_ENUM=${MINDIE_LLM_950_SOC_ENUM}>)
127target_link_options(intf_pub_cxx17 INTERFACE128target_link_options(intf_pub_cxx17 INTERFACE
128 -Wl,-z,relro129 -Wl,-z,relro
129 -Wl,-z,now130 -Wl,-z,now
130 -Wl,-z,noexecstack131 -Wl,-z,noexecstack
131 $<$<CONFIG:Release>:-s>132 $<$<CONFIG:Release>:-s>
132 $<$<CONFIG:Release>:-Wl,--build-id=none>133 $<$<CONFIG:Release>:-Wl,--build-id=none>
133- $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage> 134+ $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage>
134 )135 )
135target_link_directories(intf_pub_cxx17 INTERFACE)136target_link_directories(intf_pub_cxx17 INTERFACE)
136target_link_libraries(intf_pub_cxx17 INTERFACE137target_link_libraries(intf_pub_cxx17 INTERFACE
@@ -144,7 +145,7 @@ target_compile_options(intf_pub_aicpu INTERFACE
144 $<IF:$<VERSION_GREATER:${CMAKE_C_COMPILER_VERSION},4.8.5>,-fstack-protector-strong,-fstack-protector-all>145 $<IF:$<VERSION_GREATER:${CMAKE_C_COMPILER_VERSION},4.8.5>,-fstack-protector-strong,-fstack-protector-all>
145 $<$<CONFIG:Debug>:-g>146 $<$<CONFIG:Debug>:-g>
146 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>147 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
147- $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage> 148+ $<$<BOOL:${ENABLE_GCOV}>:-fprofile-arcs -ftest-coverage>
148)149)
149target_compile_definitions(intf_pub_aicpu INTERFACE150target_compile_definitions(intf_pub_aicpu INTERFACE
150 $<$<NOT:$<STREQUAL:${PRODUCT_SIDE},device>>:_GLIBCXX_USE_CXX11_ABI=0>151 $<$<NOT:$<STREQUAL:${PRODUCT_SIDE},device>>:_GLIBCXX_USE_CXX11_ABI=0>
@@ -1,12 +1,13 @@
1/**1/**
2 * Copyright (c) 2025 Huawei Technologies Co., Ltd.2 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+the terms and conditions of  * CANN Open Software License Agreement Version 2.0
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+(the "License").  * Please refer to the License for details. You may not use
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+this file except in compliance with the License.  * THIS SOFTWARE IS PROVIDED ON
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,  *
8- * See LICENSE in the root of the software repository for the full text of the License.8+INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A
9- */9+PARTICULAR PURPOSE.  * See LICENSE in the root of the software repository for
10+the full text of the License.  */
10 11 
11/*!12/*!
12 * \file tiling_util.cpp13 * \file tiling_util.cpp
@@ -14,6 +15,7 @@
14 */15 */
15 16 
16#include "tiling_base/tiling_util.h"17#include "tiling_base/tiling_util.h"
18+ 
17#include "platform/platform_ascendc.h"19#include "platform/platform_ascendc.h"
18 20 
19namespace Ops {21namespace Ops {
@@ -21,34 +23,33 @@ namespace Transformer {
21namespace OpTiling {23namespace OpTiling {
22static const gert::Shape g_vec_1_shape = {1};24static const gert::Shape g_vec_1_shape = {1};
23 25 
24-static bool IsRegbaseSocVersion(platform_ascendc::SocVersion version)26+static bool IsRegbaseSocVersion(platform_ascendc::SocVersion version) {
25-{
26 const static std::set<platform_ascendc::SocVersion> regbaseSocVersions = {27 const static std::set<platform_ascendc::SocVersion> regbaseSocVersions = {
27- platform_ascendc::SocVersion::ASCEND910_95};28+ platform_ascendc::SocVersion::MINDIE_LLM_950_SOC_ENUM};
28 29 
29 return regbaseSocVersions.find(version) != regbaseSocVersions.end();30 return regbaseSocVersions.find(version) != regbaseSocVersions.end();
30}31}
31 32 
32-bool IsRegbaseSocVersion(const gert::TilingParseContext* context)33+bool IsRegbaseSocVersion(const gert::TilingParseContext* context) {
33-{34+ auto ascendcPlatform =
34- auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo());35+ platform_ascendc::PlatformAscendC(context->GetPlatformInfo());
35 auto socVersion = ascendcPlatform.GetSocVersion();36 auto socVersion = ascendcPlatform.GetSocVersion();
36 return IsRegbaseSocVersion(socVersion);37 return IsRegbaseSocVersion(socVersion);
37}38}
38 39 
39-bool IsRegbaseSocVersion(const gert::TilingContext* context)40+bool IsRegbaseSocVersion(const gert::TilingContext* context) {
40-{41+ auto ascendcPlatform =
41- auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo());42+ platform_ascendc::PlatformAscendC(context->GetPlatformInfo());
42 auto socVersion = ascendcPlatform.GetSocVersion();43 auto socVersion = ascendcPlatform.GetSocVersion();
43 return IsRegbaseSocVersion(socVersion);44 return IsRegbaseSocVersion(socVersion);
44}45}
45 46 
46-const gert::Shape &EnsureNotScalar(const gert::Shape &inShape) {47+const gert::Shape& EnsureNotScalar(const gert::Shape& inShape) {
47- if (inShape.IsScalar()) {48+ if (inShape.IsScalar()) {
48- return g_vec_1_shape;49+ return g_vec_1_shape;
49- }50+ }
50- return inShape;51+ return inShape;
51}52}
52-} // namespace OpTiling53+} // namespace OpTiling
53-} // namespace Transformer54+} // namespace Transformer
54-} // namespace Ops55+} // namespace Ops
@@ -1,11 +1,13 @@
1/**1/**
2- * This program is free software, you can redistribute it and/or modify.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * Copyright (c) 2025 Huawei Technologies Co., Ltd.3+ * This program is free software, you can redistribute it and/or modify it under
4- * This file is a part of the CANN Open Software.4+ * the terms and conditions of CANN Open Software License Agreement Version 2.0
5- * Licensed under CANN Open Software License Agreement Version 2.0 (the "License").5+ * (the "License"). Please refer to the License for details. You may not use
6- * Please refer to the License for details. You may not use this file except in compliance with the License.6+ * this file except in compliance with the License. THIS SOFTWARE IS PROVIDED ON
7- * 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.7+ * AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS
9+ * FOR A PARTICULAR PURPOSE. See LICENSE in the root of the software repository
10+ * for the full text of the License.
9 */11 */
10 12 
11/*!13/*!
@@ -16,16 +18,13 @@
16#ifndef MOE_DISTRIBUTE_BASE_H18#ifndef MOE_DISTRIBUTE_BASE_H
17#define MOE_DISTRIBUTE_BASE_H19#define MOE_DISTRIBUTE_BASE_H
18 20 
19-#include "kernel_operator.h"
20- 
21constexpr uint32_t LOCAL_NOTIFY_MAX_NUM = 64;21constexpr uint32_t LOCAL_NOTIFY_MAX_NUM = 64;
22-constexpr uint32_t LOCAL_STREAM_MAX_NUM = 19U;22+constexpr uint32_t LOCAL_STREAM_MAX_NUM = 19;
23constexpr uint32_t AICPU_OP_NOTIFY_MAX_NUM = 2;23constexpr uint32_t AICPU_OP_NOTIFY_MAX_NUM = 2;
24constexpr uint32_t AICPU_MAX_RANK_NUM = 128 * 1024;24constexpr uint32_t AICPU_MAX_RANK_NUM = 128 * 1024;
25-constexpr uint32_t TIME_CYCLE = 50; // 系统cycle数转换成时间的基准单位,固定为50
26 25 
27struct HcclSignalInfo {26struct HcclSignalInfo {
28- uint64_t resId; // 在代表event时为eventid,notify时为notifyid27+ uint64_t resId;
29 uint64_t addr;28 uint64_t addr;
30 uint32_t devId;29 uint32_t devId;
31 uint32_t tsId;30 uint32_t tsId;
@@ -43,8 +42,8 @@ struct ListCommon {
43struct HcclStreamInfo {42struct HcclStreamInfo {
44 int32_t streamIds;43 int32_t streamIds;
45 uint32_t sqIds;44 uint32_t sqIds;
46- uint32_t cqIds; // 记录物理cqId45+ uint32_t cqIds;
47- uint32_t logicCqids; // 记录逻辑cqId46+ uint32_t logicCqids;
48};47};
49 48 
50struct LocalResInfoV2 {49struct LocalResInfoV2 {
@@ -53,8 +52,8 @@ struct LocalResInfoV2 {
53 HcclSignalInfo localSignals[LOCAL_NOTIFY_MAX_NUM];52 HcclSignalInfo localSignals[LOCAL_NOTIFY_MAX_NUM];
54 HcclStreamInfo streamInfo[LOCAL_STREAM_MAX_NUM];53 HcclStreamInfo streamInfo[LOCAL_STREAM_MAX_NUM];
55 HcclStreamInfo mainStreamInfo;54 HcclStreamInfo mainStreamInfo;
56- HcclSignalInfo aicpuOpNotify[AICPU_OP_NOTIFY_MAX_NUM]; // 集合通信AICPU展开资源55+ HcclSignalInfo aicpuOpNotify[AICPU_OP_NOTIFY_MAX_NUM];
57- ListCommon nextTagRes; // HccltagLocalResV256+ ListCommon nextTagRes; // HccltagLocalResV2
58};57};
59 58 
60enum class rtFloatOverflowMode_t {59enum class rtFloatOverflowMode_t {
@@ -64,14 +63,14 @@ enum class rtFloatOverflowMode_t {
64};63};
65 64 
66struct AlgoTopoInfo {65struct AlgoTopoInfo {
67- uint32_t userRank; // 通信域 RankID66+ uint32_t userRank;
68- uint32_t userRankSize; // 通信域的Rank数量67+ uint32_t userRankSize;
69 int32_t deviceLogicId;68 int32_t deviceLogicId;
70 bool isSingleMeshAggregation;69 bool isSingleMeshAggregation;
71- uint32_t deviceNumPerAggregation; // 每个Module中的Device数量70+ uint32_t deviceNumPerAggregation;
72- uint32_t superPodNum; // 集群中总的超节点数71+ uint32_t superPodNum;
73 uint32_t devicePhyId;72 uint32_t devicePhyId;
74- uint32_t topoType; // TopoType73+ uint32_t topoType; // TopoType
75 uint32_t deviceType;74 uint32_t deviceType;
76 uint32_t serverNum;75 uint32_t serverNum;
77 uint32_t meshAggregationRankSize;76 uint32_t meshAggregationRankSize;
@@ -87,27 +86,28 @@ struct AlgoTopoInfo {
87 uint32_t pairLinkCounterNum;86 uint32_t pairLinkCounterNum;
88 uint64_t pairLinkCounter;87 uint64_t pairLinkCounter;
89 uint32_t nicNum;88 uint32_t nicNum;
90- uint64_t nicList; // niclist数组指针89+ uint64_t nicList;
91- uint64_t complanRankLength; // complanRank占用的字节数90+ uint64_t complanRankLength;
92- uint64_t complanRank; // 指针91+ uint64_t complanRank;
93- uint64_t bridgeRankNum; // bridgeRank占用的个数92+ uint64_t bridgeRankNum;
94- uint64_t bridgeRank; // 指针93+ uint64_t bridgeRank;
95- uint64_t serverAndsuperPodRankLength; // serverAndsuperPodRank占用的字节数94+ uint64_t serverAndsuperPodRankLength;
96- uint64_t serverAndsuperPodRank; // 指针95+ uint64_t serverAndsuperPodRank;
97};96};
98 97 
99struct HcclOpConfig {98struct HcclOpConfig {
100- uint8_t deterministic; //确定性计算开关99+ uint8_t deterministic;
101- uint8_t retryEnable; // 是否重执行100+ uint8_t retryEnable;
102 uint8_t highPerfEnable;101 uint8_t highPerfEnable;
103- uint8_t padding[5]; // 大小需要64By对齐,未来添加参数时减小padding102+ uint8_t padding[5];
104- uint8_t linkTimeOut[8]; // 发送超时时长103+ uint8_t linkTimeOut[8];
105- uint64_t notifyWaitTime; // 超时时长,同HCCL_EXEC_TIMEOUT104+ uint64_t notifyWaitTime;
106 uint32_t retryHoldTime;105 uint32_t retryHoldTime;
107 uint32_t retryIntervalTime;106 uint32_t retryIntervalTime;
108- bool interHccsDisable = false; //使能rdma开关107+ bool interHccsDisable = false;
109- rtFloatOverflowMode_t floatOverflowMode = rtFloatOverflowMode_t::RT_OVERFLOW_MODE_UNDEF;108+ rtFloatOverflowMode_t floatOverflowMode =
110- uint32_t multiQpThreshold = 512; // 多QP每个QP分担数据量最小阈值109+ rtFloatOverflowMode_t::RT_OVERFLOW_MODE_UNDEF;
110+ uint32_t multiQpThreshold = 512;
111};111};
112 112 
113struct HcclMC2WorkSpace {113struct HcclMC2WorkSpace {
@@ -121,12 +121,12 @@ struct RemoteResPtr {
121};121};
122 122 
123struct HDCommunicateParams {123struct HDCommunicateParams {
124- uint64_t hostAddr { 0 };124+ uint64_t hostAddr{0};
125- uint64_t deviceAddr { 0 };125+ uint64_t deviceAddr{0};
126- uint64_t readCacheAddr { 0 };126+ uint64_t readCacheAddr{0};
127- uint32_t devMemSize{ 0 };127+ uint32_t devMemSize{0};
128- uint32_t buffLen{ 0 };128+ uint32_t buffLen{0};
129- uint32_t flag{ 0 };129+ uint32_t flag{0};
130};130};
131 131 
132struct HcclRankRelationResV2 {132struct HcclRankRelationResV2 {
@@ -139,150 +139,103 @@ struct HcclRankRelationResV2 {
139};139};
140 140 
141struct HcclOpResParam {141struct HcclOpResParam {
142- // 本地资源
143 HcclMC2WorkSpace mc2WorkSpace;142 HcclMC2WorkSpace mc2WorkSpace;
144- uint32_t localUsrRankId; // usrrankid143+ uint32_t localUsrRankId; // usrrankid
145- uint32_t rankSize; // 通信域内total rank个数144+ uint32_t rankSize;
146- uint64_t winSize; // 每个win大小,静态图时,可能是0,如果通信域内也有动态图,则可能为非0145+ uint64_t winSize;
147- uint64_t localWindowsIn; // 全F为无效值146+ uint64_t localWindowsIn;
148- uint64_t localWindowsOut; // 全F为无效值147+ uint64_t localWindowsOut;
149 char hcomId[128];148 char hcomId[128];
150- // aicore识别remote window
151 uint64_t winExpSize;149 uint64_t winExpSize;
152 uint64_t localWindowsExp;150 uint64_t localWindowsExp;
153- uint32_t rWinStart; // 为HcclRankRelationRes起始位置151+ uint32_t rWinStart;
154- uint32_t rWinOffset; // 为HcclRemoteRes的大小152+ uint32_t rWinOffset;
155 uint64_t version;153 uint64_t version;
156 LocalResInfoV2 localRes;154 LocalResInfoV2 localRes;
157 AlgoTopoInfo topoInfo;155 AlgoTopoInfo topoInfo;
158 156 
159- // 外部配置参数
160 HcclOpConfig config;157 HcclOpConfig config;
161 uint64_t hostStateInfo;158 uint64_t hostStateInfo;
162 uint64_t aicpuStateInfo;159 uint64_t aicpuStateInfo;
163 uint64_t lockAddr;160 uint64_t lockAddr;
164 uint32_t rsv[16];161 uint32_t rsv[16];
165- uint32_t notifysize; // RDMA场景使用,910B/910_93为4B,其余芯片为8B162+ uint32_t notifysize;
166- uint32_t remoteResNum; // 有效的remoteResNum163+ uint32_t remoteResNum;
167- RemoteResPtr remoteRes[AICPU_MAX_RANK_NUM]; //数组指针,指向HcclRankRelationResV2,下标为remoteUserRankId164+ RemoteResPtr remoteRes[AICPU_MAX_RANK_NUM];
168 165 
169 // communicate retry166 // communicate retry
170 HDCommunicateParams kfcControlTransferH2DParams;167 HDCommunicateParams kfcControlTransferH2DParams;
171 HDCommunicateParams kfcStatusTransferD2HParams;168 HDCommunicateParams kfcStatusTransferD2HParams;
172 uint64_t tinyMem; // for all2all169 uint64_t tinyMem; // for all2all
173 uint64_t tinyMemSize;170 uint64_t tinyMemSize;
174- // 零拷贝场景使用
175 uint64_t zeroCopyHeadPtr;171 uint64_t zeroCopyHeadPtr;
176 uint64_t zeroCopyTailPtr;172 uint64_t zeroCopyTailPtr;
177 uint64_t zeroCopyRingBuffer;173 uint64_t zeroCopyRingBuffer;
178- uint64_t zeroCopyIpcPtrs[16]; // 保存集合通信时每个对端的输入输出内存地址174+ uint64_t zeroCopyIpcPtrs[16];
179- uint32_t zeroCopyDevicePhyId[16]; // 保存每个rank对应的物理卡Id175+ uint32_t zeroCopyDevicePhyId[16];
180 176 
181 bool utraceStatusFlag;177 bool utraceStatusFlag;
182};178};
183 179 
184-// Transport 内存类型180+// Transport
185enum class HcclAiRMAMemType : uint32_t {181enum class HcclAiRMAMemType : uint32_t {
186 LOCAL_INPUT = 0,182 LOCAL_INPUT = 0,
187 REMOTE_INPUT,183 REMOTE_INPUT,
188- 
189 LOCAL_OUTPUT,184 LOCAL_OUTPUT,
190 REMOTE_OUTPUT,185 REMOTE_OUTPUT,
191- 
192- // 可透传更多的内存,可在MAX_NUM之前追加,例如:
193- // LOCAL_EXP,
194- // REMOTE_EXP,
195 MAX_NUM186 MAX_NUM
196};187};
197 188 
198-// Transport 内存信息
199struct HcclAiRMAMemInfo {189struct HcclAiRMAMemInfo {
200- uint32_t memMaxNum{0}; // 最大内存数量,等于 HcclAiRMAMemType::MAX_NUM190+ uint32_t memMaxNum{0};
201- uint32_t sizeOfMemDetails{0}; // sizeof(MemDetails),用于内存校验和偏移计算191+ uint32_t sizeOfMemDetails{0};
202- uint64_t memDetailPtr{0}; // MemDetails数组首地址, 个数: HcclAiRMAMemType::MAX_NUM192+ uint64_t memDetailPtr{0};
203- // 可往后追加字段
204};193};
205 194 
206-// 全部 Transport QP/Mem 信息195+// Transport QP/Mem
207struct HcclAiRMAInfo {196struct HcclAiRMAInfo {
208- uint32_t curRankId{0}; // 当前rankId197+ uint32_t curRankId{0};
209- uint32_t rankNum{0}; // rank数量198+ uint32_t rankNum{0};
210- uint32_t qpNum{0}; // 单个Transport的QP数量199+ uint32_t qpNum{0};
211- 200+ uint32_t sizeOfAiRMAWQ{0}; // sizeof(HcclAiRMAWQ)
212- uint32_t sizeOfAiRMAWQ{0}; // sizeof(HcclAiRMAWQ)201+ uint32_t sizeOfAiRMACQ{0}; // sizeof(HcclAiRMACQ)
213- uint32_t sizeOfAiRMACQ{0}; // sizeof(HcclAiRMACQ)
214 uint32_t sizeOfAiRMAMem{0}; // sizeof(HcclAiRMAMemInfo)202 uint32_t sizeOfAiRMAMem{0}; // sizeof(HcclAiRMAMemInfo)
215- 
216- // HcclAiRMAWQ二维数组首地址
217- // QP个数: rankNum * qpNum
218- // 计算偏移获取SQ指针:sqPtr + (dstRankId * qpNum + qpIndex) * sizeOfAiRMAWQ
219- // 0 <= qpIndex < qpNum
220 uint64_t sqPtr{0};203 uint64_t sqPtr{0};
221- 
222- // HcclAiRMACQ二维数组首地址
223- // QP个数: rankNum * qpNum
224- // 计算偏移获取SCQ指针:scqPtr + (dstRankId * qpNum + qpIndex) * sizeOfAiRMACQ
225- // 0 <= qpIndex < qpNum
226 uint64_t scqPtr{0};204 uint64_t scqPtr{0};
227- 
228- // HcclAiRMAWQ二维数组首地址
229- // QP个数: rankNum * qpNum
230- // 计算偏移获取RQ指针:rqPtr + (dstRankId * qpNum + qpIndex) * sizeOfAiRMAWQ
231- // 0 <= qpIndex < qpNum
232 uint64_t rqPtr{0};205 uint64_t rqPtr{0};
233- 
234- // HcclAiRMACQ二维数组首地址
235- // QP个数: rankNum * qpNum
236- // 计算偏移获取RCQ指针: rcqPtr + (dstRankId * qpNum + qpIndex) * sizeOfAiRMACQ
237- // 0 <= qpIndex < qpNum
238 uint64_t rcqPtr{0};206 uint64_t rcqPtr{0};
239- 
240- // HcclAivMemInfo一维数组
241- // 内存信息个数: rankNum
242- // 计算偏移获取内存信息指针: memPtr + rankId * sizeOfAiRMAMem
243- // srcRankId 获取自身内存信息,dstRankId 获取 Transport 内存信息
244 uint64_t memPtr{0};207 uint64_t memPtr{0};
245- // 可往后追加字段
246-};
247-struct CombinedCapability {
248- uint64_t dataplaneModeBitmap;
249};208};
250 209 
251struct HcclA2CombineOpParam {210struct HcclA2CombineOpParam {
252- uint64_t workSpace; // Address for communication between client and server,211+ uint64_t workSpace; // Address for communication between client and server,
253- // hccl requests and clears212+ // hccl requests and clears
254- uint64_t workSpaceSize; // Space for communication between client and server213+ uint64_t
255- uint32_t rankId; // id of this rank214+ workSpaceSize; // Space for communication between client and server
256- uint32_t rankNum; // num of ranks in this comm group215+ uint32_t rankId; // id of this rank
257- uint64_t winSize; // size of each windows memory216+ uint32_t rankNum; // num of ranks in this comm group
258- uint64_t windowsIn[AscendC::HCCL_MAX_RANK_NUM]; // windows address for input, windowsIn[rankId] corresponds217+ uint64_t winSize; // size of each windows memory
218+ uint64_t
219+ windowsIn[AscendC::HCCL_MAX_RANK_NUM]; // windows address for input,
220+ // windowsIn[rankId] corresponds
259 // to the local card address,221 // to the local card address,
260- // and others are cross-card mapping addresses.222+ // and others are cross-card
261- uint64_t windowsOut[AscendC::HCCL_MAX_RANK_NUM]; // windows address for output, windowsOut[rankId] corresponds223+ // mapping addresses.
262- // to the local card address,224+ uint64_t windowsOut
263- // and others are cross-card mapping addresses.225+ [AscendC::HCCL_MAX_RANK_NUM]; // windows address for output,
226+ // windowsOut[rankId] corresponds to the
227+ // local card address, and others are
228+ // cross-card mapping addresses.
264 uint8_t res[8328];229 uint8_t res[8328];
265 uint8_t multiFlag;230 uint8_t multiFlag;
266- __gm__ AscendC::IbVerbsData *data;231+ __gm__ AscendC::IbVerbsData* data;
267 uint64_t dataSize;232 uint64_t dataSize;
268- // 追加字段
269- uint64_t sizeOfAiRMAInfo; // sizeof(HcclAiRMAInfo)
270- uint64_t aiRMAInfo; // HcclAiRMAInfo* 单个结构体指针
271 233 
272- CombinedCapability* capability; // address of the communication capability information structure on the Device234+ uint64_t sizeOfAiRMAInfo;
273- uint64_t capabilitySize; // size of the communication capability information structure235+ uint64_t aiRMAInfo;
274-};
275-enum class DataplaneMode : uint32_t {
276- HOST = 0,
277- AICPU = 1,
278- AIV = 2,
279};236};
280 237 
281-enum class DBMode : int32_t {238+enum class DBMode : int32_t { INVALID_DB = -1, HW_DB = 0, SW_DB };
282- INVALID_DB = -1,
283- HW_DB = 0,
284- SW_DB
285-};
286 239 
287struct HcclAiRMAWQ {240struct HcclAiRMAWQ {
288 uint32_t wqn{0};241 uint32_t wqn{0};
@@ -291,7 +244,7 @@ struct HcclAiRMAWQ {
291 uint32_t depth{0};244 uint32_t depth{0};
292 uint64_t headAddr{0};245 uint64_t headAddr{0};
293 uint64_t tailAddr{0};246 uint64_t tailAddr{0};
294- DBMode dbMode{DBMode::INVALID_DB}; // 0-hw/1-sw247+ DBMode dbMode{DBMode::INVALID_DB}; // 0-hw/1-sw
295 uint64_t dbAddr{0};248 uint64_t dbAddr{0};
296 uint32_t sl{0};249 uint32_t sl{0};
297};250};
@@ -303,7 +256,7 @@ struct HcclAiRMACQ {
303 uint32_t depth{0};256 uint32_t depth{0};
304 uint64_t headAddr{0};257 uint64_t headAddr{0};
305 uint64_t tailAddr{0};258 uint64_t tailAddr{0};
306- DBMode dbMode{DBMode::INVALID_DB}; // 0-hw/1-sw259+ DBMode dbMode{DBMode::INVALID_DB}; // 0-hw/1-sw
307 uint64_t dbAddr{0};260 uint64_t dbAddr{0};
308};261};
309 262 
@@ -317,49 +270,28 @@ struct hns_roce_rc_sq_wqe {
317 uint64_t remoteVA;270 uint64_t remoteVA;
318};271};
319 272 
320- 
321struct hns_roce_lite_wqe_data_seg {273struct hns_roce_lite_wqe_data_seg {
322 uint32_t len;274 uint32_t len;
323 uint32_t lkey;275 uint32_t lkey;
324 uint64_t localVA;276 uint64_t localVA;
325};277};
326 278 
327-__aicore__ inline void cacheWriteThrough(__gm__ uint8_t* sourceAddr, uint64_t length) {279+__aicore__ inline void cacheWriteThrough(__gm__ uint8_t* sourceAddr,
280+ uint64_t length) {
328 __gm__ uint8_t* start =281 __gm__ uint8_t* start =
329- (__gm__ uint8_t*)((uint64_t)sourceAddr / AscendC::CACHE_LINE_SIZE * AscendC::CACHE_LINE_SIZE);282+ (__gm__ uint8_t*)((uint64_t)sourceAddr / AscendC::CACHE_LINE_SIZE *
283+ AscendC::CACHE_LINE_SIZE);
330 __gm__ uint8_t* end =284 __gm__ uint8_t* end =
331- (__gm__ uint8_t*)(((uint64_t)sourceAddr + length) / AscendC::CACHE_LINE_SIZE * AscendC::CACHE_LINE_SIZE);285+ (__gm__ uint8_t*)(((uint64_t)sourceAddr + length) /
286+ AscendC::CACHE_LINE_SIZE * AscendC::CACHE_LINE_SIZE);
332 AscendC::GlobalTensor<uint8_t> global;287 AscendC::GlobalTensor<uint8_t> global;
333 global.SetGlobalBuffer(start);288 global.SetGlobalBuffer(start);
334 for (uint32_t i = 0; i <= end - start; i += AscendC::CACHE_LINE_SIZE) {289 for (uint32_t i = 0; i <= end - start; i += AscendC::CACHE_LINE_SIZE) {
335- AscendC::DataCacheCleanAndInvalid<uint8_t, AscendC::CacheLine::SINGLE_CACHE_LINE,290+ AscendC::DataCacheCleanAndInvalid<uint8_t,
336- AscendC::DcciDst::CACHELINE_OUT>(global[i]);291+ AscendC::CacheLine::SINGLE_CACHE_LINE,
292+ AscendC::DcciDst::CACHELINE_OUT>(
293+ global[i]);
337 }294 }
338}295}
339-__aicore__ inline DataplaneMode GetDataplaneMode(GM_ADDR contextGM0) {
340- __gm__ HcclA2CombineOpParam *winContext_ = (__gm__ HcclA2CombineOpParam *)contextGM0;
341- CombinedCapability* capability = winContext_->capability;
342- uint64_t capabilitySize = winContext_->capabilitySize;
343- DataplaneMode dataplaneMode = DataplaneMode::AICPU;
344- if (capability == 0) {
345- return dataplaneMode;
346- }
347- uint64_t dataplaneModeBitmap = capability->dataplaneModeBitmap;
348- if ((dataplaneModeBitmap & 0x04) == 0x04) {
349- dataplaneMode = DataplaneMode::AIV;
350- }
351- return dataplaneMode;
352-}
353 296 
354-__aicore__ inline int64_t GetCurrentTimestampUs()297+#endif // MOE_DISTRIBUTE_BASE_H
355-{
356- return AscendC::GetSystemCycle() / TIME_CYCLE;
357-}
358- 
359-__aicore__ inline void RecordRankCommDuration(AscendC::LocalTensor<int32_t> performanceInfoU32Tensor, uint32_t rankId, int64_t startTime)
360-{
361- int64_t endTime = GetCurrentTimestampUs();
362- int32_t duration = static_cast<int32_t>(endTime - startTime); // int32_t可以表示2^31(us),约35min在实际场景下满足需要
363- performanceInfoU32Tensor.SetValue(rankId * sizeof(int64_t) / sizeof(int32_t), duration); // 使用int32_t是因为atomicAdd不支持int64_t类型,这里只赋值到int64_t的低32位。
364-}
365-#endif // MOE_DISTRIBUTE_BASE_H