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