LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ccu_alg_template - ccu_alg_template_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 26.1 % 88 23
Test Date: 2026-07-28 12:11:00 Functions: 30.4 % 23 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 "ccu_alg_template_base.h"
      12              : #include "ccu_context_utils.h"
      13              : #include "ccu_assist.h"
      14              : #include "log.h"
      15              : 
      16              : namespace Hccl {
      17            5 : CcuAlgTemplateBase::CcuAlgTemplateBase(const RankId virtualRank, const u32 tempRankSize,
      18              :                                        const std::vector<std::vector<RankId>> &tempVTopo,
      19            5 :                                        const std::map<RankId, u32>            &tempVirtRankMap)
      20            5 :     : myRank_(virtualRank), tempRankSize_(tempRankSize), tempVTopo_(tempVTopo), tempVirtRankMap_(tempVirtRankMap)
      21              : { 
      22            5 : }
      23              : 
      24            5 : CcuAlgTemplateBase::~CcuAlgTemplateBase()
      25              : {
      26            5 : }
      27              : 
      28            0 : HcclResult CcuAlgTemplateBase::CalcRes(AlgTempResReq &tempResReq)
      29              : {
      30              :     (void)tempResReq;
      31            0 :     HCCL_ERROR("[CcuAlgTemplateBase] [CalcRes] Current alg do not support detour mode!");
      32            0 :     return HcclResult::HCCL_E_INTERNAL;
      33              : }
      34              : 
      35            0 : HcclResult CcuAlgTemplateBase::CalcResDetour(const RankGraph *rankGraph, AlgTempResReq &tempResReq)
      36              : {
      37              :     (void)rankGraph;
      38              :     (void)tempResReq;
      39            0 :     HCCL_ERROR("[CcuAlgTemplateBase] [CalcRes] Current alg do not support detour mode!");
      40            0 :     return HcclResult::HCCL_E_INTERNAL;
      41              : }
      42              : 
      43            0 : HcclResult CcuAlgTemplateBase::CalcResDetour(ConnectedLinkMgr *linkMgr, AlgTempResReq &tempResReq)
      44              : {
      45              :     (void)linkMgr;
      46              :     (void)tempResReq;
      47            0 :     HCCL_ERROR("[CcuAlgTemplateBase] [CalcRes] Current alg do not support detour mode!");
      48            0 :     return HcclResult::HCCL_E_INTERNAL;
      49              : }
      50              : 
      51            0 : HcclResult CcuAlgTemplateBase::Run(const TempFuncs &tempFuncs, const RankSliceInfo &sliceInfoVec,
      52              :     const BuffInfo &buffInfo, const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
      53              : {
      54              :     (void)tempFuncs;
      55              :     (void)sliceInfoVec;
      56              :     (void)buffInfo;
      57              :     (void)tempLinks;
      58              :     (void)tempInsQues;
      59            0 :     HCCL_ERROR("[CcuAlgTemplateBase] Unsupported interface of CcuAlgTemplateBase::Run!");
      60            0 :     return HcclResult::HCCL_E_INTERNAL;
      61              : }
      62              : 
      63            0 : HcclResult CcuAlgTemplateBase::SetScratchBufferSize(uint64_t size)
      64              : {
      65            0 :     scratchBufferSize_ = size;
      66            0 :     return HcclResult::HCCL_SUCCESS;
      67              : }
      68              : 
      69            0 : HcclResult CcuAlgTemplateBase::CalcSliceInfo(const AllignInfo &allignInfo, const u64 dataSize,
      70              :         RankSliceInfo &sliceInfoVec)
      71              : {
      72              :     (void)allignInfo;
      73              :     (void)dataSize;
      74              :     (void)sliceInfoVec;
      75            0 :     HCCL_WARNING("[CcuAlgTemplateBase] Interface of CcuAlgTemplateBase::CalcSliceInfo is not implemented!");
      76            0 :     return HcclResult::HCCL_SUCCESS;
      77              : }
      78              : 
      79            1 : void CcuAlgTemplateBase::SetDmaMode(const DmaMode dmaMode)
      80              : {
      81            1 :     dmaMode_ = dmaMode;
      82            1 :     return;
      83              : }
      84              : 
      85            2 : void CcuAlgTemplateBase::SetCollOp(const CollAlgOperator &op)
      86              : {
      87            2 :     op_ = op;
      88            2 :     return;
      89              : }
      90              : 
      91            0 : void CcuAlgTemplateBase::SetDataType(const DataType &dataType)
      92              : {
      93            0 :     dataType_ = dataType;
      94            0 :     return;
      95              : }
      96              : 
      97            0 : HcclResult CcuAlgTemplateBase::GetScratchBufferInfo(const uint64_t scratchBufferSize, DataType dataType)
      98              : {
      99              :     (void)scratchBufferSize;
     100              :     (void)dataType;
     101            0 :     return HcclResult::HCCL_SUCCESS;
     102              : }
     103              : 
     104            0 : void CcuAlgTemplateBase::SetRoot(const u32 root)
     105              : {
     106            0 :     rootId_ = root;
     107            0 :     return;
     108              : }
     109              : 
     110            1 : void CcuAlgTemplateBase::SetLoadInfo(const CollAlgParams &params)
     111              : {
     112            1 :     loadFromMem_ = params.isMc2;  // 当前只有mc2场景会设置该标记,故暂作为mc2标记使用
     113            1 :     return;
     114              : }
     115              : 
     116            0 : u64 CcuAlgTemplateBase::CalcLoopMaxCount(ParamPool &paramPool)
     117              : {
     118            0 :     u64 loopMaxCount = 0;
     119            0 :     if (paramPool.params.opMode == OpMode::OPBASE) {
     120            0 :         u64 maxLoopSize = std::min(static_cast<u64>(paramPool.params.maxTmpMemSize), static_cast<u64>(UB_MAX_DATA_SIZE));
     121            0 :         loopMaxCount = maxLoopSize / (DataTypeSizeGet(paramPool.op.dataType) * tempRankSize_) * tempRankSize_;
     122              :     } else {
     123            0 :         loopMaxCount = paramPool.op.dataCount;
     124              :     }
     125            0 :     return loopMaxCount;
     126              : }
     127              : 
     128            4 : HcclResult CcuAlgTemplateBase::GetToken(const CollAlgOperator &op, uint64_t &token) const
     129              : {
     130            4 :     if (op.inputMem != nullptr && op.inputMem->GetAddr() != 0) {
     131            4 :         token = CcuRep::GetTokenInfo(static_cast<uint64_t>(op.inputMem->GetAddr()),
     132            4 :                                      static_cast<uint64_t>(op.inputMem->GetSize()));
     133            4 :         return HCCL_SUCCESS;
     134            0 :     } else if (op.outputMem != nullptr && op.outputMem->GetAddr() != 0) {
     135            0 :         token = CcuRep::GetTokenInfo(static_cast<uint64_t>(op.outputMem->GetAddr()),
     136            0 :                                      static_cast<uint64_t>(op.outputMem->GetSize()));
     137            0 :         return HCCL_SUCCESS;
     138            0 :     } else if (op.scratchMem != nullptr && op.scratchMem->GetAddr() != 0) {
     139            0 :         token = CcuRep::GetTokenInfo(static_cast<uint64_t>(op.scratchMem->GetAddr()),
     140            0 :                                      static_cast<uint64_t>(op.scratchMem->GetSize()));
     141            0 :         return HCCL_SUCCESS;
     142              :     }
     143            0 :     HCCL_WARNING("[GetToken] Both inputMem and outputMem are null");
     144            0 :     return HCCL_E_PTR;
     145              : }
     146            0 : u32 CcuAlgTemplateBase::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
     147              : {
     148              :     (void) inBuffType;
     149              :     (void) outBuffType;
     150            0 :     return 0;
     151              : }
     152              : 
     153            0 : HcclResult CcuAlgTemplateBase::GetMaxTransPortDataSize(u64 &maxTransPortDataSize) const
     154              : {
     155            0 :     maxTransPortDataSize = MAX_LOOP_GROUP_TRANS_SIZE;
     156            0 :     return HCCL_SUCCESS;
     157              : }
     158              : 
     159            0 : uint64_t CcuAlgTemplateBase::BufferTypeToAddr(const BufferType bufferType)
     160              : {
     161            0 :     if (bufferType == BufferType::INPUT && op_.inputMem != nullptr) {
     162            0 :         return static_cast<uint64_t>(op_.inputMem->GetAddr());
     163            0 :     } else if (bufferType == BufferType::OUTPUT && op_.outputMem != nullptr) {
     164            0 :         return static_cast<uint64_t>(op_.outputMem->GetAddr());
     165            0 :     } else if (bufferType == BufferType::SCRATCH && op_.scratchMem != nullptr){
     166            0 :         return static_cast<uint64_t>(op_.scratchMem->GetAddr());
     167              :     } else {
     168            0 :         return 0;
     169              :     }
     170              : }
     171              : 
     172            0 : HcclResult CcuAlgTemplateBase::AddRanksToGroup(const std::vector<std::vector<RankId>> &tempVTopo, RankGroup &rankGroupX, RankGroup &rankGroupY) const
     173              : {
     174            0 :     for (auto &peer : tempVTopo[0]) {
     175            0 :         rankGroupX.AddRank(peer);
     176              :     }
     177              : 
     178            0 :     for (auto &peer : tempVTopo[1]) {
     179            0 :         rankGroupY.AddRank(peer);
     180              :     }
     181            0 :     return HCCL_SUCCESS;
     182              : }
     183              : 
     184            0 : HcclResult CcuAlgTemplateBase::CalNumBlocks(u32& numBlocks, u64 dataSize, u32 numBlocksLimit)
     185              : {   
     186              :     (void) numBlocks;
     187              :     (void) dataSize;
     188              :     (void) numBlocksLimit;
     189            0 :     HCCL_WARNING("CalNumBlocks not support ccu template.");
     190            0 :     return HCCL_SUCCESS;
     191              : }
     192              : 
     193            1 : HcclResult CcuAlgTemplateBase::setPathNumMap(const std::map<u32, u32> &rank2PathNumMap) const
     194              : {
     195              :     (void)rank2PathNumMap;
     196            3 :     HCCL_WARNING("[CcuAlgTemplateBase] Unsupported interface of setPathNumMap!");
     197            1 :     return HCCL_SUCCESS;
     198              : }
     199              :  
     200              : 
     201              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1