Line data Source code
1 : /**
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 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 : #ifndef HCCL_ENV_CONFIG_H
12 : #define HCCL_ENV_CONFIG_H
13 :
14 : #include <vector>
15 : #include <hccl/hccl_types.h>
16 : #include "hccl/base.h"
17 : #include "alg_env_config.h"
18 :
19 : /*************** Interfaces ***************/
20 : using HcclSocketPortRange = struct HcclSocketPortRangeDef {
21 : u32 min;
22 : u32 max;
23 : };
24 :
25 : enum SocketLocation { SOCKET_HOST = 0, SOCKET_NPU = 1 };
26 :
27 : enum class InconsistentCheckMode {
28 : OFF = -1, // 完全不做校验
29 : FIRST = 0, // 仅首次算子下发校验
30 : ON = 1 // 每次算子下发都校验
31 : };
32 :
33 : // 定义结构体封装环境变量配置参数
34 : struct EnvConfigParam {
35 : std::string envName; // 环境变量名
36 : u32 defaultValue; // 默认值
37 : u32 minValue; // 最小值
38 : u32 maxValue; // 最大值
39 : u32 baseValue; // 基数(可选,默认配置为0)
40 : };
41 : constexpr s32 HCCL_MIN_CONNECT_FAULT_DETECTION_TIME = 20; // HCCL探测最小超时时间设置为20s
42 : HcclResult InitEnvConfig();
43 :
44 : bool GetExternalInputHostPortSwitch();
45 :
46 : bool GetExternalInputNpuPortSwitch();
47 :
48 : const std::vector<HcclSocketPortRange>& GetExternalInputHostSocketPortRange();
49 :
50 : const std::vector<HcclSocketPortRange>& GetExternalInputNpuSocketPortRange();
51 :
52 : const bool& GetExternalInputHcclHeartBeatEnable();
53 :
54 : const bool& GetExternalInputStuckDetect();
55 :
56 : const InconsistentCheckMode& GetExternalInconsistentCheckSwitch();
57 :
58 : s32& GetExternalInputDfsConnectionFaultDetectionTime();
59 :
60 : u32& GetExternalInputDfsTaskMonitorInterval();
61 :
62 : /*************** For Internal Use ***************/
63 :
64 : struct EnvConfig {
65 : // 初始化标识
66 : bool initialized;
67 :
68 : // 环境变量参数
69 : bool hostSocketPortSwitch; // HCCL_HOST_SOCKET_PORT_RANGE 环境变量配置则开启;否则关闭
70 : bool npuSocketPortSwitch; // HCCL_NPU_SOCKET_PORT_RANGE 环境变量配置则开启;否则关闭
71 : std::vector<HcclSocketPortRange> hostSocketPortRange;
72 : std::vector<HcclSocketPortRange> npuSocketPortRange;
73 : u32 rdmaTrafficClass;
74 : u32 rdmaServerLevel;
75 : u32 rdmaTimeOut; // RDMA超时时间,配置范围5-24,默认值为20
76 : u32 rdmaRetryCnt; // RDMA重传次数,配置范围1-7,默认值为7
77 : bool enableClusterHeartBeat;
78 : bool opCounterEnable;
79 : InconsistentCheckMode inconsistentCheckSwitch;
80 : s32 dfsConnectionFaultDetectionTime;
81 : u32 dfsTaskMonitorInterval;
82 :
83 : // HCCL_ALGO环境变量参数
84 : bool specificAlgoMode;
85 : std::map<HcclCMDType, std::vector<HcclAlgoType>> hcclAlgoConfig;
86 :
87 17965 : EnvConfig() { SetDefaultParams(); }
88 17965 : void SetDefaultParams()
89 : {
90 17965 : initialized = false;
91 : // 环境变量参数
92 17965 : hostSocketPortSwitch = false;
93 17965 : npuSocketPortSwitch = false;
94 : // 初始化 SocketPortRange 为默认值
95 17965 : hostSocketPortRange.clear();
96 17965 : npuSocketPortRange.clear();
97 : // 初始化 rdmaTrafficClass 为默认值
98 17965 : rdmaTrafficClass = HCCL_RDMA_TC_DEFAULT;
99 : // 初始化 rdmaServerLevel 为默认值
100 17965 : rdmaServerLevel = HCCL_RDMA_SL_DEFAULT;
101 17965 : rdmaTimeOut = HCCL_RDMA_TIMEOUT_DEFAULT;
102 17965 : rdmaRetryCnt = HCCL_RDMA_RETRY_CNT_DEFAULT;
103 : // 初始化 enableClusterHeartBeat 为默认值
104 17965 : enableClusterHeartBeat = true;
105 17965 : opCounterEnable = true;
106 : // 初始化 inconsistentCheckSwitch 为默认值
107 17965 : inconsistentCheckSwitch = InconsistentCheckMode::FIRST;
108 17965 : dfsConnectionFaultDetectionTime = HCCL_MIN_CONNECT_FAULT_DETECTION_TIME;
109 17965 : dfsTaskMonitorInterval = 0;
110 17965 : specificAlgoMode = false;
111 1886325 : for (u32 opType = 0; opType < static_cast<u32>(HcclCMDType::HCCL_CMD_MAX); opType++) {
112 1909024 : hcclAlgoConfig[static_cast<HcclCMDType>(opType)]
113 3736720 : = std::vector<HcclAlgoType>(HCCL_ALGO_LEVEL_NUM, HcclAlgoType::HCCL_ALGO_TYPE_DEFAULT);
114 : }
115 17965 : }
116 :
117 : static const u32 MAX_LEN_OF_DIGIT_ENV = 10; // 数字环境变量最大长度
118 :
119 : static const u32 HCCL_RDMA_TC_DEFAULT = 132; // 默认的traffic class为132(33*4)
120 : static const u32 HCCL_RDMA_TC_MIN = 0;
121 : static const u32 HCCL_RDMA_TC_MAX = 255;
122 : static const u32 HCCL_RDMA_TC_BASE = 4; // RDMATrafficClass需要时4的整数倍
123 :
124 : static const u32 HCCL_RDMA_SL_DEFAULT = 4; // 默认的server level为4
125 : static const u32 HCCL_RDMA_SL_MIN = 0;
126 : static const u32 HCCL_RDMA_SL_MAX = 7;
127 :
128 : static const u32 HCCL_RDMA_TIMEOUT_DEFAULT = 20; // 默认的TIMEOUT配置为20(对应时间4.096*2^20us)
129 : static const u32 HCCL_RDMA_TIMEOUT_MIN = 5; // TIMEOUT最小值为5
130 : static const u32 HCCL_RDMA_TIMEOUT_MAX = 24; // TIMEOUT最大值为24
131 : static const u32 HCCL_RDMA_TIMEOUT_MAX_910_93 = 20; // 910B和910_93 TIMEOUT最大值为20
132 :
133 : static const u32 HCCL_RDMA_RETRY_CNT_DEFAULT = 7; // 默认的Retry Cnt为7
134 : static const u32 HCCL_RDMA_RETRY_CNT_MIN = 1; // Retry Cnt最小值为1
135 : static const u32 HCCL_RDMA_RETRY_CNT_MAX = 7; // Retry Cnt最大值为7
136 :
137 : static const u32 HCCL_QOS_MIN = 0;
138 : static const u32 HCCL_QOS_MAX = 7;
139 : static const u32 HCCL_QOS_DEFAULT = 6;
140 : /// UBC CCU 路径:通信域 QoS 未配置或与 TP 策略分组对齐时的默认 QoS(0–7)
141 : static const u32 UB_QOS_DEFAULT = 4;
142 : // 解析RDMATrafficClass
143 : HcclResult ParseRDMATrafficClass();
144 : // 解析RDMAServerLevel
145 : HcclResult ParseRDMAServerLevel();
146 :
147 : HcclResult ParseRDMATimeOut(std::pair<u32, u32>& rdmaTimeOutRange);
148 :
149 : HcclResult ParseRDMARetryCnt();
150 :
151 : static const u32& GetExternalInputRdmaTrafficClass();
152 : static const u32& GetExternalInputRdmaServerLevel();
153 : static const u32& GetExternalInputRdmaTimeOut();
154 : static const u32& GetExternalInputRdmaRetryCnt();
155 :
156 : bool CheckEnvLen(const char* envStr, u32 envMaxLen);
157 : };
158 : static EnvConfig g_envConfig;
159 :
160 : HcclResult ResetEnvConfigInitState();
161 :
162 : HcclResult InitEnvParam();
163 :
164 : HcclResult ParseHostSocketPortRange();
165 :
166 : HcclResult ParseNpuSocketPortRange();
167 :
168 : HcclResult CheckSocketPortRangeValid(const std::string& envName, const std::vector<HcclSocketPortRange>& portRanges);
169 :
170 : HcclResult PortRangeSwitchOn(const SocketLocation& socketLoc);
171 :
172 : HcclResult ParseDFSConfig();
173 :
174 : HcclResult SetHcclAlgoConfig(const std::string& hcclAlgo);
175 :
176 : HcclResult ParseHcclAlgo();
177 :
178 : void PrintSocketPortRange(const std::string& envName, const std::vector<HcclSocketPortRange>& portRangeVec);
179 :
180 : HcclResult ParseEnvConfig(const EnvConfigParam& param, std::string& envValue, u32& resultValue);
181 :
182 : HcclResult
183 : ParseSingleDFSConfigItem(const std::string& dfsConfigEnv, const std::string& configName, std::string& configResult);
184 :
185 : HcclResult ParseMonitor(std::string& taskMonitorInterval, s32& monitorTime);
186 :
187 : HcclResult GetKeyWordPath(const std::string& cannEnvStr, const std::string& keyStr, std::string& cannPath);
188 :
189 : HcclResult ParseLibraryPath(std::string& cannPath);
190 : #endif // HCCL_ENV_INPUT_H
|