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 :
22 : namespace hcomm {
23 :
24 : class AivUrmaChannel : public Channel {
25 : public:
26 : AivUrmaChannel(EndpointHandle endpointHandle, const HcommChannelDesc &channelDesc);
27 : ~AivUrmaChannel() override;
28 :
29 : HcclResult Init() override;
30 : ChannelStatus GetStatus() override;
31 :
32 : HcclResult Clean() override;
33 : HcclResult Resume() override;
34 : virtual HcclResult GetNotifyNum(uint32_t *notifyNum) const override;
35 : HcclResult GetRemoteMems(uint32_t *memNum, CommMem **remoteMem, char ***memInfos) override;
36 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
37 : HcclResult BuildChannelEntityToDevice(void **devChannelPtr);
38 : HcclResult PreAllocChannelEntityToDevice(void **devChannelPtr);
39 : HcclResult FillChannelEntityToDevice();
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 : private:
49 : HcclResult ParseInputParam();
50 : HcclResult BuildSocket();
51 : HcclResult BuildAttr();
52 : HcclResult BuildConnection();
53 : HcclResult BuildAivUrmaTransport();
54 : void PutSocketIfNeeded();
55 : void ReleaseDeviceChannelEntity();
56 :
57 : // --------------------- 转换参数 ---------------------
58 : EndpointDesc localEp_{};
59 : EndpointDesc remoteEp_{};
60 : uint32_t notifyNum_{0};
61 :
62 : // --------------------- 入参 ---------------------
63 : EndpointHandle endpointHandle_;
64 : CommEngine engine_{COMM_ENGINE_RESERVED};
65 : HcommChannelDesc channelDesc_;
66 :
67 : // --------------------- 具体成员 ---------------------
68 : Hccl::Socket *socket_{nullptr};
69 : std::unique_ptr<Hccl::AivUrmaTransport> transport_{nullptr};
70 : Hccl::BaseMemTransport::Attribution attr_{};
71 : Hccl::BaseMemTransport::CommonLocRes commonRes_{};
72 : std::vector<std::unique_ptr<Hccl::DevUbConnection>> connections_{};
73 : RdmaHandle rdmaHandle_{nullptr};
74 : void *devChannelEntity_{nullptr};
75 : void *devChannelEntitySlab_{nullptr};
76 : size_t devChannelEntitySlabSize_{0};
77 : std::vector<hccl::DeviceMem> deviceMemories_{};
78 : std::unique_ptr<Hccl::Socket> serverSocket_;
79 : std::unique_ptr<Hccl::SocketConfig> socketConfigHolder_{nullptr};
80 : const Hccl::SocketConfig* socketConfig_{nullptr};
81 : uint32_t devicePhyId_{};
82 : };
83 :
84 : } // namespace hcomm
85 :
86 : #endif // AIV_URMA_CHANNEL_H
|