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 HCCLV2_RTSQ_BASE_H
11 : #define HCCLV2_RTSQ_BASE_H
12 : #include <vector>
13 : #include <functional>
14 : #include "types.h"
15 : #include "buffer.h"
16 : #include "notify_lite.h"
17 : #include "reduce_op.h"
18 : #include "data_type.h"
19 : #include "reduce_in.h"
20 : #include "not_support_exception.h"
21 : #include "ub_jetty_lite.h"
22 :
23 : #include "ascend_hal.h"
24 : namespace aicpu {
25 : void __attribute__((weak)) __attribute__((visibility("default")))
26 : GetSqeId(const uint32_t num, uint32_t& start, uint32_t& end);
27 : }
28 :
29 : namespace Hccl {
30 :
31 : constexpr u32 RTSQ_FULL_TIMEOUT_DEFAULT = 1836 + 20;
32 : constexpr u32 RTSQ_SQE_SIZE = 64;
33 : constexpr u32 PER_LAUNCH_SQE_CNT = 128;
34 :
35 : class RtsqBase {
36 : public:
37 : RtsqBase(u32 devPhyId, u32 streamId, u32 sqId);
38 :
39 600 : virtual ~RtsqBase() = default;
40 :
41 : virtual void Reset();
42 :
43 21 : inline u32 GetStreamId() const { return streamId_; }
44 :
45 : inline u32 GetSqDepth() const { return sqDepth_; }
46 :
47 2 : inline u32 GetHead() const { return sqHead_; }
48 :
49 2 : inline u32 GetTail() const { return sqTail_; }
50 :
51 68 : inline u32 GetTaskId() const { return taskId_; }
52 :
53 0 : void SetOpExecStatusCallback(std::function<void()> callback) { checkOpExecStatusCallback_ = callback; }
54 :
55 : void
56 2 : SetCheckExecStatusCallback(std::function<HcclResult(bool)> callback) // 自定义算子流程注册检查执行状态的回调函数
57 : {
58 2 : checkExecStatusCallback_ = callback;
59 2 : }
60 :
61 0 : virtual void LaunchTask() { MACRO_THROW(NotSupportException, StringFormat("not supported.")); }
62 :
63 0 : virtual void TryLaunchTask() { MACRO_THROW(NotSupportException, StringFormat("not supported.")); }
64 :
65 0 : virtual void NotifyWait(u32 notifyId)
66 : {
67 : (void)notifyId;
68 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
69 : }
70 :
71 0 : virtual void NotifyWait(u32 notifyId, u32 timeout)
72 : {
73 : (void)notifyId;
74 : (void)timeout;
75 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
76 : }
77 :
78 0 : virtual void Cnt1toNNotifyWait(u32 notifyId, u32 value)
79 : {
80 : (void)notifyId;
81 : (void)value;
82 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
83 : }
84 :
85 0 : virtual void Cnt1toNNotifyRecord(u32 notifyId, u32 value)
86 : {
87 : (void)notifyId;
88 : (void)value;
89 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
90 : }
91 :
92 0 : virtual void CntNto1NotifyWait(u32 notifyId, u32 value)
93 : {
94 : (void)notifyId;
95 : (void)value;
96 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
97 : }
98 :
99 0 : virtual void CntNto1NotifyRecord(u32 notifyId, u32 value)
100 : {
101 : (void)notifyId;
102 : (void)value;
103 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
104 : }
105 :
106 0 : virtual void NotifyRecordLoc(u32 notifyId)
107 : {
108 : (void)notifyId;
109 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
110 : }
111 :
112 0 : virtual void NotifyRecordRmt(u32 rmtDevPhyId, u32 notifyId) // 仅 P2P 使用
113 : {
114 : (void)rmtDevPhyId;
115 : (void)notifyId;
116 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
117 : }
118 :
119 0 : virtual void SdmaCopy(u64 srcAddr, u64 dstAddr, u32 size, u32 partId)
120 : {
121 : (void)srcAddr;
122 : (void)dstAddr;
123 : (void)size;
124 : (void)partId;
125 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
126 : }
127 :
128 0 : virtual void SdmaReduce(u64 srcAddr, u64 dstAddr, u32 size, u32 partId, const ReduceIn& reduceIn)
129 : {
130 : (void)srcAddr;
131 : (void)dstAddr;
132 : (void)size;
133 : (void)partId;
134 : (void)reduceIn;
135 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
136 : }
137 :
138 0 : virtual void P2PWriteValue(u64 remoteAddr, u32 writeValue)
139 : {
140 : (void)remoteAddr;
141 : (void)writeValue;
142 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
143 : }
144 :
145 0 : virtual void UbDbSend(const UbJettyLiteId& jettyLiteId, u16 piValue)
146 : {
147 : (void)jettyLiteId;
148 : (void)piValue;
149 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
150 : }
151 :
152 0 : virtual void RdmaDbSend(const uint64_t& dbAddr, const uint64_t& dbValue)
153 : {
154 : (void)dbAddr;
155 : (void)dbValue;
156 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
157 : }
158 :
159 0 : virtual void UbDirectSend(const UbJettyLiteId& jettyLiteId, u32 dwqeSize, const u8* wqe)
160 : {
161 : (void)jettyLiteId;
162 : (void)dwqeSize;
163 : (void)wqe;
164 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
165 : }
166 :
167 0 : virtual void UbWriteValue(u64 dbAddr, u32 piValue)
168 : {
169 : (void)dbAddr;
170 : (void)piValue;
171 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
172 : }
173 :
174 0 : virtual void CCoreNotifyWait(u64 waitAddr, u64 curTurnCntAddr, bool last)
175 : {
176 : (void)waitAddr;
177 : (void)curTurnCntAddr;
178 : (void)last;
179 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
180 : }
181 :
182 0 : virtual void CCoreNotifyRecord(u64 recordAddr, u64 curTurnCntAddr)
183 : {
184 : (void)recordAddr;
185 : (void)curTurnCntAddr;
186 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
187 : }
188 :
189 15 : virtual u64 GetSqeAddr() const { return 0; }
190 :
191 0 : virtual uint32_t GetPendingSqeCnt() const { return 0; }
192 :
193 : u32 QuerySqHead() const;
194 : u32 QuerySqTail() const;
195 :
196 0 : virtual bool IsRtsqQueueSpaceSufficient() { return true; }
197 :
198 0 : virtual HcclResult SetPreStreamSyncReady()
199 : {
200 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
201 : return HCCL_SUCCESS;
202 : }
203 :
204 0 : virtual HcclResult SetPreStreamSyncFin()
205 : {
206 0 : MACRO_THROW(NotSupportException, StringFormat("not supported."));
207 : return HCCL_SUCCESS;
208 : }
209 :
210 0 : virtual bool GetPreStreamSyncStatus() { return false; }
211 :
212 : HcclResult GetStreamIdAndTaskIdBySqIdx(u32 sqIdx, uint16_t& streamId, uint16_t& taskId) const;
213 :
214 : protected:
215 : u32 devPhyId_{0};
216 : u32 localDevId_{0};
217 : u32 streamId_{0}; // 填写到SQE中的streamId
218 : u32 sqId_{0};
219 :
220 : u32 sqHead_{0};
221 : u32 sqTail_{0};
222 : u32 sqDepth_{0};
223 : u64 sqBaseAddr_{0};
224 :
225 : u32 taskId_{0}; // 填写到SQE中的taskId,现改为由AICPU组件提供的sqeId维护
226 : u32 taskIdEnd_{0}; // 当前流已经申请到的最大taskId
227 :
228 : std::function<void()> checkOpExecStatusCallback_{nullptr};
229 : std::function<HcclResult(bool)> checkExecStatusCallback_{nullptr}; // 自定义算子流程,检查执行状态
230 :
231 : u32 QuerySqDepth() const;
232 :
233 : std::string GetHwSqDescribe() const;
234 :
235 : void ConfigSqTail(u32 value);
236 : void ConfigDisableToEnable(u32 value);
237 :
238 338 : inline void SetTaskIdBySqeId()
239 : {
240 338 : taskId_++; // taskId_的范围是aicpu::GetSqeId返回的[start, end), taskId累加到end时重新向aicpu申请, 不会翻转
241 338 : if (UNLIKELY(taskId_ >= taskIdEnd_)) { // taskEnd_视为未申请的taskId,不可使用
242 288 : constexpr u32 PER_GET_SQE_ID_NUM = 1024; // 一次性申请sqeId数量
243 288 : aicpu::GetSqeId(PER_GET_SQE_ID_NUM, taskId_, taskIdEnd_); // aicpu框架保证 taskId_ < taskIdEnd_
244 : }
245 338 : return;
246 : }
247 :
248 : private:
249 : u64 QuerySqBaseAddr() const;
250 : u32 QueryCqeStatus() const;
251 :
252 : u32 QuerySqStatusByType(drvSqCqPropType_t givenType) const;
253 : void ConfigSqStatusByType(drvSqCqPropType_t givenType, u32 value) const;
254 : };
255 :
256 : } // namespace Hccl
257 :
258 : #endif
|