LCOV - code coverage report
Current view: top level - coll_communicator_mgr/communicator - independent_op.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 49 49
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 9 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 "independent_op.h"
      12              : #include "launch_aicpu.h"
      13              : #include "manager_common.h"
      14              : #include "comm_configer.h"
      15              : #include "adapter_prof.h"
      16              : #include "hcom_host_profiling.h"
      17              : 
      18              : namespace hccl {
      19              : 
      20          601 : IndependentOp::IndependentOp(){};
      21              : 
      22          234 : HcclResult IndependentOp::SetIndependentOpConfig(const CommConfig &commConfig, const RankTable_t &rankTable,
      23              :     const HcclTopoAttr &topoAttr, const aclrtBinHandle binHandle, HDCommunicateParams &kfcControlTransferH2DParams,
      24              :     HDCommunicateParams &kfcStatusTransferD2HParams, CCLBufferManager &bufferManager)
      25              : {
      26          234 :     commEngine_ = HCCL_COMM_ENGINE_CONFIG_NOT_SET;
      27          234 :     threadNum_ = HCCL_COMM_THREADNUM_CONFIG_NOT_SET;
      28          234 :     notifyNumPerThread_ = HCCL_COMM_NOTIFY_NUM_PER_THREAD_CONFIG_NOT_SET;
      29          234 :     cclBufferSize_ = commConfig.GetConfigBufferSize();
      30          234 :     commId_ = commConfig.GetConfigCommName();
      31          234 :     commMemMgr_.CommSetHcclBufferManager(bufferManager);
      32          234 :     binHandle_ = binHandle;
      33              : 
      34              :     // aicpu侧初始化状态的回调函数
      35          234 :     ManagerCallbacks callbacks;
      36          235 :     callbacks.getAicpuCommState = [this]() { return this->GetAicpuCommState(); };
      37          235 :     callbacks.setAicpuCommState = [this](bool state) { this->SetAicpuCommState(state); };
      38          235 :     callbacks.kernelLaunchAicpuCommInit = [this]() { return this->KernelLaunchAicpuCommInit(); };
      39              : 
      40          234 :     CHK_PRT(engineResMgr_.Init(threadNum_, notifyNumPerThread_, commId_, binHandle, callbacks));
      41          234 :     CHK_PRT(channelMgr_.Init(binHandle, topoAttr.userRank, callbacks));
      42              : 
      43              :     // Aicpu通信域初始化参数
      44          234 :     snprintf_s(commAicpuParam_.hcomId, HCOMID_MAX_SIZE, HCOMID_MAX_SIZE - 1, "%s", commId_.c_str());
      45          234 :     commAicpuParam_.deviceLogicId = topoAttr.deviceLogicId;
      46          234 :     commAicpuParam_.devicePhyId = topoAttr.devicePhyId;
      47          234 :     commAicpuParam_.deviceType = static_cast<u32>(topoAttr.deviceType);
      48          234 :     commAicpuParam_.kfcControlTransferH2DParams = kfcControlTransferH2DParams;
      49          234 :     commAicpuParam_.kfcStatusTransferD2HParams = kfcStatusTransferD2HParams;
      50          234 :     commAicpuParam_.userRank = topoAttr.userRank;
      51          234 :     commAicpuParam_.userRankSize = topoAttr.userRankSize;
      52          234 :     CHK_PRT(channelMgr_.SetHcclQos(commConfig.GetConfigHcclQos()));
      53          234 :     HCCL_INFO("[IndependentOp][%s] Hcom[%s] threadNum[%u], notifyPerThread[%u], cclBufferSize[%llu], deviceLogicId[%u], "
      54              :         "devicePhyId[%u], deviceType[%u], userRank[%u], userRankSize[%u]", __func__, commId_.c_str(), threadNum_, notifyNumPerThread_,
      55              :         cclBufferSize_, commAicpuParam_.deviceLogicId, commAicpuParam_.devicePhyId,
      56              :         commAicpuParam_.deviceType, commAicpuParam_.userRank, commAicpuParam_.userRankSize);
      57          234 :     return HCCL_SUCCESS;
      58          234 : }
      59              : 
      60            2 : bool IndependentOp::GetAicpuCommState()
      61              : {
      62            2 :     return isAicpuCommInit_;
      63              : }
      64              : 
      65            1 : void IndependentOp::SetAicpuCommState(bool aicpuCommState)
      66              : {
      67            1 :     isAicpuCommInit_ = aicpuCommState;
      68            1 :     return;
      69              : }
      70              : 
      71            1 : HcclResult IndependentOp::KernelLaunchAicpuCommInit()
      72              : {
      73              :     // 创建局部流
      74            1 :     uint64_t beginTime = hrtMsprofSysCycleTime();
      75            1 :     Stream localStream(StreamType::STREAM_TYPE_ONLINE);
      76            1 :     constexpr u32 aicpuStreamMode = 1;
      77            1 :     CHK_RET(hrtStreamSetMode(localStream.ptr(), aicpuStreamMode));
      78              : 
      79              :     // 下kernel进行自定义算子aicpu侧通信域的公共初始化
      80            1 :     std::string kernelName = "RunAicpuIndOpCommInit";
      81              : 
      82            1 :     u16 timeOut = NOTIFY_DEFAULT_WAIT_TIME > std::numeric_limits<uint16_t>::max() ? 
      83              :                     std::numeric_limits<uint16_t>::max() : NOTIFY_DEFAULT_WAIT_TIME;
      84            1 :     CHK_RET(AicpuAclKernelLaunch(localStream.ptr(), reinterpret_cast<void *>(&commAicpuParam_),
      85              :         sizeof(commAicpuParam_), binHandle_, kernelName, true, timeOut));
      86            3 :     CHK_RET(hcclStreamSynchronize(localStream.ptr(), CommConfiger::GetInstance().GetCommConfigExecTimeOut("")));
      87              : 
      88              :     // 打印增加初始化对应的参数
      89            1 :     HCCL_RUN_INFO("[%s] KernelLaunchAicpuCommInit Success", __func__);
      90            1 :     const std::string profName = "RunAicpuIndOpCommInit";
      91            1 :     HCCL_INFO("[%s] RunAicpuIndOpCommInit", __func__);
      92              :     // 上报初始化kernel的时间
      93            1 :     HcommProfilingReportKernel(beginTime, profName.c_str());
      94            1 :     return HCCL_SUCCESS;
      95            1 : }
      96              : 
      97          403 : HcclResult IndependentOp::SetChannelCallbacks(const ChannelManagerCallbacks& channelCallbacks)
      98              : {
      99          403 :     return channelMgr_.SetChannelCallbacks(channelCallbacks);
     100              : }
     101              : 
     102              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1