LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs - endpoint_pair_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.9 % 28 26
Test Date: 2026-08-25 19:18:03 Functions: 100.0 % 2 2

            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 "endpoint_pair_mgr.h"
      12              : 
      13              : namespace hcomm {
      14              : 
      15          116 : HcclResult EndpointPairMgr::Get(
      16              :     const EndpointDescPair& endpointDescPair, EndpointPair*& out, const Hccl::RankIpPortMapPtr& rankIpPortMap)
      17              : {
      18              :     {
      19          116 :         std::lock_guard<std::mutex> lock(mapMtx_);
      20          116 :         if (endpointPairMap_.find(endpointDescPair) != endpointPairMap_.end()) {
      21           82 :             out = endpointPairMap_[endpointDescPair].get();
      22           82 :             return HCCL_SUCCESS;
      23              :         }
      24          116 :     }
      25              : 
      26           34 :     std::unique_ptr<EndpointPair> endpointPair = nullptr;
      27           34 :     EXCEPTION_CATCH(
      28              :         (endpointPair = std::make_unique<EndpointPair>(endpointDescPair.first, endpointDescPair.second, rankIpPortMap)),
      29              :         return HCCL_E_PTR);
      30           34 :     CHK_SMART_PTR_NULL(endpointPair);
      31           34 :     CHK_RET(endpointPair->Init());
      32              : 
      33              :     // 二次确认,防止并发修改
      34              :     {
      35           34 :         std::lock_guard<std::mutex> lock(mapMtx_);
      36           34 :         if (endpointPairMap_.find(endpointDescPair) != endpointPairMap_.end()) {
      37            0 :             out = endpointPairMap_[endpointDescPair].get();
      38            0 :             return HCCL_SUCCESS;
      39              :         }
      40           34 :         out = endpointPair.get();
      41           34 :         endpointPairMap_.emplace(endpointDescPair, std::move(endpointPair));
      42           34 :     }
      43              : 
      44           34 :     return HCCL_SUCCESS;
      45           34 : }
      46              : 
      47            2 : EpChannelMap EndpointPairMgr::GetEpChannelMap()
      48              : {
      49            2 :     std::lock_guard<std::mutex> lock(mapMtx_);
      50            2 :     EpChannelMap epChannelMap;
      51            3 :     for (const auto& endpointPair : endpointPairMap_) {
      52            1 :         auto channelList = endpointPair.second->GetChannelHandles();
      53            1 :         epChannelMap[endpointPair.first] = channelList;
      54            1 :     }
      55            2 :     return epChannelMap;
      56            2 : }
      57              : 
      58              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1