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 COLL_ALLREDUCE_COMM_EXECUTOR_H
12 : #define COLL_ALLREDUCE_COMM_EXECUTOR_H
13 :
14 : #include "coll_comm_executor.h"
15 :
16 : namespace hccl {
17 : class CollAllReduceExecutor : public CollCommExecutor {
18 : public:
19 : CollAllReduceExecutor(const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher);
20 38 : ~CollAllReduceExecutor() override = default;
21 :
22 : HcclResult Orchestrate(OpParam& param, AlgResourceResponse& algRes) override;
23 :
24 : protected:
25 : /* *************** 算法编排 *************** */
26 : // AllReduce Loop Executor公共接口
27 : virtual u64 CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize);
28 : virtual bool IsHugeData(const u64 curSize);
29 : virtual bool IsSmallData(const u64 totalSize, const u64 curSize);
30 : HcclResult RunLoop(OpParam& param, AlgResourceResponse& algRes);
31 : HcclResult AvoidSubgraphLoop(OpParam& param, AlgResourceResponse& algRes);
32 :
33 : // 工具类
34 : HcclResult GetSliceNum(const u64 totalSize, const bool isSmallData, u64& sliceNum, u32 unitSize = 0);
35 : bool IsAllReduceSmallData(u64 size);
36 : HcclResult PrepareSliceDataWithAlignSize(
37 : u64 totalSize, u32 sliceNum, u64 piplineOffset, std::vector<Slice>& dataSlice, u64 alignSize);
38 : HcclResult PrepareAivBuffers(
39 : u32 rankSize, u32 rankId, u32 rankOffset, DeviceMem& inputMem, DeviceMem& outputMem, std::vector<LINK>& links,
40 : void** dataBuffers, void** flagBuffers, UserMemType dataMemType, UserMemType flagMemType, u32 dataMemOffset,
41 : u32 flagMemOffset);
42 :
43 : bool CCLMemSlice_{true}; // 每次Loop是否需要对CCLMem进行切片
44 : bool DMAReduceFlag_{false}; // 是否DMA消减
45 : private:
46 : virtual HcclResult RunLoopInner(OpParam& param, const ReduceType& reduceType, ExecMem& execMem);
47 : };
48 :
49 : } // namespace hccl
50 :
51 : #endif
|