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_2D_MEM2MEM_H_
12 : #define HCCLV2_CCU_CONTEXT_REDUCE_MESH_2D_MEM2MEM_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 : #include "ccu_assist.h"
20 :
21 : namespace Hccl {
22 : constexpr int INPUT_XN_ID = 1;
23 : constexpr int TOKEN_XN_ID = 2;
24 : constexpr int CKE_IDX_0 = 0;
25 : constexpr int CKE_IDX_1 = 1;
26 : constexpr int CKE_IDX_2 = 2;
27 : constexpr int CKE_IDX_3 = 3;
28 : constexpr int CKE_IDX_4 = 4;
29 : constexpr uint64_t CCU_MS_SIZE = 4096;
30 : constexpr uint64_t LOCAL_COPY_MS = 8;
31 : constexpr int X_AXIS_ID = 0;
32 : constexpr int Y_AXIS_ID = 1;
33 :
34 : class CcuContextReduceMeshMem2Mem2D : public CcuContextAlgBase {
35 : public:
36 : CcuContextReduceMeshMem2Mem2D(
37 : const CcuCtxArg& arg, const std::vector<CcuTransport*>& transports, const CcuTransportGroup& group);
38 0 : ~CcuContextReduceMeshMem2Mem2D() override {}
39 :
40 : void Algorithm() override;
41 : std::vector<uint64_t> GeneArgs(const CcuTaskArg& arg) override;
42 :
43 : private:
44 : void InitResources();
45 : void LoadArgs();
46 : void PreSync();
47 : void PostSync(uint32_t signalIndex);
48 : void AxisSync(uint32_t signalIndex);
49 : void ReduceStep1();
50 : void ReduceStep2();
51 : std::vector<uint64_t> CalMeshChunkSlice(uint64_t dataSize, uint64_t sliceNum); // for mesh-chunk
52 :
53 : std::vector<uint64_t> dimSize_;
54 : uint32_t axisId_{0}; // 0 : X轴, 1 : Y轴
55 :
56 : std::vector<uint32_t> dimId_; // 本rank所在行或列的编号
57 : uint32_t localId_{0}; // 本chip所在行或列的编号
58 : uint32_t localSize_{0}; // 本rank所在行或列的总rank数
59 :
60 : std::vector<uint32_t> rootDimId_; // root所在行或列的编号
61 : uint32_t rootId_{0}; // 当rankid == rootid时,为root节点 则跳过write操作
62 : DataType dataType_;
63 : DataType outputDataType_;
64 : ReduceOp reduceOp_;
65 : std::vector<CcuRep::Variable> input_;
66 : CcuRep::Variable output_;
67 : std::vector<CcuRep::Variable> token_;
68 : CcuRep::Variable xAxisSize_;
69 : CcuRep::Variable yAxisSize_;
70 : CcuRep::Variable yAxisOffset_;
71 : CcuRep::MaskSignal locMask_;
72 :
73 : GroupOpSize xAxisGroupOpSize_;
74 : GroupOpSize yAxisGroupOpSize_;
75 : GroupOpSize curGoSize_; // for loop-group local copy
76 : // variables for mesh-chunk
77 : std::vector<CcuRep::Variable> xChunkSize_; // for xsliceszie
78 : std::vector<CcuRep::Variable> yChunkSize_; // for ysliceszie
79 : std::vector<CcuRep::Variable> chunkSize_; // for current axis
80 : CcuRep::Variable chunkOffset_;
81 :
82 : // 跨轴同步信号
83 : std::string localAxisSignalName_;
84 : std::string anotherAxisSignalName_;
85 : CcuRep::MaskSignal localAxisSignal_;
86 : CcuRep::MaskSignal anotherAxisSignal_;
87 : };
88 : } // namespace Hccl
89 :
90 : #endif // HCCLV2_CCU_CONTEXT_REDUCE_MESH_2D_MEM2MEM_H_
|