LCOV - code coverage report
Current view: top level - coll_communicator_mgr/resource_mgr/local/my_rank/comm_engine - comm_engine_res_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 79.5 % 44 35
Test Date: 2026-08-18 17:47:01 Functions: 75.0 % 12 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_engine_res_manager.h"
      12              : 
      13              : namespace hccl {
      14          798 : CommEngineResMgr::CommEngineResMgr() {};
      15              : 
      16          381 : HcclResult CommEngineResMgr::Init(
      17              :     uint32_t threadNum, uint32_t notifyNumPerThread, const std::string& commId, const aclrtBinHandle binHandle,
      18              :     const ManagerCallbacks& callbacks)
      19              : {
      20          381 :     std::lock_guard<std::mutex> lock(mtx_);
      21          381 :     HCCL_INFO(
      22              :         "[CommEngineResMgr][%s] Hcom[%s] threadNum[%u], notifyPerThread[%u]", __func__, commId.c_str(), threadNum,
      23              :         notifyNumPerThread);
      24          381 :     if (!threadMgr_) {
      25          381 :         EXCEPTION_CATCH(
      26              :             threadMgr_ = std::make_unique<ThreadMgr>(threadNum, notifyNumPerThread, commId, binHandle, callbacks),
      27              :             return HCCL_E_PTR);
      28              :     }
      29          381 :     if (!notifyMgr_) {
      30          381 :         EXCEPTION_CATCH(notifyMgr_ = std::make_unique<NotifyManager>(commId, binHandle, callbacks), return HCCL_E_PTR);
      31              :     }
      32          381 :     return HCCL_SUCCESS;
      33          381 : }
      34              : 
      35           16 : HcclResult CommEngineResMgr::HcclThreadAcquireV2(
      36              :     CommEngine engine, uint32_t threadNum, ThreadType type, const ThreadConfig* config, ThreadHandle* threads,
      37              :     std::vector<uint32_t>& threadId)
      38              : {
      39           16 :     CHK_SMART_PTR_NULL(threadMgr_);
      40           16 :     uint32_t setThreadNum = threadMgr_->GetThreadNum();
      41           16 :     CHK_PRT_RET(
      42              :         threadNum > setThreadNum,
      43              :         HCCL_ERROR(
      44              :             "[%s]Alloced thread num[%u] more than num[%u] in config type[%d]", __func__, threadNum, setThreadNum,
      45              :             static_cast<int32_t>(type)),
      46              :         HCCL_E_PARA);
      47           16 :     return threadMgr_->HcclThreadAcquireV2(engine, threadNum, type, config, threads, threadId);
      48              : }
      49              : 
      50            5 : HcclResult CommEngineResMgr::HcclThreadAcquire(
      51              :     CommEngine engine, uint32_t threadNum, ThreadType type, const ThreadConfig* config, ThreadHandle* threads,
      52              :     std::vector<uint32_t>& threadId)
      53              : {
      54            5 :     CHK_SMART_PTR_NULL(threadMgr_);
      55            5 :     uint32_t setThreadNum = threadMgr_->GetThreadNum();
      56            5 :     CHK_PRT_RET(
      57              :         threadNum > setThreadNum,
      58              :         HCCL_ERROR(
      59              :             "[%s] Alloced thread num[%u] more than num[%u] in config type[%d]", __func__, threadNum, setThreadNum,
      60              :             static_cast<int32_t>(type)),
      61              :         HCCL_E_PARA);
      62            5 :     return threadMgr_->HcclThreadAcquire(engine, threadNum, type, config, threads, threadId);
      63              : }
      64              : 
      65            2 : HcclResult CommEngineResMgr::HcclThreadAcquireWithStream(
      66              :     CommEngine engine, rtStream_t stream, uint32_t notifyNum, ThreadHandle* thread)
      67              : {
      68            2 :     CHK_SMART_PTR_NULL(threadMgr_);
      69            1 :     return threadMgr_->HcclThreadAcquireWithStream(engine, stream, notifyNum, thread);
      70              : }
      71              : 
      72              : HcclResult
      73            5 : CommEngineResMgr::HcclGetNotifyNumInThread(ThreadHandle thread, [[maybe_unused]] CommEngine engine, uint32_t* notifyNum)
      74              : {
      75            5 :     CHK_SMART_PTR_NULL(threadMgr_);
      76            4 :     return threadMgr_->HcclGetNotifyNumInThread(thread, notifyNum);
      77              : }
      78              : 
      79            0 : HcclResult CommEngineResMgr::HcclAllocNotify(
      80              :     CommEngine commEngine, ::NotifyType notifyType, uint32_t notifyNum, NotifyHandle** notifyHandleList)
      81              : {
      82            0 :     CHK_SMART_PTR_NULL(threadMgr_);
      83            0 :     return notifyMgr_->HcclAllocNotify(commEngine, notifyType, notifyNum, notifyHandleList);
      84              : }
      85              : 
      86            0 : HcclResult CommEngineResMgr::HcommFreeNotify(uint32_t notifyNum, NotifyHandle* notifyHandleList)
      87              : {
      88            0 :     CHK_SMART_PTR_NULL(threadMgr_);
      89            0 :     return notifyMgr_->HcommFreeNotify(notifyNum, notifyHandleList);
      90              : }
      91              : 
      92            4 : HcclResult CommEngineResMgr::HcclThreadExportToCommEngine(
      93              :     uint32_t threadNum, const ThreadHandle* threads, CommEngine dstCommEngine, ThreadHandle* exportedThreads)
      94              : {
      95            4 :     CHK_SMART_PTR_NULL(threadMgr_);
      96            4 :     return threadMgr_->HcclThreadExportToCommEngine(threadNum, threads, dstCommEngine, exportedThreads);
      97              : }
      98              : 
      99              : HcclResult
     100            4 : CommEngineResMgr::HcclThreadResGetInfo(ThreadHandle thread, ThreadResType resType, uint32_t infoLen, void** info)
     101              : {
     102            4 :     CHK_SMART_PTR_NULL(threadMgr_);
     103            4 :     return threadMgr_->HcclThreadResGetInfo(thread, resType, infoLen, info);
     104              : }
     105              : 
     106           10 : HcclResult CommEngineResMgr::HcclDedicatedThreadAcquire(
     107              :     HcclDedicatedThreadType useType, uint32_t notifyNumPerThread, ThreadHandle* thread)
     108              : {
     109           10 :     CHK_SMART_PTR_NULL(threadMgr_);
     110           10 :     return threadMgr_->HcclDedicatedThreadAcquire(useType, notifyNumPerThread, thread);
     111              : }
     112              : 
     113            0 : HcclResult CommEngineResMgr::RegisterOrderLaunchThread(ThreadHandle thread)
     114              : {
     115            0 :     CHK_SMART_PTR_NULL(threadMgr_);
     116            0 :     return threadMgr_->RegisterOrderLaunchThread(thread);
     117              : }
     118              : 
     119              : } // namespace hccl
        

Generated by: LCOV version 2.0-1