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 "log.h"
12 : #include "comm_topo_desc.h"
13 :
14 : namespace hccl {
15 1040 : CommTopoDesc &CommTopoDesc::GetInstance()
16 : {
17 1040 : static CommTopoDesc commTopoDesc;
18 1040 : return commTopoDesc;
19 : }
20 :
21 9 : CommTopoDesc::CommTopoDesc()
22 : {
23 9 : }
24 :
25 9 : CommTopoDesc::~CommTopoDesc()
26 : {
27 9 : }
28 :
29 520 : void CommTopoDesc::SaveRankSize(std::string &str, uint32_t rankSize)
30 : {
31 520 : std::unique_lock<std::mutex> topoDescLock(lock_);
32 520 : rankSizeMap_[str] = rankSize;
33 520 : }
34 :
35 520 : void CommTopoDesc::SaveL0TopoType(std::string &str, CommTopo topoType)
36 : {
37 520 : std::unique_lock<std::mutex> topoDescLock(lock_);
38 520 : l0TopoTypeMap_[str] = topoType;
39 520 : }
40 :
41 0 : HcclResult CommTopoDesc::GetRankSize(std::string &str, uint32_t *rankSize)
42 : {
43 0 : std::unique_lock<std::mutex> topoDescLock(lock_);
44 0 : auto it = rankSizeMap_.find(str);
45 0 : if (it != rankSizeMap_.end()) {
46 0 : *rankSize = it->second;
47 0 : return HCCL_SUCCESS;
48 : } else {
49 0 : HCCL_ERROR("commName[%s] not found, please check comm init", str.c_str());
50 0 : return HCCL_E_PARA;
51 : }
52 0 : }
53 :
54 0 : HcclResult CommTopoDesc::GetL0TopoType(std::string &str, CommTopo *topoType)
55 : {
56 0 : std::unique_lock<std::mutex> topoDescLock(lock_);
57 0 : auto it = l0TopoTypeMap_.find(str);
58 0 : if (it != l0TopoTypeMap_.end()) {
59 0 : *topoType = it->second;
60 0 : return HCCL_SUCCESS;
61 : } else {
62 0 : HCCL_ERROR("commName[%s] not found, please check comm init", str.c_str());
63 0 : return HCCL_E_PARA;
64 : }
65 0 : }
66 : }
|