LCOV - code coverage report
Current view: top level - aicpu_schedule/core/hwts_kernel - hwts_kernel_model_process.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.5 % 73 69
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 6 6

            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 "hwts_kernel_model_process.h"
      12              : 
      13              : #include "aicpusd_interface_process.h"
      14              : #include "hwts_kernel_common.h"
      15              : 
      16              : namespace AicpuSchedule {
      17              : namespace {
      18              : const std::string CFG_EXT_INFO = "AicpuCfgExtInfo";
      19              : const std::string MODEL_CONFIG = "AicpuModelConfig";
      20              : const std::string SHAPE_CONFIG = "AicpuModelShapeConfig";
      21              : const std::string ESCHED_PRIORITY = "AicpuModelEschedPriority";
      22              : const std::string CHECK_SUPPORTED = "CheckKernelSupported";
      23              : const std::string PROCESS_DATA_EXCEPTION = "ProcessDataException";
      24              : } // namespace
      25              : 
      26            4 : int32_t ConfigExtInfoTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      27              : {
      28            4 :     aicpusd_info("Begin to process ts kernel CfgExtInfo event");
      29            4 :     const auto cfgMsg = PtrToPtr<void, aicpu::AicpuExtendInfo>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
      30            4 :     if (cfgMsg == nullptr) {
      31            1 :         aicpusd_err("param base for config extension message is null.");
      32            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      33              :     }
      34              : 
      35            3 :     return AicpuModelManager::GetInstance().ProcessExtInfoCfgMsg(*cfgMsg);
      36              : }
      37              : 
      38            2 : int32_t ModelConfigTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      39              : {
      40            2 :     aicpusd_info("Begin to process ts kernel ModelConfig event");
      41            2 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
      42            2 :     constexpr uint64_t len = sizeof(aicpu::AicpuParamHead) + sizeof(AicpuModelConfig);
      43            2 :     constexpr uint64_t offset = sizeof(aicpu::AicpuParamHead);
      44            2 :     const auto baseAddr = PtrToPtr<void, char_t>(ValueToPtr(kernel.paramBase));
      45            2 :     const aicpu::AicpuParamHead* const paramHead = PtrToPtr<char_t, aicpu::AicpuParamHead>(baseAddr);
      46            2 :     if (paramHead == nullptr) {
      47            1 :         aicpusd_err("ParamHead for ModelConfig is nullptr");
      48            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      49              :     }
      50              : 
      51            1 :     if (paramHead->length != len) {
      52            0 :         aicpusd_err("ModelConfig param length[%u] should be [%lu]", paramHead->length, len);
      53            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      54              :     }
      55              : 
      56            1 :     const auto cfg = PtrToPtr<const char_t, const AicpuModelConfig>(PtrAdd<const char_t>(baseAddr, len, offset));
      57            1 :     return AicpuModelManager::GetInstance().ProcessModelConfigMsg(*cfg);
      58              : }
      59              : 
      60           10 : int32_t ShapeConfigTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      61              : {
      62           10 :     aicpusd_info("Begin to process ts kernel ModelShapeConfig event");
      63           10 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
      64           10 :     constexpr uint64_t len = sizeof(aicpu::AicpuParamHead) + sizeof(AicpuModelShapeConfig);
      65           10 :     const auto baseAddr = PtrToPtr<void, char_t>(ValueToPtr(kernel.paramBase));
      66           10 :     const aicpu::AicpuParamHead* const paramHead = PtrToPtr<char_t, aicpu::AicpuParamHead>(baseAddr);
      67           10 :     if (paramHead == nullptr) {
      68            0 :         aicpusd_err("ParamHead for ModelShapeConfig is nullptr");
      69            0 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      70              :     }
      71              : 
      72           10 :     if (paramHead->length != len) {
      73            1 :         aicpusd_err("ModelShapeConfig param length[%u] should be [%lu]", paramHead->length, len);
      74            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      75              :     }
      76              : 
      77            9 :     constexpr uint64_t offset = sizeof(aicpu::AicpuParamHead);
      78            9 :     const auto cfg = PtrToPtr<const char_t, const AicpuModelShapeConfig>(PtrAdd<const char_t>(baseAddr, len, offset));
      79            9 :     return AicpuModelManager::GetInstance().ProcessModelShapeConfigMsg(*cfg);
      80              : }
      81              : 
      82            3 : int32_t EschedPriorityTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
      83              : {
      84            3 :     aicpusd_info("Begin to process ts kernel AicpuModelEschedPriority event.");
      85            3 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
      86            3 :     constexpr uint64_t len = sizeof(aicpu::AicpuParamHead) + sizeof(AicpuPriInfo);
      87            3 :     constexpr uint64_t offset = sizeof(aicpu::AicpuParamHead);
      88            3 :     const auto baseAddr = PtrToPtr<void, char_t>(ValueToPtr(kernel.paramBase));
      89            3 :     const aicpu::AicpuParamHead* const paramHead = PtrToPtr<char_t, aicpu::AicpuParamHead>(baseAddr);
      90            3 :     if (paramHead == nullptr) {
      91            1 :         aicpusd_err("ParamHead for AicpuModelEschedPriority is nullptr");
      92            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      93              :     }
      94              : 
      95            2 :     if (paramHead->length != len) {
      96            1 :         aicpusd_err("AicpuModelEschedPriority param length[%u] should be [%lu]", paramHead->length, len);
      97            1 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      98              :     }
      99            1 :     const auto cfg = PtrToPtr<const char_t, const AicpuPriInfo>(PtrAdd<const char_t>(baseAddr, len, offset));
     100            1 :     return AicpuModelManager::GetInstance().ProcessModelPriorityMsg(*cfg, true);
     101              : }
     102              : 
     103            3 : int32_t CheckSupportedTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
     104              : {
     105            3 :     aicpusd_run_info("Begin to process kernel CheckKernelSupported event.");
     106            3 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
     107            3 :     const auto supportedCfg = PtrToPtr<void, CheckKernelSupportedConfig>(ValueToPtr(kernel.paramBase));
     108            3 :     const uint32_t kernelNameLen = supportedCfg->kernelNameLen;
     109            3 :     const char* const kernelName = PtrToPtr<void, const char>(ValueToPtr(supportedCfg->kernelNameAddr));
     110            3 :     uint32_t* resultAddr = PtrToPtr<void, uint32_t>(ValueToPtr(supportedCfg->checkResultAddr));
     111            3 :     if ((kernelName == nullptr) || (kernelNameLen == 0) || (resultAddr == nullptr)) {
     112            1 :         aicpusd_err("CheckKernelSupportedConfig params error");
     113            1 :         return AICPU_SCHEDULE_FAIL;
     114              :     }
     115              : 
     116            2 :     std::string operaterKernelName(kernelName, static_cast<uint64_t>(kernelNameLen));
     117            2 :     aicpusd_info("Task kernel name[%s].", operaterKernelName.c_str());
     118            2 :     const int32_t retCode = AicpuScheduleInterface::GetInstance().CheckKernelSupported(operaterKernelName);
     119            2 :     *resultAddr = static_cast<uint32_t>(retCode);
     120            2 :     aicpusd_run_info("Finish to process kernel CheckKernelSupported event retCode[%d].", retCode);
     121            2 :     return AICPU_SCHEDULE_OK;
     122            2 : }
     123              : 
     124            1 : int32_t ProcessDataExceptionTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
     125              : {
     126            1 :     const aicpu::HwtsCceKernel& kernel = tsKernelInfo.kernelBase.cceKernel;
     127            1 :     const auto exceptionInfo = PtrToPtr<void, DataFlowExceptionNotify>(ValueToPtr(kernel.paramBase));
     128            1 :     return AicpuScheduleInterface::GetInstance().ProcessException(exceptionInfo);
     129              : }
     130              : 
     131              : REGISTER_HWTS_KERNEL(CFG_EXT_INFO, ConfigExtInfoTsKernel);
     132              : REGISTER_HWTS_KERNEL(MODEL_CONFIG, ModelConfigTsKernel);
     133              : REGISTER_HWTS_KERNEL(SHAPE_CONFIG, ShapeConfigTsKernel);
     134              : REGISTER_HWTS_KERNEL(ESCHED_PRIORITY, EschedPriorityTsKernel);
     135              : REGISTER_HWTS_KERNEL(CHECK_SUPPORTED, CheckSupportedTsKernel);
     136              : REGISTER_HWTS_KERNEL(PROCESS_DATA_EXCEPTION, ProcessDataExceptionTsKernel);
     137              : } // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1