Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
math.hip
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#include <hip/hip_runtime.h>
37#include <device/hip/check.h>
38#include <device/hip/buffer.h>
39#include <device/hip/unified.h>
40#include "math_kernel.h"
41
42extern "C" {
43
46
47#ifdef HAVE_RCCL
50#endif
51
55 void hip_copy(void *a, void *b, int *n, hipStream_t strm) {
56 if (hip_zerocopy()) {
57 if (*n == 0) return;
58 /* The pointers may alias pageable host memory, which hipMemcpy
59 treats as a staged pageable copy (slow, serializing); copy
60 with a kernel instead, which runs at full memory bandwidth
61 on any pointer */
62 const dim3 nthrds(1024, 1, 1);
63 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
64
66 nblcks, nthrds, 0, strm,
67 (real *) a, (const real *) b, *n);
69 return;
70 }
71 HIP_CHECK(hipMemcpyAsync(a, b, (*n) * sizeof(real),
73 }
74
78 void hip_masked_copy_0(void *a, void *b, void *mask,
79 int *n, int *m, hipStream_t strm) {
80
81 const dim3 nthrds(1024, 1, 1);
82 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
83
85 nblcks, nthrds, 0, strm, (real *) a,
86 (real *) b, (int *) mask, *n, *m);
87
89
90 }
91
95 void hip_masked_copy_aligned(void *a, void *b, void *mask,
96 int *n, int *m, hipStream_t strm) {
97
98 const dim3 nthrds(1024, 1, 1);
99 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
100
102 nblcks, nthrds, 0, strm, (real *) a,
103 (real *) b, (int *) mask, *n, *m);
104
106
107 }
108
112 void hip_masked_gather_copy(void *a, void *b, void *mask,
113 int *n, int *m, hipStream_t strm) {
114
115 const dim3 nthrds(1024, 1, 1);
116 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
117
119 nblcks, nthrds, 0, strm, (real *) a,
120 (real *) b, (int *) mask, *n, *m);
122
123 }
124
128 void hip_masked_gather_copy_aligned(void *a, void *b, void *mask,
129 int *n, int *m, hipStream_t strm) {
130
131 const dim3 nthrds(1024, 1, 1);
132 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
133
135 nblcks, nthrds, 0, strm, (real *) a,
136 (real *) b, (int *) mask, *n, *m);
138
139 }
140
144 void hip_face_masked_gather_copy(void *a, void *b, void *mask,
145 void *facet, int *n1, int *n2, int *lx,
146 int *ly, int *lz, int *m,
148
149 const dim3 nthrds(1024, 1, 1);
150 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
151
153 nblcks, nthrds, 0, strm, (real *) a, (real *) b,
154 (int *) mask, (int *) facet, *n1, *n2, *lx, *ly, *lz,
155 *m);
157
158 }
159
160
164 void hip_masked_scatter_copy(void *a, void *b, void *mask,
165 int *n, int *m, hipStream_t strm) {
166
167 const dim3 nthrds(1024, 1, 1);
168 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
169
171 nblcks, nthrds, 0, strm, (real *) a,
172 (real *) b, (int *) mask, *n, *m);
173
175
176 }
177
181 void hip_masked_scatter_copy_aligned(void *a, void *b, void *mask,
182 int *n, int *m, hipStream_t strm) {
183
184 const dim3 nthrds(1024, 1, 1);
185 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
186
188 nblcks, nthrds, 0, strm, (real *) a,
189 (real *) b, (int *) mask, *n, *m);
190
192
193 }
194
198 void hip_masked_atomic_reduction(void *a, void *b, void *mask,
199 int *n, int *m, hipStream_t strm) {
200
202 const dim3 nblcks(((*m) + MASKED_ATOMIC_RED_BLOCK - 1) /
204
206 nblcks, nthrds, 0, strm, (real *) a,
207 (real *) b, (int *) mask, *n, *m);
208
210
211 }
212
216 void hip_cfill_mask(void* a, real* c, int* size, void* mask, int* mask_size,
218
219 const dim3 nthrds(1024, 1, 1);
220 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
221
223 nblcks, nthrds, 0, strm, (real*)a,
224 *c, *size, (int*)mask, *mask_size);
225
227 }
228
232 void hip_rzero(void *a, int *n, hipStream_t strm) {
233 if (hip_zerocopy()) {
234 if (*n == 0) return;
235 /* a may alias pageable host memory, which hipMemset rejects;
236 zero with a kernel instead (works on any pointer) */
237 const dim3 nthrds(1024, 1, 1);
238 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
239
241 nblcks, nthrds, 0, strm,
242 (real *) a, (real) 0.0, *n);
244 return;
245 }
246 HIP_CHECK(hipMemsetAsync(a, 0, (*n) * sizeof(real), strm));
247 }
248
252 void hip_cmult(void *a, real *c, int *n, hipStream_t strm) {
253
254 const dim3 nthrds(1024, 1, 1);
255 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
256
258 nblcks, nthrds, 0, strm, (real *) a, *c, *n);
260
261 }
262
266 void hip_cmult2(void *a, void *b, real *c, int *n, hipStream_t strm) {
267
268 const dim3 nthrds(1024, 1, 1);
269 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
270
272 nblcks, nthrds, 0, strm, (real *) a,(real *) b, *c, *n);
274
275 }
276
280 void hip_cdiv(void *a, real *c, int *n, hipStream_t strm) {
281
282 const dim3 nthrds(1024, 1, 1);
283 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
284
286 nblcks, nthrds, 0, strm, (real *) a, *c, *n);
288
289 }
290
294 void hip_cdiv2(void *a, void *b, real *c, int *n, hipStream_t strm) {
295
296 const dim3 nthrds(1024, 1, 1);
297 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
298
300 nblcks, nthrds, 0, strm, (real *) a,(real *) b, *c, *n);
302
303 }
304
308 void hip_radd(void *a, real *c, int *n, hipStream_t strm) {
309
310 const dim3 nthrds(1024, 1, 1);
311 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
312
314 nblcks, nthrds, 0, strm, (real *) a, *c, *n);
316 }
317
322 void hip_cadd2(void *a, void *b, real *c, int *n, hipStream_t strm) {
323
324 const dim3 nthrds(1024, 1, 1);
325 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
326
328 nblcks, nthrds, 0, strm, (real *) a, (real *) b, *c, *n);
330 }
331
336 void hip_cwrap(void *a, real *min_val, real *max_val, int *n,
338
339 const dim3 nthrds(1024, 1, 1);
340 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
341
343 nblcks, nthrds, 0, strm, (real *) a,
344 *min_val, *max_val, *n);
346 }
347
351 void hip_sqrt_inplace(void *a, int *n, hipStream_t strm) {
352
353 const dim3 nthrds(1024, 1, 1);
354 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
355
357 nblcks, nthrds, 0, strm, (real *) a, *n);
359 }
360
364 void hip_power(void *ap, void *a, real *p, int *n, hipStream_t strm) {
365
366 const dim3 nthrds(1024, 1, 1);
367 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
368
370 nblcks, nthrds, 0, strm,
371 (real *) ap, (real *) a, *p, *n);
373 }
374
378 void hip_cfill(void *a, real *c, int *n, hipStream_t strm) {
379
380 const dim3 nthrds(1024, 1, 1);
381 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
382
383 if (*n > 0) {
385 nblcks, nthrds, 0, strm, (real *) a, *c, *n);
387 }
388
389 }
390
395 void hip_add2(void *a, void *b, int *n, hipStream_t strm) {
396
397 const dim3 nthrds(1024, 1, 1);
398 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
399
401 nblcks, nthrds, 0, strm, (real *) a, (real *) b, *n);
403
404 }
405
410 void hip_add3(void *a, void *b, void *c, int *n, hipStream_t strm) {
411
412 const dim3 nthrds(1024, 1, 1);
413 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
414
416 nblcks, nthrds, 0, strm, (real *) a,
417 (real *) b, (real *) c, *n);
419 }
420
425 void hip_add4(void *a, void *b, void *c, void *d, int *n, hipStream_t strm) {
426
427 const dim3 nthrds(1024, 1, 1);
428 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
429
431 nblcks, nthrds, 0, strm, (real *) a,
432 (real *) b, (real *) c, (real *) d, *n);
434 }
435
441 void hip_add2s1(void *a, void *b, real *c1, int *n, hipStream_t strm) {
442
443 const dim3 nthrds(1024, 1, 1);
444 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
445
447 nblcks, nthrds, 0, strm, (real *) a,
448 (real *) b, *c1, *n);
450 }
451
457 void hip_add2s2(void *a, void *b, real *c1, int *n, hipStream_t strm) {
458
459 const dim3 nthrds(1024, 1, 1);
460 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
461
463 nblcks, nthrds, 0, strm, (real *) a, (real *) b,
464 *c1, *n);
466 }
467
474 void hip_add2s2_many(void *x, void **p, void *alpha, int *j, int *n,
476
477 const dim3 nthrds(1024, 1, 1);
478 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
479
481 nblcks, nthrds, 0, strm, (real *) x,
482 (const real **) p, (real *) alpha, *j, *n);
484
485 }
486
492 void hip_addsqr2s2(void *a, void *b, real *c1, int *n, hipStream_t strm) {
493
494 const dim3 nthrds(1024, 1, 1);
495 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
496
498 nblcks, nthrds, 0, strm, (real *) a,
499 (real *) b, *c1, *n);
501 }
502
508 void hip_add3s2(void *a, void *b, void *c, real *c1, real *c2, int *n,
510
511 const dim3 nthrds(1024, 1, 1);
512 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
513
515 nblcks, nthrds, 0, strm, (real *) a,
516 (real *) b, (real *) c, *c1, *c2, *n);
518 }
519
525 void hip_add4s3(void *a, void *b, void *c, void *d, real *c1, real *c2,
526 real *c3, int *n, hipStream_t strm) {
527
528 const dim3 nthrds(1024, 1, 1);
529 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
530
532 nblcks, nthrds, 0, strm, (real *) a,
533 (real *) b, (real *) c, (real *) d, *c1, *c2, *c3, *n);
535 }
536
542 void hip_add5s4(void *a, void *b, void *c, void *d, void *e, real *c1,
543 real *c2, real *c3, real *c4, int *n, hipStream_t strm) {
544
545 const dim3 nthrds(1024, 1, 1);
546 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
547
549 nblcks, nthrds, 0, strm, (real *) a,
550 (real *) b, (real *) c, (real *) d, (real *) e,
551 *c1, *c2, *c3, *c4, *n);
553 }
554
559 void hip_invcol1(void *a, int *n, hipStream_t strm) {
560
561 const dim3 nthrds(1024, 1, 1);
562 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
563
565 nblcks, nthrds, 0, strm, (real *) a, *n);
567 }
568
573 void hip_invcol2(void *a, void *b, int *n, hipStream_t strm) {
574
575 const dim3 nthrds(1024, 1, 1);
576 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
577
579 nblcks, nthrds, 0, strm, (real *) a, (real *) b, *n);
581 }
582
587 void hip_invcol3(void *a, void *b, void *c, int *n, hipStream_t strm) {
588
589 const dim3 nthrds(1024, 1, 1);
590 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
591
593 nblcks, nthrds, 0, strm, (real *) a,
594 (real *) b, (real *) c, *n);
596 }
597
602 void hip_col2(void *a, void *b, int *n, hipStream_t strm) {
603
604 const dim3 nthrds(1024, 1, 1);
605 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
606
608 nblcks, nthrds, 0, strm, (real *) a,
609 (real *) b, *n);
611 }
612
617 void hip_col3(void *a, void *b, void *c, int *n, hipStream_t strm) {
618
619 const dim3 nthrds(1024, 1, 1);
620 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
621
623 nblcks, nthrds, 0, strm, (real *) a,
624 (real *) b, (real *) c, *n);
626 }
627
632 void hip_subcol3(void *a, void *b, void *c, int *n, hipStream_t strm) {
633
634 const dim3 nthrds(1024, 1, 1);
635 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
636
638 nblcks, nthrds, 0, strm, (real *) a,
639 (real *) b, (real *) c, *n);
641 }
642
647 void hip_sub2(void *a, void *b, int *n, hipStream_t strm) {
648
649 const dim3 nthrds(1024, 1, 1);
650 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
651
653 nblcks, nthrds, 0, strm, (real *) a,
654 (real *) b, *n);
656 }
657
662 void hip_sub3(void *a, void *b, void *c, int *n, hipStream_t strm) {
663
664 const dim3 nthrds(1024, 1, 1);
665 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
666
668 nblcks, nthrds, 0, strm, (real *) a,
669 (real *) b, (real *) c, *n);
671 }
672
677 void hip_addcol3(void *a, void *b, void *c, int *n, hipStream_t strm) {
678
679 const dim3 nthrds(1024, 1, 1);
680 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
681
683 nblcks, nthrds, 0, strm, (real *) a,
684 (real *) b, (real *) c, *n);
686 }
687
692 void hip_addcol4(void *a, void *b, void *c, void *d, int *n,
694
695 const dim3 nthrds(1024, 1, 1);
696 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
697
699 nblcks, nthrds, 0, strm, (real *) a,
700 (real *) b, (real *) c, (real *) d, *n);
702 }
703
708 void hip_addcol3s2(void *a, void *b, void *c, real *s, int *n,
710
711 const dim3 nthrds(1024, 1, 1);
712 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
713
715 nblcks, nthrds, 0, strm, (real *) a,
716 (real *) b, (real *) c, *s, *n);
718 }
719
724 void hip_vdot3(void *dot, void *u1, void *u2, void *u3,
725 void *v1, void *v2, void *v3, int *n,
727
728 const dim3 nthrds(1024, 1, 1);
729 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
730
732 nblcks, nthrds, 0, strm,
733 (real *) dot, (real *) u1, (real *) u2, (real *) u3,
734 (real *) v1, (real *) v2, (real *) v3, *n);
736 }
737
742 void hip_vcross(void *u1, void *u2, void *u3,
743 void *v1, void *v2, void *v3,
744 void *w1, void *w2, void *w3,
745 int *n, hipStream_t strm) {
746
747 const dim3 nthrds(1024, 1, 1);
748 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
749
751 nblcks, nthrds, 0, strm,
752 (real *) u1, (real *) u2, (real *) u3,
753 (real *) v1, (real *) v2, (real *) v3,
754 (real *) w1, (real *) w2, (real *) w3, *n);
756 }
757
758
759 /*
760 * Reduction buffers, owned by the device layer and released
761 * on device teardown (hip_buffer_free_all in hip_finalize)
762 */
765
767 hip_buffer_reserve(&redbuf, (nb + 1) * sizeof(real));
768 }
769
771 hip_buffer_reserve(&redbuf_xp, (nb + 1) * sizeof(real_xp));
772 }
773
778 const hipStream_t stream) {
779 #ifdef HAVE_RCCL
781 DEVICE_NCCL_SUM, stream);
783 hipMemcpyDeviceToHost, stream));
785 #elif HAVE_DEVICE_MPI
788 #else
790 hipMemcpyDeviceToHost, stream));
792 #endif
793 }
794
799 const hipStream_t stream) {
800 #ifdef HAVE_RCCL
802 DEVICE_NCCL_SUM, stream);
804 hipMemcpyDeviceToHost, stream));
806 #elif HAVE_DEVICE_MPI
809 #else
811 hipMemcpyDeviceToHost, stream));
813 #endif
814 }
815
816
821 const hipStream_t stream) {
822 #ifdef HAVE_RCCL
824 DEVICE_NCCL_MAX, stream);
826 hipMemcpyDeviceToHost, stream));
828 #elif HAVE_DEVICE_MPI
831 #else
833 hipMemcpyDeviceToHost, stream));
835 #endif
836 }
837
842 const hipStream_t stream) {
843 #ifdef HAVE_RCCL
845 DEVICE_NCCL_MIN, stream);
847 hipMemcpyDeviceToHost, stream));
849 #elif HAVE_DEVICE_MPI
852 #else
854 hipMemcpyDeviceToHost, stream));
856 #endif
857 }
858
863 real hip_vlsc3(void *u, void *v, void *w, int *n, hipStream_t stream) {
864
865 const dim3 nthrds(1024, 1, 1);
866 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
867 const int nb = ((*n) + 1024 - 1)/ 1024;
868
870
871
873 nblcks, nthrds, 0, stream,
874 (real *) u, (real *) v,
875 (real *) w, (real *) redbuf.dev, *n);
878 1, 1024, 0, stream, (real *) redbuf.dev, nb);
880
882 sizeof(real), hipMemcpyDeviceToHost, stream));
884
885 return ((real *) redbuf.host)[0];
886 }
887
892 real_xp hip_glsc3(void *a, void *b, void *c, int *n, hipStream_t stream) {
893
894 const dim3 nthrds(1024, 1, 1);
895 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
896 const int nb = ((*n) + 1024 - 1)/ 1024;
897
899
900 if (*n > 0) {
902 nblcks, nthrds, 0, stream,
903 (real *) a, (real *) b,
904 (real *) c, (real_xp *) redbuf_xp.dev, *n);
907 1, 1024, 0, stream, (real_xp * ) redbuf_xp.dev, nb);
909 }
910 else {
912 }
914 (real_xp *) redbuf_xp.dev, 1, stream);
915
916 return ((real_xp *) redbuf_xp.host)[0];
917 }
918
923 void hip_glsc3_many(real_xp *h, void * w, void *v,void *mult, int *j, int *n,
924 hipStream_t stream){
925 int pow2 = 1;
926 while(pow2 < (*j)){
927 pow2 = 2*pow2;
928 }
929 const int nt = 1024/pow2;
930 const dim3 nthrds(pow2, nt, 1);
931 const dim3 nblcks(((*n)+nt - 1)/nt, 1, 1);
932 const dim3 nthrds_red(1024,1,1);
933 const dim3 nblcks_red( (*j),1,1);
934 const int nb = ((*n) + nt - 1)/nt;
935
937
938 if (*n > 0) {
940 nblcks, nthrds, 0, stream,
941 (const real *) w, (const real **) v,
942 (const real *)mult, (real_xp *) redbuf_xp.dev, *j, *n);
944
946 nblcks_red, nthrds_red, 0, stream,
947 (real_xp *) redbuf_xp.dev, nb, *j);
949 }
950 else {
952 }
953 hip_global_reduce_add_xp(h, redbuf_xp.dev, (*j), stream);
954 }
955
960 real_xp hip_glsc2(void *a, void *b, int *n, hipStream_t stream) {
961
962 const dim3 nthrds(1024, 1, 1);
963 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
964 const int nb = ((*n) + 1024 - 1)/ 1024;
965
966
968
969 if( *n > 0) {
971 nblcks, nthrds, 0, stream,
972 (real *) a, (real *) b, (real_xp *) redbuf_xp.dev, *n);
975 1, 1024, 0, stream, (real_xp *) redbuf_xp.dev, nb);
977 }
978 else {
980 }
982 (real_xp *) redbuf_xp.dev, 1, stream);
983
984 return ((real_xp *) redbuf_xp.host)[0];
985 }
986
991 real_xp hip_glsubnorm2(void* a, void* b, int* n, hipStream_t stream) {
992
993 const dim3 nthrds(1024, 1, 1);
994 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
995 const int nb = ((*n) + 1024 - 1) / 1024;
996
998
999 if (*n > 0) {
1001 nblcks, nthrds, 0, stream,
1002 (real *) a, (real *) b,
1003 (real_xp *) redbuf_xp.dev, *n);
1006 1, 1024, 0, stream, (real_xp *) redbuf_xp.dev, nb);
1008 }
1009 else {
1011 }
1013 (real_xp *) redbuf_xp.dev, 1, stream);
1014
1015 return ((real_xp *) redbuf_xp.host)[0];
1016 }
1017
1022 real_xp hip_glsum(void *a, int *n, hipStream_t stream) {
1023 const dim3 nthrds(1024, 1, 1);
1024 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1025 const int nb = ((*n) + 1024 - 1)/ 1024;
1026
1028 if( *n > 0) {
1030 nblcks, nthrds, 0, stream,
1031 (real *) a, (real_xp * ) redbuf_xp.dev, *n);
1034 1, 1024, 0, stream, (real_xp *) redbuf_xp.dev, nb);
1036 }
1037 else {
1039 }
1040
1042 redbuf_xp.dev, 1, stream);
1043
1044 return ((real_xp *) redbuf_xp.host)[0];
1045 }
1046
1047
1052 real hip_glmax(void *a, real *ninf, int *n, hipStream_t stream) {
1053 const dim3 nthrds(1024, 1, 1);
1054 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1055 const int nb = ((*n) + 1024 - 1)/ 1024;
1056
1058 if( *n > 0) {
1060 nblcks, nthrds, 0, stream,
1061 (real *) a, *ninf, (real *) redbuf.dev, *n);
1064 1, 1024, 0, stream, (real *) redbuf.dev, *ninf, nb);
1066 }
1067 else {
1068 int nel = (int) (redbuf.size / sizeof(real));
1069 hip_rzero(redbuf.dev, &nel, stream);
1070 }
1071
1073 (real *) redbuf.dev, 1, stream);
1074
1075 return ((real *) redbuf.host)[0];
1076 }
1077
1082 real hip_glmin(void *a, real *pinf, int *n, hipStream_t stream) {
1083 const dim3 nthrds(1024, 1, 1);
1084 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1085 const int nb = ((*n) + 1024 - 1)/ 1024;
1086
1088 if( *n > 0) {
1090 nblcks, nthrds, 0, stream,
1091 (real *) a, *pinf, (real *) redbuf.dev, *n);
1094 1, 1024, 0, stream, (real *) redbuf.dev, *pinf, nb);
1096 }
1097 else {
1098 int nel = (int) (redbuf.size / sizeof(real));
1099 hip_rzero(redbuf.dev, &nel, stream);
1100 }
1101
1103 (real *) redbuf.dev, 1, stream);
1104
1105 return ((real *) redbuf.host)[0];
1106 }
1107
1112 real hip_glamax(void *a, int *n, hipStream_t stream) {
1113 const dim3 nthrds(1024, 1, 1);
1114 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1115 const int nb = ((*n) + 1024 - 1)/ 1024;
1116 const real zero = 0.0;
1117
1119 if( *n > 0) {
1121 nblcks, nthrds, 0, stream,
1122 (real *) a, (real *) redbuf.dev, *n);
1125 1, 1024, 0, stream, (real *) redbuf.dev, zero, nb);
1127 }
1128 else {
1129 int nel = (int) (redbuf.size / sizeof(real));
1130 hip_rzero(redbuf.dev, &nel, stream);
1131 }
1132
1134 (real *) redbuf.dev, 1, stream);
1135
1136 return ((real *) redbuf.host)[0];
1137 }
1138
1143 void hip_absval(void *a, int *n, hipStream_t stream) {
1144
1145 const dim3 nthrds(1024, 1, 1);
1146 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1147
1149 nblcks, nthrds, 0, stream, (real *) a, *n);
1151
1152}
1153
1154 // ======================================================================== //
1155 // Point-wise operations.
1156
1161 void hip_pwmax_vec2(void* a, void* b, int* n, hipStream_t stream) {
1162
1163 const dim3 nthrds(1024, 1, 1);
1164 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1165
1167 nblcks, nthrds, 0, stream, (real*)a, (real*)b, *n);
1169}
1170
1175 void hip_pwmax_vec3(void *a, void *b, void *c, int *n, hipStream_t stream) {
1176
1177 const dim3 nthrds(1024, 1, 1);
1178 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1179
1181 nblcks, nthrds, 0, stream,
1182 (real *)a, (real *)b, (real *)c, *n);
1184 }
1185
1190 void hip_pwmax_sca2(void *a, real *c, int *n, hipStream_t stream) {
1191
1192 const dim3 nthrds(1024, 1, 1);
1193 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1194
1196 nblcks, nthrds, 0, stream, (real *)a, *c, *n);
1198 }
1199
1204 void hip_pwmax_sca3(void *a, void *b, real *c, int *n, hipStream_t stream) {
1205
1206 const dim3 nthrds(1024, 1, 1);
1207 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1208
1210 nblcks, nthrds, 0, stream,
1211 (real *)a, (real *)b, *c, *n);
1213 }
1214
1219 void hip_pwmin_vec2(void *a, void *b, int *n, hipStream_t stream) {
1220
1221 const dim3 nthrds(1024, 1, 1);
1222 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1223
1225 nblcks, nthrds, 0, stream,
1226 (real *)a, (real *)b, *n);
1228 }
1229
1234 void hip_pwmin_vec3(void *a, void *b, void *c, int *n, hipStream_t stream) {
1235
1236 const dim3 nthrds(1024, 1, 1);
1237 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1238
1240 nblcks, nthrds, 0, stream,
1241 (real *)a, (real *)b, (real *)c, *n);
1243 }
1244
1249 void hip_pwmin_sca2(void *a, real *c, int *n, hipStream_t stream) {
1250
1251 const dim3 nthrds(1024, 1, 1);
1252 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1253
1255 nblcks, nthrds, 0, stream,
1256 (real *)a, *c, *n);
1258 }
1259
1264 void hip_pwmin_sca3(void *a, void *b, real *c, int *n, hipStream_t stream) {
1265
1266 const dim3 nthrds(1024, 1, 1);
1267 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
1268
1270 nblcks, nthrds, 0, stream,
1271 (real *)a, (real *)b, *c, *n);
1273 }
1274
1275 // ======================================================================== //
1276
1280 void hip_iadd(void *a, int *c, int *n, hipStream_t stream) {
1281
1282 const dim3 nthrds(1024, 1, 1);
1283 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
1284
1286 nblcks, nthrds, 0, stream,
1287 (int *) a, *c, *n);
1289 }
1290
1291} /* extern "C" */
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__global__ void const T *__restrict__ u
const int e
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
__global__ void const T *__restrict__ x
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w3
#define MASKED_ATOMIC_RED_BLOCK
double real
double real_xp
#define DEVICE_MPI_MAX
#define DEVICE_MPI_MIN
#define DEVICE_MPI_SUM
void device_mpi_allreduce(void *buf_d, void *buf, int count, int nbytes, int op)
#define DEVICE_NCCL_MAX
#define DEVICE_NCCL_MIN
#define DEVICE_NCCL_SUM
void device_nccl_allreduce(void *sbuf_d, void *rbuf_d, int count, int nbytes, int op, void *stream)
void hip_buffer_reserve(hip_buffer_t *buf, size_t size)
Definition buffer.hip:47
#define HIP_BUFFER_INIT
Definition buffer.h:61
#define HIP_CHECK(err)
Definition check.h:8
void hip_vdot3(void *dot, void *u1, void *u2, void *u3, void *v1, void *v2, void *v3, int *n, hipStream_t strm)
Definition math.hip:724
void hip_global_reduce_add(real *bufred, void *bufred_d, int n, const hipStream_t stream)
Definition math.hip:777
void hip_col3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:617
void hip_cwrap(void *a, real *min_val, real *max_val, int *n, hipStream_t strm)
Definition math.hip:336
void hip_addsqr2s2(void *a, void *b, real *c1, int *n, hipStream_t strm)
Definition math.hip:492
real hip_glmax(void *a, real *ninf, int *n, hipStream_t stream)
Definition math.hip:1052
void hip_rzero(void *a, int *n, hipStream_t strm)
Definition math.hip:232
void hip_power(void *ap, void *a, real *p, int *n, hipStream_t strm)
Definition math.hip:364
void hip_cfill_mask(void *a, real *c, int *size, void *mask, int *mask_size, hipStream_t strm)
Definition math.hip:216
void hip_pwmax_sca3(void *a, void *b, real *c, int *n, hipStream_t stream)
Definition math.hip:1204
void hip_invcol3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:587
void hip_absval(void *a, int *n, hipStream_t stream)
Definition math.hip:1143
void hip_masked_gather_copy_aligned(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:128
void hip_vcross(void *u1, void *u2, void *u3, void *v1, void *v2, void *v3, void *w1, void *w2, void *w3, int *n, hipStream_t strm)
Definition math.hip:742
void hip_addcol3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:677
void hip_add3s2(void *a, void *b, void *c, real *c1, real *c2, int *n, hipStream_t strm)
Definition math.hip:508
void hip_masked_scatter_copy_aligned(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:181
void hip_add5s4(void *a, void *b, void *c, void *d, void *e, real *c1, real *c2, real *c3, real *c4, int *n, hipStream_t strm)
Definition math.hip:542
void hip_masked_copy_aligned(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:95
void hip_add2s2(void *a, void *b, real *c1, int *n, hipStream_t strm)
Definition math.hip:457
void hip_add4(void *a, void *b, void *c, void *d, int *n, hipStream_t strm)
Definition math.hip:425
void hip_redbuf_check_alloc_xp(int nb)
Definition math.hip:770
void hip_cadd2(void *a, void *b, real *c, int *n, hipStream_t strm)
Definition math.hip:322
real hip_glamax(void *a, int *n, hipStream_t stream)
Definition math.hip:1112
real hip_vlsc3(void *u, void *v, void *w, int *n, hipStream_t stream)
Definition math.hip:863
void hip_cdiv2(void *a, void *b, real *c, int *n, hipStream_t strm)
Definition math.hip:294
void hip_pwmin_sca2(void *a, real *c, int *n, hipStream_t stream)
Definition math.hip:1249
void hip_cmult2(void *a, void *b, real *c, int *n, hipStream_t strm)
Definition math.hip:266
void hip_invcol1(void *a, int *n, hipStream_t strm)
Definition math.hip:559
void hip_invcol2(void *a, void *b, int *n, hipStream_t strm)
Definition math.hip:573
void hip_global_reduce_max(real *bufred, void *bufred_d, int n, const hipStream_t stream)
Definition math.hip:820
void hip_cdiv(void *a, real *c, int *n, hipStream_t strm)
Definition math.hip:280
real_xp hip_glsubnorm2(void *a, void *b, int *n, hipStream_t stream)
Definition math.hip:991
void hip_sub2(void *a, void *b, int *n, hipStream_t strm)
Definition math.hip:647
real_xp hip_glsc2(void *a, void *b, int *n, hipStream_t stream)
Definition math.hip:960
void hip_add4s3(void *a, void *b, void *c, void *d, real *c1, real *c2, real *c3, int *n, hipStream_t strm)
Definition math.hip:525
void hip_col2(void *a, void *b, int *n, hipStream_t strm)
Definition math.hip:602
real hip_glmin(void *a, real *pinf, int *n, hipStream_t stream)
Definition math.hip:1082
void hip_pwmin_vec3(void *a, void *b, void *c, int *n, hipStream_t stream)
Definition math.hip:1234
void hip_glsc3_many(real_xp *h, void *w, void *v, void *mult, int *j, int *n, hipStream_t stream)
Definition math.hip:923
void hip_addcol3s2(void *a, void *b, void *c, real *s, int *n, hipStream_t strm)
Definition math.hip:708
void hip_masked_gather_copy(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:112
void hip_cfill(void *a, real *c, int *n, hipStream_t strm)
Definition math.hip:378
void hip_masked_atomic_reduction(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:198
void hip_masked_copy_0(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:78
void hip_add3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:410
void hip_pwmax_vec3(void *a, void *b, void *c, int *n, hipStream_t stream)
Definition math.hip:1175
void hip_add2(void *a, void *b, int *n, hipStream_t strm)
Definition math.hip:395
void hip_sqrt_inplace(void *a, int *n, hipStream_t strm)
Definition math.hip:351
real_xp hip_glsum(void *a, int *n, hipStream_t stream)
Definition math.hip:1022
real_xp hip_glsc3(void *a, void *b, void *c, int *n, hipStream_t stream)
Definition math.hip:892
void hip_global_reduce_add_xp(real_xp *bufred, void *bufred_d, int n, const hipStream_t stream)
Definition math.hip:798
hip_buffer_t redbuf
Definition math.hip:763
void hip_copy(void *a, void *b, int *n, hipStream_t strm)
Definition math.hip:55
void hip_subcol3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:632
void hip_pwmax_sca2(void *a, real *c, int *n, hipStream_t stream)
Definition math.hip:1190
void hip_iadd(void *a, int *c, int *n, hipStream_t stream)
Definition math.hip:1280
void hip_pwmin_sca3(void *a, void *b, real *c, int *n, hipStream_t stream)
Definition math.hip:1264
void hip_add2s1(void *a, void *b, real *c1, int *n, hipStream_t strm)
Definition math.hip:441
void hip_radd(void *a, real *c, int *n, hipStream_t strm)
Definition math.hip:308
void hip_redbuf_check_alloc(int nb)
Definition math.hip:766
void hip_add2s2_many(void *x, void **p, void *alpha, int *j, int *n, hipStream_t strm)
Definition math.hip:474
hip_buffer_t redbuf_xp
Definition math.hip:764
void hip_addcol4(void *a, void *b, void *c, void *d, int *n, hipStream_t strm)
Definition math.hip:692
void hip_pwmax_vec2(void *a, void *b, int *n, hipStream_t stream)
Definition math.hip:1161
void hip_pwmin_vec2(void *a, void *b, int *n, hipStream_t stream)
Definition math.hip:1219
void hip_sub3(void *a, void *b, void *c, int *n, hipStream_t strm)
Definition math.hip:662
void hip_face_masked_gather_copy(void *a, void *b, void *mask, void *facet, int *n1, int *n2, int *lx, int *ly, int *lz, int *m, hipStream_t strm)
Definition math.hip:144
void hip_masked_scatter_copy(void *a, void *b, void *mask, int *n, int *m, hipStream_t strm)
Definition math.hip:164
void hip_cmult(void *a, real *c, int *n, hipStream_t strm)
Definition math.hip:252
void hip_global_reduce_min(real *bufred, void *bufred_d, int n, const hipStream_t stream)
Definition math.hip:841
Object for handling masks in Neko.
Definition mask.f90:34
void * host
Definition buffer.h:52
size_t size
Definition buffer.h:54
void * dev
Definition buffer.h:53
int hip_zerocopy(void)
Definition unified.hip:122