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 3936 : uint16_t CcuPhyRes::Id() const
19 : {
20 3936 : return id;
21 : }
22 69 : uint16_t CcuPhyRes::DieId() const
23 : {
24 69 : return dieId;
25 : }
26 36185 : void CcuPhyRes::Reset(uint16_t id)
27 : {
28 36185 : this->id = id;
29 36185 : }
30 1419 : void CcuPhyRes::SetDieId(uint16_t dieId)
31 : {
32 1419 : this->dieId = dieId;
33 1419 : }
34 :
35 108942 : CcuVirRes::CcuVirRes(CcuRepContext *context) : context(context)
36 : {
37 108942 : phyRes = std::make_shared<CcuPhyRes>();
38 108942 : }
39 :
40 34769 : void CcuVirRes::Reset(uint16_t id)
41 : {
42 34769 : phyRes->Reset(id);
43 34769 : }
44 :
45 1415 : void CcuVirRes::Reset(uint16_t id, uint16_t dieId)
46 : {
47 1415 : phyRes->Reset(id);
48 1415 : phyRes->SetDieId(dieId);
49 1415 : }
50 :
51 3 : void CcuVirRes::SetDieId(uint16_t dieId)
52 : {
53 3 : phyRes->SetDieId(dieId);
54 3 : }
55 :
56 3871 : uint16_t CcuVirRes::Id() const
57 : {
58 3871 : return phyRes->Id();
59 : }
60 :
61 4 : uint16_t CcuVirRes::DieId() const
62 : {
63 4 : return phyRes->DieId();
64 : }
65 :
66 24875 : Variable::Variable(CcuRepContext* context) : CcuVirRes(context)
67 : {
68 24875 : }
69 :
70 53491 : Variable::Variable(const Variable& other): CcuVirRes(other.context)
71 : {
72 53491 : phyRes = other.phyRes;
73 53491 : }
74 :
75 288 : void Variable::operator=(Variable&& other)
76 : {
77 288 : phyRes = other.phyRes;
78 288 : context = other.context;
79 288 : }
80 :
81 78 : void Variable::operator=(const Variable &other)
82 : {
83 78 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
84 78 : }
85 :
86 207 : void Variable::operator=(uint64_t immediate)
87 : {
88 207 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
89 207 : }
90 :
91 : template <typename Dst, typename Lhs, typename Rhs>
92 113 : void ArithmeticAppendToContext(CcuRepContext* context, Dst& dst, CcuArithmeticOperator<Lhs, Rhs> op)
93 : {
94 113 : switch (op.type) {
95 103 : case CcuArithmeticOperatorType::ADDITION:
96 103 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
97 103 : break;
98 5 : case CcuArithmeticOperatorType::MULTIPLICATION:
99 5 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
100 5 : break;
101 5 : case CcuArithmeticOperatorType::SUBTRACTION:
102 5 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
103 5 : break;
104 0 : default:
105 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operator[%d].", op.type);
106 : }
107 113 : }
108 :
109 106 : void Variable::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
110 : {
111 106 : ArithmeticAppendToContext(context, *this, op);
112 106 : }
113 :
114 106 : void Variable::operator=(CcuArithmeticOperator<Variable, Variable> op)
115 : {
116 106 : VarVarAppendToContext(op);
117 106 : }
118 :
119 5 : void Variable::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
120 : {
121 5 : ArithmeticAppendToContext(context, *this, op);
122 5 : }
123 :
124 5 : void Variable::operator=(CcuArithmeticOperator<Variable, uint16_t> op)
125 : {
126 5 : VarImmedAppendToContext(op);
127 5 : }
128 :
129 :
130 0 : void Variable::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
131 : {
132 0 : ArithmeticAppendToContext(context, *this, op);
133 0 : }
134 :
135 0 : void Variable::operator=(CcuArithmeticOperator<Address, uint16_t> op)
136 : {
137 0 : AddrImmedAppendToContext(op);
138 0 : }
139 :
140 0 : void Variable::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
141 : {
142 0 : switch (op.type) {
143 0 : case CcuArithmeticOperatorType::ADDITION: {
144 0 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
145 0 : break;
146 : }
147 0 : default: {
148 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate in variable = addr (op) addr.");
149 : }
150 : }
151 0 : }
152 :
153 0 : void Variable::operator=(CcuArithmeticOperator<Address, Address> op)
154 : {
155 0 : AddrAddrAppendToContext(op);
156 0 : }
157 :
158 1 : void Variable::operator+=(const Variable &other)
159 : {
160 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
161 1 : }
162 :
163 1 : void Variable::operator+=(const uint16_t immediate)
164 : {
165 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
166 1 : }
167 :
168 1 : void Variable::operator*=(const Variable &other)
169 : {
170 1 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
171 1 : }
172 :
173 1 : void Variable::operator*=(uint16_t immediate)
174 : {
175 1 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
176 1 : }
177 :
178 1 : void Variable::operator-=(const Variable &other)
179 : {
180 1 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
181 1 : }
182 :
183 1 : void Variable::operator-=(uint16_t immediate)
184 : {
185 1 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
186 1 : }
187 :
188 0 : void Variable::operator&=(const Variable &other)
189 : {
190 0 : AppendToContext(context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, other));
191 0 : }
192 :
193 0 : void Variable::operator|=(const Variable &other)
194 : {
195 0 : AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, other));
196 0 : }
197 :
198 0 : void Variable::operator^=(const Variable &other)
199 : {
200 0 : AppendToContext(context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, other));
201 0 : }
202 :
203 6 : void Variable::VarVarLogicAppendToContext(CcuLogicOperator<Variable, Variable> op)
204 : {
205 6 : switch (op.type) {
206 2 : case CcuLogicOperatorType::AND: {
207 2 : AppendToContext(context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
208 2 : break;
209 : }
210 2 : case CcuLogicOperatorType::OR: {
211 2 : AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
212 2 : break;
213 : }
214 2 : case CcuLogicOperatorType::XOR: {
215 2 : AppendToContext(context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
216 2 : break;
217 : }
218 0 : default: {
219 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between var and var");
220 : }
221 : }
222 6 : }
223 :
224 1 : void Variable::AddrLogicAppendToContext(CcuLogicOperator<Variable> op)
225 : {
226 1 : switch (op.type) {
227 1 : case CcuLogicOperatorType::NOT: {
228 1 : AppendToContext(context, std::make_shared<CcuRepNot>(context->GetInsGenerator(), *this, op.lhs));
229 1 : break;
230 : }
231 0 : default: {
232 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between addr and immedB.");
233 : }
234 : }
235 1 : }
236 :
237 6 : void Variable::operator=(CcuLogicOperator<Variable, Variable> op)
238 : {
239 6 : VarVarLogicAppendToContext(op);
240 6 : }
241 :
242 1 : void Variable::operator=(CcuLogicOperator<Variable> op)
243 : {
244 1 : AddrLogicAppendToContext(op);
245 1 : }
246 :
247 0 : void Variable::operator=(CcuShiftOperator<Variable, Variable> op)
248 : {
249 0 : switch (op.type) {
250 0 : case CcuShiftType::RIGHT: {
251 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
252 0 : break;
253 : }
254 0 : case CcuShiftType::LEFT: {
255 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
256 0 : break;
257 : }
258 0 : default: {
259 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and immed.");
260 : }
261 : }
262 0 : }
263 :
264 0 : void Variable::operator<<=(const Variable &other) const
265 : {
266 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
267 0 : }
268 :
269 0 : void Variable::operator>>=(const Variable &other) const
270 : {
271 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
272 0 : }
273 :
274 9007 : Address::Address(CcuRepContext* context) : CcuVirRes(context)
275 : {
276 9007 : }
277 :
278 15941 : Address::Address(const Address& other): CcuVirRes(other.context)
279 : {
280 15941 : phyRes = other.phyRes;
281 15941 : }
282 :
283 91 : Address::Address(Variable &&other): CcuVirRes(other.GetCurContext())
284 : {
285 91 : phyRes = other.GetCurPhyRes();
286 91 : }
287 :
288 0 : void Address::operator=(Address&& other)
289 : {
290 0 : phyRes = other.phyRes;
291 0 : context = other.context;
292 0 : }
293 :
294 39 : void Address::operator=(const Address &other)
295 : {
296 39 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
297 39 : }
298 :
299 15 : void Address::operator=(const Variable &other)
300 : {
301 15 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
302 15 : }
303 :
304 12 : void Address::operator=(uint64_t immediate)
305 : {
306 12 : AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
307 12 : }
308 :
309 1 : void Address::VarAddrAppendToContext(CcuArithmeticOperator<Variable, Address> op)
310 : {
311 1 : switch (op.type) {
312 1 : case CcuArithmeticOperatorType::ADDITION: {
313 1 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
314 1 : break;
315 : }
316 0 : case CcuArithmeticOperatorType::MULTIPLICATION: {
317 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
318 0 : break;
319 : }
320 0 : case CcuArithmeticOperatorType::SUBTRACTION: {
321 0 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
322 0 : break;
323 : }
324 0 : default: {
325 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and addr.");
326 : }
327 : }
328 1 : }
329 1 : void Address::operator=(CcuArithmeticOperator<Variable, Address> op)
330 : {
331 1 : VarAddrAppendToContext(op);
332 1 : }
333 :
334 3 : void Address::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
335 : {
336 3 : switch (op.type) {
337 3 : case CcuArithmeticOperatorType::ADDITION: {
338 3 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
339 3 : break;
340 : }
341 0 : default: {
342 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate in addr = addr (op) addr .");
343 : }
344 : }
345 3 : }
346 :
347 3 : void Address::operator=(CcuArithmeticOperator<Address, Address> op)
348 : {
349 3 : AddrAddrAppendToContext(op);
350 3 : }
351 :
352 0 : void Address::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
353 : {
354 0 : ArithmeticAppendToContext(context, *this, op);
355 0 : }
356 0 : void Address::operator=(CcuArithmeticOperator<Variable, uint16_t> op)
357 : {
358 0 : VarImmedAppendToContext(op);
359 0 : }
360 :
361 2 : void Address::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
362 : {
363 2 : ArithmeticAppendToContext(context, *this, op);
364 2 : }
365 2 : void Address::operator=(CcuArithmeticOperator<Address, uint16_t> op)
366 : {
367 2 : AddrImmedAppendToContext(op);
368 2 : }
369 :
370 0 : void Address::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
371 : {
372 0 : switch (op.type) {
373 0 : case CcuArithmeticOperatorType::ADDITION: {
374 0 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
375 0 : break;
376 : }
377 0 : case CcuArithmeticOperatorType::MULTIPLICATION: {
378 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
379 0 : break;
380 : }
381 0 : default: {
382 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and var.");
383 : }
384 : }
385 0 : }
386 :
387 0 : void Address::operator=(CcuArithmeticOperator<Variable, Variable> op)
388 : {
389 0 : VarVarAppendToContext(op);
390 0 : }
391 :
392 42 : void Address::operator+=(const Variable &other)
393 : {
394 42 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
395 42 : }
396 :
397 0 : void Address::operator+=(const uint16_t immediate)
398 : {
399 0 : AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
400 0 : }
401 :
402 0 : void Address::operator*=(const Variable &other)
403 : {
404 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
405 0 : }
406 :
407 0 : void Address::operator*=(const uint16_t immediate)
408 : {
409 0 : AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
410 0 : }
411 :
412 0 : void Address::operator-=(const Variable &other)
413 : {
414 0 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
415 0 : }
416 :
417 0 : void Address::operator-=(const uint16_t immediate)
418 : {
419 0 : AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
420 0 : }
421 :
422 0 : void Address::operator=(CcuShiftOperator<Variable, Variable> op)
423 : {
424 0 : switch (op.type) {
425 0 : case CcuShiftType::LEFT: {
426 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
427 0 : break;
428 : }
429 0 : case CcuShiftType::RIGHT: {
430 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
431 0 : break;
432 : }
433 0 : default: {
434 0 : Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and var.");
435 : }
436 : }
437 0 : }
438 :
439 0 : void Address::operator<<=(const Variable &other) const
440 : {
441 0 : AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
442 0 : }
443 :
444 0 : void Address::operator>>=(const Variable &other) const
445 : {
446 0 : AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
447 0 : }
448 :
449 10 : LocalNotify::LocalNotify(CcuRepContext* context) : CcuVirRes(context)
450 : {
451 10 : }
452 :
453 1 : CcuBuffer::CcuBuffer(CcuRepContext* context) : CcuVirRes(context)
454 : {
455 1 : }
456 :
457 375 : CcuBuf::CcuBuf(CcuRepContext* context) : CcuVirRes(context)
458 : {
459 375 : }
460 1 : uint16_t CcuBuffer::Id() const
461 : {
462 1 : return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId();
463 : }
464 :
465 63 : uint16_t CcuBuf::Id() const
466 : {
467 63 : return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId();
468 : }
469 :
470 113 : Executor::Executor(CcuRepContext* context) : CcuVirRes(context)
471 : {
472 113 : }
473 :
474 5036 : CompletedEvent::CompletedEvent(CcuRepContext* context) : CcuVirRes(context)
475 : {
476 5036 : }
477 :
478 : }; // namespace CcuRep
479 : }; // namespace hcomm
|