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