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

Generated by: LCOV version 2.0-1