LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/notify - conn_local_notify_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 68.4 % 57 39
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 7 7

            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 "conn_local_notify_manager.h"
      12              : 
      13              : #include "rdma_handle_manager.h"
      14              : #include "communicator_impl.h"
      15              : #include "invalid_params_exception.h"
      16              : 
      17              : #include "ipc_local_notify.h"
      18              : #include "rdma_local_notify.h"
      19              : #include "ub_local_notify.h"
      20              : 
      21              : namespace Hccl {
      22              : 
      23          488 : ConnLocalNotifyManager::ConnLocalNotifyManager(CommunicatorImpl* communicator) : comm(communicator) {}
      24              : 
      25          488 : ConnLocalNotifyManager::~ConnLocalNotifyManager() { DECTOR_TRY_CATCH("ConnLocalNotifyManager", Destroy()); }
      26              : 
      27           12 : bool ConnLocalNotifyManager::IsExist(RankId remoteRankId, const LinkData& linkData)
      28              : {
      29           12 :     return notifyPool.count(remoteRankId) != 0 && notifyPool[remoteRankId].count(linkData) != 0;
      30              : }
      31              : 
      32            6 : void ConnLocalNotifyManager::ApplyFor(RankId remoteRankId, const LinkData& linkData)
      33              : {
      34           18 :     HCCL_INFO("Local notify for remoteRankId[%d] and linkData[%s] alloc.", remoteRankId, linkData.Describe().c_str());
      35            6 :     if (IsExist(remoteRankId, linkData)) {
      36            3 :         HCCL_WARNING(
      37              :             "Local notify for remoteRankId[%d] and linkData[%s] already exists, no need to alloc.", remoteRankId,
      38              :             linkData.Describe().c_str());
      39            1 :         return;
      40              :     }
      41              : 
      42            5 :     u32 count = 3; // 待修改: 需要定义GetCount()
      43            5 :     notifyPool[remoteRankId][linkData].resize(count);
      44              : 
      45           20 :     for (u32 i = 0; i < count; ++i) {
      46           15 :         if (linkData.GetType() == PortDeploymentType::P2P) {
      47           12 :             notifyPool[remoteRankId][linkData][i]
      48           24 :                 = make_unique<IpcLocalNotify>(comm->GetOpAiCpuTSFeatureFlag()); // 算子粒度
      49           12 :             continue;
      50            3 :         } else if (linkData.GetType() == PortDeploymentType::DEV_NET) {
      51            3 :             auto linkProtocol = linkData.GetLinkProtocol();
      52            3 :             if (linkProtocol == LinkProtocol::ROCE) {
      53            0 :                 RdmaHandle rdmaHandle = RdmaHandleManager::GetInstance().Get(
      54            0 :                     comm->GetDevicePhyId(), linkData.GetLocalPort(), linkProtocol);
      55            0 :                 notifyPool[remoteRankId][linkData][i]
      56            0 :                     = make_unique<RdmaLocalNotify>(rdmaHandle, comm->GetOpAiCpuTSFeatureFlag()); // 算子粒度
      57            0 :                 continue;
      58            0 :             } else if (
      59            3 :                 linkProtocol == LinkProtocol::UB_CTP || linkProtocol == LinkProtocol::UB_TP
      60            3 :                 || linkProtocol == LinkProtocol::UBOE || linkProtocol == LinkProtocol::UB_RTP) {
      61            6 :                 RdmaHandle rdmaHandle = RdmaHandleManager::GetInstance().Get(
      62            3 :                     comm->GetDevicePhyId(), linkData.GetLocalPort(), linkProtocol);
      63            3 :                 notifyPool[remoteRankId][linkData][i]
      64            6 :                     = make_unique<UbLocalNotify>(rdmaHandle, comm->GetOpAiCpuTSFeatureFlag()); // 算子粒度
      65              :             } else {
      66              :                 // 待修改: 仅支持 P2P 和 RDMA 申请 notify
      67              :                 string msg = StringFormat(
      68            0 :                     "Unsupported %s of link %s", linkProtocol.Describe().c_str(), linkData.Describe().c_str());
      69            0 :                 THROW<InvalidParamsException>(msg);
      70            0 :             }
      71              :         } else {
      72              :             // 待修改: 仅支持 P2P 和 RDMA 申请 notify
      73              :             string msg = StringFormat(
      74            0 :                 "Unsupported %s of link %s", linkData.GetType().Describe().c_str(), linkData.Describe().c_str());
      75            0 :             THROW<InvalidParamsException>(msg);
      76            0 :         }
      77              :     };
      78              : }
      79              : 
      80            1 : bool ConnLocalNotifyManager::Release(RankId remoteRankId, const LinkData& linkData)
      81              : {
      82            1 :     if (!IsExist(remoteRankId, linkData)) {
      83            0 :         HCCL_WARNING(
      84              :             "Notify for remoteRankId[%d] and linkData[%p] does not exist, no need to release.", remoteRankId,
      85              :             &linkData);
      86            0 :         return true;
      87              :     }
      88              : 
      89            1 :     notifyPool[remoteRankId].erase(linkData);
      90            1 :     if (notifyPool[remoteRankId].empty()) {
      91            1 :         notifyPool.erase(remoteRankId);
      92              :     }
      93            1 :     return true;
      94              : }
      95              : 
      96            5 : vector<BaseLocalNotify*> ConnLocalNotifyManager::Get(RankId remoteRankId, const LinkData& linkData)
      97              : {
      98            5 :     vector<BaseLocalNotify*> v;
      99              : 
     100            5 :     if (!IsExist(remoteRankId, linkData)) {
     101           15 :         HCCL_WARNING(
     102              :             "Get Local notify for remoteRankId[%d] and linkData[%s] does not exist", remoteRankId,
     103              :             linkData.Describe().c_str());
     104            5 :         return v;
     105              :     }
     106              : 
     107            0 :     for (const auto& i : notifyPool[remoteRankId][linkData]) {
     108            0 :         v.emplace_back(i.get());
     109              :     }
     110              : 
     111            0 :     return v;
     112            0 : }
     113              : 
     114          489 : bool ConnLocalNotifyManager::Destroy()
     115              : {
     116          489 :     notifyPool.clear();
     117          489 :     return true;
     118              : }
     119              : 
     120              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1