Nektar++
Loading...
Searching...
No Matches
SYCL_Device_API.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: SYCL_Device_API.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
37#if defined(NEKTAR_ENABLE_SYCL)
38namespace Nektar
39{
40
41// Optional optimisation decorator for a NEK_DEVICE_KERNEL kernel function. This
42// should NOT be used in a NEK_DEVCICE_INLINE function. This allows register
43// usage optimisation for CUDA/HIP backend by specifying the maximum GPU
44// blocksize. Has no effect for SYCL.
45#define __LAUNCH_BOUNDS__(x)
46
47// Shared memory must be fetched from a NEK_DEVICE_KERNEL kernel function. This
48// should NOT be used in a NEK_DEVCICE_INLINE function. Use for compatibility
49// with CUDA/HIP backend. Has no effect for SYCL.
50#define FETCH_SHARED_MEMORY(ptr)
51
52template <int dim = 0>
53NEK_DEVICE_INLINE static unsigned int getLocalIdx(
54 const sycl::nd_item<1> &threadBlock)
55{
56 if constexpr (dim == 0)
57 {
58 return threadBlock.get_local_id(0);
59 }
60 else
61 {
62 return 0;
63 }
64}
65
66template <int dim = 0>
67NEK_DEVICE_INLINE static unsigned int getLocalIdx(
68 const sycl::nd_item<2> &threadBlock)
69{
70 if constexpr (dim == 0)
71 {
72 // Fastest moving.
73 return threadBlock.get_local_id(1);
74 }
75 else if constexpr (dim == 1)
76 {
77 return threadBlock.get_local_id(0);
78 }
79 else
80 {
81 return 0;
82 }
83}
84
85template <int dim = 0>
86NEK_DEVICE_INLINE static unsigned int getLocalIdx(
87 const sycl::nd_item<3> &threadBlock)
88{
89 if constexpr (dim == 0)
90 {
91 // Fastest moving.
92 return threadBlock.get_local_id(2);
93 }
94 else if constexpr (dim == 1)
95 {
96 return threadBlock.get_local_id(1);
97 }
98 else if constexpr (dim == 2)
99 {
100 return threadBlock.get_local_id(0);
101 }
102 else
103 {
104 return 0;
105 }
106}
107
108template <int dim = 0>
109NEK_DEVICE_INLINE static unsigned int getLocalRange(
110 const sycl::nd_item<1> &threadBlock)
111{
112 if constexpr (dim == 0)
113 {
114 return threadBlock.get_local_range(0);
115 }
116 else
117 {
118 return 1;
119 }
120}
121
122template <int dim = 0>
123NEK_DEVICE_INLINE static unsigned int getLocalRange(
124 const sycl::nd_item<2> &threadBlock)
125{
126 if constexpr (dim == 0)
127 {
128 // Fastest moving.
129 return threadBlock.get_local_range(1);
130 }
131 else if constexpr (dim == 1)
132 {
133 return threadBlock.get_local_range(0);
134 }
135 else
136 {
137 return 1;
138 }
139}
140
141template <int dim = 0>
142NEK_DEVICE_INLINE static unsigned int getLocalRange(
143 const sycl::nd_item<3> &threadBlock)
144{
145 if constexpr (dim == 0)
146 {
147 // Fastest moving.
148 return threadBlock.get_local_range(2);
149 }
150 else if constexpr (dim == 1)
151 {
152 return threadBlock.get_local_range(1);
153 }
154 else if constexpr (dim == 2)
155 {
156 return threadBlock.get_local_range(0);
157 }
158 else
159 {
160 return 1;
161 }
162}
163
164template <int dim = 0>
165NEK_DEVICE_INLINE static size_t getGlobalIdx(
166 const sycl::nd_item<1> &threadBlock)
167{
168 if constexpr (dim == 0)
169 {
170 return threadBlock.get_global_id(0);
171 }
172 else
173 {
174 return 0;
175 }
176}
177
178template <int dim = 0>
179NEK_DEVICE_INLINE static size_t getGlobalIdx(
180 const sycl::nd_item<2> &threadBlock)
181{
182 if constexpr (dim == 0)
183 {
184 // Fastest moving.
185 return threadBlock.get_global_id(1);
186 }
187 else if constexpr (dim == 1)
188 {
189 return threadBlock.get_global_id(0);
190 }
191 else
192 {
193 return 0;
194 }
195}
196
197template <int dim = 0>
198NEK_DEVICE_INLINE static size_t getGlobalIdx(
199 const sycl::nd_item<3> &threadBlock)
200{
201 if constexpr (dim == 0)
202 {
203 // Fastest moving.
204 return threadBlock.get_global_id(2);
205 }
206 else if constexpr (dim == 1)
207 {
208 return threadBlock.get_global_id(1);
209 }
210 else if constexpr (dim == 2)
211 {
212 return threadBlock.get_global_id(0);
213 }
214 else
215 {
216 return 0;
217 }
218}
219
220template <int dim = 0>
221NEK_DEVICE_INLINE static size_t getGlobalRange(
222 const sycl::nd_item<1> &threadBlock)
223{
224 if constexpr (dim == 0)
225 {
226 return threadBlock.get_global_range(0);
227 }
228 else
229 {
230 return 1;
231 }
232}
233
234template <int dim = 0>
235NEK_DEVICE_INLINE static size_t getGlobalRange(
236 const sycl::nd_item<2> &threadBlock)
237{
238 if constexpr (dim == 0)
239 {
240 // Fastest moving.
241 return threadBlock.get_global_range(1);
242 }
243 else if constexpr (dim == 1)
244 {
245 return threadBlock.get_global_range(0);
246 }
247 else
248 {
249 return 1;
250 }
251}
252
253template <int dim = 0>
254NEK_DEVICE_INLINE static size_t getGlobalRange(
255 const sycl::nd_item<3> &threadBlock)
256{
257 if constexpr (dim == 0)
258 {
259 // Fastest moving.
260 return threadBlock.get_global_range(2);
261 }
262 else if constexpr (dim == 1)
263 {
264 return threadBlock.get_global_range(1);
265 }
266 else if constexpr (dim == 2)
267 {
268 return threadBlock.get_global_range(0);
269 }
270 else
271 {
272 return 1;
273 }
274}
275
276template <int dim = 0>
277NEK_DEVICE_INLINE static unsigned int getBlockIdx(
278 const sycl::nd_item<1> &threadBlock)
279{
280 if constexpr (dim == 0)
281 {
282 return threadBlock.get_group(0);
283 }
284 else
285 {
286 return 0;
287 }
288}
289
290template <int dim = 0>
291NEK_DEVICE_INLINE static unsigned int getBlockIdx(
292 const sycl::nd_item<2> &threadBlock)
293{
294 if constexpr (dim == 0)
295 {
296 // Fastest moving.
297 return threadBlock.get_group(1);
298 }
299 else if constexpr (dim == 1)
300 {
301 return threadBlock.get_group(0);
302 }
303 else
304 {
305 return 0;
306 }
307}
308
309template <int dim = 0>
310NEK_DEVICE_INLINE static unsigned int getBlockIdx(
311 const sycl::nd_item<3> &threadBlock)
312{
313 if constexpr (dim == 0)
314 {
315 // Fastest moving.
316 return threadBlock.get_group(2);
317 }
318 else if constexpr (dim == 1)
319 {
320 return threadBlock.get_group(1);
321 }
322 else if constexpr (dim == 2)
323 {
324 return threadBlock.get_group(0);
325 }
326 else
327 {
328 return 0;
329 }
330}
331
332template <int dim = 0>
333NEK_DEVICE_INLINE static unsigned int getBlockRange(
334 const sycl::nd_item<1> &threadBlock)
335{
336 if constexpr (dim == 0)
337 {
338 return threadBlock.get_group_range(0);
339 }
340 else
341 {
342 return 1;
343 }
344}
345
346template <int dim = 0>
347NEK_DEVICE_INLINE static unsigned int getBlockRange(
348 const sycl::nd_item<2> &threadBlock)
349{
350 if constexpr (dim == 0)
351 {
352 // Fastest moving.
353 return threadBlock.get_group_range(1);
354 }
355 else if constexpr (dim == 1)
356 {
357 return threadBlock.get_group_range(0);
358 }
359 else
360 {
361 return 1;
362 }
363}
364
365template <int dim = 0>
366NEK_DEVICE_INLINE static unsigned int getBlockRange(
367 const sycl::nd_item<3> &threadBlock)
368{
369 if constexpr (dim == 0)
370 {
371 // Fastest moving.
372 return threadBlock.get_group_range(2);
373 }
374 else if constexpr (dim == 1)
375 {
376 return threadBlock.get_group_range(1);
377 }
378 else if constexpr (dim == 2)
379 {
380 return threadBlock.get_group_range(0);
381 }
382 else
383 {
384 return 1;
385 }
386}
387
388template <int ndim>
389NEK_DEVICE_INLINE static unsigned int getWarpIdx(
390 const sycl::nd_item<ndim> &threadBlock)
391{
392 return threadBlock.get_sub_group().get_group_id();
393}
394
395template <int ndim>
396NEK_DEVICE_INLINE static unsigned int getLaneIdx(
397 const sycl::nd_item<ndim> &threadBlock)
398{
399 return threadBlock.get_sub_group().get_local_id();
400}
401
402template <typename T> NEK_DEVICE_INLINE T getBit(T mask, T lane)
403{
404#if defined(SYCL_ENABLE_CUDA)
405 static_assert(std::is_same_v<T, unsigned int>, "Mask must be unsigned int");
406#elif defined(SYCL_ENABLE_HIP)
407 static_assert(std::is_same_v<T, size_t>, "Mask must be size_t");
408#endif
409
410 // Shift the bit corresponding to the lane index completely to
411 // the right and check if its value is 0 or 1.
412 // e.g.: mask = 0b1001100010101110
413 // ^
414 // |
415 // lane bit
416 // mask = 0b0000000000010011
417 // shift right ---------> ^
418 // |
419 // check last bit value (0 or 1)
420 return (mask >> lane) & 0x00000001;
421}
422
423template <typename Scope, typename TData>
424NEK_DEVICE_INLINE static void atomic_add(TData *const dest, const TData val)
425{
426 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
427 {
428 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
429 sycl::memory_scope::device,
430 sycl::access::address_space::global_space>(*dest)
431 .fetch_add(val);
432 }
433 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
434 {
435 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
436 sycl::memory_scope_work_group,
437 sycl::access::address_space::generic_space>(*dest)
438 .fetch_add(val);
439 }
440}
441
442template <typename Scope, typename TData>
443NEK_DEVICE_INLINE static void atomic_sub(TData *const dest, const TData val)
444{
445 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
446 {
447 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
448 sycl::memory_scope::device,
449 sycl::access::address_space::global_space>(*dest)
450 .fetch_sub(val);
451 }
452 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
453 {
454 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
455 sycl::memory_scope_work_group,
456 sycl::access::address_space::generic_space>(*dest)
457 .fetch_sub(val);
458 }
459}
460
461template <typename Scope, typename TData>
462NEK_DEVICE_INLINE static void atomic_max(TData *const dest, const TData val)
463{
464 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
465 {
466 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
467 sycl::memory_scope::device,
468 sycl::access::address_space::global_space>(*dest)
469 .fetch_max(val);
470 }
471 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
472 {
473 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
474 sycl::memory_scope_work_group,
475 sycl::access::address_space::generic_space>(*dest)
476 .fetch_max(val);
477 }
478}
479
480template <typename Scope, typename TData>
481NEK_DEVICE_INLINE static void atomic_min(TData *const dest, const TData val)
482{
483 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
484 {
485 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
486 sycl::memory_scope::device,
487 sycl::access::address_space::global_space>(*dest)
488 .fetch_min(val);
489 }
490 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
491 {
492 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
493 sycl::memory_scope_work_group,
494 sycl::access::address_space::generic_space>(*dest)
495 .fetch_min(val);
496 }
497}
498
499template <typename Scope, typename TData>
500NEK_DEVICE_INLINE static void atomic_absmax(TData *const dest, const TData val)
501{
502 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
503 {
504 auto atomic =
505 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
506 sycl::memory_scope::device,
507 sycl::access::address_space::global_space>(*dest);
508 TData ret = atomic.load();
509 while (sycl::fabs(val) > sycl::fabs(ret) &&
510 !atomic.compare_exchange_weak(ret, val))
511 {
512 }
513 }
514 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
515 {
516 auto atomic =
517 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
518 sycl::memory_scope_work_group,
519 sycl::access::address_space::generic_space>(*dest);
520 TData ret = atomic.load();
521 while (sycl::fabs(val) > sycl::fabs(ret) &&
522 !atomic.compare_exchange_weak(ret, val))
523 {
524 }
525 }
526}
527
528template <typename Scope, typename TData>
529NEK_DEVICE_INLINE static void atomic_or(TData *const dest, const TData val)
530{
531 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
532 {
533 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
534 sycl::memory_scope::device,
535 sycl::access::address_space::global_space>(*dest)
536 .fetch_or(val);
537 }
538 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
539 {
540 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
541 sycl::memory_scope_work_group,
542 sycl::access::address_space::generic_space>(*dest)
543 .fetch_or(val);
544 }
545}
546
547template <typename Scope, typename TData>
548NEK_DEVICE_INLINE static void atomic_and(TData *const dest, const TData val)
549{
550 if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
551 {
552 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
553 sycl::memory_scope::device,
554 sycl::access::address_space::global_space>(*dest)
555 .fetch_and(val);
556 }
557 else if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
558 {
559 sycl::atomic_ref<TData, sycl::memory_order::relaxed,
560 sycl::memory_scope_work_group,
561 sycl::access::address_space::generic_space>(*dest)
562 .fetch_and(val);
563 }
564}
565
566template <int ndim, typename TData>
567NEK_DEVICE_INLINE static TData warpReduceSum(
568 const TData val, const sycl::nd_item<ndim> &threadBlock)
569{
570 return sycl::reduce_over_group(threadBlock.get_sub_group(), val,
571 sycl::plus<>());
572}
573
574// Sum of val over each aligned group of width consecutive lanes of the
575// sub-group, width a power of two no larger than the sub-group; every lane of
576// the sub-group must call it, and each lane gets its group's sum.
577template <int ndim, typename TData>
578NEK_DEVICE_INLINE static TData warpSegmentReduceSum(
579 const TData val, const unsigned int width,
580 const sycl::nd_item<ndim> &threadBlock)
581{
582 const auto subGroup = threadBlock.get_sub_group();
583 TData tmp = val;
584 for (unsigned int offset = width / 2u; offset > 0u; offset /= 2u)
585 {
586 tmp += sycl::permute_group_by_xor(subGroup, tmp, offset);
587 }
588 return tmp;
589}
590
591template <int ndim, typename TData>
592NEK_DEVICE_INLINE static TData warpReduceMax(
593 const TData val, const sycl::nd_item<ndim> &threadBlock)
594{
595 return sycl::reduce_over_group(threadBlock.get_sub_group(), val,
596 sycl::maximum<>());
597}
598
599template <int ndim, typename TData>
600NEK_DEVICE_INLINE static TData warpReduceMin(
601 const TData val, const sycl::nd_item<ndim> &threadBlock)
602{
603 return sycl::reduce_over_group(threadBlock.get_sub_group(), val,
604 sycl::minimum<>());
605}
606
607template <int ndim, typename TData>
608NEK_DEVICE_INLINE static TData warpReduceOr(
609 const TData val, const sycl::nd_item<ndim> &threadBlock)
610{
611 return sycl::reduce_over_group(threadBlock.get_sub_group(), val,
612 sycl::bit_or<>());
613}
614
615template <int ndim, typename TData>
616NEK_DEVICE_INLINE static TData warpReduceAnd(
617 const TData val, const sycl::nd_item<ndim> &threadBlock)
618{
619 return sycl::reduce_over_group(threadBlock.get_sub_group(), val,
620 sycl::bit_and<>());
621}
622
623// blockReduce{Sum,Max,Min,Or,And}: combine val over the thread block into
624// *red. Every thread of the block must call them.
625// - Scope = GlobalScope (default): *red may be shared with other thread
626// blocks. The block's total is formed first (reduce_over_group on the
627// work-group) and its first thread issues one global-scope atomic.
628// - Scope = LocalScope: *red is owned by this thread block. Each sub-group
629// combines its partial into it with a block-scope atomic, with no block
630// barrier.
631template <typename Scope = NektarSpaces::GlobalScope, int ndim, typename TData>
632NEK_DEVICE_INLINE static void blockReduceSum(
633 const TData val, const sycl::nd_item<ndim> &threadBlock, TData *red)
634{
635 if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
636 {
637 const TData tmp = warpReduceSum(val, threadBlock);
638 if (getLaneIdx(threadBlock) == 0)
639 {
640 atomic_add<NektarSpaces::LocalScope>(red, tmp);
641 }
642 }
643 else if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
644 {
645 const auto group = threadBlock.get_group();
646 const TData tmp = sycl::reduce_over_group(group, val, sycl::plus<>());
647 if (group.leader())
648 {
649 atomic_add<NektarSpaces::GlobalScope>(red, tmp);
650 }
651 }
652}
653
654template <typename Scope = NektarSpaces::GlobalScope, int ndim, typename TData>
655NEK_DEVICE_INLINE static void blockReduceMax(
656 const TData val, const sycl::nd_item<ndim> &threadBlock, TData *red)
657{
658 if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
659 {
660 const TData tmp = warpReduceMax(val, threadBlock);
661 if (getLaneIdx(threadBlock) == 0)
662 {
663 atomic_max<NektarSpaces::LocalScope>(red, tmp);
664 }
665 }
666 else if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
667 {
668 const auto group = threadBlock.get_group();
669 const TData tmp =
670 sycl::reduce_over_group(group, val, sycl::maximum<>());
671 if (group.leader())
672 {
673 atomic_max<NektarSpaces::GlobalScope>(red, tmp);
674 }
675 }
676}
677
678template <typename Scope = NektarSpaces::GlobalScope, int ndim, typename TData>
679NEK_DEVICE_INLINE static void blockReduceMin(
680 const TData val, const sycl::nd_item<ndim> &threadBlock, TData *red)
681{
682 if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
683 {
684 const TData tmp = warpReduceMin(val, threadBlock);
685 if (getLaneIdx(threadBlock) == 0)
686 {
687 atomic_min<NektarSpaces::LocalScope>(red, tmp);
688 }
689 }
690 else if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
691 {
692 const auto group = threadBlock.get_group();
693 const TData tmp =
694 sycl::reduce_over_group(group, val, sycl::minimum<>());
695 if (group.leader())
696 {
697 atomic_min<NektarSpaces::GlobalScope>(red, tmp);
698 }
699 }
700}
701
702template <typename Scope = NektarSpaces::GlobalScope, int ndim, typename TData>
703NEK_DEVICE_INLINE static void blockReduceOr(
704 const TData val, const sycl::nd_item<ndim> &threadBlock, TData *red)
705{
706 if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
707 {
708 const TData tmp = warpReduceOr(val, threadBlock);
709 if (getLaneIdx(threadBlock) == 0)
710 {
711 atomic_or<NektarSpaces::LocalScope>(red, tmp);
712 }
713 }
714 else if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
715 {
716 const auto group = threadBlock.get_group();
717 const TData tmp = sycl::reduce_over_group(group, val, sycl::bit_or<>());
718 if (group.leader())
719 {
720 atomic_or<NektarSpaces::GlobalScope>(red, tmp);
721 }
722 }
723}
724
725template <typename Scope = NektarSpaces::GlobalScope, int ndim, typename TData>
726NEK_DEVICE_INLINE static void blockReduceAnd(
727 const TData val, const sycl::nd_item<ndim> &threadBlock, TData *red)
728{
729 if constexpr (std::is_same_v<Scope, NektarSpaces::LocalScope>)
730 {
731 const TData tmp = warpReduceAnd(val, threadBlock);
732 if (getLaneIdx(threadBlock) == 0)
733 {
734 atomic_and<NektarSpaces::LocalScope>(red, tmp);
735 }
736 }
737 else if constexpr (std::is_same_v<Scope, NektarSpaces::GlobalScope>)
738 {
739 const auto group = threadBlock.get_group();
740 const TData tmp =
741 sycl::reduce_over_group(group, val, sycl::bit_and<>());
742 if (group.leader())
743 {
744 atomic_and<NektarSpaces::GlobalScope>(red, tmp);
745 }
746 }
747}
748
749template <int ndim>
750NEK_DEVICE_INLINE static int warpVoteAll(int predictate,
751 const sycl::nd_item<ndim> &threadBlock)
752{
753 auto warp = threadBlock.get_sub_group();
754 return sycl::all_of_group(warp, predictate);
755}
756
757template <int ndim>
758NEK_DEVICE_INLINE static int warpVoteAny(int predictate,
759 const sycl::nd_item<ndim> &threadBlock)
760{
761 auto warp = threadBlock.get_sub_group();
762 return sycl::any_of_group(warp, predictate);
763}
764
765#if defined(SYCL_ENABLE_CUDA)
766template <int ndim>
767NEK_DEVICE_INLINE static unsigned int warpBallot(
768 int predictate, const sycl::nd_item<ndim> &threadBlock)
769{
770 unsigned int tmp =
771 predictate ? (unsigned int)1 << getLaneIdx(threadBlock) : 0;
772 return warpReduceOr(tmp, threadBlock);
773}
774#elif defined(SYCL_ENABLE_HIP)
775template <int ndim>
776NEK_DEVICE_INLINE static unsigned long long warpBallot(
777 int predictate, const sycl::nd_item<ndim> &threadBlock)
778{
779 unsigned long long tmp =
780 predictate ? (unsigned long long)1 << getLaneIdx(threadBlock) : 0;
781 return warpReduceOr(tmp, threadBlock);
782}
783#else
784template <int ndim>
785NEK_DEVICE_INLINE static unsigned int warpBallot(
786 int predictate, [[maybe_unused]] const sycl::nd_item<ndim> &threadBlock)
787{
788 unsigned int tmp =
789 predictate ? (unsigned int)1 << getLaneIdx(threadBlock) : 0;
790 return warpReduceOr(tmp, threadBlock);
791}
792#endif
793
794template <int ndim>
795NEK_DEVICE_INLINE void localBarrier(const sycl::nd_item<ndim> &threadBlock)
796{
797#if defined(__ADAPTIVECPP__)
798 threadBlock.barrier(sycl::access::fence_space::global_and_local);
799#else
800 sycl::group_barrier(threadBlock.get_group(),
801 sycl::memory_scope::work_group);
802#endif
803}
804
805template <int ndim>
806NEK_DEVICE_INLINE int localBarrier_and(int predictate,
807 const sycl::nd_item<ndim> &threadBlock)
808{
809 threadBlock.barrier(sycl::access::fence_space::global_and_local);
810 return sycl::all_of_group(threadBlock.get_group(), predictate);
811}
812
813template <int ndim>
814NEK_DEVICE_INLINE int localBarrier_or(int predictate,
815 const sycl::nd_item<ndim> &threadBlock)
816{
817 threadBlock.barrier(sycl::access::fence_space::global_and_local);
818 return sycl::any_of_group(threadBlock.get_group(), predictate);
819}
820
821template <int ndim>
822NEK_DEVICE_INLINE int localBarrier_count(int predictate,
823 const sycl::nd_item<ndim> &threadBlock)
824{
825 threadBlock.barrier(sycl::access::fence_space::global_and_local);
826 return sycl::reduce_over_group(threadBlock.get_group(), predictate ? 1 : 0,
827 sycl::plus<>());
828}
829
830} // namespace Nektar
831#endif
#define NEK_DEVICE_INLINE
Definition Backends.hpp:283
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char const TthreadBlock & threadBlock
static void atomic_add(TData *const dest, const TData val)
static void atomic_min(TData *const dest, const TData val)
static void atomic_max(TData *const dest, const TData val)
static void atomic_and(TData *const dest, const TData val)
static void atomic_or(TData *const dest, const TData val)
static void atomic_sub(TData *const dest, const TData val)