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 : #ifndef HCCLV2_P2P_ENABLE_MANAGER_H
12 : #define HCCLV2_P2P_ENABLE_MANAGER_H
13 :
14 : #include <set>
15 : #include <mutex>
16 : #include <utility>
17 : #include <map>
18 : #include <functional>
19 : #include <thread>
20 : #include <array>
21 :
22 : #include "types.h"
23 : #include "hccl_common_v2.h"
24 : #include "orion_adapter_rts.h"
25 : #include "driver/ascend_hal.h"
26 :
27 : namespace Hccl {
28 :
29 : enum class P2PStatus {
30 : P2P_STATUS_DISABLED = 0,
31 : P2P_STATUS_ENABLING,
32 : P2P_STATUS_ENABLED
33 : };
34 :
35 : using P2PConnectionInfo = struct P2PConnectionInfoDef {
36 : uint32_t reference = 0;
37 : P2PStatus status = P2PStatus::P2P_STATUS_DISABLED;
38 : };
39 :
40 : class P2PEnableManager {
41 : public:
42 : static P2PEnableManager &GetInstance();
43 :
44 : // 测试使用
45 1 : std::set<std::pair<u32, u32>> GetSet()
46 : {
47 1 : return devicePairs;
48 : }
49 :
50 : HcclResult EnableP2P(std::vector<uint32_t> remoteDevices);
51 : HcclResult WaitP2PEnabled(std::vector<uint32_t> remoteDevices);
52 : HcclResult DisableP2P(uint32_t localDeviceLogicID, std::vector<uint32_t> remoteDevices);
53 :
54 : ~P2PEnableManager();
55 :
56 : private:
57 : std::set<std::pair<u32, u32>> devicePairs;
58 :
59 1 : P2PEnableManager() = default;
60 :
61 : P2PEnableManager(const P2PEnableManager &other) = delete;
62 :
63 : P2PEnableManager &operator=(const P2PEnableManager &other) = delete;
64 :
65 : HcclResult EnableP2P(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
66 : HcclResult WaitP2PEnabled(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
67 : HcclResult WaitP2PConnected(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
68 : HcclResult DisableP2P(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
69 :
70 : std::array<std::map<uint32_t, P2PConnectionInfo>, MAX_MODULE_DEVICE_NUM> connectionsInfo_;
71 : std::array<std::mutex, MAX_MODULE_DEVICE_NUM> connectionsLock_;
72 : };
73 : } // namespace Hccl
74 :
75 : #endif // HCCLV2_P2P_ENABLE_MANAGER_H
|