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 183 : 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(
47 : const OpParam& param, std::set<u32>& ranksLinked, 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 GetPairWiseList(HcclSendRecvItem* sendRecvInfo, u32 itemNum);
58 : virtual HcclResult
59 : CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize = 0, HcclCMDType cmdType = HcclCMDType::HCCL_CMD_INVALID);
60 : HcclResult GetNumBlocks(u32& numBlocks) const;
61 : HcclResult SetNumBlocks(const u32& numBlocks);
62 : HcclResult GetCache(HcclCacheInfo& cacheInfo);
63 : HcclResult SetOpCounter(const OpCounterInfo& opCounter);
64 :
65 77 : inline AlgDesc GetAlgDesc() { return desc_; }
66 :
67 : // 用于alltoallv算子的aicpu展开cache
68 : virtual HcclResult MarkNeedAlltoallvCache();
69 : virtual HcclResult
70 : GetHcclOffsetDstRanksMap(std::unordered_map<uint64_t, std::vector<uint32_t>>& hcclOffsetDstRanksMap) const;
71 :
72 : protected:
73 : const HcclDispatcher dispatcher_;
74 : u64 inCCLbufferSize_{0}; // CCLIN大小,用于计算scratch
75 : AlgType algType_; // 算法类型
76 : std::unique_ptr<TopoMatcher>& topoMatcher_;
77 : bool isSupportSDMAReduce_ = false;
78 : AlgOpContext algOpContext_;
79 : bool aivClearEnable_ = false;
80 : u32 numBlocks_ = MAX_NUM_BLOCKS;
81 : OpCounterInfo opCounter_;
82 : AlgDesc desc_;
83 : void* rmaInfo_ = nullptr;
84 : HcclCacheInfo cacheInfo_;
85 : };
86 : } // namespace hccl
87 : #endif
|