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_1D_TWO_SHOT_MEM2MEM_H_
12 : #define HCCLV2_CCU_INSTRUCTION_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM_H_
13 :
14 : #include <memory>
15 : #include <map>
16 : #include <vector>
17 : #include <queue>
18 : #include <string>
19 :
20 : #include <sstream>
21 : #include <ios>
22 : #include <iostream>
23 :
24 : #include "template_utils.h"
25 : #include "instruction.h"
26 : #include "ins_queue.h"
27 : #include "ccu_context_utils.h"
28 : #include "ccu_ctx_signature.h"
29 : #include "ccu_ins.h"
30 : #include "ccu_rank_group.h"
31 :
32 : namespace Hccl {
33 :
34 : // 为ReduceMeshTwoShot1D实现的CCUIns、CCUCtxArg与CCUTaskArg
35 : class CcuCtxArgReduceMeshTwoShotMem2Mem1D : public CcuCtxArg {
36 : public:
37 0 : explicit CcuCtxArgReduceMeshTwoShotMem2Mem1D(const std::vector<uint64_t> &dimSize, uint32_t rankId, uint32_t rootId,
38 : const CollAlgOperator &op, const std::vector<std::vector<RankId>> &tempVTopo)
39 0 : : dimSize_(dimSize), rankId_(rankId), rootId_(rootId), op_(op), tempVTopo_(tempVTopo)
40 : {
41 0 : }
42 0 : CcuCtxSignature GetCtxSignature() const override
43 : {
44 0 : CcuCtxSignature signature;
45 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM, op_,
46 0 : tempVTopo_);
47 0 : return signature;
48 0 : }
49 : std::vector<uint64_t> dimSize_;
50 : uint32_t rankId_;
51 : uint32_t rootId_;
52 : CollAlgOperator op_;
53 : std::vector<std::vector<RankId>> tempVTopo_;
54 : };
55 :
56 : class CcuTaskArgReduceMeshTwoShotMem2Mem1D : public CcuTaskArg {
57 : public:
58 0 : explicit CcuTaskArgReduceMeshTwoShotMem2Mem1D(uint64_t inputAddr, uint64_t outputAddr, uint64_t token,
59 : uint64_t scratchAddr, uint64_t normalSliceSize,
60 : uint64_t lastSliceSize, uint64_t mySliceSize)
61 0 : : inputAddr_(inputAddr), outputAddr_(outputAddr), token_(token), scratchAddr_(scratchAddr),
62 0 : normalSliceSize_(normalSliceSize), lastSliceSize_(lastSliceSize), mySliceSize_(mySliceSize)
63 : {
64 0 : }
65 : uint64_t inputAddr_;
66 : uint64_t outputAddr_;
67 : uint64_t token_;
68 : uint64_t scratchAddr_;
69 : uint64_t normalSliceSize_;
70 : uint64_t lastSliceSize_;
71 : uint64_t mySliceSize_;
72 : };
73 :
74 : class CcuInstructionReduceMeshTwoShotMem2Mem1D : public CcuInstruction {
75 : public:
76 0 : CcuInstructionReduceMeshTwoShotMem2Mem1D() : CcuInstruction()
77 : {
78 0 : }
79 :
80 0 : void Init(uint32_t rankId, uint32_t rootId, const CollAlgOperator &op, const std::vector<std::vector<RankId>> &tempVTopo,
81 : uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr, uint64_t token, uint64_t normalSliceSize,
82 : uint64_t lastSliceSize, uint64_t mySliceSize)
83 : {
84 0 : dimSize_.push_back(tempVTopo[0].size());
85 0 : rankId_ = rankId;
86 0 : rootId_ = rootId;
87 0 : op_ = op;
88 0 : tempVTopo_ = tempVTopo;
89 0 : inputAddr_ = inputAddr;
90 0 : outputAddr_ = outputAddr;
91 0 : scratchAddr_ = scratchAddr;
92 0 : token_ = token;
93 0 : normalSliceSize_ = normalSliceSize;
94 0 : lastSliceSize_ = lastSliceSize;
95 0 : mySliceSize_ = mySliceSize;
96 :
97 0 : return;
98 : }
99 :
100 0 : std::string Describe() const override
101 : {
102 0 : return StringFormat("CcuInstructionReduceMeshTwoShot1D rankId [%u], instType[%s]", rankId_,
103 0 : instType_.Describe().c_str());
104 : }
105 :
106 0 : CcuInstType GetInstType() const override
107 : {
108 0 : return instType_;
109 : }
110 :
111 : void SetInstType(CcuInstType instType)
112 : {
113 : instType_ = instType;
114 : }
115 :
116 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
117 : {
118 0 : return std::make_unique<CcuCtxArgReduceMeshTwoShotMem2Mem1D>(dimSize_, rankId_, rootId_, op_, tempVTopo_);
119 : }
120 :
121 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
122 : {
123 0 : return std::make_unique<CcuTaskArgReduceMeshTwoShotMem2Mem1D>(
124 0 : inputAddr_, outputAddr_, token_, scratchAddr_, normalSliceSize_,
125 0 : lastSliceSize_, mySliceSize_);
126 : }
127 :
128 0 : std::vector<LinkData> GetLinks() const override
129 : {
130 0 : return links_;
131 : }
132 :
133 0 : void SetLinks(std::vector<LinkData> &links)
134 : {
135 0 : links_ = links;
136 0 : }
137 :
138 0 : RankGroup GetRankGroup() const override
139 : {
140 0 : return rankGroup_;
141 : }
142 :
143 0 : void SetRankGroup(RankGroup &rankGroup)
144 : {
145 0 : rankGroup_ = rankGroup;
146 0 : }
147 :
148 : private:
149 : CcuInstType instType_ = CcuInstType::CCU_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM;
150 : std::vector<uint64_t> dimSize_;
151 : uint32_t rankId_{0};
152 : uint32_t rootId_{0};
153 : CollAlgOperator op_;
154 : std::vector<std::vector<RankId>> tempVTopo_;
155 : uint64_t inputAddr_{0};
156 : uint64_t outputAddr_{0};
157 : uint64_t token_{0};
158 : uint64_t scratchAddr_{0};
159 : uint64_t normalSliceSize_{0};
160 : uint64_t lastSliceSize_{0};
161 : uint64_t mySliceSize_{0};
162 : RankGroup rankGroup_;
163 : std::vector<LinkData> links_;
164 : };
165 :
166 : } // namespace Hccl
167 : #endif // HCCLV2_CCU_INSTRUCTION_REDUCE_MESH_1D_TWO_SHOT_MEM2MEM_H_
|