LCOV - code coverage report
Current view: top level - aicpu_schedule/core/hwts_kernel - hwts_kernel_register.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.0 % 42 34
Test Date: 2026-07-28 10:54:05 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_register.h"
      12              : 
      13              : #include "aicpusd_status.h"
      14              : #include "aicpusd_model_err_process.h"
      15              : 
      16              : namespace AicpuSchedule {
      17           62 : HwTsKernelRegister &HwTsKernelRegister::Instance()
      18              : {
      19           62 :     static HwTsKernelRegister instance;
      20           62 :     return instance;
      21              : }
      22              : 
      23            2 : int32_t HwTsKernelRegister::RunTsKernelTaskProcess(const aicpu::HwtsTsKernel &tsKernelInfo, const std::string &kernelName)
      24              : {
      25            2 :     std::shared_ptr<HwTsKernelHandler> kernel = GetTsKernelTaskProcess(kernelName);
      26            2 :     if (kernel == nullptr) {
      27            2 :         aicpusd_err("Cannot find aicpu hwts kernel, kernelName=%s", kernelName.c_str());
      28            2 :         return AICPU_SCHEDULE_ERROR_NOT_FOUND_LOGICAL_TASK;
      29              :     }
      30              : 
      31            0 :     aicpusd_info("Begin to process kernelName[%s].", kernelName.c_str());
      32            0 :     const int32_t ret = kernel->Compute(tsKernelInfo);
      33            0 :     if (ret != AICPU_SCHEDULE_OK) {
      34            0 :         aicpusd_err("hwts kernel compute error, ret=%d, kernelName=%s", ret, kernelName.c_str());
      35              :     }
      36            0 :     aicpusd_info("End to process kernelName[%s] result[%d].", kernelName.c_str(), ret);
      37              : 
      38            0 :     return ret;
      39            2 : }
      40              : 
      41            3 : int32_t HwTsKernelRegister::CheckTsKernelSupported(const std::string &kernelName)
      42              : {
      43            3 :     std::shared_ptr<HwTsKernelHandler> kernel = GetTsKernelTaskProcess(kernelName);
      44            3 :     if (kernel == nullptr) {
      45            2 :         aicpusd_warn("check hwts kernel[%s] is not supported.", kernelName.c_str());
      46            2 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      47              :     }
      48              : 
      49            1 :     aicpusd_info("check hwts process kernel[%s] supported", kernelName.c_str());
      50            1 :     return AICPU_SCHEDULE_OK;
      51            3 : }
      52              : 
      53            5 : std::shared_ptr<HwTsKernelHandler> HwTsKernelRegister::GetTsKernelTaskProcess(const std::string &opType)
      54              : {
      55            5 :     std::map<std::string, std::shared_ptr<HwTsKernelHandler>>::iterator iter = tsKernelInstMap_.find(opType);
      56            5 :     if (iter != tsKernelInstMap_.end()) {
      57            1 :         return iter->second;
      58              :     }
      59            4 :     aicpusd_warn("The kernel[%s] is not registered", opType.c_str());
      60            4 :     return std::shared_ptr<HwTsKernelHandler>(nullptr);
      61              : }
      62              : 
      63           57 : HwTsKernelRegister::Registerar::Registerar(
      64              :     const std::string &kernelType, const HwTsKernelCreatorFunc &func)
      65              : {
      66           57 :     HwTsKernelRegister::Instance().Register(kernelType, func);
      67           57 : }
      68              : 
      69           57 : void HwTsKernelRegister::Register(
      70              :     const std::string &kernelType, const HwTsKernelCreatorFunc &func)
      71              : {
      72           57 :     std::unique_lock<std::mutex> lock(hwtsKernelMapMutex_);
      73              :     std::map<std::string, std::shared_ptr<HwTsKernelHandler>>::iterator iter =
      74           57 :         tsKernelInstMap_.find(kernelType);
      75           57 :     if (iter != tsKernelInstMap_.end()) {
      76            0 :         aicpusd_run_warn("Hwts Kernel[%s] creator already exist.", kernelType.c_str());
      77            0 :         return;
      78              :     }
      79              : 
      80           57 :     tsKernelInstMap_[kernelType] = func();
      81           57 :     aicpusd_info("Hwts Kernel[%s] register successfully.", kernelType.c_str());
      82              : 
      83           57 :     return;
      84           57 : }
      85              : 
      86              : }  // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1