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 <sys/time.h> /* 获取时间 */
12 :
13 : #include "profiler_base_pub.h"
14 : #include "adapter_rts_common.h"
15 : #include "coll_alg_utils.h"
16 :
17 : using namespace hccl;
18 : std::array<std::map<s32, StreamRecordInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::streamRecordInfoMap_;
19 : std::array<std::map<const std::string, const std::string>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagGroupMap_;
20 : std::array<std::map<const std::string, const HcclWorkflowMode>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagModeMap_;
21 : std::array<std::map<const std::string, GroupRankInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupRankMap_;
22 : std::array<std::map<const std::string, OpDataInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagOpDataMap_;
23 : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupIndexMap_;
24 : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::aivGroupIndexMap_;
25 : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::sendRecvGroupIndexMap_;
26 : std::array<std::map<const std::string, std::string>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupUdiMap_;
27 : std::array<std::mutex, MAX_MODULE_DEVICE_NUM> ProfilerBase::streamMutex_;
28 : bool ProfilerBase::isSendRecv_[MAX_MODULE_DEVICE_NUM];
29 : u32 ProfilerBase::index_[MAX_MODULE_DEVICE_NUM];
30 :
31 : const std::array<uint32_t, HCCL_REDUCE_RESERVED> ProfilerBase::opString = {static_cast<u32>(OpDict::SUM),
32 : static_cast<u32>(OpDict::PROD), static_cast<u32>(OpDict::MAX), static_cast<u32>(OpDict::MIN)};
33 :
34 : const std::array<uint32_t, HCCL_DATA_TYPE_RESERVED> ProfilerBase::dataTypeString = {
35 : static_cast<u32>(DataType::DINT8), static_cast<u32>(DataType::DINT16), static_cast<u32>(DataType::DINT32),
36 : static_cast<u32>(DataType::DFP16), static_cast<u32>(DataType::DFP32), static_cast<u32>(DataType::DINT64),
37 : static_cast<u32>(DataType::DUINT64)
38 : };
39 : // 16位浮点在CPU中找不到对应的数据类型, 故直接写立即数 : 2
40 : const std::array<s32, HCCL_DATA_TYPE_RESERVED> ProfilerBase::sizeOf = { sizeof(s8), sizeof(short), sizeof(s32), 2,
41 : sizeof(float), sizeof(s64), sizeof(u64) };
42 950 : ProfilerBase::ProfilerBase(u32 deviceLogicId) : deviceLogicId_(deviceLogicId) {}
43 :
44 950 : ProfilerBase::~ProfilerBase() {}
45 :
46 25 : HcclResult ProfilerBase::AddStream(s32 streamID, const std::string &tag, s32 planeID, const AlgType &algType)
47 : {
48 25 : s32 deviceLogicId = -1;
49 25 : CHK_RET(hrtGetDevice(&deviceLogicId));
50 :
51 : u32 maxDeviceNum;
52 25 : CHK_RET(GetMaxDevNum(maxDeviceNum));
53 25 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("[Add][Stream]deviceLogicId_[%d]"
54 : "is bigger than HCCL_AISERVER_DEVICE_NUM[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
55 25 : HCCL_DEBUG("AddStream: streamID[%d], tag[%s], planeId[%d], algType[%s], deviceLogicId[%d]", streamID, tag.c_str(),
56 : planeID, AlgTypeToStr(algType).c_str(), deviceLogicId);
57 : {
58 25 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
59 25 : streamRecordInfoMap_[deviceLogicId][streamID] = StreamRecordInfo(planeID, algType, tag);
60 25 : }
61 25 : return HCCL_SUCCESS;
62 : }
63 :
64 21 : HcclResult ProfilerBase::DelStream(s32 streamID)
65 : {
66 21 : s32 deviceLogicId = -1;
67 21 : CHK_RET(hrtGetDevice(&deviceLogicId));
68 :
69 : u32 maxDeviceNum;
70 21 : CHK_RET(GetMaxDevNum(maxDeviceNum));
71 21 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("deviceLogicId_[%d] is bigger"
72 : "than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
73 :
74 : {
75 21 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
76 21 : HCCL_DEBUG("DelStream: streamID[%d] tag[%s], planeId[%d], algType[%s], deviceLogicId[%d]", streamID,
77 : streamRecordInfoMap_[deviceLogicId][streamID].tag.c_str(), streamRecordInfoMap_[deviceLogicId][streamID].planeId,
78 : AlgTypeToStr(streamRecordInfoMap_[deviceLogicId][streamID].algType).c_str(), deviceLogicId);
79 21 : streamRecordInfoMap_[deviceLogicId].erase(streamID);
80 21 : }
81 21 : return HCCL_SUCCESS;
82 : }
83 :
84 25 : HcclResult ProfilerBase::AddTag(const std::string &tag, const std::string &group, const HcclWorkflowMode &workFlowMode,
85 : bool isSendRecv, bool isAiv)
86 : {
87 25 : s32 deviceLogicId = -1;
88 25 : HcclResult ret = hrtGetDevice(&deviceLogicId);
89 25 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
90 : u32 maxDeviceNum;
91 25 : CHK_RET(GetMaxDevNum(maxDeviceNum));
92 25 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
93 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
94 25 : HCCL_DEBUG("AddTag: tag[%s] group[%s] deviceLogicId[%d] aivGroupIndexMap_ %d", tag.c_str(), group.c_str(), deviceLogicId, aivGroupIndexMap_[deviceLogicId][group]);
95 : {
96 25 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
97 25 : tagGroupMap_[deviceLogicId].emplace(tag, group);
98 25 : tagModeMap_[deviceLogicId].emplace(tag, workFlowMode);
99 5 : auto &targetMap = isAiv ? aivGroupIndexMap_[deviceLogicId] :
100 25 : (isSendRecv ? sendRecvGroupIndexMap_[deviceLogicId] : groupIndexMap_[deviceLogicId]);
101 25 : const auto &emplaceResult = targetMap.emplace(group, 0);
102 25 : auto &it = emplaceResult.first;
103 25 : it->second++;
104 25 : index_[deviceLogicId] = it->second;
105 25 : isSendRecv_[deviceLogicId] = isSendRecv;
106 25 : HCCL_DEBUG("IndexMap: tag[%s] group[%s] groupIndexMap_[%d]:%u sendRecvGroupIndexMap_[%d]:%u AivGroupIndexMap_[%d] %u", tag.c_str(), group.c_str(),
107 : deviceLogicId, groupIndexMap_[deviceLogicId][group], deviceLogicId, sendRecvGroupIndexMap_[deviceLogicId][group], deviceLogicId, aivGroupIndexMap_[deviceLogicId][group]);
108 25 : }
109 25 : return HCCL_SUCCESS;
110 : }
111 :
112 21 : HcclResult ProfilerBase::DelTag(const std::string &tag)
113 : {
114 21 : s32 deviceLogicId = -1;
115 21 : HcclResult ret = hrtGetDevice(&deviceLogicId);
116 21 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
117 : u32 maxDeviceNum;
118 21 : CHK_RET(GetMaxDevNum(maxDeviceNum));
119 21 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("deviceLogicId_[%d] is bigger"
120 : "than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
121 21 : HCCL_DEBUG("DelTag: tag[%s] group[%s] deviceLogicId[%d]", tag.c_str(), tagGroupMap_[deviceLogicId][tag].c_str(),
122 : deviceLogicId);
123 : {
124 21 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
125 21 : tagGroupMap_[deviceLogicId].erase(tag);
126 21 : tagModeMap_[deviceLogicId].erase(tag);
127 21 : }
128 21 : return HCCL_SUCCESS;
129 : }
130 :
131 25 : HcclResult ProfilerBase::AddOpData(const std::string &tag, u64 count, const void *src, const void *dst,
132 : HcclDataType dataType, u32 rootId, const std::string &group, HcclReduceOp reduceType)
133 : {
134 25 : s32 deviceLogicId = -1;
135 25 : HcclResult ret = hrtGetDevice(&deviceLogicId);
136 25 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
137 : u32 maxDeviceNum;
138 25 : CHK_RET(GetMaxDevNum(maxDeviceNum));
139 25 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
140 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
141 25 : HCCL_DEBUG("AddOpData: tag[%s] count[%u] src[%p] dst[%p] dataType[%s] deviceLogicId[%d] group[%s]",
142 : tag.c_str(), count, src, dst, GetDataTypeEnumStr(dataType).c_str(), deviceLogicId, group.c_str());
143 : {
144 25 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
145 25 : OpDataInfo opData;
146 25 : opData.count = count;
147 25 : opData.deviceId = deviceLogicId;
148 25 : opData.src = src;
149 25 : opData.dst = dst;
150 25 : opData.dataType = dataType;
151 25 : opData.index = index_[deviceLogicId];
152 25 : opData.rootId = rootId;
153 25 : (void)gettimeofday(&opData.tv, nullptr);
154 25 : opData.reduceType = reduceType;
155 25 : tagOpDataMap_[deviceLogicId][tag] = opData;
156 25 : }
157 25 : return HCCL_SUCCESS;
158 : }
159 :
160 22 : HcclResult ProfilerBase::DelOpData(const std::string &tag)
161 : {
162 22 : s32 deviceLogicId = -1;
163 22 : HcclResult ret = hrtGetDevice(&deviceLogicId);
164 22 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
165 : u32 maxDeviceNum;
166 22 : CHK_RET(GetMaxDevNum(maxDeviceNum));
167 22 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("deviceLogicId_[%d] is bigger"
168 : "than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
169 22 : HCCL_DEBUG("DelOpData: tag[%s] deviceLogicId[%d]", tag.c_str(), deviceLogicId);
170 : {
171 22 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
172 22 : tagOpDataMap_[deviceLogicId].erase(tag);
173 22 : }
174 22 : return HCCL_SUCCESS;
175 : }
176 :
177 25 : HcclResult ProfilerBase::AddGroupRankInfo(const std::string &group, u32 rankSize, u32 rankId, bool isSendRecv,
178 : u32 remoteRankId)
179 : {
180 25 : s32 deviceLogicId = -1;
181 25 : HcclResult ret = hrtGetDevice(&deviceLogicId);
182 25 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
183 : u32 maxDeviceNum;
184 25 : CHK_RET(GetMaxDevNum(maxDeviceNum));
185 25 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
186 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
187 25 : HCCL_DEBUG("AddGroupRankInfo: group[%s] rankSize[%u] rankId[%u] deviceLogicId[%d]", group.c_str(), rankSize,
188 : rankId, deviceLogicId);
189 : {
190 25 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
191 25 : GroupRankInfo groupRankInfo;
192 25 : groupRankInfo.rankSize = rankSize;
193 25 : groupRankInfo.rankId = rankId;
194 25 : groupRankInfo.remoteRankId = remoteRankId;
195 25 : groupRankMap_[deviceLogicId][group] = groupRankInfo;
196 25 : }
197 25 : return HCCL_SUCCESS;
198 : }
199 :
200 22 : HcclResult ProfilerBase::DelGroupRankInfo(const std::string &group)
201 : {
202 22 : s32 deviceLogicId = -1;
203 22 : HcclResult ret = hrtGetDevice(&deviceLogicId);
204 22 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
205 : u32 maxDeviceNum;
206 22 : CHK_RET(GetMaxDevNum(maxDeviceNum));
207 22 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("deviceLogicId_[%d] is bigger"
208 : "than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
209 22 : HCCL_DEBUG("DelGroupRankInfo: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
210 : {
211 22 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
212 22 : groupRankMap_[deviceLogicId].erase(group);
213 22 : }
214 22 : return HCCL_SUCCESS;
215 : }
216 :
217 182 : HcclResult ProfilerBase::GetTagByStream(u32 &streamID, std::string &tag)
218 : {
219 182 : s32 deviceLogicId = -1;
220 182 : HcclResult ret = hrtGetDevice(&deviceLogicId);
221 182 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
222 : u32 maxDeviceNum;
223 182 : CHK_RET(GetMaxDevNum(maxDeviceNum));
224 182 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("deviceLogicId_[%d] is bigger"
225 : "than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
226 :
227 182 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
228 182 : auto &streamMap = streamRecordInfoMap_[deviceLogicId];
229 182 : auto it = streamMap.find(streamID);
230 182 : CHK_PRT_RET((it == streamMap.end()), HCCL_DEBUG("stream id[%u] not found in profiler.", streamID), HCCL_SUCCESS);
231 122 : tag = it->second.tag;
232 122 : return HCCL_SUCCESS;
233 182 : }
234 :
235 47 : HcclResult ProfilerBase::GetAlgTypeByStream(u32 &streamID, AlgType &algType)
236 : {
237 47 : s32 deviceLogicId = -1;
238 47 : HcclResult ret = hrtGetDevice(&deviceLogicId);
239 47 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetAlgTypeByStream]rts get device error"), ret);
240 : u32 maxDeviceNum;
241 47 : CHK_RET(GetMaxDevNum(maxDeviceNum));
242 47 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("[GetAlgTypeByStream] "
243 : "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum),
244 : HCCL_E_INTERNAL);
245 :
246 47 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
247 47 : auto &streamMap = streamRecordInfoMap_[deviceLogicId];
248 47 : auto it = streamMap.find(streamID);
249 47 : CHK_PRT_RET((it == streamMap.end()), HCCL_DEBUG("[GetAlgTypeByStream] stream id[%u] not found in profiler.", streamID), HCCL_SUCCESS);
250 29 : algType = it->second.algType;
251 29 : return HCCL_SUCCESS;
252 47 : }
253 :
254 6 : HcclResult ProfilerBase::GetGroupNameByTag(const std::string &tag, std::string &group)
255 : {
256 6 : s32 deviceLogicId = -1;
257 6 : HcclResult ret = hrtGetDevice(&deviceLogicId);
258 6 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetGroupNameByTag]rts get device error"), ret);
259 : u32 maxDeviceNum;
260 6 : CHK_RET(GetMaxDevNum(maxDeviceNum));
261 6 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("[GetGroupNameByTag] "
262 : "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum),
263 : HCCL_E_INTERNAL);
264 :
265 6 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
266 6 : CHK_PRT_RET(tagGroupMap_[deviceLogicId].find(tag) == tagGroupMap_[deviceLogicId].end(),
267 : HCCL_DEBUG("[GetGroupNameByTag] tag[%s] not found in profiler.", tag.c_str()), HCCL_SUCCESS);
268 0 : group = tagGroupMap_[deviceLogicId][tag];
269 0 : return HCCL_SUCCESS;
270 6 : }
271 :
272 6 : HcclResult ProfilerBase::GetRankInfoByGroup(const std::string &group, GroupRankInfo &groupRankInfo)
273 : {
274 6 : s32 deviceLogicId = -1;
275 6 : HcclResult ret = hrtGetDevice(&deviceLogicId);
276 6 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetRankInfoByGroup]rts get device error"), ret);
277 : u32 maxDeviceNum;
278 6 : CHK_RET(GetMaxDevNum(maxDeviceNum));
279 6 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("[GetRankInfoByGroup] "
280 : "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum),
281 : HCCL_E_INTERNAL);
282 :
283 6 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
284 6 : CHK_PRT_RET(groupRankMap_[deviceLogicId].find(group) == groupRankMap_[deviceLogicId].end(),
285 : HCCL_DEBUG("[GetRankInfoByGroup] group[%s] not found in profiler.", group.c_str()), HCCL_SUCCESS);
286 0 : groupRankInfo = groupRankMap_[deviceLogicId][group];
287 0 : return HCCL_SUCCESS;
288 6 : }
289 :
290 6 : HcclResult ProfilerBase::GetOpDataInfoByTag(const std::string &tag, OpDataInfo &opDataInfo)
291 : {
292 6 : s32 deviceLogicId = -1;
293 6 : HcclResult ret = hrtGetDevice(&deviceLogicId);
294 6 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetOpDataInfoByTag]rts get device error"), ret);
295 : u32 maxDeviceNum;
296 6 : CHK_RET(GetMaxDevNum(maxDeviceNum));
297 6 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_WARNING("[GetOpDataInfoByTag] "
298 : "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum),
299 : HCCL_E_INTERNAL);
300 :
301 6 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
302 6 : CHK_PRT_RET(tagOpDataMap_[deviceLogicId].find(tag) == tagOpDataMap_[deviceLogicId].end(),
303 : HCCL_DEBUG("[GetOpDataInfoByTag] tag[%u] not found in profiler.", tag.c_str()), HCCL_SUCCESS);
304 0 : opDataInfo = tagOpDataMap_[deviceLogicId][tag];
305 0 : return HCCL_SUCCESS;
306 6 : }
307 :
308 80 : void ProfilerBase::GetSubmittedOpCnt(u32 &index)
309 : {
310 80 : s32 deviceLogicId = -1;
311 80 : HcclResult ret = hrtGetDevice(&deviceLogicId);
312 81 : index = 0;
313 81 : if (ret != HCCL_SUCCESS) {
314 0 : HCCL_ERROR("[GetSubmittedOpCnt]rts get device error");
315 0 : return;
316 : }
317 : u32 maxDeviceNum;
318 81 : ret = GetMaxDevNum(maxDeviceNum);
319 81 : if (ret != HCCL_SUCCESS) {
320 0 : HCCL_ERROR("[GetMaxDevNum] get maxDeviceNum error");
321 0 : return;
322 : }
323 81 : if (static_cast<u32>(deviceLogicId) >= maxDeviceNum) {
324 0 : HCCL_WARNING("[GetSubmittedOpCnt] "
325 : "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]", deviceLogicId, maxDeviceNum);
326 0 : return;
327 : }
328 :
329 81 : std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
330 81 : HCCL_DEBUG("GetSubmittedOpCnt: index_[%d][%u]", deviceLogicId, index_[deviceLogicId]);
331 81 : index = index_[deviceLogicId];
332 81 : return;
333 81 : }
334 :
335 5 : HcclResult ProfilerBase::AddGroupUdi(const std::string &group, const std::string &udi)
336 : {
337 5 : s32 deviceLogicId = -1;
338 5 : HcclResult ret = hrtGetDevice(&deviceLogicId);
339 5 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
340 : u32 maxDeviceNum;
341 5 : CHK_RET(GetMaxDevNum(maxDeviceNum));
342 5 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
343 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
344 5 : HCCL_RUN_INFO("AddGroupUdi: group[%s] udi[%s] deviceLogicId[%d]", group.c_str(), udi.c_str(),
345 : deviceLogicId);
346 5 : std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
347 10 : groupUdiMap_[deviceLogicId].insert(
348 10 : std::make_pair<const std::string &, const std::string &>(group, udi));
349 5 : return HCCL_SUCCESS;
350 5 : }
351 :
352 234 : HcclResult ProfilerBase::DelGroupUdi(const std::string &group)
353 : {
354 234 : s32 deviceLogicId = -1;
355 234 : HcclResult ret = hrtGetDevice(&deviceLogicId);
356 234 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
357 : u32 maxDeviceNum;
358 234 : CHK_RET(GetMaxDevNum(maxDeviceNum));
359 234 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
360 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
361 234 : HCCL_DEBUG("DelGroupUdi: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
362 234 : std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
363 234 : groupUdiMap_[deviceLogicId].erase(group);
364 234 : return HCCL_SUCCESS;
365 234 : }
366 :
367 12 : HcclResult ProfilerBase::GetUdiByGroup(const std::string &group, std::string &udi)
368 : {
369 12 : s32 deviceLogicId = -1;
370 12 : HcclResult ret = hrtGetDevice(&deviceLogicId);
371 12 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
372 : u32 maxDeviceNum;
373 12 : CHK_RET(GetMaxDevNum(maxDeviceNum));
374 12 : CHK_PRT_RET(static_cast<u32>(deviceLogicId) >= maxDeviceNum, HCCL_ERROR("deviceLogicId_[%d] is bigger than"
375 : " maxDeviceNum[%u]", deviceLogicId, maxDeviceNum), HCCL_E_INTERNAL);
376 12 : HCCL_DEBUG("GetUdiByGroup: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
377 12 : std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
378 12 : CHK_PRT_RET(groupUdiMap_[deviceLogicId].find(group) == groupUdiMap_[deviceLogicId].end(),
379 : HCCL_DEBUG("[GetUdiByGroup] group[%s] not found in profiler.", group.c_str()), HCCL_SUCCESS);
380 0 : udi = groupUdiMap_[deviceLogicId].find(group)->second;
381 0 : return HCCL_SUCCESS;
382 12 : }
|