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_all_to_all_v_mesh_1D.h"
14 : #include "executor_utils.h"
15 :
16 : namespace Hccl {
17 : constexpr u64 MAX_NUM_BLOCKS_ALL_TO_ALL_V = 48; // 算法不交付控核
18 :
19 0 : AivTempAlltoAllVMesh1D::AivTempAlltoAllVMesh1D(
20 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
21 0 : const std::map<RankId, u32>& tempVirtRankMap)
22 0 : : AivAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
23 0 : {}
24 :
25 0 : AivTempAlltoAllVMesh1D::~AivTempAlltoAllVMesh1D() {}
26 :
27 0 : u32 AivTempAlltoAllVMesh1D::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
28 : {
29 : (void)inBuffType;
30 : (void)outBuffType;
31 : // 单算子和图模式一致,AlltoAllV的usrIn、scratchBuffer,usrOut大小一致
32 0 : return 1;
33 : }
34 :
35 0 : HcclResult AivTempAlltoAllVMesh1D::CalcRes(AlgTempResReq& tempResReq)
36 : {
37 0 : tempResReq.queNum = 1;
38 0 : tempResReq.streamNum = tempResReq.queNum;
39 0 : HCCL_INFO("[AivTempAlltoAllVMesh1D] Calculate resource, stream number is[%u],", tempResReq.streamNum);
40 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
41 0 : return HcclResult::HCCL_SUCCESS;
42 : }
43 :
44 0 : HcclResult AivTempAlltoAllVMesh1D::GenExtIns(
45 : const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
46 : std::vector<InsQuePtr>& tempInsQues)
47 : {
48 0 : HCCL_INFO("[AivTempAlltoAllVMesh1D] Run algorithm start: rank[%d]", myRank_);
49 0 : CHK_PRT_RET(tempInsQues.empty(), HCCL_ERROR("[AivTempAlltoAllVMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
50 0 : CHK_PTR_NULL(tempInsQues[0]);
51 0 : std::vector<LinkData> allLinks;
52 0 : for (auto iter = tempLinks.begin(); iter != tempLinks.end(); ++iter) {
53 0 : allLinks.emplace_back(iter->second.at(0));
54 : }
55 :
56 0 : IncSliceId(); // 自动增长sliceId,传入aivTag
57 :
58 0 : AivOpArgs aivAlltoAllVArgs;
59 0 : aivAlltoAllVArgs.cmdType = HcclCMDType::HCCL_CMD_ALLTOALLV;
60 0 : aivAlltoAllVArgs.input = 0; // ins_rules.cc里面,这里会和起始地址累加起来作为input
61 0 : aivAlltoAllVArgs.output = 0;
62 0 : aivAlltoAllVArgs.rank = u32(myRank_);
63 0 : aivAlltoAllVArgs.rankSize = tempRankSize_;
64 0 : aivAlltoAllVArgs.count = templateDataParams.sliceSize / DataTypeSizeGet(dataType_);
65 0 : aivAlltoAllVArgs.dataType = dataType_;
66 0 : aivAlltoAllVArgs.op = reduceOp_;
67 0 : aivAlltoAllVArgs.root = root_;
68 0 : aivAlltoAllVArgs.aivTag = sliceId_; // 传入aivTag,Lauch时重新组装为aivTag
69 0 : aivAlltoAllVArgs.isOpBase = (tempFuncs.opMode == OpMode::OPBASE);
70 0 : aivAlltoAllVArgs.xRankSize = tempVTopo_[0].size();
71 0 : aivAlltoAllVArgs.yRankSize = 0;
72 0 : aivAlltoAllVArgs.zRankSize = 0;
73 0 : aivAlltoAllVArgs.numBlocks = MAX_NUM_BLOCKS_ALL_TO_ALL_V;
74 :
75 0 : for (u64 i = 0; i < tempVTopo_[0].size(); i++) {
76 0 : aivAlltoAllVArgs.extraArgs.sendCounts[i] = static_cast<u64*>(op_.all2AllVDataDes.sendCounts)[i];
77 0 : aivAlltoAllVArgs.extraArgs.sendDispls[i] = static_cast<u64*>(op_.all2AllVDataDes.sdispls)[i];
78 0 : aivAlltoAllVArgs.extraArgs.recvCounts[i] = static_cast<u64*>(op_.all2AllVDataDes.recvCounts)[i];
79 0 : aivAlltoAllVArgs.extraArgs.recvDispls[i] = static_cast<u64*>(op_.all2AllVDataDes.rdispls)[i];
80 0 : HCCL_INFO(
81 : "[AivTempAlltoAllVMesh1D] rank is [%llu], iter is [%llu], sendCounts is [%llu], sendDispls is [%llu], "
82 : "recvCounts is [%llu], recvDispls is [%llu]",
83 : u64(myRank_), i, aivAlltoAllVArgs.extraArgs.sendCounts[i], aivAlltoAllVArgs.extraArgs.sendDispls[i],
84 : aivAlltoAllVArgs.extraArgs.recvCounts[i], aivAlltoAllVArgs.extraArgs.recvDispls[i]);
85 : }
86 :
87 0 : for (u32 i = 0; i < tempVTopo_[0].size(); i++) {
88 0 : aivAlltoAllVArgs.topo_[i] = tempVTopo_[0][i];
89 : }
90 0 : if (tempVTopo_.size() > 1) {
91 0 : aivAlltoAllVArgs.yRankSize = tempVTopo_[1].size();
92 0 : for (u32 i = 0; i < tempVTopo_[1].size(); i++) {
93 0 : aivAlltoAllVArgs.topo_[TOPO_LEN_Y_OFFSET + i] = tempVTopo_[1][i];
94 : }
95 : }
96 0 : if (tempVTopo_.size() == MAX_DIM_NUM) {
97 0 : aivAlltoAllVArgs.zRankSize = tempVTopo_[MAX_DIM_NUM - 1].size();
98 0 : for (u32 i = 0; i < tempVTopo_[MAX_DIM_NUM - 1].size(); i++) {
99 0 : aivAlltoAllVArgs.topo_[TOPO_LEN_Z_OFFSET + i] = tempVTopo_[MAX_DIM_NUM - 1][i];
100 : }
101 : }
102 :
103 0 : aivAlltoAllVArgs.inputSliceStride = templateDataParams.inputSliceStride;
104 0 : aivAlltoAllVArgs.outputSliceStride = templateDataParams.outputSliceStride;
105 0 : aivAlltoAllVArgs.repeatNum = templateDataParams.repeatNum;
106 0 : aivAlltoAllVArgs.inputRepeatStride = templateDataParams.inputRepeatStride;
107 0 : aivAlltoAllVArgs.outputRepeatStride = templateDataParams.outputRepeatStride;
108 :
109 0 : std::unique_ptr<Instruction> aivInsAlltoAllVMesh1D = std::make_unique<AivInstruction>(allLinks, aivAlltoAllVArgs);
110 :
111 0 : tempInsQues[0]->Append(std::move(aivInsAlltoAllVMesh1D));
112 :
113 0 : HCCL_INFO("[AivTempAlltoAllVMesh1D] Run algorithm end: rank[%d]", myRank_);
114 0 : return HcclResult::HCCL_SUCCESS;
115 0 : }
116 :
117 : } // namespace Hccl
|