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