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_to_all_v_for_310p_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollRunAlltoAllVFor310PExecutor::CollRunAlltoAllVFor310PExecutor(
16 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 0 : : CollAlltoAllExecutor(dispatcher, topoMatcher)
18 0 : {}
19 :
20 0 : HcclResult CollRunAlltoAllVFor310PExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
21 : {
22 0 : HcclUs startut = TIME_NOW();
23 0 : HcclResult ret = HCCL_SUCCESS;
24 0 : tag_ = param.tag;
25 0 : algResResp_ = &algRes;
26 0 : AlltoAllVParam_ = param;
27 0 : ExecMem execMem;
28 0 : execMem.count = 0;
29 0 : execMem.inputPtr = param.inputPtr;
30 0 : execMem.outputPtr = param.outputPtr;
31 0 : execMem.inputMem = algRes.cclInputMem;
32 0 : execMem.outputMem = algRes.cclOutputMem;
33 0 : ret = KernelRun(param, execMem);
34 :
35 0 : CHK_PRT_RET(
36 : ret != HCCL_SUCCESS,
37 : HCCL_ERROR(
38 : "[CollRunAlltoAllVFor310PExecutor][Orchestrate]errNo[0x%016llx]executor run failed", HCCL_ERROR_CODE(ret)),
39 : ret);
40 :
41 0 : HCCL_INFO(
42 : "tag[%s], AlltoAllVFor310P orchestrate success, take time [%lld]us.", param.tag.c_str(),
43 : DURATION_US(TIME_NOW() - startut));
44 0 : return HCCL_SUCCESS;
45 0 : }
46 :
47 0 : HcclOpMetaInfo CollRunAlltoAllVFor310PExecutor::GetOpMeta(HcclCMDType opType, const u64 size)
48 : {
49 : (void)opType;
50 0 : HcclOpMetaInfoDef opMeta = HcclOpMetaInfo::GetOneForAllToAllV(CopyPattern::ZCOPY, size, true);
51 0 : return opMeta;
52 : }
53 :
54 0 : HcclResult CollRunAlltoAllVFor310PExecutor::CalcStreamNum(u32& streamNum)
55 : {
56 0 : streamNum = 0U;
57 0 : if (topoAttr_.userRank % MINORS_NUM_TWO == 0) {
58 0 : streamNum = MINORS_NUM_TWO;
59 : } else {
60 0 : streamNum = 1;
61 : }
62 :
63 0 : HCCL_INFO("[CollRunAlltoAllVFor310PExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
64 0 : return HCCL_SUCCESS;
65 : }
66 :
67 0 : HcclResult CollRunAlltoAllVFor310PExecutor::CalcLevel0CommInfo(
68 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
69 : {
70 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
71 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
72 0 : return HCCL_SUCCESS;
73 0 : }
74 :
75 : HcclResult
76 0 : CollRunAlltoAllVFor310PExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
77 : {
78 0 : inputType = TransportMemType::CCL_INPUT;
79 0 : outputType = TransportMemType::CCL_OUTPUT;
80 :
81 0 : HCCL_INFO(
82 : "[CollRunAlltoAllVFor310PExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(),
83 : inputType, outputType);
84 0 : return HCCL_SUCCESS;
85 : }
86 :
87 0 : HcclResult CollRunAlltoAllVFor310PExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
88 : {
89 0 : TransportMemType inputType = TransportMemType::RESERVED;
90 0 : TransportMemType outputType = TransportMemType::RESERVED;
91 :
92 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
93 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
94 0 : return HCCL_SUCCESS;
95 : }
96 :
97 0 : HcclResult CollRunAlltoAllVFor310PExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
98 : {
99 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollRunAlltoAllVFor310PExecutor][KernelRun] AllToAll for 310p start.");
100 :
101 : // 获取通信域
102 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
103 0 : SubCommInfo outerCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
104 : // 执行
105 : std::unique_ptr<AlgTemplateBase> executor
106 0 : = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_2_ALL_V_FOR310P, dispatcher_);
107 0 : CHK_SMART_PTR_NULL(executor);
108 0 : CHK_RET(executor->Prepare(
109 : algResResp_->paramInputMem, algResResp_->paramOutputMem, execMem.inputMem, execMem.outputMem,
110 : algResResp_->notifiesMain, algResResp_->notifiesAux, const_cast<Stream&>(param.stream),
111 : algResResp_->slaveStreams, outerCommInfo.links, topoAttr_.userRank, topoAttr_.userRankSize,
112 : allMeshAggregationSendRecvInfo_));
113 :
114 0 : u32 rankSize = outerCommInfo.localRankSize;
115 0 : CHK_RET(executor->RegisterProfiler(
116 : (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + outerCommInfo.localRank, PROF_STAGE_0, HCCL_EXEC_STEP_NOT_SET,
117 : param.stream));
118 :
119 0 : CHK_RET(executor->RunAsync());
120 :
121 0 : HCCL_INFO("[CollRunAlltoAllVFor310PExecutor] executor run success.");
122 0 : return HCCL_SUCCESS;
123 0 : }
124 :
125 : REGISTER_EXEC("RunAlltoAllVFor310PExecutor", AlltoAllVFor310P, CollRunAlltoAllVFor310PExecutor);
126 : } // namespace hccl
|