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