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 : #include "ub_conn_lite_mgr.h"
11 :
12 : namespace Hccl {
13 :
14 2 : UbConnLiteMgr::UbConnLiteMgr()
15 : {
16 2 : }
17 :
18 2 : UbConnLiteMgr::~UbConnLiteMgr()
19 : {
20 2 : ubConnLiteMap.clear();
21 2 : }
22 :
23 6 : std::string UbConnLiteMgr::GetKey(const UbConnLiteParam &liteParam) const
24 : {
25 : // dieId + funcId + jettyId + tp + eid 可唯一确定一个connection
26 6 : std::string result;
27 12 : result += to_string(liteParam.dieId) + to_string(liteParam.funcId) + to_string(liteParam.jettyId)
28 18 : + to_string(liteParam.tpn);
29 6 : result += Bytes2hex(liteParam.rmtEid.raw, sizeof(liteParam.rmtEid.raw));
30 6 : return result;
31 0 : }
32 :
33 6 : bool UbConnLiteMgr::IsExist(const std::string &key)
34 : {
35 6 : if (ubConnLiteMap.find(key) == ubConnLiteMap.end()) {
36 5 : return false;
37 : }
38 1 : return true;
39 : }
40 :
41 16 : UbConnLiteMgr &UbConnLiteMgr::GetInstance()
42 : {
43 16 : static UbConnLiteMgr ubConnLiteMgr;
44 16 : return ubConnLiteMgr;
45 : }
46 :
47 1 : RmaConnLite *UbConnLiteMgr::Get(std::vector<char> &uniqueId)
48 : {
49 1 : UbConnLiteParam liteParam(uniqueId);
50 1 : auto key = GetKey(liteParam);
51 1 : if (IsExist(key)) {
52 0 : return ubConnLiteMap[key].get();
53 : }
54 :
55 1 : ubConnLiteMap[key] = make_unique<UbConnLite>(liteParam);
56 1 : return ubConnLiteMap[key].get();
57 1 : }
58 :
59 5 : void UbConnLiteMgr::Clear(std::vector<char> &uniqueId)
60 : {
61 5 : UbConnLiteParam liteParam(uniqueId);
62 5 : auto key = GetKey(liteParam);
63 5 : if (!IsExist(key)) {
64 4 : return;
65 : }
66 :
67 1 : ubConnLiteMap.erase(key);
68 5 : }
69 :
70 : } // namespace Hccl
|