LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/operator - scatter_operator.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 50.0 % 62 31
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 4 4

            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 "scatter_operator.h"
      12              : #include "coll_alg_utils.h"
      13              : 
      14              : namespace hccl {
      15              : 
      16            1 : ScatterOperator::ScatterOperator(
      17              :     AlgConfigurator* algConfigurator, CCLBufferManager& cclBufferManager, HcclDispatcher dispatcher,
      18            1 :     std::unique_ptr<TopoMatcher>& topoMatcher)
      19            1 :     : CollAlgOperator(algConfigurator, cclBufferManager, dispatcher, topoMatcher, HcclCMDType::HCCL_CMD_SCATTER)
      20              : {
      21              :     // 由于scatter只支持server间ring、nb和nhr,其他算法需要重定向到ring
      22            3 :     if (!(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR)
      23            3 :         && !(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB)
      24            3 :         && !(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING)) {
      25            3 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RING;
      26            3 :         HCCL_INFO(
      27              :             "[ScatterOperator][ScatterOperator] algType[%s] is not supported, reset algType=ring",
      28              :             AlgTypeToStr(algType_).c_str());
      29              :     }
      30            4 : }
      31              : 
      32            8 : ScatterOperator::~ScatterOperator() {}
      33              : 
      34              : HcclResult
      35            4 : ScatterOperator::SelectAlg(const std::string& tag, const OpParam& param, std::string& algName, std::string& newTag)
      36              : {
      37            4 :     if (isDiffDeviceType_) {
      38            0 :         HCCL_ERROR("[ScatterOperator][SelectAlg] Scatter not support diffDeviceType");
      39            0 :         return HCCL_E_NOT_SUPPORT;
      40              :     }
      41            4 :     if (userRankSize_ == 1) {
      42            0 :         algName = "ScatterSingleExecutor";
      43            0 :         HCCL_INFO("[SelectAlg] Scatter SelectAlg is algName [%s]", algName.c_str());
      44            0 :         return HCCL_SUCCESS;
      45              :     }
      46            4 :     newTag = param.tag;
      47            4 :     if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE
      48            8 :         && (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_HD
      49            4 :             || algType_.algoLevel2 == AlgTypeLevel2::ALG_LEVEL2_HD)) {
      50            0 :         std::string appendTag = "";
      51            0 :         u32 serverNumPerSuperPod = superPodNum_ == 0 ? moduleNum_ : moduleNum_ / superPodNum_;
      52            0 :         if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_HD) {
      53            0 :             u32 part1Size = FACTOR_TWO * (serverNumPerSuperPod - (1 << static_cast<u32>(log2(serverNumPerSuperPod))));
      54            0 :             u32 rootId = param.root / deviceNumPerAggregation_ % serverNumPerSuperPod;
      55            0 :             appendTag += "L1_" + std::to_string((rootId >= part1Size) || ((rootId % FACTOR_TWO) == 0));
      56              :         }
      57            0 :         HCCL_DEBUG("[ScatterOperator]SelectAlg for algoLevel1");
      58            0 :         if (algType_.algoLevel2 == AlgTypeLevel2::ALG_LEVEL2_HD) {
      59            0 :             u32 part1Size = FACTOR_TWO * (superPodNum_ - (1 << static_cast<u32>(log2(superPodNum_))));
      60            0 :             u32 rootId = param.root / deviceNumPerAggregation_ / serverNumPerSuperPod;
      61            0 :             appendTag += (appendTag.empty() ? "L2_" : "_L2_")
      62            0 :                          + std::to_string((rootId >= part1Size) || ((rootId % FACTOR_TWO) == 0));
      63              :         }
      64            0 :         HCCL_DEBUG("[ScatterOperator][SelectAlg]tag is [%s]", tag.c_str());
      65            0 :         newTag = newTag + '_' + appendTag;
      66            0 :         if (GetExternalInputHcclEnableEntryLog() && param.opBaseAtraceInfo != nullptr) {
      67            0 :             CHK_RET(param.opBaseAtraceInfo->SavealgtypeTraceInfo(appendTag, param.tag));
      68              :         }
      69            0 :     }
      70              : 
      71              :     // 由于scatter只支持server间ring,nb和NHR,如果不是需要重定向到ring;910_93仅支持server间ring
      72            4 :     if (!(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR)
      73            4 :         && !(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB)
      74            4 :         && !(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING)) {
      75            0 :         HCCL_INFO(
      76              :             "[ScatterOperator][Scatter] algType[%s] is not supported, reset algType=ring",
      77              :             AlgTypeToStr(algType_).c_str());
      78            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RING;
      79              :     }
      80              : 
      81            0 :     bool isMeshTopo = topoType_ == TopoType::TOPO_TYPE_NP_MESH || topoType_ == TopoType::TOPO_TYPE_4P_MESH
      82            4 :                       || topoType_ == TopoType::TOPO_TYPE_2P_MESH || topoType_ == TopoType::TOPO_TYPE_1P_MESH;
      83            4 :     bool isRingTopo = topoType_ == TopoType::TOPO_TYPE_NP_SINGLE_RING || topoType_ == TopoType::TOPO_TYPE_8P_RING
      84            8 :                       || topoType_ == TopoType::TOPO_TYPE_NP_DOUBLE_RING;
      85              : 
      86            4 :     if (multiModuleDiffDeviceNumMode_ || multiSuperPodDiffServerNumMode_) {
      87            0 :         algName = "ScatterCommExecutor";
      88            4 :     } else if (isMeshTopo) {
      89            4 :         algName = "ScatterMeshExecutor";
      90            0 :     } else if (isRingTopo) {
      91            0 :         if (deviceType_ == DevType::DEV_TYPE_910_93) {
      92            0 :             algName = "ScatterRingFor91093Executor";
      93              :         } else {
      94            0 :             algName = "ScatterRingExecutor";
      95              :         }
      96              :     } else {
      97            0 :         algName = "ScatterCommExecutor";
      98              :     }
      99            4 :     if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     100            4 :         newTag = newTag + algName;
     101            4 :         HCCL_INFO("[SelectAlg] Scatter newTag is [%s] algName is [%s]", newTag.c_str(), algName.c_str());
     102              :     }
     103            4 :     newTag += (param.aicpuUnfoldMode ? "_device" : "_host");
     104            4 :     return HCCL_SUCCESS;
     105              : }
     106              : 
     107              : REGISTER_OP(HcclCMDType::HCCL_CMD_SCATTER, Scatter, ScatterOperator);
     108              : } // namespace hccl
        

Generated by: LCOV version 2.0-1