LCOV - code coverage report
Current view: top level - aicpu_schedule/core/operator_kernel/dequeue - operator_kernel_model_prepare.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 264 264
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 13 13

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

Generated by: LCOV version 2.0-1