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_SCATTER_PARALLEL_EXECUTOR_H
12 : #define HCCLV2_INS_SCATTER_PARALLEL_EXECUTOR_H
13 : #include "ins_coll_alg_base.h"
14 :
15 : namespace Hccl {
16 :
17 : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
18 : class InsScatterParallelExecutor : public InsCollAlgBase {
19 : public:
20 : explicit InsScatterParallelExecutor();
21 : ~InsScatterParallelExecutor() override;
22 :
23 : HcclResult CalcResOffload(const RankGraph* rankGraph, const u64& dataSize, CollOffloadOpResReq& resReq) override;
24 :
25 : // HOST 接口
26 : HcclResult Orchestrate(
27 : const RankGraph* rankGraph, const CollAlgOperator& op, const CollAlgParams& params, InsQuePtr insQue) override;
28 :
29 : HcclResult CalcRes(const RankGraph* rankGraph, CollAlgResReq& algResReq) override;
30 : // AICPU 接口
31 : HcclResult Orchestrate(
32 : const AlgTopoInfo& topoInfo, const CollAlgOperator& op, const CollAlgParams& params, ConnectedLinkMgr* linkMgr,
33 : InsQuePtr insQue) override;
34 :
35 0 : std::string Describe() const override { return "Instruction based Scatter Parallel Executor."; }
36 :
37 : private:
38 : void GenTemplateAlgParamsIntra0(
39 : const u64 dataOffset, const u64 dataCountPerLoopAixs0, const u64 scratchOffset,
40 : TemplateDataParams& tempAlgParamsIntra0) const;
41 : void GenTemplateAlgParamsInter0(
42 : const u64 dataOffset, const u64 dataCountPerLoopAixs0, const u64 scratchOffset,
43 : TemplateDataParams& tempAlgParamsInter0) const;
44 : void GenTemplateAlgParamsIntra1(
45 : const u64 dataOffset, const u64 dataCountPerLoopAixs1, const u64 scratchOffset,
46 : TemplateDataParams& tempAlgParamsIntra1) const;
47 : void GenTemplateAlgParamsInter1(
48 : const u64 dataOffset, const u64 dataCountPerLoopAixs1, const u64 scratchOffset,
49 : TemplateDataParams& tempAlgParamsInter1) const;
50 : HcclResult GenInsQuesHost(InsAlgTemplate0& tempAlgIntra, InsAlgTemplate1& tempAlgInter);
51 : HcclResult
52 : PrepareResForTemplate(const RankGraph* rankGraph, InsAlgTemplate0& tempAlgIntra, InsAlgTemplate1& tempAlgInter);
53 : HcclResult
54 : PrepareResForTemplate(ConnectedLinkMgr* linkMgr, InsAlgTemplate0& tempAlgIntra, InsAlgTemplate1& tempAlgInter);
55 : void GetParallelDataSplit(std::vector<double>& splitDataSize) const;
56 : u32 rankSizeLevel0_{0};
57 : u32 rankSizeLevel1_{0};
58 :
59 : uint64_t rankIdxLevel0_{0};
60 : uint64_t rankIdxLevel1_{0};
61 :
62 : const RankGraph* rankGraph_ = nullptr;
63 :
64 : std::vector<std::vector<RankId>> virtRanks_;
65 : std::vector<std::map<RankId, u32>> virtRankMap_; // map<virtRank, virtRankOrder>
66 : std::vector<std::vector<std::vector<RankId>>> vTopo_;
67 :
68 : ResLinks interLinks_;
69 : ResLinks intraLinks_;
70 : std::vector<InsQuePtr> requiredQue_;
71 : std::vector<InsQuePtr> interQue_;
72 : std::vector<InsQuePtr> intraQue_;
73 : std::vector<InsQuePtr> syncQueues_;
74 :
75 : const RankGraph* rankGraphPtr_ = nullptr;
76 : };
77 :
78 : } // namespace Hccl
79 :
80 : #endif // HCCLV2_INS_SCATTER_PARALLEL_EXECUTOR_H
|