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 : #ifndef HCCLV2_INS_TEMP_ALL_REDUCE_NHR
12 : #define HCCLV2_INS_TEMP_ALL_REDUCE_NHR
13 :
14 : #include "string_util.h"
15 : #include "ins_alg_template_base.h"
16 : #include "executor_utils.h"
17 : #include "ins_temp_all_gather_nhr.h"
18 :
19 : namespace Hccl {
20 :
21 : class InsTempAllReduceNHR : public InsAlgTemplateBase {
22 : public:
23 : explicit InsTempAllReduceNHR(
24 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
25 : const std::map<RankId, u32>& tempVirtRankMap);
26 : ~InsTempAllReduceNHR() override;
27 :
28 0 : std::string Describe() const override
29 : {
30 0 : return StringFormat("Template of reduce scatter NHR with tempRankSize [%u].", tempRankSize_);
31 : }
32 :
33 : u32 CalcScratchMultiple(BufferType input, BufferType output);
34 : HcclResult GenExtIns(
35 : const TempFuncs& tempFuncs, const TemplateDataParams& tempAlgParams, const ResLinks& tempLinks,
36 : std::vector<InsQuePtr>& tempInsQues);
37 : HcclResult CalcSlice(const u64 dataSize, const u64 baseOff, RankSliceInfo& sliceInfoVec);
38 : HcclResult CalcRes(AlgTempResReq& tempResReq) override;
39 :
40 : private:
41 : HcclResult PreCopy(const TemplateDataParams& tempAlgParams, std::vector<InsQuePtr>& tempInsQues);
42 : HcclResult
43 : PrepareDataForAllGather(const RankSliceInfo& sliceInfoVec, std::vector<InsQuePtr>& tempInsQues, u32 linkIdx);
44 : HcclResult PostCopy(const TemplateDataParams& tempAlgParams, std::vector<InsQuePtr>& tempInsQues);
45 : HcclResult RunReduceScatter(
46 : const RankSliceInfo& sliceInfoVec, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, u32 linkIdx);
47 : HcclResult RunAllGather(
48 : const RankSliceInfo& sliceInfoVec, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, u32 linkIdx);
49 : HcclResult GetStepInfo(u32 step, u32 nSteps, AicpuNHRStepInfo& stepInfo);
50 : HcclResult GetStepInfoList(std::vector<AicpuNHRStepInfo>& stepInfoList);
51 : RankId GetRankFromMap(const u32 rankIdx);
52 :
53 : BufferType nhrInBuffType_ = BufferType::INPUT;
54 : BufferType nhrOutBuffType_ = BufferType::OUTPUT;
55 : u64 nhrInBuffBaseOff_ = 0;
56 : u64 nhrOutBuffBaseOff_ = 0;
57 : };
58 :
59 : } // namespace Hccl
60 :
61 : #endif // !HCCLV2_INS_TEMP_ALL_REDUCE_NHR
|