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_hccs_sio_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherHccsSioExecutor::CollAllGatherHccsSioExecutor(const HcclDispatcher dispatcher,
15 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
16 0 : : CollAllGatherExecutor(dispatcher, topoMatcher)
17 : {
18 0 : desc_.isZeroCopy = false;
19 0 : DMAReduceFlag_ = true;
20 0 : }
21 :
22 0 : HcclResult CollAllGatherHccsSioExecutor::CalcStreamNum(u32& streamNum)
23 : {
24 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation + 1U;
25 : //本地拷贝两条流并发,跨片两条流并发
26 : static u32 MULTIPLIER = 2;
27 0 : streamNum = MULTIPLIER * (totalStreamNum - 1);
28 0 : HCCL_INFO("[CollAllGatherHccsSioExecutor][CalcStreamNum] tag[%s] streamNum[%u]",
29 : tag_.c_str(), streamNum);
30 :
31 0 : return HCCL_SUCCESS;
32 : }
33 :
34 0 : u64 CollAllGatherHccsSioExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
35 : {
36 : // 中转内存单次最多能够接受的output count
37 0 : u64 maxCountPerLoop = cclBuffSize / HCCL_MIN_SLICE_ALIGN
38 0 : * HCCL_MIN_SLICE_ALIGN / unitSize;
39 0 : HCCL_INFO("[CollAllGatherHccsSioExecutor][CalcLoopMaxCount]" \
40 : "using default maxCountPerLoop[%llu] as CCLBuffSize / unitSize.", maxCountPerLoop);
41 0 : return maxCountPerLoop;
42 : }
43 :
44 0 : HcclResult CollAllGatherHccsSioExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
45 : {
46 0 : TransportMemType inputType = TransportMemType::RESERVED;
47 0 : TransportMemType outputType = TransportMemType::RESERVED;
48 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
49 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
50 0 : return HCCL_SUCCESS;
51 : }
52 :
53 0 : HcclResult CollAllGatherHccsSioExecutor::CalcLevel0CommInfo(TransportMemType inputType,
54 : TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
55 : {
56 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_HCCS_PLUS_SIO);//新建通信平面
57 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
58 :
59 0 : LevelNSubCommTransport &commTransportLevel0 = opTransport[COMM_LEVEL0];
60 0 : for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
61 0 : for (auto &transportRequest : commTransportLevel0[subCommIndex].transportRequests) {//两个transport分别设置ishccs为false、true
62 : // 根据子通信索引设置isHccs的值
63 0 : transportRequest.linkType = (subCommIndex == 0) ? TransportLinkType::SIO : TransportLinkType::HCCS;
64 0 : HCCL_INFO("[CollAllGatherHccsSioExecutor][CalcLevel0CommInfo] set extral notifyNum[%u]",
65 : transportRequest.notifyNum);
66 : }
67 : }
68 0 : return HCCL_SUCCESS;
69 0 : }
70 :
71 0 : HcclResult CollAllGatherHccsSioExecutor::CalcTransportMemType(TransportMemType &inputType,
72 : TransportMemType &outputType)
73 : {
74 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
75 0 : inputType = TransportMemType::CCL_INPUT;
76 0 : outputType = TransportMemType::CCL_OUTPUT;
77 : } else {
78 0 : inputType = TransportMemType::PARAM_INPUT;
79 0 : outputType = TransportMemType::PARAM_OUTPUT;
80 : }
81 :
82 0 : HCCL_INFO("[CollAllGatherHccsSioExecutor][CalcTransportMemType]" \
83 : "tag[%s] inputType[%d], outputType[%d]", tag_.c_str(), inputType, outputType);
84 0 : return HCCL_SUCCESS;
85 : }
86 :
87 0 : HcclResult CollAllGatherHccsSioExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
88 : {
89 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] The AllGatherHccsSioExecutor starts.", __func__);
90 0 : HcomCollOpInfo opInfo = {"", execMem.inputPtr, execMem.outputPtr, param.DataDes.count, param.DataDes.dataType,
91 0 : param.root, param.reduceType};
92 :
93 : // step 1 先获取 comm inner \ comm outer 的value
94 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
95 0 : SubCommInfo outerCommInfoHccs = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
96 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_1 + 1));
97 0 : SubCommInfo outerCommInfoSio = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_1);
98 :
99 : // 执行
100 0 : std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
101 0 : TemplateType::TEMPLATE_ALL_GATHER_HCCS_SIO, dispatcher_);
102 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_GATHER_HCCS_SIO in COMM_LEVEL0", __func__);
103 0 : CHK_SMART_PTR_NULL(tempAlg);
104 :
105 0 : CHK_RET(tempAlg->Prepare(outerCommInfoHccs, outerCommInfoSio, execMem.inputMem, execMem.outputMem,
106 : execMem.count, param.DataDes.dataType, param.stream, algResResp_->slaveStreams,
107 : algResResp_->notifiesMain, algResResp_->notifiesAux, topoAttr_.userRank, &opInfo));
108 :
109 0 : CHK_RET(tempAlg->RegisterProfiler((outerCommInfoHccs.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) +
110 : outerCommInfoHccs.localRank, PROF_STAGE_1, HCCL_EXEC_STEP_NOT_SET, param.stream));
111 :
112 0 : CHK_RET(RunTemplate(tempAlg, outerCommInfoHccs));
113 :
114 0 : HCCL_INFO("[CollAllGatherHccsSioExecutor][KernelRun] AllGatherHccsSioExecutor ends.");
115 :
116 0 : return HCCL_SUCCESS;
117 0 : }
118 :
119 : REGISTER_EXEC("AllGatherHccsSioExecutor", AllGatherHccsSio, CollAllGatherHccsSioExecutor);
120 :
121 : } // namespace hccl
|