LCOV - code coverage report
Current view: top level - aicpu_schedule/core/operator_kernel/control_flow - operator_kernel_model_repeat.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.9 % 33 30
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 4 4

            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_repeat.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_REPEAT = "modelRepeat";
      23              : }  // namespace
      24              : 
      25            2 : int32_t OperatorKernelModelRepeat::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
      26              : {
      27            2 :         const auto modelIdPtr = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(kernelTaskInfo.paraBase)));
      28            2 :     if (modelIdPtr == nullptr) {
      29            1 :         aicpusd_err("ModelRepeat kernelTaskInfo paramBase is null, modelId[%u], streamId[%u], taskId[%u]",
      30              :             taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
      31            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      32              :     }
      33            1 :     if (*modelIdPtr != taskContext.modelId) {
      34            1 :         aicpusd_warn(
      35              :             "ModelRepeat kernelTaskInfo modelId[%u] is diff with context, modelId[%u], streamId[%u], taskId[%u]",
      36              :             *modelIdPtr, taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
      37              :     }
      38            1 :     ResetStaticNNModelOutputIndex(taskContext.modelId);
      39            1 :     const auto model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
      40            1 :     if ((model != nullptr) && (model->GetModelRetCode() != 0) && (model->AbnormalNeedBreak())) {
      41            0 :         aicpusd_err("Model execute failed, need to break. modelId=%u, modelRetCode=%d.",
      42              :                     taskContext.modelId, model->GetModelRetCode());
      43            0 :         return AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED;
      44              :     }
      45            1 :     return OperatorKernelModelRepeat::SendModelRepeatEvent(*modelIdPtr);
      46              : }
      47              : 
      48            4 : uint32_t OperatorKernelModelRepeat::SendModelRepeatEvent(const uint32_t modelId)
      49              : {
      50            4 :     uint32_t iterCount = 0U;
      51            4 :     uint32_t activeStreamNum = 0U;
      52            4 :     const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
      53            4 :     if (model != nullptr) {
      54            3 :         iterCount = model->GetIteratorId();
      55            3 :         activeStreamNum = model->GetActiveStreamNum();
      56              :     }
      57            4 :     aicpusd_info("Begin to execute ModelRepeat. modelId[%u], activeStreamNum[%u], iterCount[%u]",
      58              :         modelId, activeStreamNum, iterCount);
      59            4 :     AICPUSubEventInfo subEventInfo = {};
      60            4 :     subEventInfo.modelId = modelId;
      61            4 :     g_aicpuProfiler.SetRepeatStart();
      62            4 :     const int32_t ret = OperatorKernelCommon::SendAICPUSubEvent(PtrToPtr<AICPUSubEventInfo, char_t>(&subEventInfo),
      63              :         static_cast<uint32_t>(sizeof(AICPUSubEventInfo)), AICPU_SUB_EVENT_REPEAT_MODEL);
      64            4 :     g_aicpuProfiler.SetRepeatEnd();
      65              : 
      66            4 :     return ret;
      67              : }
      68              : 
      69            1 : void OperatorKernelModelRepeat::ResetStaticNNModelOutputIndex(const uint32_t modelId) const
      70              : {
      71            1 :     const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
      72            1 :     if (model == nullptr) {
      73            1 :         return;
      74              :     }
      75            0 :     model->ResetStaticNNModelOutputIndex();
      76              : }
      77              : 
      78            6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_REPEAT, OperatorKernelModelRepeat);
      79              : }  // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1