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_INSTRUCTION_REDUCE_MESH_2D_H_
12 : #define HCCLV2_CCU_INSTRUCTION_REDUCE_MESH_2D_H_
13 :
14 : #include "template_utils.h"
15 : #include "instruction.h"
16 : #include "ins_queue.h"
17 : #include "ccu_context_utils.h"
18 : #include "ccu_ctx_signature.h"
19 : #include "ccu_ins.h"
20 : #include "ccu_rank_group.h"
21 :
22 : namespace Hccl {
23 :
24 : // 为ReduceMeshMem2Mem2D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgReduceMeshMem2Mem2D : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgReduceMeshMem2Mem2D(const std::vector<uint64_t> &dSize, uint32_t rId, uint32_t rootId,
28 : uint32_t aId, const CollAlgOperator &op,
29 : const std::vector<std::vector<RankId>> &tempVTopo)
30 0 : : dimSize_(dSize), rankId_(rId), rootId_(rootId), axisId_(aId), op_(op), tempVTopo_(tempVTopo)
31 : {
32 0 : }
33 0 : CcuCtxSignature GetCtxSignature() const override
34 : {
35 0 : CcuCtxSignature signature;
36 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_REDUCE_MESH_2D_MEM2MEM, op_, tempVTopo_);
37 0 : return signature;
38 0 : }
39 :
40 : std::vector<uint64_t> dimSize_;
41 : uint32_t rankId_;
42 : uint32_t rootId_;
43 : uint32_t axisId_;
44 : CollAlgOperator op_;
45 : std::vector<std::vector<RankId>> tempVTopo_;
46 : };
47 :
48 : class CcuTaskArgReduceMeshMem2Mem2D : public CcuTaskArg {
49 : public:
50 0 : explicit CcuTaskArgReduceMeshMem2Mem2D(uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize,
51 : uint64_t xAxisSize, uint64_t yAxisSize, uint64_t token)
52 0 : : inputAddr_(inputAddr), outputAddr_(outputAddr), sliceSize_(sliceSize), xAxisSize_(xAxisSize),
53 0 : yAxisSize_(yAxisSize), token_(token)
54 : {
55 0 : }
56 :
57 : uint64_t inputAddr_;
58 : uint64_t outputAddr_;
59 : uint64_t sliceSize_;
60 : uint64_t xAxisSize_;
61 : uint64_t yAxisSize_;
62 : uint64_t token_;
63 : };
64 :
65 : class CcuInstructionReduceMeshMem2Mem2D : public CcuInstruction {
66 : public:
67 0 : CcuInstructionReduceMeshMem2Mem2D() : CcuInstruction()
68 : {
69 0 : }
70 :
71 0 : void Init(std::vector<uint64_t> dimSize, uint32_t rankId, uint32_t rootId, uint64_t axisId, uint64_t inputAddr,
72 : uint64_t outputAddr, uint64_t sliceSize, uint64_t xAxisSize, uint64_t yAxisSize, uint64_t token,
73 : CollAlgOperator &op, std::vector<std::vector<RankId>> &tempVTopo)
74 : {
75 0 : dimSize_ = dimSize;
76 0 : rankId_ = rankId;
77 0 : rootId_ = rootId;
78 0 : axisId_ = axisId;
79 0 : inputAddr_ = inputAddr;
80 0 : outputAddr_ = outputAddr;
81 0 : sliceSize_ = sliceSize;
82 0 : xAxisSize_ = xAxisSize;
83 0 : yAxisSize_ = yAxisSize;
84 0 : token_ = token;
85 0 : op_ = op;
86 0 : tempVTopo_ = tempVTopo;
87 0 : return;
88 : }
89 :
90 0 : CcuInstType GetInstType() const override
91 : {
92 0 : HCCL_INFO("CcuInstructionReduceMeshMem2Mem2D instype is CCU_REDUCE_MESH_2D_MEM2MEM.");
93 0 : return instType_;
94 : }
95 :
96 0 : std::string Describe() const override
97 : {
98 0 : return StringFormat("CcuInstructionReduceMeshMem2Mem2D rankId [%u], instType[%d]", rankId_, instType_);
99 : }
100 :
101 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
102 : {
103 0 : HCCL_INFO("[CcuInstructionReduceMeshMem2Mem2D] GetCtxArg begin");
104 0 : return std::make_unique<CcuCtxArgReduceMeshMem2Mem2D>(dimSize_, rankId_, rootId_, axisId_, op_, tempVTopo_);
105 : }
106 :
107 : void SetInstType(CcuInstType instType)
108 : {
109 : instType_ = instType;
110 : }
111 :
112 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
113 : {
114 0 : HCCL_INFO("[CcuInstructionReduceMeshMem2Mem2D] GetTaskArg begin");
115 0 : return std::make_unique<CcuTaskArgReduceMeshMem2Mem2D>(inputAddr_, outputAddr_, sliceSize_, xAxisSize_,
116 0 : yAxisSize_, token_);
117 : }
118 :
119 : private:
120 : CcuInstType instType_ = CcuInstType::CCU_REDUCE_MESH_2D_MEM2MEM;
121 : std::vector<uint64_t> dimSize_;
122 : uint32_t rankId_{0};
123 : uint32_t rootId_{0};
124 : uint64_t axisId_{0};
125 : uint64_t inputAddr_{0};
126 : uint64_t outputAddr_{0};
127 : uint64_t sliceSize_{0};
128 : uint64_t xAxisSize_{0};
129 : uint64_t yAxisSize_{0};
130 : uint64_t token_{0};
131 : CollAlgOperator op_;
132 : std::vector<std::vector<RankId>> tempVTopo_;
133 : };
134 :
135 : } // namespace Hccl
136 : #endif // HCCLV2_CCU_INSTRUCTION_REDUCE_MESH_2D_MEM2MEM_H_
|