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