LCOV - code coverage report
Current view: top level - aicpu_schedule/core/operator_kernel/enqueue - operator_kernel_model_batch_enqueue.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.2 % 34 30
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 3 3

            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_batch_enqueue.h"
      12              : 
      13              : #include "aicpusd_status.h"
      14              : #include "aicpusd_profiler.h"
      15              : #include "aicpusd_model_execute.h"
      16              : 
      17              : namespace AicpuSchedule {
      18              : namespace {
      19              : const std::string KERNEL_MODEL_BATCH_ENQUEUE = "modelBatchEnqueue";
      20              : } // namespace
      21              : 
      22            1 : int32_t OperatorKernelModelBatchEnqueue::Compute(const AicpuTaskInfo& kernelTaskInfo, const RunContext& taskContext)
      23              : {
      24            1 :     aicpusd_info(
      25              :         "Start ModelBatchEnque. modelId=%u, streamId=%u, taskId=%u.", taskContext.modelId, kernelTaskInfo.streamID,
      26              :         kernelTaskInfo.taskID);
      27            1 :     if (kernelTaskInfo.paraBase == 0UL) {
      28            0 :         aicpusd_err("kernelTaskInfo.paraBase is null");
      29            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      30              :     }
      31              : 
      32            1 :     const BatchDequeueDesc* const param = PtrToPtr<void, BatchDequeueDesc>(ValueToPtr(kernelTaskInfo.paraBase));
      33              :     const uint64_t* const mbufPtrlist =
      34            1 :         PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(param->mbufAddrsAddr)));
      35              :     const uint32_t* const outQueueIdList =
      36            1 :         PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(param->queueIdsAddr)));
      37            1 :     const uint32_t& outputNum = param->inputNums;
      38              : 
      39            1 :     if ((outputNum > 0U) && ((mbufPtrlist == nullptr) || (outQueueIdList == nullptr))) {
      40            0 :         aicpusd_err("outputNum[%u], but mbufAddrsAddr or queueIdsAddr is null.", outputNum);
      41            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      42              :     }
      43              : 
      44            1 :     return BatchEnque(taskContext, mbufPtrlist, outQueueIdList, outputNum);
      45              : }
      46              : 
      47            6 : int32_t OperatorKernelModelBatchEnqueue::BatchEnque(
      48              :     const RunContext& taskContext, const uint64_t* const mbufPtrlist, const uint32_t* const outQueueIdList,
      49              :     const uint32_t outQueueNum) const
      50              : {
      51              :     BufEnQueueInfo enqueueInfo;
      52            6 :     AicpuModel* const model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
      53            6 :     if (model == nullptr) {
      54            1 :         aicpusd_err("cannot get model by modelId:[%u]!", taskContext.modelId);
      55            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      56              :     }
      57            5 :     int32_t ret = AICPU_SCHEDULE_OK;
      58            5 :     g_aicpuProfiler.SetEqStart();
      59            5 :     ModelPostpareData& postpareData = model->GetModelPostpareData();
      60           13 :     for (; postpareData.enqueueIndex < outQueueNum; postpareData.enqueueIndex++) {
      61           10 :         enqueueInfo.mBufPtr = *(mbufPtrlist + postpareData.enqueueIndex);
      62           10 :         enqueueInfo.queueID = outQueueIdList[postpareData.enqueueIndex];
      63              : 
      64           10 :         ret = EnqueueTask(enqueueInfo, taskContext);
      65           10 :         if (ret != AICPU_SCHEDULE_OK) {
      66            1 :             return ret;
      67              :         }
      68            9 :         if (taskContext.pending) {
      69            1 :             aicpusd_info("pending is true, wait for event.");
      70            1 :             return ret;
      71              :         }
      72              :     }
      73              : 
      74            3 :     postpareData.enqueueIndex = 0;
      75            3 :     g_aicpuProfiler.SetEqEnd();
      76            3 :     return AICPU_SCHEDULE_OK;
      77              : }
      78              : 
      79            6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_BATCH_ENQUEUE, OperatorKernelModelBatchEnqueue);
      80              : } // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1