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

Generated by: LCOV version 2.0-1