LCOV - code coverage report
Current view: top level - server/hccl - hccl_so_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.0 % 33 32
Test Date: 2026-07-28 10:54:05 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 "hccl/hccl_so_manager.h"
      12              : #include <vector>
      13              : #include <mutex>
      14              : #include <dlfcn.h>
      15              : #include "common/bqs_log.h"
      16              : 
      17              : namespace dgw {
      18              : 
      19            9 : HcclSoManager *HcclSoManager::GetInstance()
      20              : {
      21            9 :     static HcclSoManager hcclSoIns;
      22            9 :     return &hcclSoIns;
      23              : }
      24              : 
      25            4 : void HcclSoManager::LoadSo()
      26              : {
      27            4 :     if (soHandle_ != nullptr) {
      28            1 :         DGW_LOG_INFO("Already load libhccd.so");
      29            2 :         return;
      30              :     }
      31            3 :     soHandle_ = dlopen("libhccd.so", RTLD_LAZY);
      32            3 :     if (soHandle_ == nullptr) {
      33            1 :         DGW_LOG_RUN_WARN("Failed to dlopen libhccd.so for: %s", dlerror());
      34            1 :         return;
      35              :     }
      36              :     const std::vector<std::string> funcName = {"HcclInitComm", "HcclFinalizeComm",
      37              :                                                "HcclIsend", "HcclImrecv", "HcclImprobe", "HcclGetCount",
      38              :                                                "HcclTestSome", "HcclRegisterMemory", "HcclUnregisterMemory",
      39            4 :                                                "HcclSetGrpIdCallback"};
      40           22 :     for (auto iter = funcName.begin(); iter != funcName.end(); iter++) {
      41           20 :         void *func = dlsym(soHandle_, iter->c_str());
      42           20 :         if (func != nullptr) {
      43           10 :             (void) funcMap_.insert(make_pair(*iter, func));
      44              :         } else {
      45           10 :             DGW_LOG_ERROR("Failed to get function [%s]", iter->c_str());
      46              :         }
      47              :     }
      48            2 :     DGW_LOG_INFO("Load libhccd.so success");
      49            2 : }
      50              : 
      51            3 : void HcclSoManager::UnloadSo()
      52              : {
      53            3 :     funcMap_.clear();
      54            3 :     if (soHandle_ != nullptr) {
      55            2 :         (void)dlclose(soHandle_);
      56            2 :         soHandle_ = nullptr;
      57              :     }
      58            3 : }
      59              : 
      60            1 : void *HcclSoManager::GetFunc(const std::string &name) const
      61              : {
      62            1 :     const auto it = funcMap_.find(name);
      63            1 :     if (it != funcMap_.end()) {
      64            0 :         return it->second;
      65              :     }
      66            1 :     return nullptr;
      67              : }
      68              : 
      69            1 : HcclSoManager::~HcclSoManager()
      70              : {
      71            1 :     UnloadSo();
      72            1 : }
      73              : }
        

Generated by: LCOV version 2.0-1