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

Generated by: LCOV version 2.0-1