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