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 HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_1D_MEM2MEM_H_
12 : #define HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_1D_MEM2MEM_H_
13 :
14 : #include <vector>
15 :
16 : #include <ios>
17 : #include "log.h"
18 : #include "ccu_context_alg_base.h"
19 : #include "ccu_datatype.h"
20 :
21 : namespace Hccl {
22 :
23 : class CcuContextAllReduceMeshMem2Mem1D : public CcuContextAlgBase {
24 : public:
25 : CcuContextAllReduceMeshMem2Mem1D(const CcuCtxArg &arg, const std::vector<CcuTransport *> &transports,
26 : const CcuTransportGroup &group);
27 0 : ~CcuContextAllReduceMeshMem2Mem1D() override
28 0 : {
29 0 : }
30 :
31 : void Algorithm() override;
32 : std::vector<uint64_t> GeneArgs(const CcuTaskArg &arg) override;
33 :
34 : protected:
35 : void InitResource();
36 : void LoadArgs();
37 : void PreSync();
38 : void PostSync();
39 : void DoRepeatAllReduce();
40 : void ReduceRmtToLoc(const std::vector<CcuRep::Variable> &srcAddr, const CcuRep::Variable &dstAddr);
41 : void BcastLocToRmt(const CcuRep::Variable &srcAddr, const std::vector<CcuRep::Variable> &dstAddr);
42 :
43 : private:
44 : DataType dataType_;
45 : DataType outputDataType_;
46 : std::vector<CcuRep::Variable> input_;
47 : std::vector<CcuRep::Variable> output_;
48 : std::vector<CcuRep::Variable> token_;
49 : std::vector<CcuRep::Variable> scratch_;
50 : CcuRep::Variable currentRankSliceInputOffset_;
51 : CcuRep::Variable currentRankSliceOutputOffset_;
52 : CcuRep::Variable normalSliceSize_;
53 : CcuRep::Variable lastSliceSize_;
54 : CcuRep::Variable mySliceSize_;
55 : CcuRep::Variable sliceOffset_;
56 : CcuRep::Variable isInputOutputEqual_;
57 : CcuRep::Variable sliceSize_;
58 : CcuRep::MaskSignal locMask_;
59 :
60 : CcuRep::Memory srcMem_;
61 : CcuRep::Memory dstMem_;
62 : std::vector<CcuRep::Memory> reduceScatterSrc_;
63 : std::vector<CcuRep::Memory> reduceScatterDst_;
64 :
65 : uint16_t selfBit_{0};
66 : uint16_t allBit_{0};
67 : GroupOpSize localGoSize_;
68 :
69 : std::string GetLoopBlockTag(std::string loopType, int32_t index);
70 : void CreateReduceLoop(uint32_t size, DataType dataType, DataType outputDataType,
71 : ReduceOp opType);
72 : void ReduceLoopGroup(CcuRep::Memory outDstOrg, CcuRep::Memory srcOrg,
73 : std::vector<CcuRep::Memory> &scratchOrg, GroupOpSize goSize, DataType dataType, DataType outputDataType,
74 : ReduceOp opType);
75 : const std::string LOOP_BLOCK_TAG{"_local_copy_reduce_loop_"};
76 : };
77 : } // namespace Hccl
78 :
79 : #endif // HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_1D_H_
|