LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ccu_alg_template - ccu_temp_all_gather_mesh_2D_mem2mem.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 65 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 5 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_all_gather_mesh_2D_mem2mem.h"
      17              : #include "alg_data_trans_wrapper.h"
      18              : #include "ccu_instruction_all_gather_mesh2d_mem2mem.h"
      19              : #include "ccu_rank_group.h"
      20              : #include "ccu_ctx_creator_registry.h"
      21              : #include "ccu_context_all_gather_mesh2d_mem2mem.h"
      22              : #include "ccu_ins_group.h"
      23              : 
      24              : namespace Hccl {
      25              : 
      26              : static CcuInstRegister<CcuContextAllGatherMeshMem2Mem2D> registrarAllGather(CcuInstType::CCU_ALLGATHER_MESH_2D_MEM2MEM);
      27              : 
      28            0 : CcuTempAllGatherMeshMem2Mem2D::CcuTempAllGatherMeshMem2Mem2D(
      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              : {
      33              :     // 填充框内的维度大小, concurrmesh的topoMatch返回的vTopo大小应当为2,对应X轴和Y轴的大小
      34            0 :     if (tempVTopo_.size() != DIM_SIZE || tempVTopo_[0].size() <= 1 || tempVTopo_[1].size() <= 1) {
      35            0 :         THROW<InvalidParamsException>(StringFormat(
      36              :             "[CcuTempAllGatherMeshMem2Mem2D] Rank[%d], Invalid tempVTopo "
      37              :             "Size[%u] or Invalid tempVTopo[0] size [%u] or tempVTopo[1] size [%u].",
      38            0 :             myRank_, tempVTopo_.size(), tempVTopo_[0].size(), tempVTopo_[1].size()));
      39              :     }
      40            0 :     dimSize_.emplace_back(tempVTopo[0].size());
      41            0 :     dimSize_.emplace_back(tempVTopo[1].size());
      42            0 : }
      43              : 
      44            0 : CcuTempAllGatherMeshMem2Mem2D::~CcuTempAllGatherMeshMem2Mem2D() {}
      45              : 
      46            0 : HcclResult CcuTempAllGatherMeshMem2Mem2D::CalcRes(AlgTempResReq& tempResReq)
      47              : {
      48            0 :     tempResReq.queNum = 1; // 只申请一个insQue,填充一个insGroup,由框架将其中的ins放在多个stream上
      49            0 :     tempResReq.streamNum = tempResReq.queNum + 1; // 多申请一个 stream 给 ccuInsGroup
      50            0 :     uint32_t dieNum = tempVTopo_.size();
      51            0 :     if (dieNum != 2) { // concurrmesh的topoMatch返回的vTopo大小应当为2,对应X轴和Y轴的大小
      52            0 :         THROW<InvalidParamsException>(
      53            0 :             StringFormat("[CcuTempAllGatherMeshMem2Mem2D] Rank[%d], Invalid IODieNum[%u].", myRank_, dieNum));
      54              :     }
      55            0 :     HCCL_INFO(
      56              :         "[CcuTempAllGatherMeshMem2Mem2D] Rank[%d] requiredQueNum[%u] VtopoSize[%zu], VtopoSize0[%zu] "
      57              :         "VtopoSize1[%zu].",
      58              :         myRank_, tempResReq.queNum, tempVTopo_.size(), tempVTopo_[0].size(), tempVTopo_[1].size());
      59              : 
      60              :     uint32_t myAlgRank;
      61            0 :     for (u32 dim = 0; dim < tempVTopo_.size(); dim++) {
      62            0 :         CHK_RET(GetAlgRank(myRank_, tempVTopo_[dim], myAlgRank));
      63            0 :         for (u32 queIdx = 0; queIdx < tempVTopo_[dim].size() - 1; queIdx++) {
      64              :             // find neighbors -> virtualRank
      65            0 :             u32 neighborAlgRank = (myAlgRank + 1 + queIdx) % (tempVTopo_[dim].size());
      66            0 :             RankId neighborRank = tempVTopo_[dim][neighborAlgRank];
      67            0 :             HCCL_INFO(
      68              :                 "[CollAlgFactory] [CcuTempAllGatherMeshMem2Mem2D] Rank[%d], Dim[%u], NeighborRank[%d].", myRank_, dim,
      69              :                 neighborRank);
      70              : 
      71              :             // LinkNum
      72            0 :             tempResReq.links[neighborRank] = 1;
      73              :         }
      74              :     }
      75              : 
      76            0 :     return HcclResult::HCCL_SUCCESS;
      77              : }
      78              : 
      79            0 : HcclResult CcuTempAllGatherMeshMem2Mem2D::GenExtIns(
      80              :     const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
      81              :     std::vector<InsQuePtr>& tempInsQues)
      82              : {
      83            0 :     opMode_ = tempFuncs.opMode;
      84            0 :     buffInfo_ = templateDataParams.buffInfo;
      85              : 
      86              :     // 分别记录两个Die上的link,构造rankGroup
      87            0 :     for (auto pair : tempLinks) {
      88            0 :         if (pair.second.size() == 0 || pair.second[0].GetHop() != 1) { // ESL环境上暂只有直连链路
      89            0 :             THROW<InvalidParamsException>(StringFormat(
      90              :                 "[CcuTempAllGatherMeshMem2Mem2D] Rank[%d]--Peer[%d], "
      91              :                 "InvalidHop[%u].",
      92            0 :                 myRank_, pair.first, pair.second[0].GetHop()));
      93              :         }
      94            0 :         if ((pair.first / dimSize_[0] == myRank_ / dimSize_[0]) && pair.second[0].GetHop() == 1) {
      95            0 :             linksX_.emplace_back(pair.second[0]);
      96            0 :         } else if ((pair.first % dimSize_[0] == myRank_ % dimSize_[0]) && pair.second[0].GetHop() == 1) {
      97            0 :             linksY_.emplace_back(pair.second[0]);
      98              :         } else {
      99            0 :             THROW<InvalidParamsException>(StringFormat(
     100              :                 "[CcuTempAllGatherMeshMem2Mem2D] Rank[%d], Unexpected peerRank[%d] in tempLinks.", myRank_,
     101            0 :                 pair.first));
     102              :         }
     103            0 :     }
     104              : 
     105            0 :     RankGroup rankGroupX;
     106            0 :     RankGroup rankGroupY;
     107            0 :     AddRanksToGroup(tempVTopo_, rankGroupX, rankGroupY);
     108              : 
     109            0 :     uint64_t inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
     110            0 :     uint64_t outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
     111            0 :     uint64_t offset = static_cast<uint64_t>(op_.inputMem->GetSize());
     112            0 :     uint64_t sliceSize = templateDataParams.sliceSize;
     113              :     uint64_t token;
     114            0 :     CHK_RET(GetToken(op_, token));
     115              : 
     116            0 :     uint64_t aSize = sliceSize * dimSize_[0] / (dimSize_[0] + dimSize_[1]);
     117            0 :     uint64_t bSize = sliceSize - aSize;
     118            0 :     std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
     119            0 :     for (uint32_t axisId = 0; axisId < 2; axisId++) { // 2D算法,需要执行两次
     120            0 :         HCCL_INFO(
     121              :             "[CcuTempAllGatherMeshMem2Mem2D][GenExtIns] Rank[%d], axisId[%u], aSize[%llu], bSize[%llu].", myRank_,
     122              :             axisId, aSize, bSize);
     123              : 
     124            0 :         CcuInstructionAllGatherMeshMem2Mem2D ins = CcuInstructionAllGatherMeshMem2Mem2D();
     125            0 :         ins.Init(myRank_, axisId, inputAddr, outputAddr, aSize, bSize, sliceSize, offset, token, op_, tempVTopo_);
     126            0 :         ins.SetLinks(axisId == 0 ? linksX_ : linksY_);
     127            0 :         ins.SetRankGroup(axisId == 0 ? rankGroupX : rankGroupY);
     128            0 :         u32 cntCkeNum = 5; // 每个transport用5个CKE
     129            0 :         ins.SetCntCkeNum(cntCkeNum);
     130            0 :         ins.Describe();
     131            0 :         insGroupPtr->Append(std::move(std::make_unique<CcuInstructionAllGatherMeshMem2Mem2D>(ins)));
     132            0 :     }
     133            0 :     tempInsQues[0]->Append(std::move(insGroupPtr)); // 只有一条流
     134              : 
     135            0 :     return HcclResult::HCCL_SUCCESS;
     136            0 : }
     137              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1