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 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 P2P_MEM_TRANSPORT_LITE_H
11 : #define P2P_MEM_TRANSPORT_LITE_H
12 :
13 : #include <vector>
14 : #include <memory>
15 : #include <unordered_map>
16 : #include "base_transport_lite_impl.h"
17 : #include "notify_lite.h"
18 : #include "task_param.h"
19 : #include "rmt_rma_buf_slice_lite.h"
20 : #include "rma_conn_lite.h"
21 : #include "kernel_param_lite.h"
22 :
23 : namespace Hccl {
24 :
25 : class P2PTransportLiteImpl : public BaseTransportLiteImpl {
26 : public:
27 : explicit P2PTransportLiteImpl(
28 : std::vector<char>& uniqueId,
29 : std::function<void(u32 streamId, u32 taskId, const TaskParam& taskParam)> callback);
30 :
31 : P2PTransportLiteImpl(std::vector<char>& uniqueId);
32 : void Init(std::vector<char>& uniqueId);
33 :
34 : ~P2PTransportLiteImpl() override;
35 :
36 : std::string Describe() const override;
37 :
38 : Buffer GetRmtBuffer(u32 index) override;
39 :
40 : HcclResult BuildLocRmaBufferLite(const uintptr_t addr, const size_t size, RmaBufferLite& rmaBufferLite) override;
41 :
42 : void Post(u32 index, const StreamLite& stream) override;
43 :
44 : void Wait(u32 index, const StreamLite& stream) override;
45 :
46 : void WaitWithTimeout(u32 index, const StreamLite& stream, u32 timeout) override;
47 :
48 : void Read(const RmaBufferLite& loc, const Buffer& rmt, const StreamLite& stream) override;
49 :
50 : void ReadReduce(
51 : const RmaBufferLite& loc, const Buffer& rmt, const ReduceIn& reduceIn, const StreamLite& stream) override;
52 :
53 : void BatchTransfer(
54 : const std::vector<RmaBufferLite>& loc, const std::vector<Buffer>& rmt,
55 : const std::vector<TransferOp>& transferOp, const StreamLite& stream) override;
56 :
57 : private:
58 : u32 notifyNum{0};
59 : u32 bufferNum{0};
60 :
61 : struct RmtP2PNotifyLite {
62 : u64 addr;
63 : u64 size;
64 : u32 id;
65 6 : std::string Describe() const
66 : {
67 6 : return StringFormat("RmtP2PNotifyLite[addr=0x%llx, size=0x%llx, id=%u]", addr, size, id);
68 : }
69 : };
70 :
71 : struct P2PBufLite {
72 : u64 addr;
73 : u64 size;
74 3 : std::string Describe() const { return StringFormat("P2PBufLite[addr=0x%llx, size=0x%llx]", addr, size); }
75 : };
76 :
77 : std::vector<RmtP2PNotifyLite> rmtNotifyVec;
78 : std::vector<P2PBufLite> rmtBufferVec;
79 : std::vector<P2PBufLite> locBufferVec;
80 :
81 : std::vector<std::unique_ptr<NotifyLite>> locNotifyVec;
82 :
83 : std::function<void(u32 streamId, u32 taskId, const TaskParam& taskParam)> callback_{nullptr};
84 :
85 : void ParseLocNotifyVec(std::vector<char>& data);
86 :
87 : void ParseRmtNotifyVec(std::vector<char>& data, std::vector<RmtP2PNotifyLite>& vec) const;
88 :
89 : void ParseRmtBufferVec(std::vector<char>& data, std::vector<P2PBufLite>& vec) const;
90 :
91 : void BuildNotifyRecordTask(const StreamLite& stream, u64 rmtNotifyAddr);
92 :
93 : void BuildNotifyWaitTask(const StreamLite& stream, u32 notifyId);
94 :
95 : void BuildP2PRead(const StreamLite& stream, const RmaBufferLite& loc, const Buffer& rmt);
96 :
97 : void
98 : BuildP2PReadReduce(const StreamLite& stream, const RmaBufferLite& loc, const Buffer& rmt, const ReduceIn& reduceIn);
99 : };
100 :
101 : } // namespace Hccl
102 : #endif
|