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_REDUCESCATTER_EXECUTOR_H
12 : #define COLL_REDUCESCATTER_EXECUTOR_H
13 : #include "coll_comm_executor.h"
14 :
15 : namespace hccl {
16 :
17 : constexpr u64 CCE_REDUCE_ALIGN_FACTOR = 2; // cce reduce数据大小32字节对齐 2是指前后各有
18 :
19 : class CollReduceScatterExecutor : public CollCommExecutor {
20 : public:
21 : explicit CollReduceScatterExecutor(const HcclDispatcher dispatcher,
22 : std::unique_ptr<TopoMatcher> &topoMatcher);
23 50 : ~CollReduceScatterExecutor() override = default;
24 :
25 : HcclResult Orchestrate(OpParam& param, AlgResourceResponse& algRes) override;
26 : protected:
27 : // ReduceScatter Loop Executor公共接口
28 : virtual u64 CalcLoopMaxCount(const u32 unitSize);
29 : virtual bool IsHugeData(const u64 curSize, OpParam *param = nullptr);
30 : virtual bool IsSmallData(const u64 totalSize, const u64 curSize);
31 : virtual bool IsPreloadCopyOptimizeCondition(const OpParam ¶m, ExecMem &execMem);
32 : virtual HcclResult RunLoop(OpParam ¶m, AlgResourceResponse &algRes);
33 : virtual HcclResult RunLoopV(OpParam ¶m, AlgResourceResponse &algRes);
34 :
35 : // 工具类
36 : std::vector<std::vector<Slice>> ReduceScatterRingSlicePrepare(u32 ringNum, u32 sliceNum,
37 : bool useInlineReduce, const DeviceMem& outputMem, std::vector<Slice>& dataSegsSlice, const std::string &tag);
38 : std::vector<std::vector<Slice>> ReduceScatterRingSlicePrepareContinuous(u32 ringNum, u32 sliceNum,
39 : bool useInlineReduce, DeviceMem& outputMem, u32 level1RankSize, u32 level2RankSize, std::vector<Slice>& dataSegsSlice, const std::string &tag);
40 : std::vector<std::vector<Slice>> AnyPathReduceScatterRingSlicePrepare(u32 ringNum, u32 sliceNum,
41 : bool useInlineReduce, DeviceMem& outputMem, std::vector<Slice>& dataSegsSlice, const std::string &tag);
42 : HcclResult PrepareAivBuffers(u32 rankSize, u32 rankId, u32 rankOffset,
43 : DeviceMem &inputMem, DeviceMem &outputMem, std::vector<LINK> &links, void **dataBuffers, void **flagBuffers,
44 : UserMemType dataMemType, UserMemType flagMemType, u32 dataMemOffset, u32 flagMemOffset);
45 : HcclResult RetryPostSync(OpParam& param, ExecMem &execMem);
46 : bool CCLMemSlice_{true}; // 每次Loop是否需要对CCLMem进行切片
47 : bool DMAReduceFlag_{false}; // 是否DMA消减
48 : bool scratchMemFlag_{false}; // 是否需要申请scratch memory,不需要申请则传入outputmem为scratchmem
49 : u64 totalSize_{0}; // 总数据量
50 : bool isReduceScatterV_{false};
51 :
52 : private:
53 : HcclResult RunLoopInner(OpParam ¶m, const ReduceType &reduceType, ExecMem &execMem);
54 : HcclResult RunLoopInnerV(OpParam ¶m, const ReduceType &reduceType, ExecMem &execMem);
55 :
56 : bool CalcCurCountsAndCurDispls(const u64 maxTotalCount, std::vector<u64> &countsLeft, std::vector<u64> &displs,
57 : std::vector<u64> &curCounts, std::vector<u64> &curDispls, u32 unitSize);
58 : void PrintCurCountAndCurDispls(const std::vector<u64> &curCounts, const std::vector<u64> &curDispls);
59 : };
60 :
61 : } // namespace hccl
62 :
63 : #endif
|