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 HCCL_COLL_EXECUTOR_BASE_H
12 : #define HCCL_COLL_EXECUTOR_BASE_H
13 :
14 : #include "hccl_impl.h"
15 : #include "topo_matcher.h"
16 : #include "coll_alg_param.h"
17 : #include "executor_impl.h"
18 : #include "coll_alg_utils.h"
19 : #include "hccl_aiv.h"
20 :
21 : namespace hccl {
22 :
23 : class CollExecutorBase {
24 : public:
25 : CollExecutorBase(const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher);
26 184 : virtual ~CollExecutorBase() = default;
27 :
28 : // 每次构造完必须调用 SetAlgType
29 : HcclResult SetAlgType(const AlgType algType);
30 :
31 : HcclResult SetCCLInBuffer(u64 cclbufferSize);
32 : HcclResult SetIsSupportSDMAReduce(bool isSupportSDMAReduce);
33 : HcclResult SetAlgOpContext(AlgOpContext algOpContext);
34 : HcclResult SetAivClearEnable(bool aivClearEnable);
35 :
36 : virtual HcclResult CalcResRequest(const OpParam& param, AlgResourceRequest &resourceRequest) = 0;
37 : virtual HcclResult Orchestrate(OpParam& param, AlgResourceResponse& algRes) = 0;
38 : virtual HcclResult GetAivExecParam(const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs &args);
39 : virtual HcclResult GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo);
40 : // AIV拷贝通信域信息到device上
41 : virtual HcclResult PrepareCommInfoToDevice(AlgResourceResponse& algResource);
42 : // AIV支持Roce直通Rma信息拷贝
43 : HcclResult SetRmaInfo(void* rmaInfo);
44 :
45 : // batchsendrecv需要增量建链
46 : virtual HcclResult CalcIncreLinkRequest(const OpParam& param, std::set<u32>& ranksLinked,
47 : AlgResourceRequest &resourceRequest, bool& needIncreLink);
48 :
49 : virtual void SetWorkflowMode(HcclWorkflowMode workflowMode);
50 : virtual HcclWorkflowMode GetExecutorWorkflowMode() const;
51 :
52 : static HcclResult RunTemplate(const std::unique_ptr<AlgTemplateBase> &tempAlg, const SubCommInfo &commInfo);
53 :
54 : //batchsendrecv retry使用
55 : virtual HcclResult CreatePairWiseList(HcclSendRecvItem *sendRecvInfo, u32 itemNum);
56 : virtual HcclResult GetPairWiseList(std::vector<std::vector<HcclSendRecvItem*>> &sendRecvPairList);
57 : virtual HcclResult CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize = 0, HcclCMDType cmdType = HcclCMDType::HCCL_CMD_INVALID);
58 : HcclResult GetNumBlocks(u32& numBlocks) const;
59 : HcclResult SetNumBlocks(const u32& numBlocks);
60 : HcclResult GetCache(HcclCacheInfo& cacheInfo);
61 : HcclResult SetOpCounter(const OpCounterInfo& opCounter);
62 :
63 77 : inline AlgDesc GetAlgDesc() {return desc_;}
64 :
65 : // 用于alltoallv算子的aicpu展开cache
66 : virtual HcclResult MarkNeedAlltoallvCache();
67 : virtual HcclResult GetHcclOffsetDstRanksMap(std::unordered_map<uint64_t, std::vector<uint32_t>>& hcclOffsetDstRanksMap) const;
68 : protected:
69 : const HcclDispatcher dispatcher_;
70 : u64 inCCLbufferSize_{0}; // CCLIN大小,用于计算scratch
71 : AlgType algType_; // 算法类型
72 : std::unique_ptr<TopoMatcher> &topoMatcher_;
73 : bool isSupportSDMAReduce_ = false;
74 : AlgOpContext algOpContext_;
75 : bool aivClearEnable_ = false;
76 : u32 numBlocks_ = MAX_NUM_BLOCKS;
77 : OpCounterInfo opCounter_;
78 : AlgDesc desc_;
79 : void* rmaInfo_ = nullptr;
80 : HcclCacheInfo cacheInfo_;
81 : };
82 : }
83 : #endif
|