alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
9 
10 #include <type_traits>
11 
12 namespace alpaka
13 {
15  {
16  };
17 
18  //! The block synchronization traits.
19  namespace trait
20  {
21  //! The block synchronization operation trait.
22  template<typename TBlockSync, typename TSfinae = void>
24 
25  //! The block synchronization and predicate operation trait.
26  template<typename TOp, typename TBlockSync, typename TSfinae = void>
28  } // namespace trait
29 
30  //! Synchronizes all threads within the current block (independently for all blocks).
31  //!
32  //! \tparam TBlockSync The block synchronization implementation type.
33  //! \param blockSync The block synchronization implementation.
35  template<typename TBlockSync>
36  ALPAKA_FN_ACC auto syncBlockThreads(TBlockSync const& blockSync) -> void
37  {
40  }
41 
42  //! The counting function object.
43  struct BlockCount
44  {
45  enum
46  {
47  InitialValue = 0u
48  };
49 
51  template<typename T>
52  ALPAKA_FN_HOST_ACC auto operator()(T const& currentResult, T const& value) const -> T
53  {
54  return currentResult + static_cast<T>(value != static_cast<T>(0));
55  }
56  };
57 
58  //! The logical and function object.
59  struct BlockAnd
60  {
61  enum
62  {
63  InitialValue = 1u
64  };
65 
67  template<typename T>
68  ALPAKA_FN_HOST_ACC auto operator()(T const& currentResult, T const& value) const -> T
69  {
70  return static_cast<T>(currentResult && (value != static_cast<T>(0)));
71  }
72  };
73 
74  //! The logical or function object.
75  struct BlockOr
76  {
77  enum
78  {
79  InitialValue = 0u
80  };
81 
83  template<typename T>
84  ALPAKA_FN_HOST_ACC auto operator()(T const& currentResult, T const& value) const -> T
85  {
86  return static_cast<T>(currentResult || (value != static_cast<T>(0)));
87  }
88  };
89 
90  //! Synchronizes all threads within the current block (independently for all blocks),
91  //! evaluates the predicate for all threads and returns the combination of all the results
92  //! computed via TOp.
93  //!
94  //! \tparam TOp The operation used to combine the predicate values of all threads.
95  //! \tparam TBlockSync The block synchronization implementation type.
96  //! \param blockSync The block synchronization implementation.
97  //! \param predicate The predicate value of the current thread.
99  template<typename TOp, typename TBlockSync>
100  ALPAKA_FN_ACC auto syncBlockThreadsPredicate(TBlockSync const& blockSync, int predicate) -> int
101  {
104  blockSync,
105  predicate);
106  }
107 } // namespace alpaka
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
Definition: Common.hpp:38
#define ALPAKA_FN_HOST_ACC
Definition: Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
typename detail::ImplementationBaseType< TInterface, TDerived >::type ImplementationBase
Returns the type that implements the given interface in the inheritance hierarchy.
Definition: Interface.hpp:66
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
The logical and function object.
Definition: Traits.hpp:60
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto operator()(T const &currentResult, T const &value) const -> T
Definition: Traits.hpp:68
The counting function object.
Definition: Traits.hpp:44
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto operator()(T const &currentResult, T const &value) const -> T
Definition: Traits.hpp:52
The logical or function object.
Definition: Traits.hpp:76
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto operator()(T const &currentResult, T const &value) const -> T
Definition: Traits.hpp:84
The block synchronization and predicate operation trait.
Definition: Traits.hpp:27
The block synchronization operation trait.
Definition: Traits.hpp:23