LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ccu_alg_template - ccu_temp_reduce_mesh_1D_two_shot_mem2mem.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 70 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 8 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 <ios>
      12              : #include <iostream>
      13              : 
      14              : #include "log.h"
      15              : 
      16              : #include "ccu_temp_reduce_mesh_1D_two_shot_mem2mem.h"
      17              : #include "alg_data_trans_wrapper.h"
      18              : #include "ccu_instruction_reduce_mesh1d_two_shot_mem2mem.h"
      19              : #include "ccu_rank_group.h"
      20              : #include "ccu_ctx_creator_registry.h"
      21              : #include "ccu_context_reduce_mesh1d_two_shot_mem2mem.h"
      22              : 
      23              : namespace Hccl {
      24              : 
      25              : static CcuInstRegister<CcuContextReduceMeshTwoShotMem2Mem1D>
      26              :     registrarReduce(CcuInstType::CCU_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM);
      27              : 
      28            0 : CcuTempReduceMeshTwoShotMem2Mem1D::CcuTempReduceMeshTwoShotMem2Mem1D(
      29              :     const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
      30            0 :     const std::map<RankId, u32>& tempVirtRankMap)
      31            0 :     : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
      32            0 : {}
      33              : 
      34            0 : CcuTempReduceMeshTwoShotMem2Mem1D::~CcuTempReduceMeshTwoShotMem2Mem1D() {}
      35              : 
      36            0 : void CcuTempReduceMeshTwoShotMem2Mem1D::InitReduceInfo(const ReduceOp& reduceOp, const DataType& dataType)
      37              : {
      38            0 :     reduceOp_ = reduceOp;
      39            0 :     dataType_ = dataType;
      40            0 : }
      41              : 
      42            0 : HcclResult CcuTempReduceMeshTwoShotMem2Mem1D::CalcSlice(const u64 dataSize, RankSliceInfo& sliceInfoVec)
      43              : {
      44            0 :     std::vector<SliceInfo> tmp(tempVTopo_.size());
      45            0 :     sliceInfoVec.resize(tempRankSize_, tmp);
      46              : 
      47            0 :     u64 unitAllignSize = DataTypeSizeGet(dataType_);
      48            0 :     u64 chunkSize = RoundUp(dataSize, (tempRankSize_ * unitAllignSize)) * unitAllignSize;
      49            0 :     HCCL_INFO(
      50              :         "chunkSize[%llu], dataSize[%llu], tempRankSize_[%u], unitAllignSize[%llu]", chunkSize, dataSize, tempRankSize_,
      51              :         unitAllignSize);
      52            0 :     u64 accumOff = 0;
      53            0 :     for (u32 rankIdx = 0; rankIdx < tempRankSize_; rankIdx++) {
      54            0 :         u64 currChunkSize = ((dataSize - accumOff) > chunkSize) ? chunkSize : (dataSize - accumOff);
      55            0 :         SliceInfo slice = {accumOff, currChunkSize};
      56            0 :         sliceInfoVec[rankIdx][0] = slice;
      57            0 :         accumOff += currChunkSize;
      58              :     }
      59              : 
      60            0 :     CHK_PRT_RET(
      61              :         (sliceInfoVec[tempRankSize_ - 1][0].offset + sliceInfoVec[tempRankSize_ - 1][0].size != dataSize),
      62              :         HCCL_ERROR(
      63              :             "[CcuTempReduceMeshTwoShotMem2Mem1D] chunkSize:[%llu], Rank:[%d], SliceInfo calculation error!", chunkSize,
      64              :             myRank_),
      65              :         HcclResult::HCCL_E_INTERNAL);
      66            0 :     return HcclResult::HCCL_SUCCESS;
      67            0 : }
      68              : 
      69            0 : HcclResult CcuTempReduceMeshTwoShotMem2Mem1D::CalcRes(AlgTempResReq& tempResReq)
      70              : {
      71            0 :     tempResReq.queNum = 1;
      72            0 :     tempResReq.streamNum = tempResReq.queNum + 1; // 多申请一个 stream 给 ccuInsGroup
      73            0 :     HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
      74            0 :     CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
      75            0 :     return HcclResult::HCCL_SUCCESS;
      76              : }
      77              : 
      78            0 : HcclResult CcuTempReduceMeshTwoShotMem2Mem1D::GenExtIns(
      79              :     const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
      80              :     std::vector<InsQuePtr>& tempInsQues)
      81              : {
      82            0 :     buffInfo_ = templateDataParams.buffInfo;
      83            0 :     opMode_ = tempFuncs.opMode;
      84            0 :     CcuInstructionReduceMeshTwoShotMem2Mem1D ccuIns;
      85            0 :     std::vector<uint64_t> dimSize;
      86            0 :     dimSize.push_back(tempRankSize_);
      87            0 :     RankSliceInfo sliceInfoVec;
      88            0 :     CHK_RET(CalcSlice(templateDataParams.sliceSize, sliceInfoVec));
      89              : 
      90            0 :     uint32_t rankId = tempVirtRankMap_[myRank_];
      91            0 :     uint32_t rootId = tempVirtRankMap_[rootId_];
      92              : 
      93            0 :     const CollAlgOperator& op = op_;
      94            0 :     const std::vector<std::vector<RankId>>& tempVTopo = tempVTopo_;
      95            0 :     uint64_t inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
      96            0 :     uint64_t outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
      97            0 :     uint64_t scratchAddr = BufferTypeToAddr(buffInfo_.scratBuffType) + buffInfo_.scratchBuffBaseOff;
      98              :     uint64_t token;
      99            0 :     CHK_RET(GetToken(op_, token));
     100            0 :     uint64_t normalSliceSize = sliceInfoVec[0][0].size;
     101            0 :     uint64_t lastSliceSize = sliceInfoVec[tempRankSize_ - 1][0].size;
     102            0 :     uint64_t mySliceSize = sliceInfoVec[rankId][0].size;
     103              : 
     104            0 :     ccuIns.Init(
     105              :         rankId, rootId, op, tempVTopo, inputAddr, outputAddr, scratchAddr, token, normalSliceSize, lastSliceSize,
     106              :         mySliceSize);
     107              : 
     108            0 :     HCCL_INFO(
     109              :         "[CcuTempReduceMeshTwoShotMem2Mem1D] Run Init: rankId[%u], rootId[%u], inputAddr[%llu], outputAddr[%llu],"
     110              :         "scratchAddr[%llu], normalSliceSize[%llu], lastSliceSize[%llu], mySliceSize[%llu]",
     111              :         rankId, rootId, inputAddr, outputAddr, scratchAddr, normalSliceSize, lastSliceSize, mySliceSize);
     112              : 
     113            0 :     std::vector<LinkData> links;
     114            0 :     for (auto& pair : tempLinks) {
     115            0 :         if (pair.second.empty()) {
     116            0 :             continue;
     117              :         }
     118            0 :         links.push_back(pair.second[0]);
     119              :     }
     120            0 :     HCCL_DEBUG("[CcuTempReduceMeshTwoShotMem2Mem1D] links.size[%zu]", links.size());
     121            0 :     ccuIns.SetLinks(links);
     122              : 
     123            0 :     RankGroup rankGroup;
     124            0 :     for (auto& peer : tempVTopo_[0]) {
     125            0 :         rankGroup.AddRank(peer);
     126              :     }
     127            0 :     u32 cntCkeNum = 4;
     128            0 :     ccuIns.SetCntCkeNum(cntCkeNum);
     129            0 :     ccuIns.SetRankGroup(rankGroup);
     130            0 :     HCCL_DEBUG("CcuTempReduceMeshTwoShotMem2Mem1D is [%s]", ccuIns.Describe().c_str());
     131            0 :     tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionReduceMeshTwoShotMem2Mem1D>(ccuIns)));
     132              : 
     133            0 :     return HcclResult::HCCL_SUCCESS;
     134            0 : }
     135              : 
     136            0 : HcclResult CcuTempReduceMeshTwoShotMem2Mem1D::GenExtIns(
     137              :     const RankGraph* rankGraph, const TemplateInfo& tmpInfo, const std::vector<InsQuePtr>& tempInsQues) const
     138              : {
     139              :     (void)rankGraph;
     140              :     (void)tmpInfo;
     141              :     (void)tempInsQues;
     142              :     // 框架解析aicpuIns,算法的algCompnnetLite在device侧直接调用Run()
     143            0 :     return HcclResult::HCCL_SUCCESS;
     144              : }
     145              : 
     146              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1