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 : #include "param_check_v2.h"
12 : #include <linux/limits.h>
13 : #include <unordered_set>
14 : #include <map>
15 : #include <vector>
16 : #include <fstream>
17 : #include <linux/limits.h>
18 : #include <adapter_error_manager_pub.h>
19 : #include "log.h"
20 : #include "exception_util.h"
21 : #include "data_type.h"
22 : #include "rank_table_crc_bridge.h"
23 :
24 : using namespace std;
25 : using namespace Hccl;
26 : struct EnumHashV2 {
27 : template <typename T>
28 243 : std::size_t operator()(T t) const {
29 243 : return static_cast<std::size_t>(t);
30 : }
31 : };
32 :
33 : constexpr u64 SYS_MAX_COUNT = 0x7FFFFFFFF; // 系统当前支持的最大count数
34 :
35 : const std::unordered_set<HcclDataType, EnumHashV2> HCCL_SUPPORT_DATA_TYPE_V2 = {
36 : HCCL_DATA_TYPE_INT8,
37 : HCCL_DATA_TYPE_INT16,
38 : HCCL_DATA_TYPE_INT32,
39 : HCCL_DATA_TYPE_FP16,
40 : HCCL_DATA_TYPE_FP32,
41 : HCCL_DATA_TYPE_INT64,
42 : HCCL_DATA_TYPE_UINT64,
43 : HCCL_DATA_TYPE_UINT8,
44 : HCCL_DATA_TYPE_UINT16,
45 : HCCL_DATA_TYPE_UINT32,
46 : HCCL_DATA_TYPE_FP64,
47 : HCCL_DATA_TYPE_BFP16,
48 : HCCL_DATA_TYPE_HIF8,
49 : HCCL_DATA_TYPE_FP8E4M3,
50 : HCCL_DATA_TYPE_FP8E5M2,
51 : HCCL_DATA_TYPE_FP8E8M0
52 : };
53 :
54 : const std::unordered_set<HcclReduceOp, EnumHashV2> HCCL_SUPPORT_REDUCE_OP_V2 = {
55 : HCCL_REDUCE_SUM,
56 : HCCL_REDUCE_MAX,
57 : HCCL_REDUCE_MIN,
58 : HCCL_REDUCE_PROD
59 : };
60 :
61 : const std::unordered_set<HcclDataType, EnumHashV2> HCCL_SUPPORT_PROD_DATA_TYPE_V2 = {
62 : HCCL_DATA_TYPE_INT64,
63 : HCCL_DATA_TYPE_UINT64,
64 : HCCL_DATA_TYPE_FP64
65 : };
66 :
67 : const std::map<HcclReduceOp, std::string> HCOM_REDUCE_OP_STR_MAP_V2 {
68 : {HcclReduceOp::HCCL_REDUCE_SUM, "sum"},
69 : {HcclReduceOp::HCCL_REDUCE_MAX, "max"},
70 : {HcclReduceOp::HCCL_REDUCE_MIN, "min"},
71 : {HcclReduceOp::HCCL_REDUCE_RESERVED, "reserved"}
72 : };
73 :
74 : const std::map<HcclDataType, std::string> HCOM_DATA_TYPE_STR_MAP_V2 {
75 : {HcclDataType::HCCL_DATA_TYPE_INT8, "int8"},
76 : {HcclDataType::HCCL_DATA_TYPE_INT16, "int16"},
77 : {HcclDataType::HCCL_DATA_TYPE_INT32, "int32"},
78 : {HcclDataType::HCCL_DATA_TYPE_INT64, "int64"},
79 : {HcclDataType::HCCL_DATA_TYPE_UINT64, "uint64"},
80 : {HcclDataType::HCCL_DATA_TYPE_FP16, "float16"},
81 : {HcclDataType::HCCL_DATA_TYPE_FP32, "float32"},
82 : {HcclDataType::HCCL_DATA_TYPE_UINT8, "uint8"},
83 : {HcclDataType::HCCL_DATA_TYPE_UINT16, "uint16"},
84 : {HcclDataType::HCCL_DATA_TYPE_UINT32, "uint32"},
85 : {HcclDataType::HCCL_DATA_TYPE_FP64, "float64"},
86 : {HcclDataType::HCCL_DATA_TYPE_BFP16, "bfloat16"},
87 : {HcclDataType::HCCL_DATA_TYPE_INT128, "int128"},
88 : {HcclDataType::HCCL_DATA_TYPE_HIF8, "hif8"},
89 : {HcclDataType::HCCL_DATA_TYPE_FP8E4M3, "fp8e4m3"},
90 : {HcclDataType::HCCL_DATA_TYPE_FP8E5M2, "fp8e5m2"},
91 : {HcclDataType::HCCL_DATA_TYPE_FP8E8M0, "fp8e8m0"},
92 : {HcclDataType::HCCL_DATA_TYPE_RESERVED, "reserved"}
93 : };
94 :
95 57 : std::string GetDataTypeEnumStrV2(HcclDataType dataType)
96 : {
97 57 : auto iter = HCOM_DATA_TYPE_STR_MAP_V2.find(dataType);
98 57 : if (iter == HCOM_DATA_TYPE_STR_MAP_V2.end()) {
99 0 : return "HcclDataType(" + std::to_string(dataType) + ")";
100 : } else {
101 57 : return iter->second;
102 : }
103 : }
104 :
105 90 : HcclResult HcomCheckTagV2(const char *tag)
106 : {
107 90 : CHK_PTR_NULL(tag);
108 :
109 90 : u32 tagLen = strnlen(tag, TAG_MAX_LEN + 1);
110 90 : if (tagLen == (TAG_MAX_LEN + 1) || tagLen == 0) {
111 0 : string errReason = "please check tagLen that is out of range, range[1," + std::to_string(TAG_MAX_LEN) + "]";
112 0 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
113 : vector<string>({"HcomCheckTagV2", std::to_string(tagLen), "tag", errReason}));
114 0 : if (tagLen == 0) {
115 0 : HCCL_ERROR("[Check][Tag]errNo[0x%llx] tag is empty", HCCL_E_PARA);
116 : } else {
117 0 : HCCL_ERROR("[Check][Tag]errNo[0x%llx] tag is too long, range[1,%u]", HCCL_E_PARA, TAG_MAX_LEN);
118 : }
119 0 : return HCCL_E_PARA;
120 0 : }
121 90 : return HCCL_SUCCESS;
122 0 : }
123 :
124 54 : HcclResult HcomCheckGroupNameV2(const char *group)
125 : {
126 54 : if (group != nullptr) {
127 43 : u32 groupLen = strnlen(group, GROUP_NAME_MAX_LEN + 1);
128 43 : if (groupLen == (GROUP_NAME_MAX_LEN + 1) || groupLen == 0) {
129 0 : string errReason = "please check groupLen that is out of range, range[1," + std::to_string(GROUP_NAME_MAX_LEN ) + "]";
130 0 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
131 : vector<string>({"HcomCheckGroupNameV2", std::to_string(groupLen), "group name", errReason}));
132 0 : HCCL_ERROR("[Check][GroupName]errNo[0x%llx] group name[%s] length[%lu] is invalid",
133 : HCCL_E_PARA, group, groupLen);
134 0 : return HCCL_E_PARA;
135 0 : }
136 : }
137 54 : return HCCL_SUCCESS;
138 0 : }
139 :
140 154 : HcclResult HcomCheckCountV2(const u64 count)
141 : {
142 154 : if (count > SYS_MAX_COUNT) {
143 3 : string errReason = "please check count that is bigger than MAX[" + std::to_string(SYS_MAX_COUNT) + "]";
144 3 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
145 : vector<string>({"HcomCheckCountV2", std::to_string(count), "count", errReason}));
146 9 : HCCL_ERROR("[Check][Count]errNo[0x%llx] count[%llu] is invalid(bigger than MAX count[%llu])",
147 : HCCL_E_PARA, count, SYS_MAX_COUNT);
148 3 : return HCCL_E_PARA;
149 3 : }
150 151 : return HCCL_SUCCESS;
151 0 : }
152 :
153 12 : std::string GetReduceOpEnumStrV2(HcclReduceOp reduceOp)
154 : {
155 12 : auto iter = HCOM_REDUCE_OP_STR_MAP_V2.find(reduceOp);
156 12 : if (iter == HCOM_REDUCE_OP_STR_MAP_V2.end()) {
157 1 : return "HcclReduceOp(" + std::to_string(reduceOp) + ")";
158 : } else {
159 11 : return iter->second;
160 : }
161 : }
162 :
163 169 : HcclResult HcomCheckDataTypeV2(const HcclDataType dataType)
164 : {
165 169 : if (HCCL_SUPPORT_DATA_TYPE_V2.find(dataType) == HCCL_SUPPORT_DATA_TYPE_V2.end()) {
166 5 : std::string expect;
167 5 : bool isFirst = true;
168 85 : for (auto type : HCCL_SUPPORT_DATA_TYPE_V2) {
169 80 : auto it = DATA_TYPE_TO_STRING_MAP.find(type);
170 80 : if (it != DATA_TYPE_TO_STRING_MAP.end()) {
171 80 : if (!isFirst) {
172 75 : expect += ",";
173 : }
174 80 : expect += it->second;
175 80 : isFirst = false;
176 : }
177 : }
178 5 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
179 : vector<string>({"HcomCheckDataTypeV2", GetDataTypeEnumStrV2(dataType).c_str(), "dataType", expect}));
180 15 : HCCL_ERROR("[Check][DataType]errNo[0x%llx] data type[%s] not supported",
181 : HCCL_E_NOT_SUPPORT, GetDataTypeEnumStrV2(dataType).c_str());
182 5 : return HCCL_E_NOT_SUPPORT;
183 5 : }
184 164 : return HCCL_SUCCESS;
185 0 : }
186 :
187 14 : HcclResult HcomCheckOpParamV2(const char *tag, const u64 count, const HcclDataType dataType, const char *group,
188 : const void *stream)
189 : {
190 14 : HcclResult ret = HcomCheckGroupNameV2(group);
191 14 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] group name is invalid",
192 : ret), ret);
193 :
194 14 : CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
195 :
196 14 : return HCCL_SUCCESS;
197 : }
198 :
199 35 : HcclResult HcomCheckOpParamV2(const u64 count, const HcclDataType dataType, const char *group)
200 : {
201 35 : HcclResult ret = HcomCheckGroupNameV2(group);
202 35 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] group name is invalid",
203 : ret), ret);
204 :
205 35 : CHK_RET(HcomCheckOpParamV2(count, dataType));
206 :
207 35 : return HCCL_SUCCESS;
208 : }
209 :
210 89 : HcclResult HcomCheckOpParamV2(const char *tag, const u64 count, const HcclDataType dataType, const void *stream) // 校验opParam失败都上报EI0003
211 : {
212 107 : CHK_RET(HcomCheckOpParamV2(tag, count, dataType));
213 :
214 83 : if (stream == nullptr) {
215 0 : HCCL_ERROR("[Check][Stream]errNo[0x%016llx] stream is NULL.", HCCL_E_PTR);
216 0 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
217 : vector<string>({"HcomCheckOpParamV2", "NULL", "stream",
218 : "please check stream that should not be nullptr"}));
219 0 : return HCCL_E_PTR;
220 : }
221 :
222 83 : return HCCL_SUCCESS;
223 : }
224 :
225 89 : HcclResult HcomCheckOpParamV2(const char *tag, const u64 count, const HcclDataType dataType)
226 : {
227 89 : HcclResult ret = HcomCheckTagV2(tag);
228 89 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] tag is invalid",
229 : ret), ret);
230 :
231 89 : ret = HcomCheckCountV2(count);
232 95 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] count is out of range",
233 : ret), ret);
234 :
235 87 : ret = HcomCheckDataTypeV2(dataType);
236 99 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] dataType is invalid",
237 : ret), ret);
238 :
239 83 : return HCCL_SUCCESS;
240 : }
241 :
242 63 : HcclResult HcomCheckOpParamV2(const u64 count, const HcclDataType dataType)
243 : {
244 63 : HcclResult ret = HcomCheckCountV2(count);
245 63 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] count is out of range",
246 : ret), ret);
247 :
248 63 : ret = HcomCheckDataTypeV2(dataType);
249 63 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Check][OpParam]errNo[0x%llx] dataType is invalid",
250 : ret), ret);
251 :
252 63 : return HCCL_SUCCESS;
253 : }
254 :
255 45 : HcclResult HcomCheckReductionOpV2(const HcclReduceOp op)
256 : {
257 45 : if (HCCL_SUPPORT_REDUCE_OP_V2.find(op) == HCCL_SUPPORT_REDUCE_OP_V2.end()) {
258 1 : std::string supportedList;
259 1 : bool first = true;
260 5 : for(const auto& validOp : HCCL_SUPPORT_REDUCE_OP_V2) {
261 4 : if (!first) {
262 3 : supportedList += ", ";
263 : }
264 4 : supportedList += GetReduceOpEnumStrV2(validOp);
265 4 : first = false;
266 : }
267 1 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
268 : vector<string>({"HcomCheckReductionOpV2", GetReduceOpEnumStrV2(op), "op",
269 : "one of " + supportedList}));
270 3 : HCCL_ERROR("[Check][ReductionOp]errNo[0x%016llx] Op:[%s] not supported", HCCL_E_PARA,
271 : GetReduceOpEnumStrV2(op).c_str());
272 1 : return HCCL_E_NOT_SUPPORT;
273 1 : }
274 44 : return HCCL_SUCCESS;
275 0 : }
276 :
277 6 : HcclResult HcomCheckProdDataTypeV2(const HcclDataType dataType)
278 : {
279 6 : if (HCCL_SUPPORT_PROD_DATA_TYPE_V2.find(dataType) == HCCL_SUPPORT_PROD_DATA_TYPE_V2.end()) {
280 6 : std::string supportedList;
281 6 : bool first = true;
282 24 : for(const auto& validType : HCCL_SUPPORT_PROD_DATA_TYPE_V2) {
283 18 : if (!first) {
284 12 : supportedList += ", ";
285 : }
286 18 : supportedList += GetDataTypeEnumStrV2(validType);
287 18 : first = false;
288 : }
289 6 : RPT_INPUT_ERR(true, "EI0003", vector<string>({"ccl_op", "value", "parameter", "expect"}),\
290 : vector<string>({"HcomCheckProdDataTypeV2", GetDataTypeEnumStrV2(dataType), "dataType",
291 : "one of " + supportedList}));
292 18 : HCCL_ERROR("[Check][ProdDataType]errNo[0x%016llx] DataType:[%s] not supported PROD", HCCL_E_PARA,
293 : GetDataTypeEnumStrV2(dataType).c_str());
294 6 : return HCCL_E_NOT_SUPPORT;
295 6 : }
296 0 : return HCCL_SUCCESS;
297 0 : }
298 :
299 44 : HcclResult HcomCheckReduceDataTypeV2(const HcclDataType dataType, const HcclReduceOp op)
300 : {
301 44 : switch (op) {
302 38 : case HCCL_REDUCE_SUM:
303 : case HCCL_REDUCE_MAX:
304 : case HCCL_REDUCE_MIN:
305 38 : break;
306 6 : case HCCL_REDUCE_PROD:
307 24 : CHK_RET(HcomCheckProdDataTypeV2(dataType));
308 0 : break;
309 0 : default:
310 0 : break;
311 : }
312 38 : return HCCL_SUCCESS;
313 : }
314 :
315 3 : HcclResult HcomCheckAlltoAllVExternalMemV2(const void *sendBuf, const void *sendCounts,
316 : const void *recvBuf, const void *recvCounts, u32 rankSize)
317 : {
318 3 : CHK_PRT_RET(sendBuf != nullptr && recvBuf != nullptr && sendBuf == recvBuf,
319 : HCCL_ERROR("[HcomCheckAlltoAllVExternalMem] sendBuf and recvBuf cannot be same."),
320 : HCCL_E_PARA);
321 6 : CHECK_NULLPTR(sendCounts, "[HcomCheckAlltoAllVExternalMemV2] sendCounts is nullptr!");
322 3 : CHECK_NULLPTR(recvCounts, "[HcomCheckAlltoAllVExternalMemV2] recvCounts is nullptr!");
323 3 : u64 *sendCountsPtr = const_cast<u64 *>(static_cast<const u64 *>(sendCounts));
324 3 : u64 *recvCountsPtr = const_cast<u64 *>(static_cast<const u64 *>(recvCounts));
325 3 : bool hasSend = false;
326 3 : bool hasRecv = false;
327 3 : bool invalidSendCount = false;
328 3 : bool invalidRecvCount = false;
329 3 : for (u32 i = 0; i < rankSize; i++) {
330 0 : if (*(sendCountsPtr + i) != 0) {
331 0 : invalidSendCount = invalidSendCount || (*(sendCountsPtr + i) > SYS_MAX_COUNT);
332 0 : hasSend = true;
333 : }
334 0 : if (*(recvCountsPtr + i) != 0) {
335 0 : invalidRecvCount = invalidRecvCount || (*(recvCountsPtr + i) > SYS_MAX_COUNT);
336 0 : hasRecv = true;
337 : }
338 : }
339 :
340 3 : if (invalidSendCount || invalidRecvCount || HcclCheckLogLevel(DLOG_DEBUG)) {
341 6 : std::string sendCountStr = "sendCounts:";
342 3 : std::string recvCountStr = "recvCounts:";
343 3 : for (u32 i = 0; i < rankSize; i++) {
344 0 : sendCountStr += ' ' + std::to_string(*(sendCountsPtr + i));
345 0 : recvCountStr += ' ' + std::to_string(*(recvCountsPtr + i));
346 : }
347 :
348 3 : CHK_PRT_RET(invalidSendCount,
349 : HCCL_ERROR("HcomCheckAlltoAllVExternalMem sendCounts[%s] is invalid.(bigger than MAX count[%llu])",
350 : sendCountStr.c_str(), SYS_MAX_COUNT),
351 : HCCL_E_PARA);
352 3 : CHK_PRT_RET(invalidRecvCount,
353 : HCCL_ERROR("HcomCheckAlltoAllVExternalMem recvCounts[%s] is invalid.(bigger than MAX count[%llu])",
354 : recvCountStr.c_str(), SYS_MAX_COUNT),
355 : HCCL_E_PARA);
356 :
357 9 : HCCL_INFO("[HcomCheckAlltoAllVExternalMem] sendCounts: %s", sendCountStr.c_str());
358 9 : HCCL_INFO("[HcomCheckAlltoAllVExternalMem] recvCounts: %s", recvCountStr.c_str());
359 3 : }
360 :
361 3 : if (hasSend) {
362 0 : CHK_PTR_NULL(sendBuf);
363 : }
364 3 : if (hasRecv) {
365 0 : CHK_PTR_NULL(recvBuf);
366 : }
367 3 : return HCCL_SUCCESS;
368 : }
369 :
370 0 : HcclResult HcomCheckAlltoAllVCExternalMemV2(const void *sendBuf, const void *sendCountMatrix,
371 : const void *recvBuf, u32 rankSize, u32 rank)
372 : {
373 0 : CHK_PRT_RET(sendBuf != nullptr && recvBuf != nullptr && sendBuf == recvBuf,
374 : HCCL_ERROR("[HcomCheckAlltoAllVCExternalMemV2] sendBuf and recvBuf addr cannot be same."),
375 : HCCL_E_PARA);
376 :
377 0 : CHECK_NULLPTR(sendCountMatrix, "[HcomCheckAlltoAllVCExternalMemV2] sendCountMatrix is nullptr!");
378 0 : u64 *sendCountMatrixPtr = const_cast<u64 *>(static_cast<const u64 *>(sendCountMatrix));
379 0 : bool hasSend = false;
380 0 : bool hasRecv = false;
381 :
382 0 : for (u32 i = 0; i < rankSize; i++) {
383 0 : u64 sendCount = *(sendCountMatrixPtr + rank * rankSize + i);
384 0 : CHK_RET(HcomCheckCountV2(sendCount));
385 0 : if (hasSend == false && sendCount != 0) {
386 0 : hasSend = true;
387 : }
388 0 : u64 recvCount = *(sendCountMatrixPtr + i * rankSize + rank);
389 0 : if (hasRecv == false && recvCount != 0) {
390 0 : hasRecv = true;
391 : }
392 0 : HCCL_DEBUG("[HcomCheckAlltoAllVCExternalMemV2] myrank[%u] rmtrank[%u] sendCount[%llu] recvCount[%llu]",
393 : rank, i, sendCount, recvCount);
394 : }
395 0 : if (hasSend) {
396 0 : CHK_PTR_NULL(sendBuf);
397 : }
398 0 : if (hasRecv) {
399 0 : CHK_PTR_NULL(recvBuf);
400 : }
401 0 : return HCCL_SUCCESS;
402 : }
403 :
404 3 : HcclResult HcomCheckAlltoAllVCEmptyV2(const void *sendBuf, const void *sendCountMatrix,
405 : const void *recvBuf, u32 rankSize, bool &isEmpty)
406 : {
407 3 : CHK_PRT_RET(sendBuf != nullptr && recvBuf != nullptr && sendBuf == recvBuf,
408 : HCCL_ERROR("[HcomCheckAlltoAllVCEmptyV2] sendBuf and recvBuf addr cannot be same."),
409 : HCCL_E_PARA);
410 :
411 3 : CHECK_NULLPTR(sendCountMatrix, "[HcomCheckAlltoAllVCEmptyV2] sendCountMatrix is nullptr!");
412 3 : u64 *sendCountMatrixPtr = const_cast<u64 *>(static_cast<const u64 *>(sendCountMatrix));
413 3 : bool hasSend = false;
414 3 : bool hasRecv = false;
415 :
416 3 : for (u32 i = 0; i < rankSize; i++) {
417 0 : for(u32 j = 0; j < rankSize; j++) {
418 0 : u64 sendCount = *(sendCountMatrixPtr + i * rankSize + j);
419 0 : CHK_RET(HcomCheckCountV2(sendCount));
420 0 : if (hasSend == false && sendCount != 0) {
421 0 : hasSend = true;
422 : }
423 0 : u64 recvCount = *(sendCountMatrixPtr + j * rankSize + i);
424 0 : CHK_RET(HcomCheckCountV2(recvCount));
425 0 : if (hasRecv == false && recvCount != 0) {
426 0 : hasRecv = true;
427 : }
428 0 : HCCL_DEBUG("[HcomCheckAlltoAllVCEmptyV2] myrank[%u] rmtrank[%u] sendCount[%llu] recvCount[%llu]",
429 : i, j, sendCount, recvCount);
430 : }
431 : }
432 3 : isEmpty = !(hasSend || hasRecv);
433 3 : return HCCL_SUCCESS;
434 : }
435 :
436 18 : HcclResult HcomCheckUserRankV2(const u32 totalRanks, const u32 userRank)
437 : {
438 18 : if (userRank >= totalRanks) {
439 3 : HCCL_ERROR("[Check][UserRank]errNo[0x%016llx] userRank:[%u] is out of range[0 ~ %u]",
440 : HCOM_ERROR_CODE(HCCL_E_PARA), userRank, totalRanks - 1);
441 1 : return HCCL_E_PARA;
442 : }
443 17 : return HCCL_SUCCESS;
444 : }
445 :
446 6 : HcclResult HcomLoadRankTableFileV2(const char *clusterInfo, std::string &rankTableM)
447 : {
448 6 : CHK_PTR_NULL(clusterInfo);
449 6 : CHK_PRT_RET(strlen(clusterInfo) >= PATH_MAX,
450 : HCCL_ERROR("[HcomLoadRankTableFileV2]clusterInfo exceeds PATH_MAX[%u]", PATH_MAX), HCCL_E_PARA);
451 :
452 : // 校验文件是否存在
453 6 : char resolvedPath[PATH_MAX] = {0};
454 6 : if (realpath(clusterInfo, resolvedPath) == nullptr) {
455 1 : std::string rankTablePath(clusterInfo);
456 1 : RPT_INPUT_ERR(true, "EI0004", std::vector<std::string>({"error_reason", "ranktable_path"}),
457 : std::vector<std::string>({rankTablePath, "The rankTable file path does not exist, the permission is insufficient, or the JSON format is incorrect."}));
458 3 : HCCL_ERROR("RanktableRealPath: %s is not a valid real path", clusterInfo);
459 1 : return HCCL_E_PARA;
460 1 : }
461 :
462 15 : HCCL_INFO("[RankTable]waiting for json file load complete");
463 5 : std::ifstream infoFile(resolvedPath, std::ifstream::in | std::ifstream::ate); // ate模式打开文件,方便获取size
464 5 : if (!infoFile) {
465 0 : HCCL_ERROR("[RankTable]open file %s failed", resolvedPath);
466 0 : return HCCL_E_INTERNAL;
467 : }
468 :
469 5 : uint64_t fileSize = infoFile.tellg();
470 5 : if (fileSize > RANKTABLE_MAX_SIZE) {
471 0 : HCCL_ERROR("[RankTable]load ranktable failed, file size = %llu is too large", fileSize);
472 0 : return HCCL_E_PARA;
473 : }
474 :
475 5 : infoFile.seekg(0, std::ifstream::beg); // 重置文件指针到开头,准备读取文件内容
476 5 : std::stringstream rankTableStr;
477 5 : rankTableStr << infoFile.rdbuf();
478 5 : rankTableM = rankTableStr.str();
479 5 : if (rankTableM.empty()) {
480 0 : HCCL_ERROR("[RankTable]load ranktable failed, file is empty");
481 0 : return HCCL_E_PARA;
482 : }
483 5 : s32 deviceLogicId = 0;
484 5 : aclrtGetDevice(&deviceLogicId);
485 5 : RankTableCrcBridge::GetInstance().RecordRankTableJsonCrc(deviceLogicId, rankTableM);
486 5 : return HCCL_SUCCESS;
487 5 : }
488 :
489 18 : HcclResult HcomCheckVOpParamV2(u32 rankId, u32 rankSize, u64 count, void *inCounts)
490 : {
491 18 : u64* counts = static_cast<u64 *>(inCounts);
492 18 : CHK_PRT_RET(
493 : rankId > rankSize,
494 : HCCL_ERROR("[%s] rankId[%u] is invalid(larger than rankSize[%u])", __func__, rankId, rankSize),
495 : HCCL_E_PARA);
496 36 : CHK_PRT_RET(
497 : count != counts[rankId],
498 : HCCL_ERROR("[%s] sendCount[%llu] is invalid(not equal to Counts[%llu])", __func__, count, counts[rankId]),
499 : HCCL_E_PARA);
500 12 : return HCCL_SUCCESS;
501 : }
502 :
503 0 : void HcomGetHashFromSendCountMatrixV2(u64 &sendCountMatrixHash, const void *sendCountMatrix,
504 : u64 rankSize, const std::string &tag)
505 : {
506 0 : std::string sendCountMatrixStr;
507 : std::hash<std::string> hashString;
508 0 : for (u32 i = 0; i < rankSize; i++) {
509 0 : for (u32 j = 0; j < rankSize; j++) {
510 : std::string curSendCountStr =
511 0 : std::to_string(*(static_cast<const u64 *>(sendCountMatrix) + i * rankSize + j));
512 0 : sendCountMatrixStr += curSendCountStr + '_';
513 0 : }
514 : }
515 0 : sendCountMatrixHash = hashString(sendCountMatrixStr.c_str());
516 0 : HCCL_DEBUG("[HcomGetHashFromSendCountMatrix] tag[%s], sendCountMatrixHash[%llu]",
517 : tag.c_str(), sendCountMatrixHash);
518 0 : }
|