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 { P2P_STATUS_DISABLED = 0, P2P_STATUS_ENABLING, P2P_STATUS_ENABLED };
30 :
31 : using P2PConnectionInfo = struct P2PConnectionInfoDef {
32 : uint32_t reference = 0;
33 : P2PStatus status = P2PStatus::P2P_STATUS_DISABLED;
34 : };
35 :
36 : class P2PEnableManager {
37 : public:
38 : static P2PEnableManager& GetInstance();
39 :
40 : // 测试使用
41 1 : std::set<std::pair<u32, u32>> GetSet() { return devicePairs; }
42 :
43 : HcclResult EnableP2P(std::vector<uint32_t> remoteDevices);
44 : HcclResult WaitP2PEnabled(std::vector<uint32_t> remoteDevices);
45 : HcclResult DisableP2P(uint32_t localDeviceLogicID, std::vector<uint32_t> remoteDevices);
46 :
47 : ~P2PEnableManager();
48 :
49 : private:
50 : std::set<std::pair<u32, u32>> devicePairs;
51 :
52 1 : P2PEnableManager() = default;
53 :
54 : P2PEnableManager(const P2PEnableManager& other) = delete;
55 :
56 : P2PEnableManager& operator=(const P2PEnableManager& other) = delete;
57 :
58 : HcclResult EnableP2P(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
59 : HcclResult WaitP2PEnabled(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
60 : HcclResult WaitP2PConnected(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
61 : HcclResult DisableP2P(uint32_t localDeviceLogicID, uint32_t remoteDevicePhysicID);
62 :
63 : std::array<std::map<uint32_t, P2PConnectionInfo>, MAX_MODULE_DEVICE_NUM> connectionsInfo_;
64 : std::array<std::mutex, MAX_MODULE_DEVICE_NUM> connectionsLock_;
65 : };
66 : } // namespace Hccl
67 :
68 : #endif // HCCLV2_P2P_ENABLE_MANAGER_H
|