alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
BlockSyncGenericSycl.hpp
Go to the documentation of this file.
1/* Copyright 2022 Jan Stephan
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8
9#ifdef ALPAKA_ACC_SYCL_ENABLED
10
11# include <sycl/sycl.hpp>
12
13namespace alpaka
14{
15 //! The SYCL block synchronization.
16 template<typename TDim>
17 class BlockSyncGenericSycl : public interface::Implements<ConceptBlockSync, BlockSyncGenericSycl<TDim>>
18 {
19 public:
20 using BlockSyncBase = BlockSyncGenericSycl<TDim>;
21
22 BlockSyncGenericSycl(sycl::nd_item<TDim::value> work_item) : my_item{work_item}
23 {
24 }
25
26 sycl::nd_item<TDim::value> my_item;
27 };
28} // namespace alpaka
29
30namespace alpaka::trait
31{
32 template<typename TDim>
33 struct SyncBlockThreads<BlockSyncGenericSycl<TDim>>
34 {
35 static auto syncBlockThreads(BlockSyncGenericSycl<TDim> const& blockSync) -> void
36 {
37 blockSync.my_item.barrier();
38 }
39 };
40
41 template<typename TDim>
42 struct SyncBlockThreadsPredicate<BlockCount, BlockSyncGenericSycl<TDim>>
43 {
44 static auto syncBlockThreadsPredicate(BlockSyncGenericSycl<TDim> const& blockSync, int predicate) -> int
45 {
46 auto const group = blockSync.my_item.get_group();
47 blockSync.my_item.barrier();
48
49 auto const counter = (predicate != 0) ? 1 : 0;
50 return sycl::reduce_over_group(group, counter, sycl::plus<>{});
51 }
52 };
53
54 template<typename TDim>
55 struct SyncBlockThreadsPredicate<BlockAnd, BlockSyncGenericSycl<TDim>>
56 {
57 static auto syncBlockThreadsPredicate(BlockSyncGenericSycl<TDim> const& blockSync, int predicate) -> int
58 {
59 auto const group = blockSync.my_item.get_group();
60 blockSync.my_item.barrier();
61
62 return static_cast<int>(sycl::all_of_group(group, static_cast<bool>(predicate)));
63 }
64 };
65
66 template<typename TDim>
67 struct SyncBlockThreadsPredicate<BlockOr, BlockSyncGenericSycl<TDim>>
68 {
69 static auto syncBlockThreadsPredicate(BlockSyncGenericSycl<TDim> const& blockSync, int predicate) -> int
70 {
71 auto const group = blockSync.my_item.get_group();
72 blockSync.my_item.barrier();
73
74 return static_cast<int>(sycl::any_of_group(group, static_cast<bool>(predicate)));
75 }
76 };
77} // namespace alpaka::trait
78
79#endif
The accelerator traits.
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto syncBlockThreads(TBlockSync const &blockSync) -> void
Synchronizes all threads within the current block (independently for all blocks).
Definition Traits.hpp:36
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto syncBlockThreadsPredicate(TBlockSync const &blockSync, int predicate) -> int
Synchronizes all threads within the current block (independently for all blocks), evaluates the predi...
Definition Traits.hpp:100