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_broadcast_smallcount_executor.h"
12 : #include <cmath>
13 :
14 : namespace hccl {
15 :
16 0 : CollBroadcastSmallCountExecutor::CollBroadcastSmallCountExecutor(
17 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher)
18 0 : : CollBroadcastExecutor(dispatcher, topoMatcher)
19 : {
20 0 : DMAReduceFlag_ = true;
21 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB) {
22 0 : scratchMemFlag_ = true;
23 : }
24 0 : }
25 :
26 0 : void CollBroadcastSmallCountExecutor::ParseParam(const OpParam ¶m)
27 : {
28 0 : tag_ = param.tag;
29 0 : root_ = param.root;
30 0 : aicpuUnfoldMode_ = param.aicpuUnfoldMode;
31 0 : totalSize_ = param.DataDes.count * SIZE_TABLE[param.DataDes.dataType];
32 0 : }
33 :
34 0 : HcclResult CollBroadcastSmallCountExecutor::CalcScratchMemSize(u64 &scratchMemSize)
35 : {
36 0 : const u32 base = 2;
37 0 : scratchMemSize = 0U;
38 0 : if (scratchMemFlag_) {
39 0 : scratchMemSize = static_cast<u64>(log2(base * topoAttr_.userRankSize - 1)) - 1;
40 0 : scratchMemSize *= totalSize_;
41 : }
42 0 : HCCL_INFO("[CollBroadcastSmallCountExecutor][CalcScratchMemSize] tag[%s] scratchMemSize[%llu]",
43 : tag_.c_str(), scratchMemSize);
44 0 : return HCCL_SUCCESS;
45 : }
46 :
47 0 : HcclResult CollBroadcastSmallCountExecutor::CalcStreamNum(u32 &streamNum)
48 : {
49 0 : streamNum = 1;
50 0 : HCCL_INFO("[CollBroadcastSmallCountExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
51 0 : return HCCL_SUCCESS;
52 : }
53 :
54 0 : HcclResult CollBroadcastSmallCountExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport> &opTransport)
55 : {
56 0 : TransportMemType inputType = TransportMemType::RESERVED;
57 0 : TransportMemType outputType = TransportMemType::RESERVED;
58 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
59 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
60 0 : return HCCL_SUCCESS;
61 : }
62 :
63 0 : HcclResult CollBroadcastSmallCountExecutor::CalcLevel0CommInfo(
64 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport> &opTransport)
65 : {
66 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
67 0 : commParaLevel0.meshSinglePlane = true;
68 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
69 0 : return HCCL_SUCCESS;
70 0 : }
71 :
72 0 : HcclResult CollBroadcastSmallCountExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
73 : {
74 0 : HCCL_CONFIG_INFO(HCCL_ALG,
75 : "[CollBroadcastSmallCountExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
76 0 : std::vector<Slice> dataSegsSlice;
77 :
78 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
79 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
80 0 : CHK_RET(ActiveSlaveStreams(param.stream));
81 0 : HcomCollOpInfo opInfoPtr = {"", execMem.inputPtr, nullptr, param.DataDes.count, param.DataDes.dataType, param.root};
82 :
83 0 : std::unique_ptr<AlgTemplateBase> level0TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
84 0 : TemplateType::TEMPLATE_BROADCAST_HD, dispatcher_);
85 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_BROADCAST_HD in COMM_LEVEL0", __func__);
86 0 : CHK_SMART_PTR_NULL(level0TempAlg);
87 :
88 0 : u32 rootRank = 0;
89 0 : HcclResult ret = GetRankByUserRank(COMM_LEVEL0, COMM_INDEX_0, param.root, rootRank);
90 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
91 : HCCL_ERROR("[CollBroadcastSmallCountExecutor][KernelRun]invalid root [%u] to get userrank", param.root), ret);
92 :
93 0 : CHK_RET(level0TempAlg->Prepare(execMem.inputMem,
94 : execMem.outputMem,
95 : execMem.outputMem,
96 : execMem.count,
97 : param.DataDes.dataType,
98 : param.stream,
99 : HCCL_REDUCE_RESERVED,
100 : rootRank,
101 : algResResp_->slaveStreams,
102 : algResResp_->notifiesMain,
103 : algResResp_->notifiesAux,
104 : level0CommInfo.localRank,
105 : &opInfoPtr));
106 :
107 0 : CHK_RET(level0TempAlg->RegisterProfiler(
108 : (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank,
109 : PROF_STAGE_1,
110 : HCCL_EXEC_STEP_NOT_SET,
111 : param.stream));
112 0 : CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
113 0 : HCCL_INFO("broadcast small count executor run success.");
114 0 : return HCCL_SUCCESS;
115 0 : }
116 :
117 : REGISTER_EXEC("BroadCastSmallCountExecutor", BroadcastSmallCount, CollBroadcastSmallCountExecutor);
118 :
119 : } // namespace hccl
|