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_TRANSPORT_H
11 : #define AIV_URMA_TRANSPORT_H
12 : #include "base_mem_transport.h"
13 : #include "task_param.h"
14 : #include "orion_adapter_hccp.h"
15 : #include "dev_ub_connection.h"
16 : #include "hcomm/hcomm_res_entity_defs.h"
17 : #include "mem_device_pub.h"
18 : namespace Hccl {
19 :
20 : class AivUrmaTransport {
21 : public:
22 : AivUrmaTransport(
23 : BaseMemTransport::CommonLocRes& commonLocRes, BaseMemTransport::Attribution& attr, const LinkData& linkData,
24 : const Socket& socket, RdmaHandle rdmaHandle);
25 :
26 : TransportStatus GetStatus();
27 : std::string Describe() const;
28 : void GetEntityCountsForLayout(uint32_t& bufNum, uint32_t& connNum) const;
29 : void PrepareHostChannelEntity(ChannelEntity* channelEntitiesHost);
30 : void SetQueueIndexDeviceMem(void* sqPiMem, void* sqCiMem, void* cqPiMem, void* cqCiMem, size_t memSize);
31 : void GetHostChannelEntity(ChannelEntity* channelEntitiesHost);
32 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos);
33 :
34 : private:
35 167 : MAKE_ENUM(UrmaStatus, INIT, SOCKET_OK, SEND_DATA, RECV_DATA, SEND_FIN, RECV_FIN, PROCESS_DATA, CONN_OK)
36 : UrmaStatus urmaStatus_{UrmaStatus::INIT};
37 :
38 : // 获取ChannelEntity
39 : void GetSqContext();
40 : void GetCqContext();
41 : void GetProtectionInfo();
42 : void EnsureQueueIndexDeviceMem();
43 :
44 : // 建链过程
45 : using RemoteBufferVec = std::vector<std::unique_ptr<RemoteUbRmaBuffer>>;
46 : using LocalBufferVec = std::vector<std::unique_ptr<LocalUbRmaBuffer>>;
47 :
48 : void SendExchangeData();
49 : void RecvExchangeData();
50 : void SendFinish();
51 : void RecvFinish();
52 : void RmtBufferVecUnpackProc(uint32_t locNum, BinaryStream& binaryStream, RemoteBufferVec& bufferVec);
53 : bool ConnVecUnpackProc(BinaryStream& binaryStream);
54 : bool IsResReady();
55 : bool IsConnsReady();
56 : bool RecvDataProcess();
57 : std::string GetLinkDescInfo();
58 : void CheckLocBuffer(BaseMemTransport::CommonLocRes& res);
59 : void CheckLocConn(BaseMemTransport::CommonLocRes& res);
60 : void CheckCommonLocRes(BaseMemTransport::CommonLocRes& res);
61 : void HandshakeMsgPack(BinaryStream& binaryStream);
62 : void BufferVecPack(BinaryStream& binaryStream);
63 : void ConnVecPack(BinaryStream& binaryStream);
64 : void HandshakeMsgUnpack(BinaryStream& binaryStream);
65 : bool IsSocketReady();
66 : bool PrepareGetStatus();
67 : void ProcessUrmaStatus();
68 :
69 : BaseMemTransport::CommonLocRes commonLocRes_{};
70 : BaseMemTransport::Attribution attr_{};
71 : LinkData linkData_;
72 : Socket* socket_{nullptr};
73 : TransportType transportType_{TransportType::UB};
74 : RdmaHandle rdmaHandle_{nullptr};
75 :
76 : vector<char> sendData_{};
77 : vector<char> recvData_{};
78 : size_t exchangeDataSize_{0};
79 : vector<char> sendFinishMsg_{};
80 : vector<char> recvFinishMsg_{};
81 : TransportStatus transportStatus_{TransportStatus::INIT};
82 :
83 : RemoteBufferVec rmtBufferVec_{}; // 远端 buffer
84 : std::mutex remoteMemsMutex_; // 远端内存列表互斥锁
85 : LocalBufferVec localBuffers_{}; // 本地 buffer
86 : vector<char> rmtHandshakeMsg_{0}; // 远端握手消息
87 : AcceleratorState rmtOpAcceState_{AcceleratorState::AIV};
88 :
89 : std::vector<RegedBufferEntity> localBufferInfo_{};
90 : std::vector<RegedBufferEntity> remoteBufferInfo_{};
91 : std::vector<SqContext> sqContextVec_{};
92 : std::vector<CqContext> cqContextVec_{};
93 : hccl::DeviceMem sqPiMem_{};
94 : hccl::DeviceMem sqCiMem_{};
95 : hccl::DeviceMem cqPiMem_{};
96 : hccl::DeviceMem cqCiMem_{};
97 : uint32_t connNum_{0};
98 : bool cacheValid_{false}; // 缓存是否有效
99 : std::vector<CommMem> remoteUserMems_{}; // 内存基本信息缓存
100 : std::vector<std::string> memInfoCopies_{}; // 储存 Tag 字符串副本
101 : std::vector<char*> memInfoPointers_{}; // Tag 缓存
102 : };
103 : } // namespace Hccl
104 : #endif
|