LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/communicator - comm_configer.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.2 % 155 84
Test Date: 2026-08-18 17:47:01 Functions: 64.3 % 14 9

            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 "comm_configer.h"
      12              : #include "alg_env_config.h"
      13              : 
      14              : namespace hccl {
      15         1241 : CommConfiger& CommConfiger::GetInstance()
      16              : {
      17         1241 :     static CommConfiger configer;
      18         1241 :     return configer;
      19              : }
      20              : 
      21           14 : CommConfiger::CommConfiger() : initialized_(true) {}
      22              : 
      23          411 : HcclResult CommConfiger::SetCommConfig(CommConfig config, const std::string& identifier)
      24              : {
      25          411 :     std::lock_guard<std::mutex> lock(lock_);
      26          411 :     if (identifier.empty()) {
      27           37 :         HCCL_WARNING("[CommConfiger][SetCommConfig]: identifier is empty.");
      28           37 :         return HCCL_SUCCESS;
      29              :     }
      30          374 :     auto commConfigIter = commConfigMap_.find(identifier);
      31          374 :     if (commConfigIter != commConfigMap_.end()) {
      32          107 :         HCCL_WARNING(
      33              :             "[CommConfiger][SetCommConfig]: commConfig of identifier[%s] is already existed.", identifier.c_str());
      34              :     }
      35          374 :     commConfigMap_[identifier] = config;
      36          374 :     HCCL_INFO("[CommConfiger][SetCommConfig]: commConfig of identifier[%s]", identifier.c_str());
      37          374 :     return HCCL_SUCCESS;
      38          411 : }
      39              : 
      40            0 : HcclResult CommConfiger::SetCommConfigExecTimeOut(s32 execTimeOut, const std::string& identifier)
      41              : {
      42            0 :     std::lock_guard<std::mutex> lock(lock_);
      43            0 :     if (identifier.empty()) {
      44            0 :         HCCL_WARNING("[CommConfiger][SetCommConfigExecTimeOut]: identifier is empty.");
      45            0 :         return HCCL_SUCCESS;
      46              :     }
      47            0 :     auto commConfigIter = commConfigMap_.find(identifier);
      48            0 :     if (commConfigIter == commConfigMap_.end()) {
      49            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.", identifier.c_str());
      50            0 :         return HCCL_SUCCESS;
      51              :     }
      52            0 :     return commConfigMap_[identifier].SetConfigExecTimeOut(execTimeOut);
      53            0 : }
      54              : 
      55           13 : s32 CommConfiger::GetCommConfigExecTimeOut(const std::string& identifier)
      56              : {
      57           13 :     std::lock_guard<std::mutex> lock(lock_);
      58           13 :     s32 execTimeOut = GetInternalExecTimeOut();
      59           13 :     if (identifier.empty()) {
      60            3 :         HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: identifier is empty.");
      61            3 :         return execTimeOut;
      62              :     }
      63           10 :     auto commConfigIter = commConfigMap_.find(identifier);
      64           10 :     if (commConfigIter == commConfigMap_.end()) {
      65            9 :         HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.", identifier.c_str());
      66            9 :         return execTimeOut;
      67              :     }
      68            1 :     execTimeOut = commConfigMap_[identifier].GetConfigExecTimeOut();
      69            1 :     HCCL_INFO(
      70              :         "[CommConfiger][GetCommConfigExecTimeOut]: identifier[%s], execTimeOut[%d]s", identifier.c_str(), execTimeOut);
      71            1 :     return execTimeOut;
      72           13 : }
      73              : 
      74            0 : bool CommConfiger::GetCommConfigExecTimeOutSet(const std::string& identifier)
      75              : {
      76            0 :     std::lock_guard<std::mutex> lock(lock_);
      77            0 :     bool execTimeOutSet = false;
      78            0 :     if (identifier.empty()) {
      79            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOutSet]: identifier is empty.");
      80            0 :         return execTimeOutSet;
      81              :     }
      82            0 :     auto commConfigIter = commConfigMap_.find(identifier);
      83            0 :     if (commConfigIter == commConfigMap_.end()) {
      84            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.", identifier.c_str());
      85            0 :         return execTimeOutSet;
      86              :     }
      87            0 :     execTimeOutSet = commConfigMap_[identifier].GetConfigExecTimeOutSet();
      88            0 :     HCCL_INFO(
      89              :         "[CommConfiger][GetCommConfigExecTimeOutSet]: identifier[%s], execTimeOutSet[%d]", identifier.c_str(),
      90              :         execTimeOutSet);
      91            0 :     return execTimeOutSet;
      92            0 : }
      93              : 
      94            5 : std::vector<HcclAlgoType> CommConfiger::GetCommConfigAlgoConfig(const std::string& identifier, HcclCMDType opType)
      95              : {
      96            5 :     std::lock_guard<std::mutex> lock(lock_);
      97            5 :     if (identifier.empty()) {
      98            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigAlgoConfig]: identifier is empty.");
      99            0 :         return GetExternalInputHcclAlgoConfig(opType);
     100              :     }
     101            5 :     auto commConfigIter = commConfigMap_.find(identifier);
     102            5 :     if (commConfigIter == commConfigMap_.end()) {
     103            5 :         HCCL_WARNING("[CommConfiger][GetCommConfigAlgoConfig]: CommConfig of [%s] is not found.", identifier.c_str());
     104            5 :         return GetExternalInputHcclAlgoConfig(opType);
     105              :     }
     106            0 :     return commConfigMap_[identifier].GetConfigHcclAlgo(opType);
     107            5 : }
     108              : 
     109            0 : bool CommConfiger::GetCommConfigInterServerRetryEnable(const std::string& identifier)
     110              : {
     111            0 :     std::lock_guard<std::mutex> lock(lock_);
     112            0 :     bool isRetry = GetExternalInputInterServerRetryEnable();
     113            0 :     if (identifier.empty()) {
     114            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigInterServerRetryEnable]: identifier is empty.");
     115            0 :         return isRetry;
     116              :     }
     117            0 :     auto commConfigIter = commConfigMap_.find(identifier);
     118            0 :     if (commConfigIter == commConfigMap_.end()) {
     119            0 :         HCCL_WARNING(
     120              :             "[CommConfiger][GetCommConfigInterServerRetryEnable]: CommConfig of [%s] is not found.",
     121              :             identifier.c_str());
     122            0 :         return isRetry;
     123              :     }
     124            0 :     isRetry = commConfigMap_[identifier].GetConfigInterServerRetryEnable();
     125            0 :     HCCL_INFO(
     126              :         "[CommConfiger][GetCommConfigInterServerRetryEnable]: identifier[%s], isRetry[%d].", identifier.c_str(),
     127              :         isRetry);
     128            0 :     return isRetry;
     129            0 : }
     130              : 
     131            0 : bool CommConfiger::GetCommConfigInterSuperPodRetryEnable(const std::string& identifier)
     132              : {
     133            0 :     std::lock_guard<std::mutex> lock(lock_);
     134            0 :     bool isRetry = GetExternalInputInterSuperPodRetryEnable();
     135            0 :     if (identifier.empty()) {
     136            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: identifier is empty.");
     137            0 :         return isRetry;
     138              :     }
     139            0 :     auto commConfigIter = commConfigMap_.find(identifier);
     140            0 :     if (commConfigIter == commConfigMap_.end()) {
     141            0 :         HCCL_WARNING(
     142              :             "[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: CommConfig of [%s] is not found.",
     143              :             identifier.c_str());
     144            0 :         return isRetry;
     145              :     }
     146            0 :     isRetry = commConfigMap_[identifier].GetConfigInterSuperPodRetryEnable();
     147            0 :     HCCL_INFO(
     148              :         "[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: identifier[%s], isRetry[%d].", identifier.c_str(),
     149              :         isRetry);
     150            0 :     return isRetry;
     151            0 : }
     152              : 
     153            0 : u32 CommConfiger::GetCommConfigRetryMaxCnt(const std::string& identifier)
     154              : {
     155            0 :     std::lock_guard<std::mutex> lock(lock_);
     156            0 :     u32 retryMaxCnt = GetExternalInputRetryMaxCnt();
     157            0 :     if (identifier.empty()) {
     158            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigRetryMaxCnt]: identifier is empty.");
     159            0 :         return retryMaxCnt;
     160              :     }
     161            0 :     auto commConfigIter = commConfigMap_.find(identifier);
     162            0 :     if (commConfigIter == commConfigMap_.end()) {
     163            0 :         HCCL_WARNING("[CommConfiger][GetCommConfigRetryMaxCnt]: CommConfig of [%s] is not found.", identifier.c_str());
     164            0 :         return retryMaxCnt;
     165              :     }
     166            0 :     retryMaxCnt = commConfigMap_[identifier].GetConfigRetryMaxCnt();
     167            0 :     HCCL_INFO(
     168              :         "[CommConfiger][GetCommConfigRetryMaxCnt]: identifier[%s], retryMaxCnt[%d].", identifier.c_str(), retryMaxCnt);
     169            0 :     return retryMaxCnt;
     170            0 : }
     171              : 
     172            4 : u32 CommConfiger::GetCommConfigRetryHoldTime(const std::string& identifier)
     173              : {
     174            4 :     std::lock_guard<std::mutex> lock(lock_);
     175            4 :     u32 retryHoldTime = GetExternalInputRetryHoldTime();
     176            4 :     if (identifier.empty()) {
     177            2 :         HCCL_WARNING("[CommConfiger][GetCommConfigRetryHoldTime]: identifier is empty.");
     178            2 :         return retryHoldTime;
     179              :     }
     180            2 :     auto commConfigIter = commConfigMap_.find(identifier);
     181            2 :     if (commConfigIter == commConfigMap_.end()) {
     182            1 :         HCCL_WARNING(
     183              :             "[CommConfiger][GetCommConfigRetryHoldTime]: CommConfig of [%s] is not found.", identifier.c_str());
     184            1 :         return retryHoldTime;
     185              :     }
     186            1 :     retryHoldTime = commConfigMap_[identifier].GetConfigRetryHoldTime();
     187            1 :     HCCL_INFO(
     188              :         "[CommConfiger][GetCommConfigRetryHoldTime]: identifier[%s], retryHoldTime[%d ms].", identifier.c_str(),
     189              :         retryHoldTime);
     190            1 :     return retryHoldTime;
     191            4 : }
     192              : 
     193            3 : u32 CommConfiger::GetCommConfigRetryIntervalTime(const std::string& identifier)
     194              : {
     195            3 :     std::lock_guard<std::mutex> lock(lock_);
     196            3 :     u32 retryIntervalTime = GetExternalInputRetryIntervalTime();
     197            3 :     if (identifier.empty()) {
     198            1 :         HCCL_WARNING("[CommConfiger][GetCommConfigRetryIntervalTime]: identifier is empty.");
     199            1 :         return retryIntervalTime;
     200              :     }
     201            2 :     auto commConfigIter = commConfigMap_.find(identifier);
     202            2 :     if (commConfigIter == commConfigMap_.end()) {
     203            1 :         HCCL_WARNING(
     204              :             "[CommConfiger][GetCommConfigRetryIntervalTime]: CommConfig of [%s] is not found.", identifier.c_str());
     205            1 :         return retryIntervalTime;
     206              :     }
     207            1 :     retryIntervalTime = commConfigMap_[identifier].GetConfigRetryIntervalTime();
     208            1 :     HCCL_INFO(
     209              :         "[CommConfiger][GetCommConfigRetryIntervalTime]: identifier[%s], retryIntervalTime[%d ms].", identifier.c_str(),
     210              :         retryIntervalTime);
     211            1 :     return retryIntervalTime;
     212            3 : }
     213              : 
     214          809 : void CommConfiger::UnRegisterToCommConfiger(const std::string& identifier)
     215              : {
     216          809 :     if (initialized_ == false) {
     217            0 :         HCCL_WARNING("CommConfiger has been destroyed");
     218          542 :         return;
     219              :     }
     220          809 :     std::lock_guard<std::mutex> lock(lock_);
     221          809 :     if (identifier.empty()) {
     222          433 :         HCCL_WARNING("[CommConfiger][UnRegisterToCommConfiger]: identifier is empty.");
     223          433 :         return;
     224              :     }
     225          376 :     auto commConfigIter = commConfigMap_.find(identifier);
     226          376 :     if (commConfigIter == commConfigMap_.end()) {
     227          109 :         HCCL_WARNING("[CommConfiger][UnRegisterToCommConfiger]: CommConfig of [%s] is not found.", identifier.c_str());
     228          109 :         return;
     229              :     }
     230          267 :     commConfigMap_.erase(identifier);
     231          809 : }
     232              : 
     233           14 : CommConfiger::~CommConfiger()
     234              : {
     235           14 :     std::lock_guard<std::mutex> lock(lock_);
     236           14 :     initialized_ = false;
     237           14 :     commConfigMap_.clear();
     238           14 : }
     239              : } // namespace hccl
        

Generated by: LCOV version 2.0-1