Line data Source code
1 : /*
2 : * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
3 : * Description: Ccu representation datatype implementation file
4 : * Author: sunzhepeng
5 : * Create: 2024-07-06
6 : */
7 : #include "ccu_datatype_v1.h"
8 : #include "ccu_rep_v1.h"
9 : #include "ccu_kernel_resource.h"
10 : #include "ccu_interface_assist_v1.h"
11 :
12 : #include "exception_util.h"
13 : #include "ccu_api_exception.h"
14 :
15 : namespace hcomm {
16 : namespace CcuRep {
17 :
18 4953 : uint16_t CcuPhyRes::Id() const { return id; }
19 77 : uint16_t CcuPhyRes::DieId() const { return dieId; }
20 42987 : void CcuPhyRes::Reset(uint16_t id) { this->id = id; }
21 1515 : void CcuPhyRes::SetDieId(uint16_t dieId) { this->dieId = dieId; }
22 :
23 129827 : CcuVirRes::CcuVirRes(CcuRepContext* context) : context(context) { phyRes = std::make_shared<CcuPhyRes>(); }
24 :
25 41475 : void CcuVirRes::Reset(uint16_t id) { phyRes->Reset(id); }
26 :
27 1511 : void CcuVirRes::Reset(uint16_t id, uint16_t dieId)
28 : {
29 1511 : phyRes->Reset(id);
30 1511 : phyRes->SetDieId(dieId);
31 1511 : }
32 :
33 3 : void CcuVirRes::SetDieId(uint16_t dieId) { phyRes->SetDieId(dieId); }
34 :
35 4880 : uint16_t CcuVirRes::Id() const { return phyRes->Id(); }
36 :
37 4 : uint16_t CcuVirRes::DieId() const { return phyRes->DieId(); }
38 :
39 29463 : Variable::Variable(CcuRepContext* context) : CcuVirRes(context) {}
40 :
41 63882 : Variable::Variable(const Variable& other) : CcuVirRes(other.context) { phyRes = other.phyRes; }
42 :
43 288 : void Variable::operator=(Variable&& other)
44 : {
45 288 : phyRes = other.phyRes;
46 288 : context = other.context;
47 288 : }
48 :
49 159 : void Variable::operator=(const Variable& other)
50 : {
51 159 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
52 159 : }
53 :
54 284 : void Variable::operator=(uint64_t immediate)
55 : {
56 284 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
57 284 : }
58 :
59 : template <typename Dst, typename Lhs, typename Rhs>
60 123 : void ArithmeticAppendToContext(CcuRepContext* context, Dst& dst, CcuArithmeticOperator<Lhs, Rhs> op)
61 : {
62 123 : switch (op.type) {
63 113 : case CcuArithmeticOperatorType::ADDITION:
64 113 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
65 113 : break;
66 5 : case CcuArithmeticOperatorType::MULTIPLICATION:
67 5 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
68 5 : break;
69 5 : case CcuArithmeticOperatorType::SUBTRACTION:
70 5 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
71 5 : break;
72 0 : default:
73 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operator[%d].", op.type);
74 : }
75 123 : }
76 :
77 116 : void Variable::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
78 : {
79 116 : ArithmeticAppendToContext(context, *this, op);
80 116 : }
81 :
82 116 : void Variable::operator=(CcuArithmeticOperator<Variable, Variable> op) { VarVarAppendToContext(op); }
83 :
84 5 : void Variable::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
85 : {
86 5 : ArithmeticAppendToContext(context, *this, op);
87 5 : }
88 :
89 5 : void Variable::operator=(CcuArithmeticOperator<Variable, uint16_t> op) { VarImmedAppendToContext(op); }
90 :
91 0 : void Variable::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
92 : {
93 0 : ArithmeticAppendToContext(context, *this, op);
94 0 : }
95 :
96 0 : void Variable::operator=(CcuArithmeticOperator<Address, uint16_t> op) { AddrImmedAppendToContext(op); }
97 :
98 0 : void Variable::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
99 : {
100 0 : switch (op.type) {
101 0 : case CcuArithmeticOperatorType::ADDITION: {
102 0 : AppendToContext(
103 0 : context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
104 0 : break;
105 : }
106 0 : default: {
107 0 : Hccl::THROW<Hccl::NotSupportException>(
108 : "Not supported Arithmetic operate in variable = addr (op) addr.");
109 : }
110 : }
111 0 : }
112 :
113 0 : void Variable::operator=(CcuArithmeticOperator<Address, Address> op) { AddrAddrAppendToContext(op); }
114 :
115 1 : void Variable::operator+=(const Variable& other)
116 : {
117 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
118 1 : }
119 :
120 1 : void Variable::operator+=(const uint16_t immediate)
121 : {
122 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
123 1 : }
124 :
125 1 : void Variable::operator*=(const Variable& other)
126 : {
127 1 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
128 1 : }
129 :
130 1 : void Variable::operator*=(uint16_t immediate)
131 : {
132 1 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
133 1 : }
134 :
135 1 : void Variable::operator-=(const Variable& other)
136 : {
137 1 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
138 1 : }
139 :
140 1 : void Variable::operator-=(uint16_t immediate)
141 : {
142 1 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
143 1 : }
144 :
145 0 : void Variable::operator&=(const Variable& other)
146 : {
147 0 : AppendToContext(context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, other));
148 0 : }
149 :
150 0 : void Variable::operator|=(const Variable& other)
151 : {
152 0 : AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, other));
153 0 : }
154 :
155 0 : void Variable::operator^=(const Variable& other)
156 : {
157 0 : AppendToContext(context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, other));
158 0 : }
159 :
160 6 : void Variable::VarVarLogicAppendToContext(CcuLogicOperator<Variable, Variable> op)
161 : {
162 6 : switch (op.type) {
163 2 : case CcuLogicOperatorType::AND: {
164 2 : AppendToContext(
165 4 : context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
166 2 : break;
167 : }
168 2 : case CcuLogicOperatorType::OR: {
169 2 : AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
170 2 : break;
171 : }
172 2 : case CcuLogicOperatorType::XOR: {
173 2 : AppendToContext(
174 4 : context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
175 2 : break;
176 : }
177 0 : default: {
178 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between var and var");
179 : }
180 : }
181 6 : }
182 :
183 1 : void Variable::AddrLogicAppendToContext(CcuLogicOperator<Variable> op)
184 : {
185 1 : switch (op.type) {
186 1 : case CcuLogicOperatorType::NOT: {
187 1 : AppendToContext(context, std::make_shared<CcuRepNot>(context->GetInsGenerator(), *this, op.lhs));
188 1 : break;
189 : }
190 0 : default: {
191 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between addr and immedB.");
192 : }
193 : }
194 1 : }
195 :
196 6 : void Variable::operator=(CcuLogicOperator<Variable, Variable> op) { VarVarLogicAppendToContext(op); }
197 :
198 1 : void Variable::operator=(CcuLogicOperator<Variable> op) { AddrLogicAppendToContext(op); }
199 :
200 4 : void Variable::operator=(CcuShiftOperator<Variable, Variable> op)
201 : {
202 4 : switch (op.type) {
203 2 : case CcuShiftType::RIGHT: {
204 2 : AppendToContext(
205 4 : context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
206 2 : break;
207 : }
208 2 : case CcuShiftType::LEFT: {
209 2 : AppendToContext(
210 4 : context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
211 2 : break;
212 : }
213 0 : default: {
214 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and immed.");
215 : }
216 : }
217 4 : }
218 :
219 0 : void Variable::operator<<=(const Variable& other) const
220 : {
221 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
222 0 : }
223 :
224 0 : void Variable::operator>>=(const Variable& other) const
225 : {
226 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
227 0 : }
228 :
229 10801 : Address::Address(CcuRepContext* context) : CcuVirRes(context) {}
230 :
231 19086 : Address::Address(const Address& other) : CcuVirRes(other.context) { phyRes = other.phyRes; }
232 :
233 91 : Address::Address(Variable&& other) : CcuVirRes(other.GetCurContext()) { phyRes = other.GetCurPhyRes(); }
234 :
235 0 : void Address::operator=(Address&& other)
236 : {
237 0 : phyRes = other.phyRes;
238 0 : context = other.context;
239 0 : }
240 :
241 39 : void Address::operator=(const Address& other)
242 : {
243 39 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
244 39 : }
245 :
246 15 : void Address::operator=(const Variable& other)
247 : {
248 15 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
249 15 : }
250 :
251 14 : void Address::operator=(uint64_t immediate)
252 : {
253 14 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
254 14 : }
255 :
256 1 : void Address::VarAddrAppendToContext(CcuArithmeticOperator<Variable, Address> op)
257 : {
258 1 : switch (op.type) {
259 1 : case CcuArithmeticOperatorType::ADDITION: {
260 1 : AppendToContext(
261 2 : context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
262 1 : break;
263 : }
264 0 : case CcuArithmeticOperatorType::MULTIPLICATION: {
265 0 : AppendToContext(
266 0 : context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
267 0 : break;
268 : }
269 0 : case CcuArithmeticOperatorType::SUBTRACTION: {
270 0 : AppendToContext(
271 0 : context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
272 0 : break;
273 : }
274 0 : default: {
275 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and addr.");
276 : }
277 : }
278 1 : }
279 1 : void Address::operator=(CcuArithmeticOperator<Variable, Address> op) { VarAddrAppendToContext(op); }
280 :
281 3 : void Address::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
282 : {
283 3 : switch (op.type) {
284 3 : case CcuArithmeticOperatorType::ADDITION: {
285 3 : AppendToContext(
286 6 : context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
287 3 : break;
288 : }
289 0 : default: {
290 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate in addr = addr (op) addr .");
291 : }
292 : }
293 3 : }
294 :
295 3 : void Address::operator=(CcuArithmeticOperator<Address, Address> op) { AddrAddrAppendToContext(op); }
296 :
297 0 : void Address::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
298 : {
299 0 : ArithmeticAppendToContext(context, *this, op);
300 0 : }
301 0 : void Address::operator=(CcuArithmeticOperator<Variable, uint16_t> op) { VarImmedAppendToContext(op); }
302 :
303 2 : void Address::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
304 : {
305 2 : ArithmeticAppendToContext(context, *this, op);
306 2 : }
307 2 : void Address::operator=(CcuArithmeticOperator<Address, uint16_t> op) { AddrImmedAppendToContext(op); }
308 :
309 0 : void Address::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
310 : {
311 0 : switch (op.type) {
312 0 : case CcuArithmeticOperatorType::ADDITION: {
313 0 : AppendToContext(
314 0 : context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
315 0 : break;
316 : }
317 0 : case CcuArithmeticOperatorType::MULTIPLICATION: {
318 0 : AppendToContext(
319 0 : context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
320 0 : break;
321 : }
322 0 : default: {
323 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and var.");
324 : }
325 : }
326 0 : }
327 :
328 0 : void Address::operator=(CcuArithmeticOperator<Variable, Variable> op) { VarVarAppendToContext(op); }
329 :
330 42 : void Address::operator+=(const Variable& other)
331 : {
332 42 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
333 42 : }
334 :
335 0 : void Address::operator+=(const uint16_t immediate)
336 : {
337 0 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
338 0 : }
339 :
340 0 : void Address::operator*=(const Variable& other)
341 : {
342 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
343 0 : }
344 :
345 0 : void Address::operator*=(const uint16_t immediate)
346 : {
347 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
348 0 : }
349 :
350 0 : void Address::operator-=(const Variable& other)
351 : {
352 0 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
353 0 : }
354 :
355 0 : void Address::operator-=(const uint16_t immediate)
356 : {
357 0 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
358 0 : }
359 :
360 0 : void Address::operator=(CcuShiftOperator<Variable, Variable> op)
361 : {
362 0 : switch (op.type) {
363 0 : case CcuShiftType::LEFT: {
364 0 : AppendToContext(
365 0 : context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
366 0 : break;
367 : }
368 0 : case CcuShiftType::RIGHT: {
369 0 : AppendToContext(
370 0 : context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
371 0 : break;
372 : }
373 0 : default: {
374 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and var.");
375 : }
376 : }
377 0 : }
378 :
379 0 : void Address::operator<<=(const Variable& other) const
380 : {
381 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
382 0 : }
383 :
384 0 : void Address::operator>>=(const Variable& other) const
385 : {
386 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
387 0 : }
388 :
389 10 : LocalNotify::LocalNotify(CcuRepContext* context) : CcuVirRes(context) {}
390 :
391 1 : CcuBuffer::CcuBuffer(CcuRepContext* context) : CcuVirRes(context) {}
392 :
393 377 : CcuBuf::CcuBuf(CcuRepContext* context) : CcuVirRes(context) {}
394 1 : uint16_t CcuBuffer::Id() const { return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId(); }
395 :
396 71 : uint16_t CcuBuf::Id() const { return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId(); }
397 :
398 113 : Executor::Executor(CcuRepContext* context) : CcuVirRes(context) {}
399 :
400 6001 : CompletedEvent::CompletedEvent(CcuRepContext* context) : CcuVirRes(context) {}
401 :
402 : }; // namespace CcuRep
403 : }; // namespace hcomm
|