DFT-EFE
 
Loading...
Searching...
No Matches
DeviceDataTypeOverloads.hip.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16
17
18#ifndef dftefeDeviceDataTypeOverloads_hiph
19#define dftefeDeviceDataTypeOverloads_hiph
20
21#include <complex>
22#include <hip/hip_complex.h>
23#include <hip/hip_runtime.h>
24#include <utils/TypeConfig.h>
25
26namespace dftefe
27{
28 namespace utils
29 {
30 template <typename T1, typename T2>
31 __device__ inline void
32 atomicAddWrapper(T1 *addr, T2 value)
33 {
34 atomicAdd(addr, value);
35 }
36
37 __forceinline__ __device__ hipDoubleComplex
38 makeComplex(double realPart, double imagPart)
39 {
40 return make_hipDoubleComplex(realPart, imagPart);
41 }
42
43 __forceinline__ __device__ hipFloatComplex
44 makeComplex(float realPart, float imagPart)
45 {
46 return make_hipFloatComplex(realPart, imagPart);
47 }
48
49 //
50 // copyValue for homogeneous types
51 //
52 __forceinline__ __device__ void
53 copyValue(double *a, const double b)
54 {
55 *a = b;
56 }
57
58 __forceinline__ __device__ void
59 copyValue(float *a, const float b)
60 {
61 *a = b;
62 }
63
64 __forceinline__ __device__ void
65 copyValue(hipDoubleComplex *a, const hipDoubleComplex b)
66 {
67 *a = b;
68 }
69
70 __forceinline__ __device__ void
71 copyValue(hipFloatComplex *a, const hipFloatComplex b)
72 {
73 *a = b;
74 }
75
76 //
77 // copyValue for heteregenous types
78 //
79 __forceinline__ __device__ void
80 copyValue(float *a, const double b)
81 {
82 *a = b;
83 }
84
85 __forceinline__ __device__ void
86 copyValue(double *a, const float b)
87 {
88 *a = b;
89 }
90
91 __forceinline__ __device__ void
92 copyValue(hipDoubleComplex *a, const hipFloatComplex b)
93 {
94 *a = make_hipDoubleComplex(b.x, b.y);
95 }
96
97 __forceinline__ __device__ void
98 copyValue(hipFloatComplex *a, const hipDoubleComplex b)
99 {
100 *a = make_hipFloatComplex(b.x, b.y);
101 }
102
103 __forceinline__ __device__ void
104 copyValue(hipDoubleComplex *a, const double b)
105 {
106 *a = make_hipDoubleComplex(b, 0);
107 }
108
109 __forceinline__ __device__ void
110 copyValue(hipFloatComplex *a, const float b)
111 {
112 *a = make_hipFloatComplex(b, 0);
113 }
114
115 __forceinline__ __device__ void
116 copyValue(hipDoubleComplex *a, const float b)
117 {
118 *a = make_hipDoubleComplex(b, 0);
119 }
120
121 __forceinline__ __device__ void
122 copyValue(hipFloatComplex *a, const double b)
123 {
124 *a = make_hipFloatComplex(b, 0);
125 }
126
127 // real part obverloads
128
129 __forceinline__ __device__ double
130 realPartDevice(double a)
131 {
132 return a;
133 }
134
135 __forceinline__ __device__ float
136 realPartDevice(float a)
137 {
138 return a;
139 }
140
141 __forceinline__ __device__ double
142 realPartDevice(hipDoubleComplex a)
143 {
144 return a.x;
145 }
146
147 __forceinline__ __device__ float
148 realPartDevice(hipFloatComplex a)
149 {
150 return a.x;
151 }
152
153 // imag part obverloads
154
155 __forceinline__ __device__ double
156 imagPartDevice(double a)
157 {
158 return 0;
159 }
160
161 __forceinline__ __device__ float
162 imagPartDevice(float a)
163 {
164 return 0;
165 }
166
167 __forceinline__ __device__ double
168 imagPartDevice(hipDoubleComplex a)
169 {
170 return a.y;
171 }
172
173 __forceinline__ __device__ float
174 imagPartDevice(hipFloatComplex a)
175 {
176 return a.y;
177 }
178
179 // abs obverloads
180
181 __forceinline__ __device__ double
182 abs(double a)
183 {
184 return fabs(a);
185 }
186
187 __forceinline__ __device__ float
188 abs(float a)
189 {
190 return fabs(a);
191 }
192
193 __forceinline__ __device__ double
194 abs(hipDoubleComplex a)
195 {
196 return hipCabs(a);
197 }
198
199 __forceinline__ __device__ float
200 abs(hipFloatComplex a)
201 {
202 return hipCabsf(a);
203 }
204
205 //
206 // conjugate overloads
207 //
208
209 __forceinline__ __device__ unsigned int
210 conj(unsigned int a)
211 {
212 return a;
213 }
214
215 __forceinline__ __device__ unsigned long int
216 conj(unsigned long int a)
217 {
218 return a;
219 }
220
221 __forceinline__ __device__ int
222 conj(int a)
223 {
224 return a;
225 }
226
227 __forceinline__ __device__ float
228 conj(float a)
229 {
230 return a;
231 }
232 __forceinline__ __device__ double
233 conj(double a)
234 {
235 return a;
236 }
237
238 __forceinline__ __device__ hipDoubleComplex
239 conj(hipDoubleComplex a)
240 {
241 return hipConj(a);
242 }
243
244 __forceinline__ __device__ hipFloatComplex
245 conj(hipFloatComplex a)
246 {
247 return hipConjf(a);
248 }
249
250
251 //
252 // mult for real homogeneous types e.g. (double, double)
253 //
254 __forceinline__ __device__ unsigned int
255 mult(unsigned int a, unsigned int b)
256 {
257 return a * b;
258 }
259
260 __forceinline__ __device__ unsigned long int
261 mult(unsigned long int a, unsigned long int b)
262 {
263 return a * b;
264 }
265
266 __forceinline__ __device__ int
267 mult(int a, int b)
268 {
269 return a * b;
270 }
271
272 __forceinline__ __device__ double
273 mult(double a, double b)
274 {
275 return a * b;
276 }
277
278 __forceinline__ __device__ float
279 mult(float a, float b)
280 {
281 return a * b;
282 }
283
284 __forceinline__ __device__ double
285 mult(float a, double b)
286 {
287 return a * b;
288 }
289
290 __forceinline__ __device__ double
291 mult(double a, float b)
292 {
293 return a * b;
294 }
295
296 //
297 // mult for complex homogenous types
298 // (e.g., hipDoubleComplex and hipDoubleComplex)
299 //
300 __forceinline__ __device__ hipDoubleComplex
301 mult(hipDoubleComplex a, hipDoubleComplex b)
302 {
303 return hipCmul(a, b);
304 }
305
306 __forceinline__ __device__ hipFloatComplex
307 mult(hipFloatComplex a, hipFloatComplex b)
308 {
309 return hipCmulf(a, b);
310 }
311
312
313 //
314 // mult for complex heterogeneous types e.g. (hipDoubleComplex,
315 // hipFloatComplex)
316 //
317 __forceinline__ __device__ hipDoubleComplex
318 mult(hipFloatComplex a, hipDoubleComplex b)
319 {
320 return hipCmul(make_hipDoubleComplex(a.x, a.y), b);
321 }
322
323 __forceinline__ __device__ hipDoubleComplex
324 mult(hipDoubleComplex a, hipFloatComplex b)
325 {
326 return hipCmul(a, make_hipDoubleComplex(b.x, b.y));
327 }
328
329
330 //
331 // mult for real-complex heterogeneous types e.g. (double, hipFloatComplex)
332 //
333 __forceinline__ __device__ hipDoubleComplex
334 mult(double a, hipDoubleComplex b)
335 {
336 return make_hipDoubleComplex(a * b.x, a * b.y);
337 }
338
339 __forceinline__ __device__ hipDoubleComplex
340 mult(hipDoubleComplex a, double b)
341 {
342 return make_hipDoubleComplex(b * a.x, b * a.y);
343 }
344
345 __forceinline__ __device__ hipFloatComplex
346 mult(float a, hipFloatComplex b)
347 {
348 return make_hipFloatComplex(a * b.x, a * b.y);
349 }
350
351 __forceinline__ __device__ hipFloatComplex
352 mult(hipFloatComplex a, float b)
353 {
354 return make_hipFloatComplex(b * a.x, b * a.y);
355 }
356
357 __forceinline__ __device__ hipDoubleComplex
358 mult(double a, hipFloatComplex b)
359 {
360 return make_hipDoubleComplex(a * b.x, a * b.y);
361 }
362
363 __forceinline__ __device__ hipDoubleComplex
364 mult(hipFloatComplex a, double b)
365 {
366 return make_hipDoubleComplex(b * a.x, b * a.y);
367 }
368
369
370 __forceinline__ __device__ unsigned int
371 add(unsigned int a, unsigned int b)
372 {
373 return a + b;
374 }
375
376 __forceinline__ __device__ unsigned long int
377 add(unsigned long int a, unsigned long int b)
378 {
379 return a + b;
380 }
381
382 __forceinline__ __device__ int
383 add(int a, int b)
384 {
385 return a + b;
386 }
387
388 __forceinline__ __device__ double
389 add(double a, double b)
390 {
391 return a + b;
392 }
393
394 __forceinline__ __device__ float
395 add(float a, float b)
396 {
397 return a + b;
398 }
399
400 __forceinline__ __device__ hipDoubleComplex
401 add(hipDoubleComplex a, hipDoubleComplex b)
402 {
403 return hipCadd(a, b);
404 }
405
406
407 __forceinline__ __device__ hipFloatComplex
408 add(hipFloatComplex a, hipFloatComplex b)
409 {
410 return hipCaddf(a, b);
411 }
412
413 __forceinline__ __device__ double
414 add(double a, float b)
415 {
416 return a + b;
417 }
418
419 __forceinline__ __device__ double
420 add(float a, double b)
421 {
422 return a + b;
423 }
424
425 __forceinline__ __device__ hipDoubleComplex
426 add(hipDoubleComplex a, hipFloatComplex b)
427 {
428 return hipCadd(a, make_hipDoubleComplex(b.x, b.y));
429 }
430
431
432 __forceinline__ __device__ hipDoubleComplex
433 add(hipFloatComplex a, hipDoubleComplex b)
434 {
435 return hipCadd(make_hipDoubleComplex(a.x, a.y), b);
436 }
437
438
439 __forceinline__ __device__ unsigned int
440 sub(unsigned int a, unsigned int b)
441 {
442 return a - b;
443 }
444
445 __forceinline__ __device__ unsigned long int
446 sub(unsigned long int a, unsigned long int b)
447 {
448 return a - b;
449 }
450
451 __forceinline__ __device__ int
452 sub(int a, int b)
453 {
454 return a - b;
455 }
456
457 __forceinline__ __device__ double
458 sub(double a, double b)
459 {
460 return a - b;
461 }
462
463 __forceinline__ __device__ float
464 sub(float a, float b)
465 {
466 return a - b;
467 }
468
469 __forceinline__ __device__ hipDoubleComplex
470 sub(hipDoubleComplex a, hipDoubleComplex b)
471 {
472 return hipCsub(a, b);
473 }
474
475 __forceinline__ __device__ hipFloatComplex
476 sub(hipFloatComplex a, hipFloatComplex b)
477 {
478 return hipCsubf(a, b);
479 }
480
481 __forceinline__ __device__ unsigned int
482 div(unsigned int a, unsigned int b)
483 {
484 return a / b;
485 }
486
487 __forceinline__ __device__ unsigned long int
488 div(unsigned long int a, unsigned long int b)
489 {
490 return a / b;
491 }
492
493 __forceinline__ __device__ int
494 div(int a, int b)
495 {
496 return a / b;
497 }
498
499 __forceinline__ __device__ double
500 div(double a, double b)
501 {
502 return a / b;
503 }
504
505 __forceinline__ __device__ float
506 div(float a, float b)
507 {
508 return a / b;
509 }
510
511 __forceinline__ __device__ double
512 div(float a, double b)
513 {
514 return (double)a / b;
515 }
516
517 __forceinline__ __device__ double
518 div(double a, float b)
519 {
520 return a / (double)b;
521 }
522
523 __forceinline__ __device__ hipDoubleComplex
524 div(hipDoubleComplex a, hipDoubleComplex b)
525 {
526 return hipCdiv(a, b);
527 }
528
529 __forceinline__ __device__ hipFloatComplex
530 div(hipFloatComplex a, hipFloatComplex b)
531 {
532 return hipCdivf(a, b);
533 }
534
535 //
536 // div for complex heterogeneous types e.g. (hipDoubleComplex,
537 // hipFloatComplex)
538 //
539 __forceinline__ __device__ hipDoubleComplex
540 div(hipFloatComplex a, hipDoubleComplex b)
541 {
542 return hipCdiv(make_hipDoubleComplex(a.x, a.y), b);
543 }
544
545 __forceinline__ __device__ hipDoubleComplex
546 div(hipDoubleComplex a, hipFloatComplex b)
547 {
548 return hipCdiv(a, make_hipDoubleComplex(b.x, b.y));
549 }
550
551
552 //
553 // div for real-complex heterogeneous types e.g. (double, hipFloatComplex)
554 //
555 __forceinline__ __device__ hipDoubleComplex
556 div(double a, hipDoubleComplex b)
557 {
558 return make_hipDoubleComplex(a / b.x, a / b.y);
559 }
560
561 __forceinline__ __device__ hipDoubleComplex
562 div(hipDoubleComplex a, double b)
563 {
564 return make_hipDoubleComplex(b / a.x, b / a.y);
565 }
566
567 __forceinline__ __device__ hipFloatComplex
568 div(float a, hipFloatComplex b)
569 {
570 return make_hipFloatComplex(a / b.x, a / b.y);
571 }
572
573 __forceinline__ __device__ hipFloatComplex
574 div(hipFloatComplex a, float b)
575 {
576 return make_hipFloatComplex(b / a.x, b / a.y);
577 }
578
579 __forceinline__ __device__ hipDoubleComplex
580 div(double a, hipFloatComplex b)
581 {
582 return make_hipDoubleComplex(a / b.x, a / b.y);
583 }
584
585 __forceinline__ __device__ hipDoubleComplex
586 div(hipFloatComplex a, double b)
587 {
588 return make_hipDoubleComplex(b / a.x, b / a.y);
589 }
590
592
593
594 inline int *
596 {
597 return a;
598 }
599
600 inline const int *
601 makeDataTypeDeviceCompatible(const int *a)
602 {
603 return a;
604 }
605
606 inline long int *
608 {
609 return a;
610 }
611
612 inline const long int *
613 makeDataTypeDeviceCompatible(const long int *a)
614 {
615 return a;
616 }
617
618 inline long long int *
619 makeDataTypeDeviceCompatible(long long int *a)
620 {
621 return a;
622 }
623
624 inline const long long int *
625 makeDataTypeDeviceCompatible(const long long int *a)
626 {
627 return a;
628 }
629
630
631 inline unsigned int *
632 makeDataTypeDeviceCompatible(unsigned int *a)
633 {
634 return a;
635 }
636
637 inline const unsigned int *
638 makeDataTypeDeviceCompatible(const unsigned int *a)
639 {
640 return a;
641 }
642
643 inline unsigned long int *
644 makeDataTypeDeviceCompatible(unsigned long int *a)
645 {
646 return a;
647 }
648
649 inline const unsigned long int *
650 makeDataTypeDeviceCompatible(const unsigned long int *a)
651 {
652 return a;
653 }
654
655 inline unsigned long long int *
656 makeDataTypeDeviceCompatible(unsigned long long int *a)
657 {
658 return a;
659 }
660
661 inline const unsigned long long int *
662 makeDataTypeDeviceCompatible(const unsigned long long int *a)
663 {
664 return a;
665 }
666
667 inline double *
669 {
670 return a;
671 }
672
673 inline const double *
674 makeDataTypeDeviceCompatible(const double *a)
675 {
676 return a;
677 }
678
679 inline float *
681 {
682 return a;
683 }
684
685 inline const float *
686 makeDataTypeDeviceCompatible(const float *a)
687 {
688 return a;
689 }
690
691 inline hipDoubleComplex *
692 makeDataTypeDeviceCompatible(std::complex<double> *a)
693 {
694 return reinterpret_cast<hipDoubleComplex *>(a);
695 }
696
697 inline const hipDoubleComplex *
698 makeDataTypeDeviceCompatible(const std::complex<double> *a)
699 {
700 return reinterpret_cast<const hipDoubleComplex *>(a);
701 }
702
703 inline hipFloatComplex *
704 makeDataTypeDeviceCompatible(std::complex<float> *a)
705 {
706 return reinterpret_cast<hipFloatComplex *>(a);
707 }
708
709 inline const hipFloatComplex *
710 makeDataTypeDeviceCompatible(const std::complex<float> *a)
711 {
712 return reinterpret_cast<const hipFloatComplex *>(a);
713 }
714
715 inline int
717 {
718 return a;
719 }
720
721 inline long int
723 {
724 return a;
725 }
726
727 inline unsigned int
728 makeDataTypeDeviceCompatible(unsigned int a)
729 {
730 return a;
731 }
732
733 inline unsigned long int
734 makeDataTypeDeviceCompatible(unsigned long int a)
735 {
736 return a;
737 }
738
739 inline double
741 {
742 return a;
743 }
744
745 inline float
747 {
748 return a;
749 }
750
751 inline hipDoubleComplex
752 makeDataTypeDeviceCompatible(std::complex<double> a)
753 {
754 return make_hipDoubleComplex(a.real(), a.imag());
755 }
756
757 inline hipFloatComplex
758 makeDataTypeDeviceCompatible(std::complex<float> a)
759 {
760 return make_hipFloatComplex(a.real(), a.imag());
761 }
762
763
764 inline bool
766 {
767 return a;
768 }
769
770 inline bool *
772 {
773 return a;
774 }
775 } // namespace utils
776
777} // namespace dftefe
778
779#endif
__forceinline__ __device__ void copyValue(double *a, const double b)
Definition: DeviceDataTypeOverloads.cu.h:53
__forceinline__ __device__ unsigned int div(unsigned int a, unsigned int b)
Definition: DeviceDataTypeOverloads.cu.h:482
__forceinline__ __device__ unsigned int mult(unsigned int a, unsigned int b)
Definition: DeviceDataTypeOverloads.cu.h:255
__forceinline__ __device__ double imagPartDevice(double a)
Definition: DeviceDataTypeOverloads.cu.h:156
__forceinline__ __device__ unsigned int sub(unsigned int a, unsigned int b)
Definition: DeviceDataTypeOverloads.cu.h:440
RealType< T >::Type imagPart(const T &x)
Definition: DataTypeOverloads.h:132
__forceinline__ __device__ double realPartDevice(double a)
Definition: DeviceDataTypeOverloads.cu.h:130
__forceinline__ __device__ double abs(double a)
Definition: DeviceDataTypeOverloads.cu.h:182
int * makeDataTypeDeviceCompatible(int *a)
Definition: DeviceDataTypeOverloads.cu.h:595
__forceinline__ __device__ unsigned int conj(unsigned int a)
Definition: DeviceDataTypeOverloads.cu.h:210
__device__ void atomicAddWrapper(T1 *addr, T2 value)
Definition: DeviceDataTypeOverloads.cu.h:32
RealType< T >::Type realPart(const T &x)
Definition: DataTypeOverloads.h:94
__forceinline__ __device__ unsigned int add(unsigned int a, unsigned int b)
Definition: DeviceDataTypeOverloads.cu.h:371
__forceinline__ __device__ cuDoubleComplex makeComplex(double realPart, double imagPart)
Definition: DeviceDataTypeOverloads.cu.h:38
dealii includes
Definition: AtomFieldDataSpherical.cpp:31