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 "coll_all_gather_small_count_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherSmallCountExecutor::CollAllGatherSmallCountExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollAllGatherExecutor(dispatcher, topoMatcher)
17 : {
18 0 : DMAReduceFlag_ = true;
19 0 : }
20 :
21 0 : HcclResult CollAllGatherSmallCountExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
22 : {
23 0 : TransportMemType inputType = TransportMemType::RESERVED;
24 0 : TransportMemType outputType = TransportMemType::RESERVED;
25 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
26 0 : CHK_RET(CalcCombinedCommInfo(inputType, outputType, opTransport));
27 0 : return HCCL_SUCCESS;
28 : }
29 :
30 0 : HcclResult CollAllGatherSmallCountExecutor::CalcStreamNum(u32& streamNum)
31 : {
32 0 : constexpr u64 streamForSmallCount = 3;
33 0 : streamNum = streamForSmallCount;
34 0 : HCCL_INFO("[CollAllGatherSmallCountExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
35 0 : return HCCL_SUCCESS;
36 : }
37 :
38 0 : bool CollAllGatherSmallCountExecutor::IsSmallData([[maybe_unused]] const u64 size) { return true; }
39 :
40 0 : u64 CollAllGatherSmallCountExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
41 : {
42 : // 中转内存单次最多能够接受的output count
43 0 : u64 maxCountPerLoop = cclBuffSize / (unitSize * topoAttr_.userRankSize);
44 0 : if (topoAttr_.userRankSize % HCCL_DEVICE_NUM_FOUR == 0) {
45 0 : maxCountPerLoop = maxCountPerLoop * HCCL_DEVICE_NUM_FOUR;
46 0 : } else if (topoAttr_.userRankSize % HCCL_DEVICE_NUM_TWO == 0) {
47 0 : maxCountPerLoop = maxCountPerLoop * HCCL_DEVICE_NUM_TWO;
48 : }
49 0 : HCCL_INFO(
50 : "[CollAllGatherSmallCountExecutor][CalcLoopMaxCount]"
51 : "maxCountPerLoop[%llu]",
52 : maxCountPerLoop);
53 0 : return maxCountPerLoop;
54 : }
55 :
56 : HcclResult
57 0 : CollAllGatherSmallCountExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
58 : {
59 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
60 0 : inputType = TransportMemType::CCL_INPUT;
61 0 : outputType = TransportMemType::CCL_OUTPUT;
62 : } else {
63 0 : inputType = TransportMemType::PARAM_INPUT;
64 0 : outputType = TransportMemType::PARAM_OUTPUT;
65 : }
66 0 : HCCL_INFO(
67 : "[CollAllGatherSmallCountExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(),
68 : inputType, outputType);
69 0 : return HCCL_SUCCESS;
70 : }
71 :
72 0 : HcclResult CollAllGatherSmallCountExecutor::CalcCombinedCommInfo(
73 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
74 : {
75 0 : CommPlane commPlane = COMM_COMBINE;
76 0 : if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
77 0 : commPlane = COMM_COMBINE_ORDER;
78 : }
79 :
80 0 : CommParaInfo commParaInfo(commPlane, CommType::COMM_TAG_MESH);
81 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[commPlane], inputType, outputType));
82 :
83 0 : return HCCL_SUCCESS;
84 0 : }
85 :
86 0 : HcclResult CollAllGatherSmallCountExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
87 : {
88 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] starts.", __func__);
89 0 : CommPlane commPlane = COMM_COMBINE_ORDER;
90 :
91 0 : CHK_RET(CheckCommSize(commPlane, COMM_INDEX_0 + 1));
92 0 : SubCommInfo combinedCommInfo = GetSubCommInfo(commPlane, COMM_INDEX_0);
93 :
94 : // 构造ring algorithm对应的all_gather实例
95 : std::unique_ptr<AlgTemplateBase> algTemplate
96 0 : = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_HD_STAGE, dispatcher_);
97 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_GATHER_HD_STAGE in COMM_COMBINE_ORDER", __func__);
98 0 : CHK_RET(ActiveSlaveStreams(param.stream));
99 0 : HcomCollOpInfo opInfo = {"",
100 0 : execMem.inputPtr,
101 0 : execMem.outputPtr,
102 0 : param.DataDes.count,
103 0 : param.DataDes.dataType,
104 0 : param.root,
105 0 : param.reduceType,
106 0 : 0};
107 0 : CHK_SMART_PTR_NULL(algTemplate);
108 :
109 0 : PrepareData prepareData;
110 0 : prepareData.userRank = topoAttr_.userRank;
111 0 : prepareData.opInfo = &opInfo;
112 0 : prepareData.inputMem = execMem.inputMem;
113 0 : prepareData.outputMem = execMem.outputMem;
114 0 : prepareData.scratchMem = execMem.outputMem;
115 0 : prepareData.count = execMem.count;
116 0 : prepareData.dataType = param.DataDes.dataType;
117 0 : prepareData.stream = param.stream;
118 0 : prepareData.subStreamsPtr = &algResResp_->slaveStreams;
119 0 : prepareData.signalPtr = &algResResp_->notifiesMain;
120 0 : prepareData.signalAuxPtr = &algResResp_->notifiesAux;
121 :
122 0 : CHK_RET(algTemplate->Prepare(prepareData));
123 :
124 0 : CHK_RET(RunTemplate(algTemplate, combinedCommInfo));
125 :
126 0 : return HCCL_SUCCESS;
127 0 : }
128 :
129 : REGISTER_EXEC("AllGatherSmallCount", AllGatherSmallCount, CollAllGatherSmallCountExecutor);
130 :
131 : } // namespace hccl
|