Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HOST_CPU_URMA_CHANNEL_H
12 : #define HOST_CPU_URMA_CHANNEL_H
13 :
14 : #include "../channel.h"
15 : #include <mutex>
16 : #include "urma_types.h"
17 :
18 : // Orion
19 : #include "../../../../../../src/legacy/ascend950/unified_platform/resource/socket/socket.h"
20 : #include "../../sockets/socket_mgr.h"
21 : #include "ub_mem_transport.h"
22 : #include "host_ub_connection.h"
23 : #include "ub_local_notify.h"
24 : #include "aicpu_res_package_helper.h"
25 : #include "hcomm_adapter_hccp.h"
26 :
27 : namespace hcomm {
28 :
29 : class HostCpuUrmaChannel : public Channel {
30 : public:
31 : HostCpuUrmaChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc);
32 : ~HostCpuUrmaChannel() override;
33 :
34 : HcclResult Init() override;
35 : HcclResult GetNotifyNum(uint32_t* notifyNum) const override;
36 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override;
37 : ChannelStatus GetStatus() override;
38 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
39 :
40 : // 数据面接口
41 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
42 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
43 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override;
44 : HcclResult Write(void* dst, const void* src, uint64_t len) override;
45 : HcclResult Read(void* dst, const void* src, uint64_t len) override;
46 : HcclResult ChannelFence() override;
47 :
48 : HcclResult Clean() override;
49 : HcclResult Resume() override;
50 :
51 : private:
52 : HcclResult ParseInputParam();
53 : HcclResult StartListen();
54 : HcclResult BuildSocket();
55 : HcclResult BuildConnection();
56 : HcclResult BuildUbMemTransport();
57 : HcclResult GetLocSeg(const void* addr, const size_t size, u64* seg);
58 : HcclResult UrmaPostJettySendWr(urma_opcode_t opcode, void* dst, const void* src, uint64_t len);
59 : HcclResult GetSplitNum(uint64_t len, uint64_t maxJettyWrDataLen, uint64_t& splitNum);
60 : HcclResult
61 : GetLocalAndRemoteSeg(urma_opcode_t opcode, void* dst, const void* src, uint64_t len, u64& localSeg, u64& remoteSeg);
62 :
63 : private:
64 : // --------------------- 入参 ---------------------
65 : EndpointHandle endpointHandle_;
66 : HcommChannelDesc channelDesc_;
67 :
68 : // --------------------- 转换参数 ---------------------
69 : EndpointDesc localEp_{};
70 : EndpointDesc remoteEp_{};
71 :
72 : // --------------------- 具体成员 ---------------------
73 : Hccl::Socket* socket_{nullptr};
74 : const Hccl::SocketConfig* socketConfig_{nullptr};
75 : RdmaHandle rdmaHandle_{nullptr};
76 : std::unique_ptr<Hccl::UbMemTransport> memTransport_{nullptr};
77 : Hccl::BaseMemTransport::Attribution attr_{};
78 : Hccl::BaseMemTransport::CommonLocRes commonRes_{};
79 : std::vector<std::unique_ptr<Hccl::HostUbConnection>> connections_{};
80 : std::unique_ptr<Hccl::Socket> serverSocket_{nullptr};
81 :
82 : urma_jfc_t jfc_{};
83 : urma_jetty_t jetty_{};
84 : urma_target_jetty_t tjetty_{};
85 : uint32_t wqeNum_{0};
86 : bool fenceFlag_{false};
87 :
88 : std::mutex jfcMutex_;
89 : std::mutex fenceMutex_;
90 : bool Onetime_{false};
91 : DevBaseAttr devBaseAttr_{};
92 : uint32_t devicePhyId_{};
93 : };
94 :
95 : } // namespace hcomm
96 :
97 : #endif // HOST_CPU_URMA_CHANNEL_H
|