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