LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels/aicpu/device - dev_aicpu_ts_channel_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.8 % 39 28
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 "dev_aicpu_ts_channel_mgr.h"
      12              : #include "dev_aicpu_ts_roce_channel.h"
      13              : #include "dev_aicpu_ts_hccs_channel.h"
      14              : #include "dev_aicpu_ts_roce_channel_v2.h"
      15              : #include "log.h"
      16              : 
      17            3 : DevAicpuTsChannelMgr& DevAicpuTsChannelMgr::Instance()
      18              : {
      19            3 :     static DevAicpuTsChannelMgr inst;
      20            3 :     return inst;
      21              : }
      22              : 
      23            2 : DevAicpuTsChannel* DevAicpuTsChannelMgr::GetOrCreateAicpuTsChannel(hcomm::HcommChannelKind kind)
      24              : {
      25            2 :     std::lock_guard<std::mutex> lock(mutex_);
      26            2 :     auto it = channelMap_.find(kind);
      27            2 :     if (it != channelMap_.end()) {
      28            0 :         return it->second.get();
      29              :     }
      30              : 
      31            2 :     std::unique_ptr<DevAicpuTsChannel> channel;
      32            2 :     switch (kind) {
      33            1 :         case hcomm::HcommChannelKind::AICPU_TS_ROCE:
      34            1 :             channel = std::make_unique<DevAicpuTsRoceChannel>();
      35            1 :             break;
      36            0 :         case hcomm::HcommChannelKind::AICPU_TS_HCCS:
      37            0 :             channel = std::make_unique<hccl::DevAicpuTsHccsChannel>();
      38            0 :             break;
      39            0 :         case hcomm::HcommChannelKind::AICPU_TS_ROCE_V2:
      40            0 :             channel = std::make_unique<Hccl::DevAicpuTsRoceChannelV2>();
      41            0 :             break;
      42            1 :         default:
      43            1 :             HCCL_ERROR(
      44              :                 "[DevAicpuTsChannelMgr][GetOrCreateAicpuTsChannel] unsupported kind[%u]", static_cast<uint32_t>(kind));
      45            1 :             return nullptr;
      46              :     }
      47              : 
      48            1 :     if (channel == nullptr) {
      49            0 :         HCCL_ERROR(
      50              :             "[DevAicpuTsChannelMgr][GetOrCreateAicpuTsChannel] alloc failed for kind[%u]", static_cast<uint32_t>(kind));
      51            0 :         return nullptr;
      52              :     }
      53              : 
      54            1 :     DevAicpuTsChannel* ptr = channel.get();
      55            1 :     channelMap_.emplace(kind, std::move(channel));
      56            1 :     HCCL_DEBUG(
      57              :         "[DevAicpuTsChannelMgr][GetOrCreateAicpuTsChannel] created channel for kind[%u]", static_cast<uint32_t>(kind));
      58            1 :     return ptr;
      59            2 : }
      60              : 
      61            1 : bool DevAicpuTsChannelMgr::DestroyChannel(ChannelHandle handle)
      62              : {
      63            1 :     std::lock_guard<std::mutex> lock(mutex_);
      64            1 :     for (auto& entry : channelMap_) {
      65            1 :         if (entry.second && entry.second->Destroy(handle)) {
      66            1 :             HCCL_DEBUG("[DevAicpuTsChannelMgr][DestroyChannel] destroyed handle[0x%llx]", handle);
      67            1 :             return true;
      68              :         }
      69              :     }
      70            0 :     HCCL_WARNING("[DevAicpuTsChannelMgr][DestroyChannel] handle[0x%llx] not found", handle);
      71            0 :     return false;
      72            1 : }
        

Generated by: LCOV version 2.0-1