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