LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/common - dlhal_function.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.0 % 73 65
Test Date: 2026-08-18 17:47:01 Functions: 83.3 % 6 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 "dlhal_function.h"
      12              : 
      13              : #include <string>
      14              : #include <map>
      15              : #include "log.h"
      16              : #include "hccl_dl.h"
      17              : 
      18              : namespace hccl {
      19        16210 : DlHalFunction& DlHalFunction::GetInstance()
      20              : {
      21        16210 :     static DlHalFunction hcclDlHalFunction;
      22        16209 :     return hcclDlHalFunction;
      23              : }
      24              : 
      25           19 : DlHalFunction::DlHalFunction() : handle_(nullptr) {}
      26              : 
      27           19 : DlHalFunction::~DlHalFunction()
      28              : {
      29           19 :     if (handle_ != nullptr) {
      30           19 :         (void)HcclDlclose(handle_);
      31           19 :         handle_ = nullptr;
      32              :     }
      33           19 : }
      34              : 
      35         4015 : HcclResult DlHalFunction::DlHalFunctionEschedInit()
      36              : {
      37              :     dlHalEschedSubmitEvent
      38         4015 :         = (drvError_t(*)(unsigned int, struct event_summary*))HcclDlsym(handle_, "halEschedSubmitEvent");
      39         4015 :     CHK_SMART_PTR_NULL(dlHalEschedSubmitEvent);
      40              : 
      41         4015 :     dlHalEschedAttachDevice = (drvError_t(*)(unsigned int))HcclDlsym(handle_, "halEschedAttachDevice");
      42         4015 :     CHK_SMART_PTR_NULL(dlHalEschedAttachDevice);
      43              : 
      44         4015 :     dlHalGetAPIVersion = (drvError_t(*)(int*))HcclDlsym(handle_, "halGetAPIVersion");
      45         4015 :     CHK_SMART_PTR_NULL(dlHalGetAPIVersion);
      46              : 
      47         4015 :     dlHalEschedDettachDevice = (drvError_t(*)(unsigned int))HcclDlsym(handle_, "halEschedDettachDevice");
      48         4015 :     CHK_SMART_PTR_NULL(dlHalEschedDettachDevice);
      49              : 
      50              :     dlHalEschedCreateGrp
      51         4015 :         = (drvError_t(*)(unsigned int, unsigned int, GROUP_TYPE))HcclDlsym(handle_, "halEschedCreateGrp");
      52         4015 :     CHK_SMART_PTR_NULL(dlHalEschedCreateGrp);
      53              : 
      54              :     dlHalEschedRegisterAckFunc
      55            0 :         = (drvError_t(*)(unsigned int, unsigned int, void (*ackFunc)(unsigned int, unsigned int, u8*, unsigned int)))
      56         4015 :             HcclDlsym(handle_, "halEschedRegisterAckFunc");
      57         4015 :     CHK_SMART_PTR_NULL(dlHalEschedRegisterAckFunc);
      58              : 
      59            0 :     dlHalDrvQueryProcessHostPid = (drvError_t(*)(
      60         4015 :         int, unsigned int*, unsigned int*, unsigned int*, unsigned int*))HcclDlsym(handle_, "drvQueryProcessHostPid");
      61         4015 :     CHK_SMART_PTR_NULL(dlHalDrvQueryProcessHostPid);
      62              : 
      63            0 :     dlDrvMemCpy = (DVresult(*)(
      64              :         unsigned long long dst, unsigned long long destMax, unsigned long long src,
      65         4015 :         unsigned long long count))HcclDlsym(handle_, "drvMemcpy");
      66         4015 :     CHK_SMART_PTR_NULL(dlDrvMemCpy);
      67              : 
      68         4015 :     dlHalDrvGetDevNum = (drvError_t(*)(uint32_t*))HcclDlsym(handle_, "drvGetDevNum");
      69         4015 :     CHK_SMART_PTR_NULL(dlHalDrvGetDevNum);
      70              : 
      71         4015 :     dlDrvDeviceGetBareTgid = (pid_t(*)(void))HcclDlsym(handle_, "drvDeviceGetBareTgid");
      72         4015 :     CHK_SMART_PTR_NULL(dlDrvDeviceGetBareTgid);
      73              : 
      74         4015 :     dlHalGetDeviceInfo = (drvError_t(*)(uint32_t, int32_t, int32_t, int64_t*))HcclDlsym(handle_, "halGetDeviceInfo");
      75         4015 :     CHK_SMART_PTR_NULL(dlHalGetDeviceInfo);
      76              : 
      77         4015 :     dlHalGrpQuery = (drvError_t(*)(GroupQueryCmdType, void*, unsigned int, void*, unsigned int*))HcclDlsym(
      78         4015 :         handle_, "halGrpQuery");
      79         4015 :     CHK_SMART_PTR_NULL(dlHalGrpQuery);
      80              : 
      81         4015 :     dlHalDrvGetPlatformInfo = (drvError_t(*)(uint32_t*))HcclDlsym(handle_, "drvGetPlatformInfo");
      82         4015 :     CHK_SMART_PTR_NULL(dlHalDrvGetPlatformInfo);
      83              : 
      84         4015 :     dlHalGetChipInfo = (drvError_t(*)(uint32_t, halChipInfo*))HcclDlsym(handle_, "halGetChipInfo");
      85         4015 :     if (dlHalGetChipInfo == nullptr) {
      86            0 :         HCCL_WARNING("dlHalGetChipInfo is nullptr, can not use halGetChipInfo");
      87              :     }
      88              : 
      89         4015 :     dlHalBindCgroup = (drvError_t(*)(BIND_CGROUP_TYPE))HcclDlsym(handle_, "halBindCgroup");
      90         4015 :     if (dlHalBindCgroup == nullptr) {
      91            0 :         HCCL_WARNING("dlHalBindCgroup is nullptr, can not use dlHalBindCgroup");
      92              :     }
      93              : 
      94              :     dlHalHostRegister
      95         4015 :         = (drvError_t(*)(void*, uint64_t, uint32_t, uint32_t, void**))HcclDlsym(handle_, "halHostRegister");
      96         4015 :     if (dlHalHostRegister == nullptr) {
      97            0 :         HCCL_WARNING("dlHalHostRegister is nullptr, can not use dlHalHostRegister");
      98              :     }
      99              : 
     100         4015 :     dlHalHostUnregister = (drvError_t(*)(void*, uint32_t))HcclDlsym(handle_, "halHostUnregister");
     101         4015 :     if (dlHalHostUnregister == nullptr) {
     102            0 :         HCCL_WARNING("dlHalHostUnregister is nullptr, can not use dlHalHostUnregister");
     103              :     }
     104              : 
     105         4015 :     dlHalHostUnregisterEx = (drvError_t(*)(void*, uint32_t, uint32_t))HcclDlsym(handle_, "halHostUnregisterEx");
     106         4015 :     if (dlHalHostUnregisterEx == nullptr) {
     107            0 :         HCCL_WARNING("dlHalHostUnregisterEx is nullptr, can not use dlHalHostUnregisterEx");
     108              :     }
     109              : 
     110         4015 :     dlHalMemCtl = (drvError_t(*)(int, void*, size_t, void*, size_t*))HcclDlsym(handle_, "halMemCtl");
     111         4015 :     CHK_SMART_PTR_NULL(dlHalMemCtl);
     112              : #ifdef CCL_KERNEL
     113              :     dlHalSensorNodeRegister
     114         4015 :         = (drvError_t(*)(uint32_t, struct halSensorNodeCfg*, uint64_t*))HcclDlsym(handle_, "halSensorNodeRegister");
     115         4015 :     CHK_SMART_PTR_NULL(dlHalSensorNodeRegister);
     116              : 
     117         4015 :     dlHalSensorNodeUnregister = (drvError_t(*)(uint32_t, uint64_t))HcclDlsym(handle_, "halSensorNodeUnregister");
     118         4015 :     CHK_SMART_PTR_NULL(dlHalSensorNodeUnregister);
     119              : 
     120              :     dlHalSensorNodeUpdateState
     121         4015 :         = (drvError_t(*)(uint32_t, uint64_t, int, halGeneralEventType_t))HcclDlsym(handle_, "halSensorNodeUpdateState");
     122         4015 :     CHK_SMART_PTR_NULL(dlHalSensorNodeUpdateState);
     123              : #endif
     124         4015 :     return HCCL_SUCCESS;
     125              : }
     126              : 
     127         4015 : HcclResult DlHalFunction::DlHalFunctionInit()
     128              : {
     129         4015 :     std::lock_guard<std::mutex> lock(handleMutex_);
     130         4015 :     if (handle_ == nullptr) {
     131           20 :         handle_ = HcclDlopen("libascend_hal.so", RTLD_NOW);
     132           20 :         const char* errMsg = dlerror();
     133           20 :         CHK_PRT_RET(
     134              :             handle_ == nullptr,
     135              :             HCCL_ERROR(
     136              :                 "dlopen [%s] failed, %s", "libascend_hal.so",
     137              :                 (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),
     138              :             HCCL_E_OPEN_FILE_FAILURE);
     139              :     }
     140              : 
     141         4015 :     CHK_RET(DlHalFunctionEschedInit());
     142         4015 :     return HCCL_SUCCESS;
     143         4015 : }
     144              : } // namespace hccl
        

Generated by: LCOV version 2.0-1