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