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 BASE_MEM_TRANSPORT_LITE_H
11 : #define BASE_MEM_TRANSPORT_LITE_H
12 :
13 : #include <memory>
14 : #include <vector>
15 : #include <unordered_map>
16 : #include "stream_lite.h"
17 : #include "buffer.h"
18 : #include "internal_exception.h"
19 : #include "rma_buffer_lite.h"
20 : #include "mem_transport_common.h"
21 : #include "rmt_rma_buf_slice_lite.h"
22 : #include "task_param.h"
23 : namespace Hccl {
24 :
25 4 : inline HcclReduceOp ConvertReduceOpToHcclReduceOp(ReduceOp reduceOp)
26 : {
27 : static std::map<ReduceOp, HcclReduceOp> reduceTypeMap = {{ReduceOp::SUM, HcclReduceOp::HCCL_REDUCE_SUM},
28 : {ReduceOp::PROD, HcclReduceOp::HCCL_REDUCE_PROD},
29 : {ReduceOp::MAX, HcclReduceOp::HCCL_REDUCE_MAX},
30 6 : {ReduceOp::MIN, HcclReduceOp::HCCL_REDUCE_MIN}};
31 4 : if (UNLIKELY(reduceTypeMap.find(reduceOp) == reduceTypeMap.end())) {
32 0 : THROW<InternalException>(StringFormat("reduceOp[%u] is invalid", reduceOp));
33 : }
34 4 : return reduceTypeMap[reduceOp];
35 : }
36 :
37 185 : MAKE_ENUM(TransferType, WRITE, WRITE_REDUCE, WRITE_WITH_NOTIFY, WRITE_REDUCE_WITH_NOTIFY, READ, READ_REDUCE, NOTIFY_RECORD)
38 :
39 : class BaseTransportLiteImpl {
40 : public:
41 177 : BaseTransportLiteImpl() = default;
42 :
43 177 : virtual ~BaseTransportLiteImpl() = default;
44 :
45 0 : virtual std::string Describe() const
46 : {
47 0 : return "BaseTransportLiteImpl";
48 : }
49 :
50 : struct TransferOp {
51 : TransferType transType;
52 : ReduceIn reduceIn;
53 : };
54 :
55 0 : virtual Buffer GetRmtBuffer(u32 index)
56 : {
57 : (void)index;
58 0 : return Buffer(0, 0);
59 : }
60 :
61 0 : virtual HcclResult BuildLocRmaBufferLite(const uintptr_t addr, const size_t size, RmaBufferLite &rmaBufferLite)
62 : {
63 : (void)addr;
64 : (void)size;
65 0 : rmaBufferLite = RmaBufferLite(0, 0, 0, 0);
66 0 : return HCCL_SUCCESS;
67 : }
68 :
69 0 : virtual void Post(u32 index, const StreamLite &stream)
70 : {
71 : (void)index;
72 : (void)stream;
73 0 : }
74 :
75 0 : virtual void Wait(u32 index, const StreamLite &stream)
76 : {
77 : (void)index;
78 : (void)stream;
79 0 : }
80 :
81 0 : virtual void WaitWithTimeout(u32 index, const StreamLite &stream, u32 timeout)
82 : {
83 : (void)index;
84 : (void)stream;
85 : (void)timeout;
86 0 : }
87 :
88 0 : virtual void Read(const RmaBufferLite &loc, const Buffer &rmt, const StreamLite &stream)
89 : {
90 : (void)loc;
91 : (void)rmt;
92 : (void)stream;
93 0 : }
94 :
95 0 : virtual void Write(const RmaBufferLite &loc, const Buffer &rmt, const StreamLite &stream)
96 : {
97 : (void)loc;
98 : (void)rmt;
99 : (void)stream;
100 0 : }
101 :
102 0 : virtual void ReadReduce(const RmaBufferLite &loc, const Buffer &rmt, const ReduceIn &reduceIn,
103 : const StreamLite &stream)
104 : {
105 : (void)loc;
106 : (void)rmt;
107 : (void)reduceIn;
108 : (void)stream;
109 0 : }
110 :
111 0 : virtual void WriteReduce(const RmaBufferLite &loc, const Buffer &rmt, const ReduceIn &reduceIn,
112 : const StreamLite &stream)
113 : {
114 : (void)loc;
115 : (void)rmt;
116 : (void)reduceIn;
117 : (void)stream;
118 0 : }
119 :
120 0 : virtual void WriteWithNotify(const RmaBufferLite &loc, const Buffer &rmt, const WithNotifyIn &withNotify,
121 : const StreamLite &stream)
122 : {
123 : (void)loc;
124 : (void)rmt;
125 : (void)withNotify;
126 : (void)stream;
127 0 : }
128 :
129 0 : virtual void WriteReduceWithNotify(const RmaBufferLite &loc, const Buffer &rmt, const ReduceIn &reduceIn,
130 : const WithNotifyIn &withNotify, const StreamLite &stream)
131 : {
132 : (void)loc;
133 : (void)rmt;
134 : (void)reduceIn;
135 : (void)withNotify;
136 : (void)stream;
137 0 : }
138 :
139 0 : virtual void BatchOneSidedWrite(const std::vector<RmaBufSliceLite> &loc, const std::vector<RmtRmaBufSliceLite> &rmt,
140 : const StreamLite &stream)
141 : {
142 : (void)loc;
143 : (void)rmt;
144 : (void)stream;
145 0 : }
146 :
147 0 : virtual void BatchOneSidedRead(const std::vector<RmaBufSliceLite> &loc, const std::vector<RmtRmaBufSliceLite> &rmt,
148 : const StreamLite &stream)
149 : {
150 : (void)loc;
151 : (void)rmt;
152 : (void)stream;
153 0 : }
154 :
155 2 : virtual void BatchTransfer(const std::vector<RmaBufferLite> &loc, const std::vector<Buffer> &rmt,
156 : const std::vector<TransferOp> &transferOp, const StreamLite &stream)
157 : {
158 : (void)loc;
159 : (void)rmt;
160 : (void)transferOp;
161 : (void)stream;
162 2 : }
163 :
164 0 : virtual void Drain(const StreamLite &stream)
165 : {
166 : (void)stream;
167 0 : }
168 :
169 0 : virtual HcclResult Fence()
170 : {
171 0 : return HCCL_SUCCESS;
172 : }
173 :
174 : // 自定义算子流程上报task的Callback
175 6 : HcclResult SetAddTaskInfoCallback(std::function<HcclResult(u32, u32, const TaskParam&, u64)> callback)
176 : {
177 6 : CHK_PTR_NULL(callback);
178 6 : newCallback_ = callback;
179 6 : return HCCL_SUCCESS;
180 : }
181 : protected:
182 : std::function<HcclResult(u32, u32, const TaskParam&, u64)> newCallback_{nullptr};
183 : private:
184 : };
185 :
186 : } // namespace Hccl
187 : #endif
|