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 AICPU_TS_P2P_CHANNEL_H
11 : #define AICPU_TS_P2P_CHANNEL_H
12 :
13 : #include <cstdint>
14 : #include <memory>
15 : #include <string>
16 : #include <vector>
17 :
18 : #include "../channel.h"
19 : #include "aicpu_ts_channel_helper.h"
20 : #include "../../sockets/socket_mgr.h"
21 :
22 : #include "../../../../../../legacy/ascend950/unified_platform/resource/socket/socket.h"
23 : #include "../../../../../../src/legacy/ascend950/unified_platform/resource/buffer/local_ipc_rma_buffer_v2.h"
24 : #include "p2p_transport.h"
25 : #include "p2p_connection.h"
26 : #include "ipc_local_notify.h"
27 : #include "aicpu_res_package_helper.h"
28 :
29 : namespace hcomm {
30 :
31 : class AicpuTsP2pChannel : public Channel {
32 : public:
33 : AicpuTsP2pChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc);
34 : ~AicpuTsP2pChannel() override;
35 :
36 : HcclResult Init() override;
37 : HcclResult GetNotifyNum(uint32_t* notifyNum) const override;
38 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override;
39 : ChannelStatus GetStatus() override;
40 : HcclResult UpdateMemInfo(HcommMemHandle* memHandles, uint32_t memHandleNum) override;
41 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
42 : HcclResult H2DResPack(std::vector<char>& buffer);
43 :
44 : virtual HcclResult Clean() override;
45 : virtual HcclResult Resume() override;
46 :
47 : // 数据面接口
48 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
49 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
50 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override;
51 : HcclResult Write(void* dst, const void* src, uint64_t len) override;
52 : HcclResult Read(void* dst, const void* src, uint64_t len) override;
53 : HcclResult ChannelFence() override;
54 :
55 0 : AicpuTsChannelHelper* GetAicpuTsHelper() override { return &aicpuTsHelper_; }
56 :
57 : private:
58 : AicpuTsChannelHelper aicpuTsHelper_;
59 : HcclResult SetModuleDataName(Hccl::ModuleData& module, const std::string& name);
60 : HcclResult ParseInputParam();
61 : HcclResult BuildAttr();
62 : HcclResult BuildConnection();
63 : HcclResult BuildNotify();
64 : HcclResult BuildP2pMemTransport();
65 : HcclResult BuildSocket();
66 :
67 : HcclResult PackOpData(std::vector<char>& data);
68 :
69 : private:
70 : EndpointHandle endpointHandle_;
71 : HcommChannelDesc channelDesc_;
72 :
73 : EndpointDesc localEp_{};
74 : EndpointDesc remoteEp_{};
75 : uint32_t notifyNum_{0};
76 :
77 : Hccl::Socket* socket_{nullptr};
78 : std::unique_ptr<Hccl::P2PTransport> memTransport_{nullptr};
79 : Hccl::BaseMemTransport::Attribution attr_{};
80 : Hccl::BaseMemTransport::CommonLocRes commonRes_{};
81 : std::vector<std::unique_ptr<Hccl::P2PConnection>> connections_{};
82 : std::vector<std::unique_ptr<Hccl::IpcLocalNotify>> localNotifies_{};
83 : std::unique_ptr<Hccl::Socket> serverSocket_;
84 : const Hccl::SocketConfig* socketConfig_{nullptr};
85 : uint32_t devicePhyId_{};
86 : };
87 :
88 : } // namespace hcomm
89 :
90 : #endif // AICPU_TS_P2P_CHANNEL_H
|