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_SCATTER_MESH_2D_MEM2MEM_H_
12 : #define HCCLV2_CCU_CONTEXT_REDUCE_SCATTER_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 :
23 : class CcuContextReduceScatterMeshMem2Mem2D : public CcuContextAlgBase {
24 : public:
25 : CcuContextReduceScatterMeshMem2Mem2D(const CcuCtxArg &arg,
26 : const std::vector<CcuTransport*> &transports,
27 : const CcuTransportGroup &group);
28 0 : ~CcuContextReduceScatterMeshMem2Mem2D() override {}
29 :
30 : void Algorithm() override;
31 : std::vector<uint64_t> GeneArgs(const CcuTaskArg &arg) override;
32 :
33 : protected:
34 : void InitResources();
35 :
36 : private:
37 : void CreateLocalCopyLoop(); // for loop-group local copy
38 : void LocalCopyByLoopGroup(CcuRep::Memory dst, CcuRep::Memory src); // for loop-group local copy
39 : std::vector<uint64_t> CalMeshChunkSlice(uint64_t dataSize, uint64_t sliceNum); // for mesh-chunk
40 : void PreSync();
41 : void PostSync(uint32_t signalIndex);
42 : void LoadArgs();
43 : void AxisSync(uint32_t signalIndex);
44 : void Step1Reduce();
45 : void Step2Reduce();
46 :
47 : // 在构造函数中初始化
48 : uint32_t axisId_{0}; // 值为 0 表示 x 轴, 值为 1 表示 y 轴
49 : std::vector<uint64_t> dimSize_; // [0] mesh2d 拓扑的列数
50 : std::vector<uint32_t> dimId_; // [0] 当前 NPU 所在列编号, [1] 当前 NPU 所在行编号
51 : uint32_t localId_{0}; // 当前 rank 在指定 axisId_ 上的编号
52 : uint32_t localSize_{0}; // mesh2d 拓扑在指定 axisId_ 轴上的维度
53 : uint32_t oppsiteSize_{0}; // mesh2d 拓扑在与指定 axisId_ 轴相反的轴上的维度
54 : DataType dataType_;
55 : DataType outputDataType_;
56 : // load 进来的参数
57 : std::vector<CcuRep::Variable> input_;
58 : std::vector<CcuRep::Variable> output_;
59 : std::vector<CcuRep::Variable> token_;
60 : CcuRep::Variable xAxisSize_;
61 : CcuRep::Variable yAxisSize_;
62 : CcuRep::Variable step0BaseOffset_;
63 : CcuRep::Variable step0AddOffset_;
64 : CcuRep::Variable step1AddOffset_;
65 : CcuRep::Variable yAxisOffset_;
66 : GroupOpSize xAxisGroupOpSize_;
67 : GroupOpSize yAxisGroupOpSize_;
68 : GroupOpSize curGoSize_; // for loop-group local copy
69 :
70 : // For mesh-chunk
71 : std::vector<CcuRep::Variable> xlocalSlice_;
72 : std::vector<CcuRep::Variable> ylocalSlice_;
73 :
74 : CcuRep::Variable inputSize_;
75 : CcuRep::Variable offset_;
76 : CcuRep::Variable sliceOffset_;
77 : CcuRep::Variable strideSize_;
78 :
79 : // 跨轴同步信号
80 : std::string localAxisSignalName_; // 由 axisId_ 初始化
81 : std::string anotherAxisSignalName_; // 由 axisId_ 初始化
82 : CcuRep::MaskSignal localAxisSignal_;
83 : CcuRep::MaskSignal anotherAxisSignal_;
84 : }; // class CcuContextReduceScatterMeshMem2Mem2D
85 : } // namespace Hccl
86 :
87 : #endif // HCCLV2_CCU_CONTEXT_REDUCE_SCATTER_MESH_2D_MEM2MEM_H_
|