LCOV - code coverage report
Current view: top level - server/hccl - hccl_so_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.8 % 31 30
Test Date: 2026-08-12 11:05:07 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           29 : HcclSoManager* HcclSoManager::GetInstance()
      20              : {
      21           29 :     static HcclSoManager hcclSoIns;
      22           29 :     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 = {
      37              :         "HcclInitComm", "HcclFinalizeComm", "HcclIsend",          "HcclImrecv",           "HcclImprobe",
      38            4 :         "HcclGetCount", "HcclTestSome",     "HcclRegisterMemory", "HcclUnregisterMemory", "HcclSetGrpIdCallback"};
      39           22 :     for (auto iter = funcName.begin(); iter != funcName.end(); iter++) {
      40           20 :         void* func = dlsym(soHandle_, iter->c_str());
      41           20 :         if (func != nullptr) {
      42           10 :             (void)funcMap_.insert(make_pair(*iter, func));
      43              :         } else {
      44           10 :             DGW_LOG_ERROR("Failed to get function [%s]", iter->c_str());
      45              :         }
      46              :     }
      47            2 :     DGW_LOG_INFO("Load libhccd.so success");
      48            2 : }
      49              : 
      50            3 : void HcclSoManager::UnloadSo()
      51              : {
      52            3 :     funcMap_.clear();
      53            3 :     if (soHandle_ != nullptr) {
      54            2 :         (void)dlclose(soHandle_);
      55            2 :         soHandle_ = nullptr;
      56              :     }
      57            3 : }
      58              : 
      59            1 : void* HcclSoManager::GetFunc(const std::string& name) const
      60              : {
      61            1 :     const auto it = funcMap_.find(name);
      62            1 :     if (it != funcMap_.end()) {
      63            0 :         return it->second;
      64              :     }
      65            1 :     return nullptr;
      66              : }
      67              : 
      68            1 : HcclSoManager::~HcclSoManager() { UnloadSo(); }
      69              : } // namespace dgw
        

Generated by: LCOV version 2.0-1