LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/selector - mc2_selector.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 81 0
Test Date: 2026-07-28 12:11:00 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 "log.h"
      12              : #include "mc2_selector.h"
      13              : #include "selector_registry.h"
      14              : #include "coll_operator.h"
      15              : #include "coll_alg_params.h"
      16              : 
      17              : namespace Hccl {
      18              : const std::map<OpType, std::string> MC2_CCU_1D_DEFAULT_ALG_MAP = {
      19              :     {OpType::ALLGATHER, "CcuAllGatherMesh1D"},
      20              :     {OpType::REDUCESCATTER, "CcuReduceScatterMesh1D"},
      21              :     {OpType::ALLREDUCE, "CcuAllReduceMesh1D"},
      22              :     {OpType::REDUCE, "CcuReduceMesh1D"},
      23              :     {OpType::ALLTOALL, "CcuAlltoAllMesh1D"},
      24              :     {OpType::ALLTOALLV, "CcuAlltoAllVMesh1D"},
      25              :     {OpType::HALFALLTOALLV, "CcuHalfAll2AllVMesh1D"},
      26              : };
      27              : 
      28              : const std::map<OpType, std::string> MC2_CCU_SCHED_1D_DEFAULT_ALG_MAP = {
      29              :     {OpType::ALLGATHER, "CcuAllGatherMeshMem2Mem1D"},
      30              :     {OpType::REDUCESCATTER, "CcuReduceScatterMeshMem2Mem1D"},
      31              :     {OpType::ALLREDUCE, "CcuAllReduceMeshMem2Mem1D"},
      32              :     {OpType::ALLTOALL, "CcuAlltoAllMesh1D"},
      33              :     {OpType::ALLTOALLV, "CcuAlltoAllVMesh1D"},
      34              :     {OpType::HALFALLTOALLV, "CcuHalfAll2AllVMesh1D"},
      35              : };
      36              : 
      37              : const std::map<OpType, std::string> MC2_CCU_2D_DEFAULT_ALG_MAP = {
      38              :     {OpType::ALLGATHER, "CcuAllGatherMesh2D"},
      39              :     {OpType::REDUCESCATTER, "CcuReduceScatterMesh2D"},
      40              :     {OpType::ALLREDUCE, "CcuAllReduceMesh2DOneShot"},
      41              :     {OpType::REDUCE, "CcuReduceMesh2D"},
      42              :     {OpType::ALLTOALL, "CcuAlltoAllMesh2D"},
      43              : };
      44              : 
      45              : const std::map<OpType, std::string> MC2_AICPU_1D_DEFAULT_ALG_MAP = {
      46              :     {OpType::ALLGATHER, "InsAllGatherMesh"},
      47              :     {OpType::REDUCESCATTER, "InsReduceScatterNHR"},
      48              :     {OpType::ALLREDUCE, "InsAllReduceNHR"},
      49              :     {OpType::REDUCE, "InsReduceNHR"},
      50              :     {OpType::ALLTOALL, "InsAlltoAllMesh"},
      51              :     {OpType::ALLTOALLV, "InsAlltoAllvMesh"},
      52              :     {OpType::BATCHSENDRECV, "InsBatchSendRecv"},
      53              :     {OpType::BROADCAST, "InsBroadcastNHR"},
      54              :     {OpType::SCATTER, "InsScatterNHR"},
      55              :     {OpType::SEND, "InsSend"},
      56              :     {OpType::RECV, "InsRecv"},
      57              : };
      58              : 
      59            0 : AlgorithmType Mc2Selector::GetAlgorithmTypeForMC2CCU(const std::string& name) {
      60            0 :     auto it = algorithmMap_.find(name);
      61            0 :     if (it == algorithmMap_.end()) {
      62            0 :         THROW<InvalidParamsException>(StringFormat("Unknown algorithm name: [%s] ", name.c_str()));
      63              :     }
      64            0 :     return it->second;
      65              : }
      66              : 
      67              : const std::map<OpType, std::string> MC2_AICPU_2D_DEFAULT_ALG_MAP = {
      68              : };
      69              : 
      70            0 : SelectorStatus Mc2Selector::SelectDefaultCcuMsAlgo(const CollAlgOperator &op,const CollAlgParams &params,
      71              :                                    std::string &primQueueGenName) const
      72              : {
      73              :     (void) params;
      74            0 :     TopoInfo topoInfo;
      75            0 :     CalcTopoShape(topoInfo);
      76            0 :     std::map<OpType, string> algMap;
      77            0 :     if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
      78            0 :         algMap = MC2_CCU_1D_DEFAULT_ALG_MAP;
      79            0 :     } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
      80            0 :         algMap = MC2_CCU_2D_DEFAULT_ALG_MAP;
      81              :     } else {
      82            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultCcuMsAlgo] only support 1D mesh and 2D mesh algo.");
      83            0 :         return SelectorStatus::NOT_MATCH;
      84              :     }
      85            0 :     auto it = algMap.find(op.opType);
      86            0 :     if (it != algMap.end()) {
      87            0 :         primQueueGenName = it->second;
      88              :     } else {
      89            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultCcuMsAlgo] op.opType[%s] Level0Shape[%d] does not have any default mc2 algo.",
      90              :             op.opType.Describe().c_str(), topoInfo.level0Shape);
      91            0 :         return SelectorStatus::NOT_MATCH;
      92              :     }
      93            0 :     return SelectorStatus::MATCH;
      94            0 : }
      95              : 
      96            0 : SelectorStatus Mc2Selector::SelectDefaultCcuSchedAlgo(const CollAlgOperator &op, const CollAlgParams &params,
      97              :                                    std::string &primQueueGenName) const
      98              : {
      99              :     (void) params;
     100            0 :     TopoInfo topoInfo;
     101            0 :     CalcTopoShape(topoInfo);
     102            0 :     std::map<OpType, string> algMap;
     103            0 :     if (topoInfo.level0Shape == Level0Shape::MESH_1D || topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
     104            0 :         algMap = MC2_CCU_SCHED_1D_DEFAULT_ALG_MAP;
     105              :     } else {
     106            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultCcuSchedAlgo] only support 1D mesh algo.");
     107            0 :         return SelectorStatus::NOT_MATCH;
     108              :     }
     109            0 :     auto it = algMap.find(op.opType);
     110            0 :     if (it != algMap.end()) {
     111            0 :         primQueueGenName = it->second;
     112              :     } else {
     113            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultCcuSchedAlgo] op.opType[%s] Level0Shape[%d] does not have any default mc2 algo.",
     114              :             op.opType.Describe().c_str(), topoInfo.level0Shape);
     115            0 :         return SelectorStatus::NOT_MATCH;
     116              :     }
     117            0 :     return SelectorStatus::MATCH;
     118            0 : }
     119              : 
     120            0 : SelectorStatus Mc2Selector::SelectDefaultAicpuAlgo(const CollAlgOperator &op,const CollAlgParams &params,
     121              :                                    std::string &primQueueGenName) const
     122              : {
     123              :     (void) params;
     124            0 :     TopoInfo topoInfo;
     125            0 :     CalcTopoShape(topoInfo);
     126            0 :     std::map<OpType, string> algMap;
     127            0 :     if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
     128            0 :         algMap = MC2_AICPU_1D_DEFAULT_ALG_MAP;
     129            0 :     } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
     130            0 :         algMap = MC2_AICPU_2D_DEFAULT_ALG_MAP;
     131              :     } else {
     132            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultAicpuAlgo] only support 1D mesh and 2D mesh algo.");
     133            0 :         return SelectorStatus::NOT_MATCH;
     134              :     }
     135            0 :     auto it = algMap.find(op.opType);
     136            0 :     if (it != algMap.end()) {
     137            0 :         primQueueGenName = it->second;
     138              :     } else {
     139            0 :         HCCL_ERROR("[Algo][Mc2Selector][SelectDefaultAicpuAlgo] op.opType[%s] Level0Shape[%d] does not have any default mc2 algo.",
     140              :             op.opType.Describe().c_str(), topoInfo.level0Shape);
     141            0 :         return SelectorStatus::NOT_MATCH;
     142              :     }
     143            0 :     return SelectorStatus::MATCH;
     144            0 : }
     145              : 
     146            0 : SelectorStatus Mc2Selector::SelectCcuMsAlgo(const CollAlgOperator &op, CollAlgParams &params,
     147              :                                    std::string &primQueueGenName) const
     148              : {
     149              :     // 校验 algConfig 是否为空
     150            0 :     if (params.algConfig.empty()) {
     151            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectCcuMsAlgo] algConfig is [%s].", params.algConfig.c_str());
     152              :         // 没有配置算法类型,返回默认算法
     153            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectCcuMsAlgo] MC2 CCU MS does not support algConfig yet.");
     154              :     }
     155              : 
     156              :     // 当前 ccu 模式只有默认算法选择,不支持配置 algConfig
     157            0 :     return SelectDefaultCcuMsAlgo(op, params, primQueueGenName);
     158              : }
     159              : 
     160            0 : SelectorStatus Mc2Selector::SelectCcuSchedAlgo(const CollAlgOperator &op, CollAlgParams &params,
     161              :                                    std::string &primQueueGenName) const
     162              : {
     163              :     // 校验 algConfig 是否为空
     164            0 :     if (params.algConfig.empty()) {
     165            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectCcuSchedAlgo] algConfig is [%s].", params.algConfig.c_str());
     166              :         // 没有配置算法类型,返回默认算法
     167            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectCcuSchedAlgo] MC2 CCU Sched does not support algConfig yet.");
     168              :     }
     169              :  
     170              :     // 当前 ccu 模式只有默认算法选择,不支持配置 algConfig
     171            0 :     return SelectDefaultCcuSchedAlgo(op, params, primQueueGenName);
     172              : }
     173              : 
     174            0 : SelectorStatus Mc2Selector::SelectAicpuAlgo(const CollAlgOperator &op, CollAlgParams &params,
     175              :                                    std::string &primQueueGenName) const
     176              : {
     177              :     // 校验 algConfig 是否为空
     178            0 :     if (params.algConfig.empty()) {
     179            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectAicpuAlgo] algConfig is [%s].", params.algConfig.c_str());
     180              :         // 没有配置算法类型,返回默认算法
     181            0 :         HCCL_INFO("[Algo][Mc2Selector][SelectAicpuAlgo] MC2 AICPU does not support algConfig yet.");
     182              :     }
     183              : 
     184              :     // 当前 ccu 模式只有默认算法选择,不支持配置 algConfig
     185            0 :     return SelectDefaultAicpuAlgo(op, params, primQueueGenName);
     186              : }
     187              : 
     188            0 : SelectorStatus Mc2Selector::Select(const CollAlgOperator &op, CollAlgParams &params,
     189              :                                    std::string &primQueueGenName)
     190              : {
     191            0 :     if (rankGraph_ == nullptr) {
     192            0 :         HCCL_ERROR("[Algo][Mc2Selector] rankGraph_ is nullptr.");
     193            0 :         return SelectorStatus::NOT_MATCH;
     194              :     }
     195              : 
     196            0 :     if (params.opExecuteConfig.accState == AcceleratorState::CCU_MS) {
     197            0 :         return SelectCcuMsAlgo(op, params, primQueueGenName);
     198            0 :     } else if (params.opExecuteConfig.accState == AcceleratorState::CCU_SCHED) {
     199            0 :         return SelectCcuSchedAlgo(op, params, primQueueGenName);
     200            0 :     } else if (params.opExecuteConfig.accState == AcceleratorState::AICPU_TS) {
     201            0 :         return SelectAicpuAlgo(op, params, primQueueGenName);
     202              :     } else {
     203              :         // 当前 MC2 场景不支持回退,当遇到不支持的 AcceleratorState 时直接报错
     204            0 :         HCCL_ERROR("[Algo][Mc2Selector] AcceleratorState[%s] is not supported, match failed",
     205              :             params.opExecuteConfig.accState.Describe().c_str());
     206            0 :         return SelectorStatus::NOT_MATCH;
     207              :     }
     208              : }
     209              : 
     210              : REGISTER_SELECTOR(18, Mc2Selector);
     211              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1