LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ccu_alg_template - ccu_temp_all_to_all_v_mesh_2Die.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 % 7 0

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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_temp_all_to_all_v_mesh_2Die.h"
      12              : 
      13              : #include <ios>
      14              : #include <iostream>
      15              : 
      16              : #include "log.h"
      17              : #include "ccu_rank_group.h"
      18              : #include "ccu_ctx_creator_registry.h"
      19              : #include "ccu_ins_group.h"
      20              : #include "ccu_context_all_to_all_v_mesh2die.h"
      21              : 
      22              : namespace Hccl {
      23              : 
      24              : static CcuInstRegister<CcuContextAllToAllVMesh2Die> registerAlltoAllV2Die(CcuInstType::CCU_ALLTOALLV_MESH_2DIE_DIRECT);
      25              : 
      26            0 : CcuTempAlltoAllVMesh2Die::CcuTempAlltoAllVMesh2Die(
      27              :     const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
      28            0 :     const std::map<RankId, u32>& tempVirtRankMap)
      29            0 :     : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
      30              : {
      31            0 :     if (tempRankSize_ <= 1 || tempRankSize_ % 2 != 0) {
      32            0 :         THROW<InvalidParamsException>(
      33            0 :             StringFormat("[CcuTempAlltoAllVMesh2Die] Rank[%d], Invalid rankSize[%u].", myRank_, tempRankSize_));
      34              :     }
      35              : 
      36            0 :     if (tempVTopo_.size() != 1) {
      37            0 :         THROW<InvalidParamsException>(StringFormat(
      38              :             "[CcuTempAlltoAllVMesh2Die] Rank[%d], Invalid tempVTopo size[%u].", myRank_, tempVTopo_.size()));
      39              :     }
      40            0 :     if (tempVTopo_[0].size() != tempRankSize_) {
      41            0 :         THROW<InvalidParamsException>(StringFormat(
      42              :             "[CcuTempAlltoAllVMesh2Die] Rank[%d], Invalid tempVTopo[0] size[%u] is not equal to rankSize[%u].", myRank_,
      43            0 :             tempVTopo_[0].size(), tempRankSize_));
      44              :     }
      45              :     // 填充框内的维度大小
      46            0 :     dimSize_.push_back(tempRankSize_);
      47            0 : }
      48              : 
      49            0 : CcuTempAlltoAllVMesh2Die::~CcuTempAlltoAllVMesh2Die() {}
      50              : 
      51            0 : void CcuTempAlltoAllVMesh2Die::SetA2ASendRecvInfo(const A2ASendRecvInfo& sendRecvInfo)
      52              : {
      53            0 :     localSendRecvInfo_ = sendRecvInfo;
      54            0 :     return;
      55              : }
      56              : 
      57            0 : HcclResult CcuTempAlltoAllVMesh2Die::CalcRes(AlgTempResReq& tempResReq)
      58              : {
      59            0 :     tempResReq.queNum = 1; // 只申请一个insQue,填充一个insGroup,由框架将其中的ins放在多个stream上
      60            0 :     tempResReq.streamNum = tempResReq.queNum + 1; // 多申请一个 stream 给 ccuInsGroup
      61              : 
      62            0 :     HCCL_INFO(
      63              :         "[CcuTempAlltoAllVMesh2Die] Rank[%d] requiredQueNum[%u] VtopoSize[%u], VtopoSize0[%u].", myRank_,
      64              :         tempResReq.queNum, tempVTopo_.size(), tempVTopo_[0].size());
      65            0 :     CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
      66              : 
      67            0 :     return HcclResult::HCCL_SUCCESS;
      68              : }
      69              : 
      70            0 : HcclResult CcuTempAlltoAllVMesh2Die::FillLinks(const ResLinks& tempLinks)
      71              : {
      72            0 :     for (const auto& pair : tempLinks) {
      73            0 :         CHK_PRT_RET(
      74              :             pair.second.empty(), // ESL环境上暂只有直连链路
      75              :             HCCL_ERROR("[CcuTempAlltoAllVMesh2Die] Rank[%d]--peerRank[%d] no link.", myRank_, pair.first),
      76              :             HcclResult::HCCL_E_PARA);
      77            0 :         for (const auto& linkData : pair.second) {
      78            0 :             const u32 dieId = linkData.GetLocalDieId();
      79            0 :             if (dieId == 0) {
      80            0 :                 HCCL_INFO(
      81              :                     "[CcuTempAlltoAllVMesh2Die][Run] Rank[%d] insert link to peerRank[%d] in links(Die0).", myRank_,
      82              :                     pair.first);
      83            0 :             } else if (dieId == 1) {
      84            0 :                 HCCL_INFO(
      85              :                     "[CcuTempAlltoAllVMesh2Die][Run] Rank[%d] insert link to peerRank[%d] in links(Die1).", myRank_,
      86              :                     pair.first);
      87              :             } else {
      88            0 :                 HCCL_ERROR(
      89              :                     "[CcuTempAlltoAllVMesh2Die] Rank[%d]--peerRank[%d], Unexpected dieId[%u] in link.", myRank_,
      90              :                     pair.first, dieId);
      91            0 :                 return HcclResult::HCCL_E_PARA;
      92              :             }
      93            0 :             links_[dieId].emplace_back(linkData);
      94            0 :             rankGroup_[dieId].AddRank(pair.first);
      95              :         }
      96              :     }
      97            0 :     rankGroup_[0].AddRank(myRank_); // keep myRank_ at last, sync with context
      98            0 :     rankGroup_[1].AddRank(myRank_);
      99            0 :     uint32_t minLinks = std::min(links_[0].size(), links_[1].size());
     100            0 :     uint32_t maxLinks = std::max(links_[0].size(), links_[1].size());
     101            0 :     CHK_PRT_RET(
     102              :         minLinks + 1 != maxLinks,
     103              :         HCCL_ERROR(
     104              :             "[CcuTempAlltoAllVMesh2Die] Rank[%d], Unexpected links size, minLinks+1[%u] != maxLinks[%u].", myRank_,
     105              :             minLinks + 1, maxLinks),
     106              :         HcclResult::HCCL_E_PARA);
     107            0 :     return HcclResult::HCCL_SUCCESS;
     108              : }
     109              : 
     110            0 : HcclResult CcuTempAlltoAllVMesh2Die::Run(
     111              :     const TempFuncs& tempFuncs, const RankSliceInfo& sliceInfoVec, const BuffInfo& buffInfo, const ResLinks& tempLinks,
     112              :     std::vector<InsQuePtr>& tempInsQues)
     113              : {
     114              :     (void)tempFuncs;
     115              :     (void)sliceInfoVec;
     116              :     (void)buffInfo;
     117              : 
     118            0 :     CHK_PRT_RET(
     119              :         tempInsQues.empty(), HCCL_ERROR("[CcuTempAlltoAllVMesh2Die][Run] tempInsQues is empty."),
     120              :         HcclResult::HCCL_E_INTERNAL);
     121              : 
     122            0 :     CHK_PRT_RET(
     123              :         op_.inputMem == nullptr || op_.outputMem == nullptr,
     124              :         HCCL_ERROR(
     125              :             "[CcuTempAlltoAllVMesh2Die][Run] Rank[%d] inputmem[%p] or outputmem[%p] is null", myRank_,
     126              :             op_.inputMem.get(), op_.outputMem.get()),
     127              :         HcclResult::HCCL_E_PTR);
     128              : 
     129            0 :     uint64_t inputAddr = op_.inputMem == nullptr ? 0 : op_.inputMem->GetAddr();
     130            0 :     uint64_t outputAddr = op_.outputMem == nullptr ? 0 : op_.outputMem->GetAddr();
     131            0 :     uint64_t scratchAddr = op_.scratchMem == nullptr ? 0 : op_.scratchMem->GetAddr();
     132              : 
     133            0 :     HCCL_INFO(
     134              :         "[CcuTempAlltoAllVMesh2Die][Run] Rank[%d], input[%#llx], output[%#llx], scratch[%#llx], dataType[%d], "
     135              :         "sendType[%d].",
     136              :         myRank_, inputAddr, outputAddr, scratchAddr, op_.dataType, op_.all2AllVDataDes.sendType);
     137              : 
     138              :     // 分别记录两个Die上的link,构造rankGroup
     139            0 :     CHK_RET(FillLinks(tempLinks));
     140              : 
     141              :     uint64_t token;
     142            0 :     CHK_RET(GetToken(op_, token));
     143              : 
     144            0 :     std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
     145            0 :     for (uint32_t axisId = 0; axisId < 2; axisId++) { // 2Die算法,需要执行两次
     146            0 :         CcuInstructionAllToAllVMesh2Die ins = CcuInstructionAllToAllVMesh2Die(op_, dimSize_, tempVTopo_);
     147            0 :         bool withMyRank = links_[axisId].size() < links_[1 - axisId].size();
     148            0 :         ins.Init(myRank_, withMyRank, inputAddr, outputAddr, scratchAddr, token, localSendRecvInfo_);
     149            0 :         ins.SetLinks(links_[axisId]);
     150            0 :         ins.SetRankGroup(rankGroup_[axisId]);
     151            0 :         const u32 ckeNum = 5;
     152            0 :         ins.SetCntCkeNum(ckeNum);
     153            0 :         insGroupPtr->Append(std::move(std::make_unique<CcuInstructionAllToAllVMesh2Die>(ins)));
     154            0 :     }
     155            0 :     tempInsQues[0]->Append(std::move(insGroupPtr)); // 只有一条流
     156              : 
     157            0 :     return HcclResult::HCCL_SUCCESS;
     158            0 : }
     159              : 
     160              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1