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