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_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM_H_
12 : #define HCCLV2_CCU_CONTEXT_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM_H_
13 :
14 : #include <vector>
15 :
16 : #include <ios>
17 : #include "log.h"
18 : #include "ccu_ctx.h"
19 : #include "ccu_datatype.h"
20 :
21 : namespace Hccl {
22 :
23 : class CcuContextReduceMeshTwoShotMem2Mem1D : public CcuContext {
24 : public:
25 : CcuContextReduceMeshTwoShotMem2Mem1D(
26 : const CcuCtxArg& arg, const std::vector<CcuTransport*>& transports, const CcuTransportGroup& group);
27 0 : ~CcuContextReduceMeshTwoShotMem2Mem1D() 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 DoRepeatReduceTwoShot();
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 : uint64_t rankSize_{0};
43 : uint32_t rankId_{0};
44 : uint32_t rootId_{0};
45 : DataType dataType_;
46 : DataType outputDataType_;
47 : ReduceOp reduceOp_;
48 :
49 : std::vector<CcuRep::Variable> input_;
50 : std::vector<CcuRep::Variable> output_;
51 : std::vector<CcuRep::Variable> token_;
52 : std::vector<CcuRep::Variable> scratch_;
53 :
54 : CcuRep::Variable normalSliceSize_;
55 : CcuRep::Variable lastSliceSize_;
56 : CcuRep::Variable mySliceSize_;
57 : std::vector<CcuRep::Variable> sliceOffset_;
58 : std::vector<CcuRep::Variable> len_;
59 : CcuRep::Variable isInputOutputEqual_;
60 : CcuRep::Variable sliceSize_;
61 : CcuRep::MaskSignal locMask_;
62 :
63 : CcuRep::Memory srcMem_;
64 : CcuRep::Memory dstMem_;
65 : std::vector<CcuRep::Memory> reduceScatterSrc_;
66 : std::vector<CcuRep::Memory> reduceScatterDst_;
67 : std::vector<CcuRep::Memory> gatherSrc_;
68 : std::vector<CcuRep::Memory> gatherDst_;
69 :
70 : uint16_t selfBit_{0};
71 : uint16_t allBit_{0};
72 : GroupOpSize localGoSize_;
73 :
74 : std::string GetLoopBlockTag(std::string loopType, int32_t index);
75 : void CreateReduceLoop(uint32_t size, DataType dataType, DataType outputDataType, ReduceOp opType);
76 : void ReduceLoopGroup(
77 : CcuRep::Memory outDstOrg, CcuRep::Memory srcOrg, std::vector<CcuRep::Memory>& scratchOrg, GroupOpSize goSize,
78 : DataType dataType, DataType outputDataType, ReduceOp opType);
79 : const std::string LOOP_BLOCK_TAG{"_local_copy_reduce_loop_"};
80 : };
81 : } // namespace Hccl
82 :
83 : #endif // HCCLV2_CCU_CONTEXT_ALL_REDUCE_MESH_1D_H_
|