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