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 : #ifndef HCCLV2_INNER_NET_DEVICE_MANAGER_H
11 : #define HCCLV2_INNER_NET_DEVICE_MANAGER_H
12 :
13 : #include <mutex>
14 : #include <unordered_map>
15 : #include "port.h"
16 : #include "orion_adapter_hccp.h"
17 : #include "ip_address.h"
18 : #include "inner_net_dev.h"
19 : #include "net_device.h"
20 :
21 : namespace Hccl {
22 : class InnerNetDevManager {
23 : public:
24 : // 获取单例实例(线程安全)
25 : static InnerNetDevManager& GetInstance();
26 :
27 : // 删除拷贝构造和赋值运算符,防止实例复制
28 : InnerNetDevManager(const InnerNetDevManager&) = delete;
29 : InnerNetDevManager& operator=(const InnerNetDevManager&) = delete;
30 :
31 : // 添加设备(增加引用计数)
32 : HcclResult AddDevice(const NetDevInfo& info, HcclNetDevice*& device);
33 :
34 : // 删除设备(减少引用计数,计数为0时删除)
35 : HcclResult DeleteDevice(HcclNetDevice* device);
36 :
37 : // 删除设备(减少引用计数,计数为0时删除)
38 : HcclResult RemoveDevice(const NetDevInfo& info);
39 :
40 : private:
41 : // 私有构造函数和析构函数
42 2 : InnerNetDevManager() = default;
43 2 : ~InnerNetDevManager() = default;
44 :
45 : std::unordered_map<NetDevInfo, unique_ptr<InnerNetDev>> netDevMap_;
46 : std::unordered_map<NetDevInfo, uint32_t> netDevCnt_;
47 : };
48 :
49 : } // namespace Hccl
50 :
51 : #endif // HCCLV2_INNER_NET_DEVICE_MANAGER_H
|