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 CUPT_KERNEL_CCU_CONTEXT_REDUCE_SCATTER_NHR_1D_H_
12 : #define CUPT_KERNEL_CCU_CONTEXT_REDUCE_SCATTER_NHR_1D_H_
13 : #include <vector>
14 : #include <ios>
15 : #include "log.h"
16 : #include "ccu_context_alg_base.h"
17 : #include "ccu_datatype.h"
18 : #include "ccu_instruction_reduce_scatter_nhr1d_mem2mem.h"
19 :
20 : namespace Hccl {
21 :
22 : class CcuContextReduceScatterNHR1DMem2Mem : public CcuContextAlgBase {
23 : public:
24 : CcuContextReduceScatterNHR1DMem2Mem(const CcuCtxArg &arg, const std::vector<CcuTransport*> &transports,
25 : const CcuTransportGroup &group);
26 0 : ~CcuContextReduceScatterNHR1DMem2Mem() override {}
27 :
28 : void Algorithm() override;
29 : std::vector<uint64_t> GeneArgs(const CcuTaskArg &arg) override;
30 : private:
31 : void LoadArgs();
32 : void InitResources();
33 : void PreSync();
34 : void PostSync();
35 : void AxisSync(uint32_t signalIndex);
36 : void DoRepeatReduceScatterNHR();
37 : void DoRepeatReduceScatterNHRSingleStep(const NHRStepInfo &nhrStepInfo,
38 : const std::vector<CcuRep::Variable> &inputSliceOffset);
39 : void DoRepeatSendRecvSlices(const u32 &toRank, CcuRep::Memory &src, CcuRep::Memory &dst);
40 :
41 : // 构造函数中
42 : uint64_t dimSize_{0};
43 : uint32_t axisId_{0};
44 : uint32_t localSize_{0}; // 本rank所在行或列的总rank数
45 : uint32_t myRankIdx_{0};
46 : uint32_t signalNum_{0}; // 需要使用的signal数量
47 : DataType dataType_;
48 : DataType outputDataType_;
49 : std::vector<NHRStepInfo> stepInfoVector_; // nhr算法执行过程中的参数
50 : std::map<u32, u32> indexMap_;
51 : uint32_t linkNum_{0};
52 :
53 : // load进来参数
54 : std::vector<CcuRep::Variable> input_;
55 : CcuRep::Variable output_;
56 : std::vector<CcuRep::Variable> token_;
57 : CcuRep::Variable die0Size_;
58 : CcuRep::Variable die1Size_;
59 : CcuRep::Variable inputSliceStride_;
60 : CcuRep::Variable outputSliceStride_;
61 : CcuRep::Variable inputRepeatStride_;
62 : CcuRep::Variable outputRepeatStride_;
63 : CcuRep::Variable repeatNumVar_;
64 : CcuRep::Variable isBottom_;
65 : CcuRep::Variable repeatNumVarTemp_;
66 : // 用于记录每次writereduce的数据
67 : CcuRep::Variable sliceSize_;
68 :
69 : // 跨轴同步信号
70 : std::string localAxisSignalName_;
71 : std::string anotherAxisSignalName_;
72 : CcuRep::MaskSignal localAxisSignal_;
73 : CcuRep::MaskSignal anotherAxisSignal_;
74 : CcuRep::MaskSignal localSignal_;
75 :
76 : CcuRep::Variable repeatInputOffset_;
77 : CcuRep::Variable repeatOutputOffset_;
78 : CcuRep::Variable myrankInputSliceOffset_;
79 :
80 : CcuRep::Memory srcMem_;
81 : CcuRep::Memory dstMem_;
82 : CcuRep::Variable flag_; // 用于判断是否是第一次循环
83 : };
84 : } // namespace Hccl
85 :
86 : #endif // HCCLV2_CCU_CONTEXT_REDUCE_SCATTER_NHR_1D_H_
|