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