LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/aiv_alg_template - aiv_temp_all_reduce_mesh_1D_twoshot.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 68 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 7 0

            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 "hccl_aiv_utils.h"
      12              : #include "aiv_ins.h"
      13              : #include "aiv_temp_all_reduce_mesh_1D_twoshot.h"
      14              : 
      15              : namespace Hccl {
      16              : 
      17            0 : AivTempAllReduceMesh1DTwoShot::AivTempAllReduceMesh1DTwoShot(const RankId virtualRank, const u32 tempRankSize,
      18            0 :     const std::vector<std::vector<RankId>> &tempVTopo, const std::map<RankId, u32> &tempVirtRankMap)
      19            0 :     : AivAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
      20              : {
      21            0 :      HCCL_INFO("[AivTempAllReduceMesh1DTwoShot] Init.");
      22            0 : }
      23              : 
      24            0 : AivTempAllReduceMesh1DTwoShot::~AivTempAllReduceMesh1DTwoShot()
      25              : {
      26            0 :     HCCL_INFO("[AivTempAllReduceMesh1DTwoShot] exit.");
      27            0 : }
      28              : 
      29            0 : HcclResult AivTempAllReduceMesh1DTwoShot::CalcRes(AlgTempResReq &tempResReq)
      30              : {
      31            0 :     tempResReq.queNum = 1;
      32            0 :     tempResReq.streamNum = tempResReq.queNum;
      33            0 :     HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
      34            0 :     CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
      35            0 :     return HcclResult::HCCL_SUCCESS;
      36              : }
      37              : 
      38            0 : u32 AivTempAllReduceMesh1DTwoShot::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
      39              : {
      40              :     (void) inBuffType;
      41              :     (void) outBuffType;
      42            0 :     u32 multiplier = 4;
      43            0 :     return multiplier;
      44              : }
      45              : 
      46            0 : HcclResult AivTempAllReduceMesh1DTwoShot::CalNumBlocks(u32& numBlocks, u64 dataSize, u32 numBlocksLimit)
      47              : {   
      48              :     (void) dataSize;
      49              : 
      50            0 :     if (numBlocksLimit >= (tempRankSize_ + 1)) {
      51            0 :         u32 coreNumPerRank = numBlocksLimit / (tempRankSize_ + 1);
      52            0 :         numBlocks           = coreNumPerRank * (tempRankSize_ + 1);
      53              :     } else {
      54              :         // 如果要用更少的核心可以在这里折算,比如rankSize/2个核心
      55            0 :         numBlocks = numBlocksLimit;
      56              :     }
      57            0 :     return HcclResult::HCCL_SUCCESS;
      58              : }
      59              : 
      60            0 : HcclResult AivTempAllReduceMesh1DTwoShot::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams, 
      61              :         const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
      62              : {
      63            0 :     HCCL_INFO("[AivTempAllReduceMesh1DTwoShot] start.");
      64            0 :     CHK_PRT_RET(tempInsQues.empty(),
      65              :         HCCL_ERROR("[AivTempAllReduceMesh1DTwoShot] empty queue"), HcclResult::HCCL_E_INTERNAL);
      66            0 :     CHK_PTR_NULL(tempInsQues[0]);
      67            0 :     std::vector<LinkData> allLinks;
      68            0 :     for (auto iter = tempLinks.begin(); iter != tempLinks.end(); ++iter) {
      69            0 :         allLinks.emplace_back(iter->second.at(0));
      70              :     }
      71            0 :     IncSliceId();  // 自动增长sliceId,传入aivTag
      72              : 
      73            0 :     AivOpArgs aivAllreduceArgs;
      74            0 :     aivAllreduceArgs.cmdType = HcclCMDType::HCCL_CMD_ALLREDUCE;
      75            0 :     aivAllreduceArgs.argsType = KernelArgsType::ARGS_TYPE_TWO_SHOT;
      76            0 :     aivAllreduceArgs.input = templateDataParams.buffInfo.inBuffBaseOff;
      77            0 :     aivAllreduceArgs.output = templateDataParams.buffInfo.outBuffBaseOff;
      78            0 :     aivAllreduceArgs.rank = myRank_;
      79            0 :     aivAllreduceArgs.rankSize = tempRankSize_;
      80            0 :     aivAllreduceArgs.count = templateDataParams.sliceSize / DataTypeSizeGet(dataType_);
      81            0 :     aivAllreduceArgs.dataType = dataType_;
      82            0 :     aivAllreduceArgs.op = reduceOp_;
      83            0 :     aivAllreduceArgs.root = root_;
      84            0 :     aivAllreduceArgs.aivTag = sliceId_;  // 传入aivTag,Lauch时重新组装为aivTag
      85            0 :     aivAllreduceArgs.isOpBase = (tempFuncs.opMode == OpMode::OPBASE);
      86            0 :     aivAllreduceArgs.xRankSize = tempVTopo_[0].size();
      87            0 :     CalNumBlocks(aivAllreduceArgs.numBlocks, templateDataParams.sliceSize, op_.numBlocksLimit);
      88            0 :     HCCL_INFO("[AivTempAllReduceMesh1DTwoShot] Actually use core num[%u]",aivAllreduceArgs.numBlocks);
      89              : 
      90            0 :     for(u32 i = 0; i < tempVTopo_[0].size(); i ++){
      91            0 :         aivAllreduceArgs.topo_[i] = tempVTopo_[0][i];
      92              :     }
      93              : 
      94            0 :     u32 sizeOne = 1, sizeTwo = 1;
      95            0 :     if (tempVTopo_.size() > sizeOne){
      96            0 :         aivAllreduceArgs.yRankSize = tempVTopo_[1].size();
      97            0 :         for (u32 i = 0; i < tempVTopo_[1].size(); i++){
      98            0 :             aivAllreduceArgs.topo_[TOPO_LEN_Y_OFFSET + i] = tempVTopo_[1][i];
      99              :         }
     100              :     }
     101            0 :     if (tempVTopo_.size() > sizeTwo){
     102            0 :         aivAllreduceArgs.zRankSize = tempVTopo_[2].size();
     103            0 :         for (u32 i = 0; i < tempVTopo_[2].size(); i++){
     104            0 :             aivAllreduceArgs.topo_[TOPO_LEN_Z_OFFSET + i] = tempVTopo_[2][i];
     105              :         }
     106              :     }
     107              : 
     108            0 :     aivAllreduceArgs.inputSliceStride = templateDataParams.inputSliceStride;
     109            0 :     aivAllreduceArgs.outputSliceStride = templateDataParams.outputSliceStride;
     110            0 :     aivAllreduceArgs.repeatNum = templateDataParams.repeatNum;
     111            0 :     aivAllreduceArgs.inputRepeatStride = templateDataParams.inputRepeatStride;
     112            0 :     aivAllreduceArgs.outputRepeatStride = templateDataParams.outputRepeatStride;
     113            0 :     std::unique_ptr<Instruction> aivInsAllreduceMesh1D = std::make_unique<AivInstruction>(allLinks, aivAllreduceArgs);
     114            0 :     tempInsQues[0]->Append(std::move(aivInsAllreduceMesh1D));
     115            0 :     HCCL_INFO("[AivTempAllReduceMesh1DTwoShot] GenExtIns finished");
     116            0 :     return HcclResult::HCCL_SUCCESS;
     117            0 : }
     118              : 
     119              : }  // namespace Hccl
        

Generated by: LCOV version 2.0-1