LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ccu_alg_template - ccu_temp_all_reduce_mesh_1D.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 75 0
Test Date: 2026-08-04 10:52:23 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_instruction_all_reduce_mesh1d.h"
      17              : #include "ccu_rank_group.h"
      18              : #include "ccu_ctx_creator_registry.h"
      19              : #include "ccu_context_all_reduce_mesh1d.h"
      20              : #include "ccu_temp_all_reduce_mesh_1D.h"
      21              : 
      22              : namespace Hccl {
      23              : static CcuInstRegister<CcuContextAllReduceMesh1D> g_registrarAllReduce(
      24              :     CcuInstType::CCU_ALL_REDUCE_MESH_1D_DIRECT);
      25              : 
      26            0 : CcuTempAllReduceMesh1D::CcuTempAllReduceMesh1D(const RankId virtualRank, const u32 tempRankSize,
      27              :                                    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 : }
      32              : 
      33            0 : CcuTempAllReduceMesh1D::~CcuTempAllReduceMesh1D()
      34              : {
      35            0 : }
      36              : 
      37            0 : void CcuTempAllReduceMesh1D::InitReduceInfo(const ReduceOp &reduceOp, const DataType &dataType) {
      38            0 :     reduceOp_ = reduceOp;
      39            0 :     dataType_ = dataType;
      40            0 : }
      41              : 
      42            0 : HcclResult CcuTempAllReduceMesh1D::CalcSliceInfo(const AllignInfo &allignInfo, const u64 dataSize,
      43              :                                             RankSliceInfo &sliceInfoVec)
      44              : {
      45            0 :     CHK_RET(CalcSliceInfoAllReduce(allignInfo, tempRankSize_, dataSize, sliceInfoVec));
      46            0 :     return HcclResult::HCCL_SUCCESS;
      47              : }
      48              : 
      49            0 : HcclResult CcuTempAllReduceMesh1D::CalcRes(AlgTempResReq &tempResReq)
      50              : {
      51            0 :     tempResReq.queNum = 1;
      52            0 :     tempResReq.streamNum = tempResReq.queNum;
      53            0 :     HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
      54            0 :     CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
      55            0 :     return HcclResult::HCCL_SUCCESS;
      56              : }
      57              : 
      58              : /* CCU数据类型校验规则
      59              :  * Reduce算子:
      60              :  *      高精度模式,当dataType==outputDataType时,可选类型为FP32、FP16、BF16、UINT8、INT16、INT32;
      61              :  *      低精度模式,当dataType!=outputDataType时,dataType可选范围HIF8、E4M3、E5M2、INT8;outputDataType可选范围FP32、FP16、BF16;
      62              :  * 非Reduce算子:任意数据类型,dataType==outputDataType即可。
      63              :  */
      64            0 : HcclResult CcuTempAllReduceMesh1D::CheckCcuDataType() const
      65              : {
      66            0 :     if (op_.dataType == op_.outputDataType) {
      67              :         // allreduce算子高精度模式
      68            0 :         HCCL_INFO("HIGH PRECISION");
      69              :         set<DataType> highPrecisionSupportedInputDataType
      70            0 :             = {DataType::FP32,  DataType::FP16,  DataType::BFP16, DataType::UINT8, DataType::INT16, DataType::INT32};
      71            0 :         if (highPrecisionSupportedInputDataType.count(op_.dataType) == 0) {
      72            0 :             HCCL_ERROR("Unsupported DataType [%s] For OpType [%s].",
      73              :                 op_.dataType.Describe().c_str(), op_.opType.Describe().c_str());
      74            0 :             return HcclResult::HCCL_E_PARA;
      75              :         }
      76            0 :     } else if (op_.outputDataType != DataType::INVALID) {
      77              :         // allreduce算子低精度模式
      78            0 :         HCCL_INFO("LOW PRECISION");
      79            0 :         HCCL_ERROR("Unsupported LOW PRECISION, Output DataType [%s] For OpType [%s].",
      80              :             op_.outputDataType.Describe().c_str(), op_.opType.Describe().c_str());
      81            0 :         return HcclResult::HCCL_E_PARA;
      82              :     }
      83            0 :     HCCL_INFO("CheckCcuDataType Success!");
      84            0 :     return HcclResult::HCCL_SUCCESS;
      85              : }
      86              : 
      87            0 : HcclResult CcuTempAllReduceMesh1D::Run(const TempFuncs &tempFuncs, const RankSliceInfo &sliceInfoVec,
      88              :                                           const BuffInfo &buffInfo, const ResLinks &tempLinks,
      89              :                                           std::vector<InsQuePtr> &tempInsQues)
      90              : {
      91            0 :     CHK_PRT_RET(tempInsQues.empty(),
      92              :         HCCL_ERROR("[CcuTempAllReduceMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
      93            0 :     CHK_PTR_NULL(tempInsQues[0]);
      94            0 :     opMode_   = tempFuncs.opMode;
      95            0 :     buffInfo_ = buffInfo;
      96            0 :     CcuInstructionAllReduceMesh1D ccuInsAllReduceMesh1D;
      97            0 :     std::vector<uint64_t> dimSize;
      98            0 :     dimSize.push_back(tempRankSize_);
      99              :     uint64_t inputAddr;
     100              :     uint64_t outputAddr;
     101              : 
     102            0 :     if (op_.outputDataType == DataType::INVALID) {
     103            0 :         op_.outputDataType = op_.dataType;
     104              :     }
     105            0 :     CHK_RET(CheckCcuDataType());
     106            0 :     if (opMode_ == OpMode::OPBASE) {
     107            0 :         if (tempFuncs.isForepart) {
     108            0 :             inputAddr = BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()) + tempFuncs.usrData.usrInSlices[0].GetOffset();
     109              :         } else {
     110            0 :             inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
     111              :         }
     112            0 :         if (tempFuncs.isBottom) {
     113            0 :             outputAddr = BufferTypeToAddr(tempFuncs.usrData.usrOutSlices[0].GetType()) + tempFuncs.usrData.usrOutSlices[0].GetOffset();
     114              :         } else {
     115            0 :             outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
     116              :         }
     117              :     } else {
     118            0 :         inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff + tempFuncs.usrData.usrInSlices[0].GetOffset();
     119            0 :         outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff + tempFuncs.usrData.usrOutSlices[0].GetOffset();
     120              :     }
     121            0 :     HCCL_INFO("inputAddr[%llu], outputAddr[%llu]", inputAddr, outputAddr);
     122              : 
     123            0 :     uint64_t sliceSize = sliceInfoVec[myRank_][0].size;  // 获取本rank需要处理的数据量
     124            0 :     uint64_t offset = sliceInfoVec[myRank_][0].offset;   // 自己需要 reduce 的数据基于 inputAddr 的偏移
     125              :     uint64_t token;
     126            0 :     CHK_RET(GetToken(op_, token));
     127            0 :     ccuInsAllReduceMesh1D.Init(static_cast<uint32_t>(myRank_), inputAddr, outputAddr, sliceSize, offset, token, op_, tempVTopo_);
     128            0 :     HCCL_INFO("[CcuTempAllReduceMesh1D] Run Init: myRank_[%d], dimSize[%llu], inputAddr[%llu], outputAddr[%llu],"\
     129              :         "sliceSize[%llu], offset[%llu]", myRank_, dimSize[0], inputAddr, outputAddr, sliceSize, offset);
     130              : 
     131            0 :     std::vector<LinkData> links;
     132            0 :     for (auto &pair : tempLinks) {
     133            0 :         if (pair.second.empty()) {
     134            0 :             continue;
     135              :         }
     136            0 :         links.push_back(pair.second[0]);
     137              :     }
     138            0 :     HCCL_INFO("[CcuTempAllReduceMesh1D] links.size[%zu]", links.size());
     139            0 :     ccuInsAllReduceMesh1D.SetLinks(links);
     140              : 
     141            0 :     RankGroup rankGroup;
     142              : 
     143            0 :     for (auto &peer : tempVTopo_[0]) {
     144            0 :         rankGroup.AddRank(peer);
     145              :     }
     146            0 :     u32 cntCkeNum = 4;
     147            0 :     ccuInsAllReduceMesh1D.SetCntCkeNum(cntCkeNum);
     148            0 :     ccuInsAllReduceMesh1D.SetRankGroup(rankGroup);
     149            0 :     HCCL_INFO("CCUInsAllReducemesh1D is [%s]", ccuInsAllReduceMesh1D.Describe().c_str());
     150            0 :     tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionAllReduceMesh1D>(ccuInsAllReduceMesh1D)));
     151              : 
     152            0 :     return HcclResult::HCCL_SUCCESS;
     153            0 : }
     154              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1