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