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