LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/core - aicpusd_op_executor.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 38 38
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 5 5

            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 "aicpusd_op_executor.h"
      12              : #include <cstring>
      13              : #include <securec.h>
      14              : #include "aicpusd_info.h"
      15              : #include "aicpu_engine.h"
      16              : #include "aicpu_context.h"
      17              : #include "aicpusd_monitor.h"
      18              : #include "aicpusd_status.h"
      19              : namespace AicpuSchedule {
      20           40 : CustomOpExecutor& CustomOpExecutor::GetInstance()
      21              : {
      22              :     static CustomOpExecutor instance;
      23           40 :     return instance;
      24              : }
      25              : 
      26           21 : void CustomOpExecutor::InitOpExecutor(const pid_t pid, const std::string& custSoPath)
      27              : {
      28           21 :     hostPid_ = pid;
      29           21 :     aicpusd_run_info("Cust so path is %s.", custSoPath.c_str());
      30           21 : }
      31              : 
      32            5 : int32_t CustomOpExecutor::OpenKernelSo(const event_info_priv& privEventInfo) const
      33              : {
      34            5 :     const uint32_t soNameLen = privEventInfo.msg_len;
      35            5 :     if ((soNameLen == 0U) || (soNameLen > MAX_CUST_SO_NAME_LEN)) {
      36            2 :         aicpusd_err(
      37              :             "Input param custom so name length is zero or max reached(%u), soNameBufLen=%u.", MAX_CUST_SO_NAME_LEN,
      38              :             soNameLen);
      39            2 :         return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
      40              :     }
      41              : 
      42              :     // custom so name
      43            3 :     const std::string customSoName(privEventInfo.msg, static_cast<size_t>(soNameLen));
      44              :     // load so
      45            3 :     const uint32_t loadSoCnt = 1U;
      46            3 :     const char_t* soNames[loadSoCnt] = {customSoName.c_str()};
      47              :     const aeStatus_t ret =
      48            3 :         aeBatchLoadKernelSo(static_cast<uint32_t>(aicpu::KERNEL_TYPE_AICPU_CUSTOM), loadSoCnt, &(soNames[0]));
      49            3 :     if (ret != AE_STATUS_SUCCESS) {
      50            2 :         aicpusd_err("Failed to OpenSingleSo, customSoName[%s].", customSoName.c_str());
      51            2 :         return static_cast<int32_t>(ret);
      52              :     }
      53            1 :     aicpusd_info("Open custom so handle success, customSoName=%s.", customSoName.c_str());
      54            1 :     return AICPU_SCHEDULE_OK;
      55            3 : }
      56              : 
      57            4 : int32_t CustomOpExecutor::OpenKernelSoByAicpuEvent(const struct TsdSubEventInfo* const msg)
      58              : {
      59            4 :     if (msg == nullptr) {
      60            1 :         aicpusd_err("open custom so msg is null");
      61            1 :         return AicpuSchedule::AICPU_SCHEDULE_ERROR_INNER_ERROR;
      62              :     }
      63            3 :     event_info_priv privEventInfo = {};
      64            3 :     const errno_t errRet = strcpy_s(privEventInfo.msg, EVENT_MAX_MSG_LEN, msg->priMsg);
      65            3 :     if (errRet != EOK) {
      66            1 :         aicpusd_err("Copy %s failed, error[%d]", msg->priMsg, errRet);
      67            1 :         return AicpuSchedule::AICPU_SCHEDULE_ERROR_INNER_ERROR;
      68              :     }
      69            2 :     privEventInfo.msg_len = strnlen(privEventInfo.msg, MAX_CUST_SO_NAME_LEN);
      70            2 :     return CustomOpExecutor::GetInstance().OpenKernelSo(privEventInfo);
      71              : }
      72              : 
      73            9 : int32_t CustomOpExecutor::ExecuteKernel(aicpu::HwtsTsKernel& tsKernelInfo) const
      74              : {
      75            9 :     const auto ret = aeCallInterface(&tsKernelInfo);
      76            9 :     if ((ret == AE_STATUS_SUCCESS) || (ret == AE_STATUS_END_OF_SEQUENCE) || (ret == AE_STATUS_TASK_WAIT)) {
      77            8 :         aicpusd_info("Aicpu cust engine process success.");
      78              :     } else {
      79            1 :         aicpusd_err("Aicpu cust engine process failed, result[%d].", static_cast<int32_t>(ret));
      80              :     }
      81            9 :     return static_cast<int32_t>(ret);
      82              : }
      83              : } // namespace AicpuSchedule
        

Generated by: LCOV version 2.0-1