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 AIV_URMA_CHANNEL_H
12 : #define AIV_URMA_CHANNEL_H
13 :
14 : #include "../channel.h"
15 :
16 : // Orion
17 : #include "aiv_urma_transport.h"
18 : #include "buffer_key.h"
19 : #include "resource/notify/ub_local_notify.h"
20 : #include "resource/socket/socket.h"
21 : #include "socket_mgr.h"
22 : #include "hcomm_adapter_hccp.h"
23 :
24 : namespace hcomm {
25 :
26 : struct UbConnBuildContext;
27 :
28 : class AivUrmaChannel : public Channel {
29 : public:
30 : AivUrmaChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc);
31 : ~AivUrmaChannel() override;
32 :
33 : HcclResult Init() override;
34 : ChannelStatus GetStatus() override;
35 :
36 : HcclResult Clean() override;
37 : HcclResult Resume() override;
38 : virtual HcclResult GetNotifyNum(uint32_t* notifyNum) const override;
39 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override;
40 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
41 : HcclResult BuildChannelEntityToDevice(void** devChannelPtr);
42 : HcclResult PreAllocChannelEntityToDevice(void** devChannelPtr);
43 : HcclResult FillChannelEntityToDevice();
44 :
45 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
46 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
47 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override;
48 : HcclResult Write(void* dst, const void* src, uint64_t len) override;
49 : HcclResult Read(void* dst, const void* src, uint64_t len) override;
50 : HcclResult ChannelFence() override;
51 :
52 : private:
53 : HcclResult ParseInputParam();
54 : HcclResult StartListen();
55 : HcclResult BuildSocket();
56 : HcclResult BuildAttr();
57 : HcclResult BuildConnection();
58 : HcclResult BuildAivUrmaTransport();
59 : void PutSocketIfNeeded();
60 : void ReleaseDeviceChannelEntity();
61 :
62 : HcclResult CreateUbConnectionByProtocol(
63 : const UbConnBuildContext& ctx, std::unique_ptr<Hccl::DevUbConnection>& ubConn,
64 : Hccl::DevUbConnection::JettyMode jettyMode = Hccl::DevUbConnection::JettyMode::SELF_CREATE);
65 : HcclResult AcquireSharedJettyInBuildConnection(const UbConnBuildContext& ctx, Hccl::DevUbConnection* connection);
66 : static std::unique_ptr<Hccl::DevUbConnection> CreateSharedJettyConnection(
67 : Hccl::RdmaHandle rdmaHandle, const Hccl::IpAddress& locAddr, const Hccl::IpAddress& rmtAddr, u8 qosPre,
68 : Hccl::LinkProtocol protocol, u8 taTimeOut, u32 sqDepth);
69 :
70 : // --------------------- 转换参数 ---------------------
71 : EndpointDesc localEp_{};
72 : EndpointDesc remoteEp_{};
73 : uint32_t notifyNum_{0};
74 :
75 : // --------------------- 入参 ---------------------
76 : EndpointHandle endpointHandle_;
77 : CommEngine engine_{COMM_ENGINE_RESERVED};
78 : HcommChannelDesc channelDesc_;
79 :
80 : // --------------------- 具体成员 ---------------------
81 : Hccl::Socket* socket_{nullptr};
82 : std::unique_ptr<Hccl::AivUrmaTransport> transport_{nullptr};
83 : Hccl::BaseMemTransport::Attribution attr_{};
84 : Hccl::BaseMemTransport::CommonLocRes commonRes_{};
85 : std::vector<std::unique_ptr<Hccl::DevUbConnection>> connections_{};
86 : RdmaHandle rdmaHandle_{nullptr};
87 : void* devChannelEntity_{nullptr};
88 : void* devChannelEntitySlab_{nullptr};
89 : size_t devChannelEntitySlabSize_{0};
90 : std::vector<hccl::DeviceMem> deviceMemories_{};
91 : DevBaseAttr devBaseAttr_{};
92 : std::unique_ptr<Hccl::SocketConfig> socketConfigHolder_{nullptr};
93 : const Hccl::SocketConfig* socketConfig_{nullptr};
94 : uint32_t devicePhyId_{};
95 :
96 : // 共享 jetty 模式下从 Endpoint::SharedJettyCtx 取得的 PI/CI device 内存指针,
97 : // BuildChannelEntityToDevice 时绑给 transport,使同 endpoint 下多 channel 共用同一 PI/CI。
98 : void* sharedSqPiPtr_{nullptr};
99 : void* sharedSqCiPtr_{nullptr};
100 : void* sharedCqPiPtr_{nullptr};
101 : void* sharedCqCiPtr_{nullptr};
102 : };
103 :
104 : } // namespace hcomm
105 :
106 : #endif // AIV_URMA_CHANNEL_H
|