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_2D_TWO_SHOT_H_
12 : #define HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_2D_TWO_SHOT_H_
13 :
14 : #include <vector>
15 : #include <ios>
16 : #include "log.h"
17 : #include "ccu_context_alg_base.h"
18 : #include "ccu_datatype.h"
19 :
20 : namespace Hccl {
21 :
22 : class CcuContextAllReduceMesh2DTwoShot : public CcuContextAlgBase {
23 : public:
24 : CcuContextAllReduceMesh2DTwoShot(const CcuCtxArg &arg, const std::vector<CcuTransport*> &transports,
25 : const CcuTransportGroup &group);
26 0 : ~CcuContextAllReduceMesh2DTwoShot() override {}
27 :
28 : void Algorithm() override;
29 : std::vector<uint64_t> GeneArgs(const CcuTaskArg &arg) override;
30 : private:
31 : void InitVariables();
32 : void LoadArgs();
33 : void SyncAll(int ckeIdx);
34 : void PreSync();
35 : void GetSliceOffsetAndGoSize(uint64_t currentSliceRankIdx, uint64_t currStepSliceType, CcuRep::Variable &currOffset,
36 : GroupOpSize &currGoSize);
37 : void DoAxisSync(uint32_t signalIdx);
38 : void DoGroupSync(int ckeIdx, uint16_t selfBit, uint16_t allBit);
39 : void DoGroupReduce(std::vector<CcuRep::Variable> &srcBase, CcuRep::Variable &dstBase,
40 : CcuRep::Variable &offset, GroupOpSize &goSize);
41 : void DoGroupBroadcast(CcuRep::Variable &srcBase, std::vector<CcuRep::Variable> &dstBase, CcuRep::Variable &offset,
42 : GroupOpSize &goSize);
43 :
44 : uint32_t axisId_{0};
45 : DataType dataType_;
46 : DataType outputDataType_;
47 : uint16_t selfBit_{0};
48 : uint16_t allBit_{0};
49 : uint32_t otherAxisId_{0};
50 : std::vector<uint64_t> myRankIdxInAxis_;
51 : uint64_t myRankIdxInCurrentAxis_{0};
52 : uint64_t currentAxisRankSize_{0};
53 : uint64_t myRankIdxInOtherAxis_{0};
54 : uint64_t otherAxisRankSize_{0};
55 :
56 : std::vector<uint64_t> dimSize_;
57 : std::vector<CcuRep::Variable> inputAddr_;
58 : std::vector<CcuRep::Variable> outputAddr_;
59 : std::vector<CcuRep::Variable> token_;
60 :
61 : CcuRep::Variable normalRankXSliceSize_;
62 : CcuRep::Variable normalRankYSliceSize_;
63 : CcuRep::Variable lastRankXSliceSize_;
64 : CcuRep::Variable lastRankYSliceSize_;
65 :
66 : GroupOpSize normalRankXGoSize_;
67 : GroupOpSize normalRankYGoSize_;
68 : GroupOpSize lastRankXGoSize_;
69 : GroupOpSize lastRankYGoSize_;
70 :
71 : std::string currAxisSignalName_;
72 : std::string otherAxisSignalName_;
73 : CcuRep::MaskSignal currAxisSignal_;
74 : CcuRep::MaskSignal otherAxisSignal_;
75 :
76 : // 算法模板运行时的参数
77 : std::vector<CcuRep::Memory> tmpAddrList_;
78 : CcuRep::Memory tmpAddr_;
79 : };
80 : } // namespace Hccl
81 :
82 : #endif // HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_2D_TWO_SHOT_H_
|