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