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 : #include "operator_kernel_model_prepare.h"
12 :
13 : #include "aicpusd_status.h"
14 : #include "aicpusd_profiler.h"
15 : #include "aicpusd_model_execute.h"
16 : #include "aicpusd_resource_manager.h"
17 : #include "operator_kernel_common.h"
18 :
19 :
20 : namespace AicpuSchedule {
21 : namespace {
22 : const std::string KERNEL_MODEL_PREPARE = "modelPrepare";
23 : constexpr uint32_t ONLY_ONE_QUEUE = 1U;
24 : } // namespace
25 :
26 42 : int32_t OperatorKernelModelPrepare::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
27 : {
28 42 : const auto prepareInfo = PtrToPtr<void, AicpuPrepareInfo>(ValueToPtr(kernelTaskInfo.paraBase));
29 42 : if (prepareInfo == nullptr) {
30 1 : aicpusd_err("ModelPrepare kernelTaskInfo paramBase is null, modelId[%u], streamId[%u], taskId[%u].",
31 : taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
32 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
33 : }
34 41 : if (prepareInfo->aicpuPareInfoSize != sizeof(AicpuPrepareInfo)) {
35 1 : aicpusd_err("Failed check AicpuPrepareInfo size. msgInfo.aicpuPareInfoSize is [%u], "
36 : "calc AicpuPrepareInfo is [%zu].",
37 : prepareInfo->aicpuPareInfoSize, sizeof(AicpuPrepareInfo));
38 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
39 : }
40 40 : if (ChecPrepareNullptr(*prepareInfo) != AICPU_SCHEDULE_OK) {
41 10 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
42 : }
43 30 : if (CheckPrepareMaxSize(*prepareInfo) != AICPU_SCHEDULE_OK) {
44 5 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
45 : }
46 25 : if (!CheckPointListNullptr(PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(prepareInfo->inputAddrList))),
47 : prepareInfo->inputAddrNum)) {
48 1 : aicpusd_err("inputAddrList has null pointers!");
49 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
50 : }
51 24 : if (!CheckPointListNullptr(PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(prepareInfo->outputAddrList))),
52 : prepareInfo->outputAddrNum)) {
53 1 : aicpusd_err("outputAddrList has null pointers!");
54 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
55 : }
56 23 : if (prepareInfo->inQueueNum > prepareInfo->inputAddrNum) {
57 1 : aicpusd_err("Failed check AicpuPrepareInfo, inQueueNum[%u] is bigger then inputAddrNum[%u].",
58 : prepareInfo->inQueueNum, prepareInfo->inputAddrNum);
59 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
60 : }
61 22 : if ((prepareInfo->outQueueNum != ONLY_ONE_QUEUE) && (prepareInfo->outQueueNum != prepareInfo->outputMbufNum)) {
62 1 : aicpusd_err("Failed check AicpuPrepareInfo, outQueueNum[%u] is not 1 or equal with outputMbufNum[%u].",
63 : prepareInfo->outQueueNum, prepareInfo->outputMbufNum);
64 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
65 : }
66 21 : return DoCompute(*prepareInfo, taskContext);
67 : }
68 :
69 40 : int32_t OperatorKernelModelPrepare::ChecPrepareNullptr(const AicpuPrepareInfo &prepareInfo) const
70 : {
71 40 : if (prepareInfo.inputAddrNum == 0U) {
72 1 : aicpusd_err("inputAddrNum is zero!");
73 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
74 : }
75 39 : if (prepareInfo.outputAddrNum == 0U) {
76 1 : aicpusd_err("outputAddrNum is zero!");
77 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
78 : }
79 38 : if (prepareInfo.outputMbufNum == 0U) {
80 1 : aicpusd_err("outputMbufNum is zero!");
81 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
82 : }
83 37 : if (prepareInfo.inputAddrList == 0UL) {
84 1 : aicpusd_err("inputAddrList pointers is nullptr!");
85 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
86 : }
87 36 : if (prepareInfo.inputIndexList == 0UL) {
88 1 : aicpusd_err("inputIndexList pointers is nullptr!");
89 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
90 : }
91 35 : if (prepareInfo.outputAddrList == 0UL) {
92 1 : aicpusd_err("outputAddrList pointers is nullptr!");
93 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
94 : }
95 34 : if (prepareInfo.outputIndexList == 0UL) {
96 1 : aicpusd_err("outputIndexList pointers is nullptr!");
97 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
98 : }
99 33 : if (prepareInfo.outDataSizeList == 0UL) {
100 1 : aicpusd_err("outDataSizeList pointers is nullptr!");
101 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
102 : }
103 32 : if (prepareInfo.inQueueIdList == 0UL) {
104 1 : aicpusd_err("inQueueIdList pointers is nullptr!");
105 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
106 : }
107 31 : if (prepareInfo.mbufPtrlist == 0UL) {
108 1 : aicpusd_err("mbufPtrlist pointers is nullptr!");
109 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
110 : }
111 30 : return AICPU_SCHEDULE_OK;
112 : }
113 :
114 30 : int32_t OperatorKernelModelPrepare::CheckPrepareMaxSize(const AicpuPrepareInfo &prepareInfo) const
115 : {
116 30 : if (prepareInfo.inputAddrNum > MAX_SIZE_NUM) {
117 1 : aicpusd_err("inputAddrNum:[%u] out of max size:[%u]!", prepareInfo.inputAddrNum, MAX_SIZE_NUM);
118 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
119 : }
120 29 : if (prepareInfo.outputAddrNum > MAX_SIZE_NUM) {
121 1 : aicpusd_err("outputAddrNum:[%u] out of max size:[%u]!", prepareInfo.outputAddrNum, MAX_SIZE_NUM);
122 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
123 : }
124 28 : if (prepareInfo.outputMbufNum > MAX_SIZE_NUM) {
125 1 : aicpusd_err("outputMbufNum:[%u] out of max size:[%u]!", prepareInfo.outputMbufNum, MAX_SIZE_NUM);
126 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
127 : }
128 27 : if (prepareInfo.inQueueNum > MAX_SIZE_NUM) {
129 1 : aicpusd_err("inQueueNum:[%u] out of max size:[%u]!", prepareInfo.inQueueNum, MAX_SIZE_NUM);
130 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
131 : }
132 26 : if (prepareInfo.outQueueNum > MAX_SIZE_NUM) {
133 1 : aicpusd_err("outQueueNum:[%u] out of max size:[%u]!", prepareInfo.outQueueNum, MAX_SIZE_NUM);
134 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
135 : }
136 25 : return AICPU_SCHEDULE_OK;
137 : }
138 :
139 49 : bool OperatorKernelModelPrepare::CheckPointListNullptr(const uint64_t * const pointList, const uint32_t pointSize) const
140 : {
141 263 : for (uint32_t i = 0U; i < pointSize; i++) {
142 216 : if (*(pointList + i) == 0UL) {
143 2 : return false;
144 : }
145 : }
146 47 : return true;
147 : }
148 :
149 23 : int32_t OperatorKernelModelPrepare::DoCompute(AicpuPrepareInfo &msgInfo, const RunContext &taskContext) const
150 : {
151 23 : AicpuModel *model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
152 23 : if (model == nullptr) {
153 1 : aicpusd_err("cannot get model by modelId:[%u]!", taskContext.modelId);
154 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
155 : }
156 22 : ModelPrepareData &prepareData = model->GetModelPrepareData();
157 22 : std::vector<void *> &inputDataPtrs = model->GetInputDataPtrs();
158 :
159 22 : auto ret = DequeueMbufList(msgInfo, prepareData, inputDataPtrs, taskContext);
160 22 : if (ret != AICPU_SCHEDULE_OK) {
161 7 : return ret;
162 : }
163 15 : if (taskContext.pending) {
164 1 : aicpusd_info("Model stream pending on.");
165 1 : return ret;
166 : }
167 14 : g_aicpuProfiler.SetModelStart();
168 14 : Mbuf *lastInputMbuflist = reinterpret_cast<Mbuf *>(prepareData.lastInputMbuflistPtr);
169 :
170 14 : ret = CopyDequeueDataPtrToInputAddr(msgInfo, inputDataPtrs);
171 14 : if (ret != AICPU_SCHEDULE_OK) {
172 1 : return ret;
173 : }
174 13 : Mbuf *mbufPtrStore[MAX_SIZE_NUM] = {};
175 13 : ret = AllocOutputMbufList(msgInfo, &lastInputMbuflist, mbufPtrStore, taskContext);
176 13 : if (ret != AICPU_SCHEDULE_OK) {
177 6 : return ret;
178 : }
179 7 : void *dataPtrStore[MAX_SIZE_NUM] = {};
180 7 : ret = GetDataPtrsFromMbufs(msgInfo, mbufPtrStore, dataPtrStore);
181 7 : if (ret != AICPU_SCHEDULE_OK) {
182 1 : return ret;
183 : }
184 6 : ret = CopyOutputDataPtrToOutputAddr(msgInfo, dataPtrStore);
185 6 : if (ret != AICPU_SCHEDULE_OK) {
186 1 : return ret;
187 : }
188 5 : ret = BuildEnqueueMbufPtrList(msgInfo, mbufPtrStore);
189 5 : if (ret != AICPU_SCHEDULE_OK) {
190 1 : return ret;
191 : }
192 :
193 4 : return AICPU_SCHEDULE_OK;
194 : }
195 :
196 20 : int32_t OperatorKernelModelPrepare::DequeueMbufList(const AicpuPrepareInfo &msgInfo, ModelPrepareData &prepareData,
197 : std::vector<void *> &inputsData, const RunContext &taskContext) const
198 : {
199 20 : int32_t ret = AICPU_SCHEDULE_OK;
200 20 : void *mBufListPtr = nullptr;
201 20 : uint32_t mbufListNum = 0U;
202 : BufEnQueueInfo bufInfo;
203 20 : const uint32_t *inQueueIdList = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.inQueueIdList)));
204 :
205 20 : g_aicpuProfiler.SetDqStart();
206 70 : for (; prepareData.dequeueIndex < msgInfo.inQueueNum; prepareData.dequeueIndex++) {
207 58 : bufInfo.queueID = *(inQueueIdList + prepareData.dequeueIndex);
208 58 : bufInfo.mBufPtr = reinterpret_cast<uintptr_t>(&mBufListPtr);
209 58 : ret = DequeueTask(bufInfo, taskContext, true);
210 58 : if (ret != AICPU_SCHEDULE_OK) {
211 3 : return ret;
212 : }
213 55 : if (taskContext.pending) {
214 1 : aicpusd_info("Model stream pending on.");
215 1 : return ret;
216 : }
217 :
218 54 : if (prepareData.dequeueIndex == 0U) {
219 16 : prepareData.lastInputMbuflistPtr = mBufListPtr;
220 : }
221 :
222 : // store dataptr
223 54 : const auto drvRet = halMbufChainGetMbufNum(static_cast<Mbuf *>(mBufListPtr), &mbufListNum);
224 54 : if (drvRet != DRV_ERROR_NONE) {
225 1 : aicpusd_err("Failed to get mbuf number, ret[%d].", drvRet);
226 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
227 : }
228 53 : if (mbufListNum == 0U) {
229 1 : aicpusd_err("Get error number form mbuf, ret[%d].", ret);
230 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
231 : }
232 103 : for (uint32_t mbufRangeIndex = 0U; mbufRangeIndex < mbufListNum; mbufRangeIndex++) {
233 53 : void *dataPtr = nullptr;
234 53 : ret = GetMbufListDataPtr(mBufListPtr, &dataPtr, mbufRangeIndex);
235 53 : if (ret != AICPU_SCHEDULE_OK) {
236 2 : aicpusd_err("Failed to get mbuf data addr, ret:%d, index:%u.", ret, mbufRangeIndex);
237 2 : return ret;
238 : }
239 51 : inputsData.push_back(dataPtr);
240 : }
241 : }
242 12 : g_aicpuProfiler.SetDqEnd();
243 12 : return AICPU_SCHEDULE_OK;
244 : }
245 :
246 12 : int32_t OperatorKernelModelPrepare::CopyDequeueDataPtrToInputAddr(AicpuPrepareInfo &msgInfo,
247 : const std::vector<void *> &inputsData) const
248 : {
249 12 : int32_t ret = AICPU_SCHEDULE_OK;
250 12 : const uint32_t *inputIndexList = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.inputIndexList)));
251 12 : uint64_t *inputAddrList = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.inputAddrList)));
252 : // zero copy
253 12 : uint64_t *inputAddrPtr = nullptr;
254 71 : for (size_t addrIndex = 0UL; addrIndex < static_cast<size_t>(msgInfo.inputAddrNum); addrIndex++) {
255 60 : if (*(PtrAdd<const uint32_t>(inputIndexList, msgInfo.inputAddrNum, addrIndex)) < inputsData.size()) {
256 59 : inputAddrPtr = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(*(PtrAdd<uint64_t>(inputAddrList, msgInfo.inputAddrNum, addrIndex)))));
257 59 : *(inputAddrPtr) = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(
258 59 : inputsData[static_cast<size_t>(*(PtrAdd<const uint32_t>(inputIndexList, msgInfo.inputAddrNum, addrIndex)))]));
259 : } else {
260 1 : aicpusd_err("Prepare dequeue mbuf index out of range, index:[%u], inputIndexList[addrIndex]:[%zu], "
261 : "number of mbuf is:[%zu].",
262 : addrIndex, inputIndexList[addrIndex], inputsData.size());
263 1 : ret = AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
264 1 : break;
265 : }
266 : }
267 12 : return ret;
268 : }
269 :
270 13 : int32_t OperatorKernelModelPrepare::AllocOutputMbufList(AicpuPrepareInfo &msgInfo,
271 : Mbuf **lastInputMbuflistPptr,
272 : Mbuf *(&mbufPtrStore)[MAX_SIZE_NUM],
273 : const RunContext &taskContext) const
274 : {
275 13 : int32_t ret = AICPU_SCHEDULE_OK;
276 13 : uint32_t * const outDataSizeList = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.outDataSizeList)));
277 :
278 13 : g_aicpuProfiler.SetPrepareOutStart();
279 13 : if (msgInfo.outQueueNum == ONLY_ONE_QUEUE) {
280 5 : ret = BufManager::GetInstance().MallocAndGuardBufList(outDataSizeList, msgInfo.outputMbufNum,
281 5 : taskContext.modelId, true, &mbufPtrStore[0]);
282 5 : if (ret != AICPU_SCHEDULE_OK) {
283 3 : return ret;
284 : }
285 8 : } else if (msgInfo.outputMbufNum == msgInfo.outQueueNum) {
286 7 : ret = BufManager::GetInstance().MallocAndGuardBufList(outDataSizeList, msgInfo.outputMbufNum,
287 7 : taskContext.modelId, false, &mbufPtrStore[0]);
288 7 : if (ret != AICPU_SCHEDULE_OK) {
289 2 : return ret;
290 : }
291 : } else {
292 1 : aicpusd_err("error outputMbufNum. outputMbufNum:%u, outQueueNum:%u.", msgInfo.outputMbufNum,
293 : msgInfo.outQueueNum);
294 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
295 : }
296 7 : g_aicpuProfiler.SetPrepareOutEnd();
297 :
298 7 : void *headerInfoBuf = nullptr;
299 7 : uint32_t headerInfoBufSize = 0U;
300 7 : const auto drvRet = halMbufGetPrivInfo(*lastInputMbuflistPptr, &headerInfoBuf, &headerInfoBufSize);
301 7 : if (drvRet != DRV_ERROR_NONE) {
302 1 : aicpusd_err("Failed to get head info in input information, ret[%d].", drvRet);
303 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
304 : }
305 :
306 21 : for (uint32_t i = 0U; i < msgInfo.outputMbufNum; i++) {
307 16 : ret = OperatorKernelCommon::CopyMbufHeadInfo(headerInfoBuf, headerInfoBufSize, mbufPtrStore[i]);
308 16 : if (ret != AICPU_SCHEDULE_OK) {
309 1 : return ret;
310 : }
311 : }
312 5 : g_aicpuProfiler.SetMbufHead(headerInfoBuf);
313 5 : return AICPU_SCHEDULE_OK;
314 : }
315 :
316 10 : int32_t OperatorKernelModelPrepare::GetDataPtrsFromMbufs(const AicpuPrepareInfo &msgInfo,
317 : Mbuf *(&mbufPtrStore)[MAX_SIZE_NUM],
318 : void *(&dataPtrStore)[MAX_SIZE_NUM]) const
319 : {
320 10 : int32_t ret = AICPU_SCHEDULE_OK;
321 10 : void *dataPtr = nullptr;
322 10 : if (msgInfo.outQueueNum == ONLY_ONE_QUEUE) {
323 4 : uint32_t mbufListNum = 0U;
324 4 : const auto drvRet = halMbufChainGetMbufNum(mbufPtrStore[0U], &mbufListNum);
325 4 : if (drvRet != DRV_ERROR_NONE) {
326 1 : aicpusd_err("Failed to get mbuf number, ret[%d].", drvRet);
327 3 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
328 : }
329 3 : if (mbufListNum == 0U) {
330 1 : aicpusd_err("Get error number form mbuf, ret[%d].", ret);
331 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
332 : }
333 5 : for (uint32_t i = 0U; i < mbufListNum; i++) {
334 4 : ret = GetMbufListDataPtr(mbufPtrStore[0U], &dataPtr, i);
335 4 : if (ret != AICPU_SCHEDULE_OK) {
336 1 : aicpusd_err("Failed to get mbuf data addr.");
337 1 : return ret;
338 : }
339 3 : dataPtrStore[i] = dataPtr;
340 : }
341 6 : } else if (msgInfo.outputMbufNum == msgInfo.outQueueNum) {
342 17 : for (uint32_t i = 0U; i < msgInfo.outputMbufNum; i++) {
343 26 : ret = OperatorKernelCommon::GetMbufDataPtr(
344 13 : reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(&(mbufPtrStore[i]))), &dataPtr);
345 13 : if (ret != AICPU_SCHEDULE_OK) {
346 1 : aicpusd_err("Failed to get mbuf data addr.");
347 1 : return ret;
348 : }
349 12 : dataPtrStore[i] = dataPtr;
350 : }
351 : } else {
352 1 : aicpusd_err("error GetDataPtrsFromMbufs. outputMbufNum:%u, outQueueNum:%u.", msgInfo.outputMbufNum,
353 : msgInfo.outQueueNum);
354 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
355 : }
356 5 : return AICPU_SCHEDULE_OK;
357 : }
358 :
359 5 : int32_t OperatorKernelModelPrepare::CopyOutputDataPtrToOutputAddr(AicpuPrepareInfo &msgInfo,
360 : void * const (&dataPtrStore)[MAX_SIZE_NUM]) const
361 : {
362 5 : uint64_t * const outputAddrList = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.outputAddrList)));
363 : const uint32_t * const outputIndexList =
364 5 : PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.outputIndexList)));
365 :
366 : // zero copy
367 5 : uint64_t *outputAddrPtr = nullptr;
368 24 : for (uint32_t addrIndex = 0U; addrIndex < msgInfo.outputAddrNum; addrIndex++) {
369 20 : if (outputIndexList[addrIndex] < msgInfo.outputMbufNum) {
370 19 : outputAddrPtr = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(outputAddrList[addrIndex])));
371 19 : *(outputAddrPtr) =
372 19 : static_cast<uint64_t>(reinterpret_cast<uintptr_t>(dataPtrStore[outputIndexList[addrIndex]]));
373 : } else {
374 1 : aicpusd_err("Prepare output datas index out of range, index:[%u], outputIndexList[addrIndex]:[%u], "
375 : "msgInfo.outputMbufNum is:[%u].",
376 : addrIndex, outputIndexList[addrIndex], msgInfo.outputMbufNum);
377 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
378 : }
379 : }
380 4 : return AICPU_SCHEDULE_OK;
381 : }
382 :
383 7 : int32_t OperatorKernelModelPrepare::BuildEnqueueMbufPtrList(AicpuPrepareInfo &msgInfo,
384 : Mbuf *(&mbufPtrStore)[MAX_SIZE_NUM]) const
385 : {
386 7 : Mbuf **mbufPtrlist = reinterpret_cast<Mbuf **>(static_cast<uintptr_t>(msgInfo.mbufPtrlist));
387 7 : if ((msgInfo.outQueueNum == ONLY_ONE_QUEUE) && (*mbufPtrStore != nullptr)) {
388 2 : mbufPtrlist[0U] = mbufPtrStore[0U];
389 2 : return AICPU_SCHEDULE_OK;
390 : }
391 :
392 5 : if (msgInfo.outputMbufNum == msgInfo.outQueueNum) {
393 16 : for (size_t i = 0UL; i < msgInfo.outQueueNum; i++) {
394 12 : mbufPtrlist[i] = mbufPtrStore[i];
395 : }
396 4 : return AICPU_SCHEDULE_OK;
397 : }
398 1 : aicpusd_err("BuildEnqueueMbufPtrList:error outputMbufNum. outputMbufNum:%u, outQueueNum:%u.",
399 : msgInfo.outputMbufNum, msgInfo.outQueueNum);
400 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
401 : }
402 :
403 62 : int32_t OperatorKernelModelPrepare::GetMbufListDataPtr(void *mbufPtr, void **dataAddrPtr, const uint32_t mbufIndex) const
404 : {
405 62 : if (dataAddrPtr == nullptr) {
406 1 : aicpusd_err("Mbuf data ptr is null.");
407 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
408 : }
409 :
410 61 : if (mbufPtr == nullptr) {
411 1 : aicpusd_err("mbufPtr is null.");
412 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
413 : }
414 60 : Mbuf *dataMbuf = nullptr;
415 60 : const auto drvRet = halMbufChainGetMbuf(PtrToPtr<void, Mbuf>(mbufPtr), mbufIndex, &dataMbuf);
416 60 : if (drvRet != DRV_ERROR_NONE) {
417 3 : aicpusd_err("Failed to get mbuf from mbuflist, ret[%d].", drvRet);
418 3 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
419 : }
420 57 : if (dataMbuf == nullptr) {
421 1 : aicpusd_err("Mbuf get from mbuflist is nullptr, ret[%d].", drvRet);
422 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
423 : }
424 :
425 56 : const auto ret = OperatorKernelCommon::GetMbufDataPtr(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(&dataMbuf)),
426 : dataAddrPtr);
427 56 : if (ret != AICPU_SCHEDULE_OK) {
428 1 : aicpusd_err("Failed to get mbuf data addr. ret is [%d]", ret);
429 1 : return ret;
430 : }
431 55 : return AICPU_SCHEDULE_OK;
432 : }
433 :
434 :
435 6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_PREPARE, OperatorKernelModelPrepare);
436 : } // namespace AicpuSchedule
|