LCOV - code coverage report
Current view: top level - coll_communicator_mgr/dfx - hcclCommDfxLite.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.7 % 53 38
Test Date: 2026-08-04 10:52:23 Functions: 70.0 % 10 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 "hcclCommDfxLite.h"
      12              : #include "hccl_common.h"
      13              : 
      14              : namespace hccl {
      15              : // HcclCommDfxLite构造函数实现
      16           54 : HcclCommDfxLite::HcclCommDfxLite() {
      17           54 : }
      18              : 
      19              : // HcclCommDfxLite初始化流程 - 修改为返回HcclResult类型
      20           36 : HcclResult HcclCommDfxLite::Init(u32 deviceId, const std::string& commTag, u32 rankSize) {
      21           36 :     if (initializedFlag_) {
      22            1 :         return HCCL_SUCCESS;
      23              :     }
      24           35 :     HCCL_INFO("[HcclCommDfxLite][Init] Init begin deviceId[%u], commTag[%s]", deviceId, commTag.c_str());
      25           35 :     deviceId_ = deviceId;
      26           35 :     commTag_ = commTag;
      27           35 :     rankSize_ = rankSize;
      28              :     /*1. 如果mirrorTaskManagerLite_为空,则创建新的MirrorTaskManager
      29              :     注意:实际实现中应该避免这种情况,CommunicatorImplLite应该传入已经存在的MirrorTaskManager*/
      30           35 :     EXCEPTION_CATCH(mirrorTaskManagerLite_ = std::make_unique<Hccl::MirrorTaskManagerLite>(), return HCCL_E_PTR);
      31            0 :     auto getChannelRemoteRankId = [this](u64 handle) { return this->GetChannelRemoteRankId(handle); };
      32           35 :     mirrorTaskManagerLite_->RegGetRemoteRankCallBack(getChannelRemoteRankId);
      33              : 
      34              :     // 2. 创建Profiling管理类
      35           35 :     EXCEPTION_CATCH(profilingImpl_ = std::make_unique<HcclCommProfilingLite>(deviceId_, mirrorTaskManagerLite_.get()), return HCCL_E_PTR);
      36           35 :     CHK_RET(profilingImpl_->Init());
      37              : 
      38              :     // 3. 注册回调到单例
      39           70 :     addTaskCallback_ = [this](u32 streamId, u32 taskId, const Hccl::TaskParam &taskParam, u64 handle) {
      40            0 :         return this->mirrorTaskManagerLite_->AddTaskInfo(streamId, taskId, taskParam, handle);
      41           35 :     };
      42              : 
      43           35 :     Hccl::ProfilingHandlerLite::GetInstance().SetCachedGroupName(commTag_, rankSize_);
      44           35 :     initializedFlag_ = true;
      45           35 :     return HCCL_SUCCESS; // 初始化成功返回成功码
      46              : }
      47              : 
      48              : // HcclCommDfxLite接口实现 - 修改为返回HcclResult类型
      49            0 : HcclResult HcclCommDfxLite::SetCurrDfxOpInfo(std::shared_ptr<Hccl::DfxOpInfo> dfxOpInfo)
      50              : {
      51            0 :     auto it = Hccl::CMD_OP_TYPE_INFO_MAP.find(static_cast<HcclCMDType>(dfxOpInfo->op_.oldOpType));
      52            0 :     if (it == Hccl::CMD_OP_TYPE_INFO_MAP.end()) {
      53            0 :         HCCL_WARNING("[%s] dfxOpInfo.opType[%u] not supported.", __func__, dfxOpInfo->op_.oldOpType);
      54              :     } else {
      55            0 :         dfxOpInfo->op_.opType = it->second.first;
      56            0 :         dfxOpInfo->tag_ = it->second.second;
      57              :     }
      58            0 :     dfxOpInfo->op_.dataType = Hccl::HcclDataTypeToDataType(
      59            0 :         static_cast<HcclDataType>(dfxOpInfo->op_.oldDataType));
      60              : 
      61              :     // 如果是a5老流程  还是从通信域里面取
      62            0 :     if ((Hccl::ProfilingHandlerLite::GetInstance().GetProfL1State()
      63            0 :         || Hccl::ProfilingHandlerLite::GetInstance().GetProfL0State() ) && !dfxOpInfo->isIndop_) {
      64            0 :         Hccl::ProfilingHandlerLite::GetInstance().SetCachedGroupName(dfxOpInfo->groupName_.c_str(), dfxOpInfo->rankSize_);
      65              :     }
      66            0 :     CHK_RET(mirrorTaskManagerLite_->SetCurrDfxOpInfo(std::move(dfxOpInfo)));
      67            0 :     return HCCL_SUCCESS;
      68              : }
      69              : 
      70            1 : HcclResult HcclCommDfxLite::ReportAllTasks() {
      71            1 :     profilingImpl_->ReportAllTasks();
      72            1 :     return HCCL_SUCCESS;
      73              : }
      74              : 
      75            1 : HcclResult HcclCommDfxLite::UpdateProfStat() {
      76            1 :     profilingImpl_->UpdateProfStat();
      77            1 :     return HCCL_SUCCESS;
      78              : }
      79              : 
      80            3 : void HcclCommDfxLite::AddChannelRemoteRankId(u64 handle, u32 remoteRankId) {
      81            3 :     HCCL_INFO("[%s] commTag[%s], handle[%llu], remoteRankId[%u]", __func__, commTag_.c_str(), handle, remoteRankId);
      82            3 :     channelRemoteRankIdLite_[handle] = remoteRankId;
      83            3 : }
      84              : 
      85            5 : u32 HcclCommDfxLite::GetChannelRemoteRankId(u64 handle) {
      86            5 :     if (handle == INVALID_U64) {
      87            1 :         return INVALID_UINT;
      88              :     }
      89            4 :     auto it = channelRemoteRankIdLite_.find(handle);
      90            4 :     if (UNLIKELY(it == channelRemoteRankIdLite_.end())) {
      91            1 :         HCCL_ERROR("[%s]handle[%llu] not found, commTag[%s]", __func__, handle, commTag_.c_str());
      92            1 :         return INVALID_UINT;
      93              :     }
      94            3 :     return it->second;
      95              : }
      96              : 
      97           10 : Hccl::MirrorTaskManagerLite* HcclCommDfxLite::GetMirrorTaskManagerLite() const {
      98           10 :     return mirrorTaskManagerLite_.get();
      99              : }
     100              : }
        

Generated by: LCOV version 2.0-1