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