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