LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/common - dltdt_function.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 27 27
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 <string>
      12              : #include <map>
      13              : #include "hccl_dl.h"
      14              : #include "log.h"
      15              : #include "dltdt_function.h"
      16              : 
      17              : namespace hccl {
      18         2001 : DlTdtFunction& DlTdtFunction::GetInstance()
      19              : {
      20         2001 :     static DlTdtFunction hcclDlTdtFunction;
      21         2001 :     return hcclDlTdtFunction;
      22              : }
      23              : 
      24           14 : DlTdtFunction::DlTdtFunction() : handle_(nullptr) {}
      25              : 
      26           14 : DlTdtFunction::~DlTdtFunction()
      27              : {
      28           14 :     if (handle_ != nullptr) {
      29           14 :         (void)HcclDlclose(handle_);
      30           14 :         handle_ = nullptr;
      31              :     }
      32           14 : }
      33         1574 : HcclResult DlTdtFunction::DlTdtFunctionInit()
      34              : {
      35              : #ifndef HCCD
      36         1574 :     std::lock_guard<std::mutex> lock(handleMutex_);
      37         1574 :     if (handle_ == nullptr) {
      38           14 :         handle_ = HcclDlopen("libtsdclient.so", RTLD_NOW);
      39           14 :         const char* errMsg = dlerror();
      40           14 :         CHK_PRT_RET(
      41              :             handle_ == nullptr,
      42              :             HCCL_ERROR(
      43              :                 "dlopen [%s] failed, %s", "libtsdclient.so",
      44              :                 (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),
      45              :             HCCL_E_OPEN_FILE_FAILURE);
      46              :     }
      47              :     dlTsdCapabilityGet
      48         1574 :         = (uint32_t(*)(uint32_t deviceLogicId, int32_t type, uint64_t ptr))HcclDlsym(handle_, "TsdCapabilityGet");
      49         1574 :     CHK_SMART_PTR_NULL(dlTsdCapabilityGet);
      50         1574 :     return HCCL_SUCCESS;
      51              : #else
      52              :     HCCL_ERROR("[DlTdtFunctionInit]Does not support this interface.");
      53              :     return HCCL_E_NOT_SUPPORT;
      54              : #endif
      55         1574 : }
      56              : 
      57           16 : HcclResult DlTdtFunction::DlTdtFunctionHeterogInit()
      58              : {
      59           16 :     std::lock_guard<std::mutex> lock(handleMutex_);
      60           16 :     if (handle_ == nullptr) {
      61            1 :         handle_ = HcclDlopen("libtsdclient.so", RTLD_NOW);
      62            1 :         const char* errMsg = dlerror();
      63            1 :         CHK_PRT_RET(
      64              :             handle_ == nullptr,
      65              :             HCCL_ERROR(
      66              :                 "dlopen [%s] failed, %s", "libtsdclient.so",
      67              :                 (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),
      68              :             HCCL_E_OPEN_FILE_FAILURE);
      69              :     }
      70           16 :     return HCCL_SUCCESS;
      71           16 : }
      72              : 
      73              : } // namespace hccl
        

Generated by: LCOV version 2.0-1