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

Generated by: LCOV version 2.0-1