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 : protected:
24 : /* *************** 算法编排 *************** */
25 : // AllReduce Loop Executor公共接口
26 : virtual u64 CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize);
27 : virtual bool IsHugeData(const u64 curSize);
28 : virtual bool IsSmallData(const u64 totalSize, const u64 curSize);
29 : HcclResult RunLoop(OpParam ¶m, AlgResourceResponse &algRes);
30 : HcclResult AvoidSubgraphLoop(OpParam ¶m, AlgResourceResponse &algRes);
31 :
32 : // 工具类
33 : HcclResult GetSliceNum(const u64 totalSize, const bool isSmallData, u64& sliceNum, u32 unitSize=0);
34 : bool IsAllReduceSmallData(u64 size);
35 : HcclResult PrepareSliceDataWithAlignSize(u64 totalSize, u32 sliceNum,
36 : u64 piplineOffset, std::vector<Slice>& dataSlice, u64 alignSize);
37 : HcclResult PrepareAivBuffers(u32 rankSize, u32 rankId, u32 rankOffset,
38 : DeviceMem &inputMem, DeviceMem &outputMem, std::vector<LINK> &links, void **dataBuffers, void **flagBuffers,
39 : UserMemType dataMemType, UserMemType flagMemType, u32 dataMemOffset, u32 flagMemOffset);
40 :
41 : bool CCLMemSlice_{true}; // 每次Loop是否需要对CCLMem进行切片
42 : bool DMAReduceFlag_{false}; // 是否DMA消减
43 : private:
44 : virtual HcclResult RunLoopInner(OpParam ¶m, const ReduceType &reduceType, ExecMem &execMem);
45 : };
46 :
47 : } // namespace hccl
48 :
49 : #endif
|