Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 URMA_DIRECT_TRANSPORT_H
11 : #define URMA_DIRECT_TRANSPORT_H
12 : #include "base_mem_transport.h"
13 : #include "task_param.h"
14 : #include "mc2_type.h"
15 : #include "orion_adapter_hccp.h"
16 : #include "dev_ub_connection.h"
17 :
18 : namespace Hccl {
19 :
20 : class UrmaDirectTransport : public BaseMemTransport {
21 : public:
22 : UrmaDirectTransport(
23 : CommonLocRes& commonLocRes, Attribution& attr, const LinkData& linkData, const Socket& socket,
24 : RdmaHandle rdmaHandle1);
25 : UrmaDirectTransport(
26 : CommonLocRes& commonLocRes, Attribution& attr, const LinkData& linkData, const Socket& socket,
27 : RdmaHandle rdmaHandle1, std::function<void(u32 streamId, u32 taskId, const TaskParam& taskParam)> callback);
28 :
29 : TransportStatus GetStatus() override;
30 :
31 : HcclAiRMAWQ GetAiRMAWQ();
32 : HcclAiRMACQ GetAiRMACQ();
33 :
34 : std::string Describe() const override;
35 :
36 : RemoteUbRmaBuffer* GetRmtBuffer() const;
37 :
38 : private:
39 : RdmaHandle rdmaHandle;
40 :
41 0 : MAKE_ENUM(UrmaStatus, INIT, SOCKET_OK, SEND_DATA, RECV_DATA, SEND_FIN, RECV_FIN, PROCESS_DATA, CONN_OK)
42 : UrmaStatus urmaStatus{UrmaStatus::INIT};
43 :
44 : using RemoteBufferVec = std::vector<std::unique_ptr<RemoteUbRmaBuffer>>;
45 : RemoteBufferVec rmtBufferVec; // 远端 buffer
46 :
47 : void SendExchangeData();
48 : void RecvExchangeData();
49 :
50 : void SendFinish();
51 : void RecvFinish();
52 :
53 : void BufferVecPack(BinaryStream& binaryStream);
54 :
55 : void RmtBufferVecUnpackProc(u32 locNum, BinaryStream& binaryStream, RemoteBufferVec& bufferVec);
56 : bool ConnVecUnpackProc(BinaryStream& binaryStream);
57 :
58 : std::vector<char> GetBufferUniqueId(RemoteBufferVec& bufferVec);
59 :
60 : bool IsResReady();
61 : bool IsConnsReady();
62 : bool RecvDataProcess();
63 :
64 : vector<char> sendData{};
65 : vector<char> recvData{};
66 : vector<char> sendFinishMsg{};
67 : vector<char> recvFinishMsg{};
68 : };
69 : } // namespace Hccl
70 : #endif
|