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 "hccl_aiv_utils.h"
12 : #include "aiv_ins.h"
13 : #include "aiv_temp_reduce_scatter_mesh_1D.h"
14 : #include "executor_utils.h"
15 :
16 : namespace Hccl {
17 :
18 0 : AivTempReduceScatterMesh1D::AivTempReduceScatterMesh1D(const RankId virtualRank, const u32 tempRankSize,
19 0 : const std::vector<std::vector<RankId>> &tempVTopo, const std::map<RankId, u32> &tempVirtRankMap)
20 0 : : AivAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
21 : {
22 0 : }
23 :
24 0 : AivTempReduceScatterMesh1D::~AivTempReduceScatterMesh1D()
25 : {
26 0 : }
27 :
28 0 : u32 AivTempReduceScatterMesh1D::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
29 : {
30 : (void) inBuffType;
31 : (void) outBuffType;
32 : // 小数据量下,这里是2*rankSize基本不影响,大数据量下,需要2倍的cclBuffer去并发读
33 0 : return 2 * tempRankSize_;
34 : }
35 :
36 0 : HcclResult AivTempReduceScatterMesh1D::CalcRes(AlgTempResReq &tempResReq)
37 : {
38 0 : tempResReq.queNum = 1;
39 0 : tempResReq.streamNum = tempResReq.queNum;
40 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
41 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
42 0 : return HcclResult::HCCL_SUCCESS;
43 : }
44 :
45 0 : HcclResult AivTempReduceScatterMesh1D::CalNumBlocks(u32& numBlocks, u64 dataSize, u32 numBlocksLimit)
46 : {
47 0 : numBlocks = numBlocksLimit;
48 0 : if (dataSize < REDUCE_SCATTER_SMALL_COUNT_512KB) { // 小数据量,走原来极致低时延的流程
49 0 : constexpr uint32_t stepNum = 2;
50 0 : if (numBlocks > stepNum * tempRankSize_) {
51 0 : numBlocks = stepNum * tempRankSize_;
52 : }
53 : }
54 0 : HCCL_INFO("[AivTempReduceScatterMesh1D] Actually use core num[%u]", numBlocks);
55 0 : return HcclResult::HCCL_SUCCESS;
56 : }
57 :
58 0 : HcclResult AivTempReduceScatterMesh1D::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams,
59 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
60 : {
61 0 : HCCL_INFO("[AivTempReduceScatterMesh1D] GenExtIns start");
62 0 : CHK_PRT_RET(tempInsQues.empty(),
63 : HCCL_ERROR("[AivTempReduceScatterMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
64 0 : CHK_PTR_NULL(tempInsQues[0]);
65 0 : std::vector<LinkData> allLinks;
66 0 : for (auto iter = tempLinks.begin(); iter != tempLinks.end(); ++iter) {
67 0 : allLinks.emplace_back(iter->second.at(0));
68 : }
69 :
70 0 : IncSliceId(); // 自动增长sliceId,传入aivTag
71 :
72 0 : AivOpArgs aivReduceScatterArgs;
73 0 : aivReduceScatterArgs.cmdType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
74 0 : aivReduceScatterArgs.input = templateDataParams.buffInfo.inBuffBaseOff;
75 0 : aivReduceScatterArgs.output = templateDataParams.buffInfo.outBuffBaseOff;
76 0 : aivReduceScatterArgs.rank = u32(myRank_);
77 0 : aivReduceScatterArgs.rankSize = tempRankSize_;
78 0 : aivReduceScatterArgs.count = templateDataParams.sliceSize / DataTypeSizeGet(dataType_);
79 0 : aivReduceScatterArgs.dataType = dataType_;
80 0 : aivReduceScatterArgs.op = reduceOp_;
81 0 : aivReduceScatterArgs.root = root_;
82 0 : aivReduceScatterArgs.aivTag = sliceId_; // 传入aivTag,Lauch时重新组装为aivTag
83 0 : aivReduceScatterArgs.isOpBase = (tempFuncs.opMode == OpMode::OPBASE);
84 0 : aivReduceScatterArgs.xRankSize = tempVTopo_[0].size();
85 0 : aivReduceScatterArgs.yRankSize = 0;
86 0 : aivReduceScatterArgs.zRankSize = 0;
87 0 : for (u32 i = 0; i < tempVTopo_[0].size(); i++){
88 0 : aivReduceScatterArgs.topo_[i] = tempVTopo_[0][i];
89 : }
90 0 : if (tempVTopo_.size() > 1){
91 0 : aivReduceScatterArgs.yRankSize = tempVTopo_[1].size();
92 0 : for (u32 i = 0; i < tempVTopo_[1].size(); i++){
93 0 : aivReduceScatterArgs.topo_[TOPO_LEN_Y_OFFSET + i] = tempVTopo_[1][i];
94 : }
95 : }
96 0 : if (tempVTopo_.size() == MAX_DIM_NUM){
97 0 : aivReduceScatterArgs.zRankSize = tempVTopo_[MAX_DIM_NUM - 1].size();
98 0 : for (u32 i = 0; i < tempVTopo_[MAX_DIM_NUM - 1].size(); i++){
99 0 : aivReduceScatterArgs.topo_[TOPO_LEN_Z_OFFSET + i] = tempVTopo_[MAX_DIM_NUM - 1][i];
100 : }
101 : }
102 :
103 0 : u64 dataSize = op_.dataCount * DataTypeSizeGet(dataType_);
104 0 : CHK_RET(CalNumBlocks(aivReduceScatterArgs.numBlocks, dataSize, op_.numBlocksLimit));
105 :
106 0 : aivReduceScatterArgs.inputSliceStride = templateDataParams.inputSliceStride;
107 0 : aivReduceScatterArgs.outputSliceStride = templateDataParams.outputSliceStride;
108 0 : aivReduceScatterArgs.repeatNum = templateDataParams.repeatNum;
109 0 : aivReduceScatterArgs.inputRepeatStride = templateDataParams.inputRepeatStride;
110 0 : aivReduceScatterArgs.outputRepeatStride = templateDataParams.outputRepeatStride;
111 :
112 0 : std::unique_ptr<Instruction> aivInsReduceScatterMesh1D = std::make_unique<AivInstruction>(allLinks, aivReduceScatterArgs);
113 :
114 0 : tempInsQues[0]->Append(std::move(aivInsReduceScatterMesh1D));
115 :
116 0 : HCCL_INFO("[AivTempReduceScatterMesh1D] GenExtIns finished");
117 0 : return HcclResult::HCCL_SUCCESS;
118 0 : }
119 :
120 : } // namespace Hccl
|