RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
privatizer.hpp
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other
3 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
4 // files for dates and other details. No copyright assignment is required
5 // to contribute to RAJA.
6 //
7 // SPDX-License-Identifier: (BSD-3-Clause)
8 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
9 
10 #ifndef __RAJA_PRIVATIZER_HPP
11 #define __RAJA_PRIVATIZER_HPP
12 
13 #include "RAJA/config.hpp"
14 #include "camp/camp.hpp"
15 #include "camp/concepts.hpp"
16 
17 namespace RAJA
18 {
19 
20 namespace internal
21 {
22 
23 // template <typename T>
24 // struct HasPrivatizer : DefineConcept(typename T::privatizer(camp::val<T>()))
25 // {
26 // };
27 // DefineTypeTraitFromConcept(has_privatizer, HasPrivatizer);
28 
29 template<typename T>
31 {
32 private:
33  template<typename C>
34  static auto Test(void*)
35  -> decltype(camp::val<typename C::privatizer>(), camp::true_type {});
36 
37  template<typename>
38  static camp::false_type Test(...);
39 
40 public:
41  static bool const value = decltype(Test<T>(0))::value;
42 };
43 
44 static_assert(!has_privatizer<int>::value, "if this fires, abandon all hope");
45 
47 {};
48 
49 template<typename T>
50 struct Privatizer
51 {
52  using value_type = camp::decay<T>;
55  static_assert(!has_privatizer<T>::value,
56  "Privatizer selected inappropriately, this is almost certainly "
57  "a bug");
58  static_assert(!std::is_base_of<GenericWrapperBase, T>::value,
59  "Privatizer selected inappropriately, this is almost certainly "
60  "a bug");
61 
63  RAJA_HOST_DEVICE Privatizer(const T& o) : priv {o} {}
64 
67 };
68 
86 template<typename T,
87  typename std::enable_if<!has_privatizer<T>::value>::type* = nullptr>
89 {
90  return Privatizer<T> {item};
91 }
92 
94 template<typename T,
95  typename std::enable_if<has_privatizer<T>::value>::type* = nullptr>
96 RAJA_HOST_DEVICE auto thread_privatize(const T& item) -> typename T::privatizer
97 {
98  return typename T::privatizer {item};
99 }
100 
101 } // namespace internal
102 
103 } // namespace RAJA
104 
105 #endif /* __RAJA_PRIVATIZER_HPP */
Definition: privatizer.hpp:31
static bool const value
Definition: privatizer.hpp:41
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_SUPPRESS_HD_WARN
Definition: macros.hpp:68
RAJA_HOST_DEVICE auto thread_privatize(const T &item) -> Privatizer< T >
Create a private copy of the argument to be stored on the current thread's stack in a class of the Pr...
Definition: privatizer.hpp:88
Definition: AlignedRangeIndexSetBuilders.cpp:35
auto privatizer
Definition: launch.hpp:176
Definition: privatizer.hpp:47
Definition: privatizer.hpp:51
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE Privatizer(const T &o)
Definition: privatizer.hpp:63
value_type priv
Definition: privatizer.hpp:54
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE reference_type get_priv()
Definition: privatizer.hpp:66
value_type & reference_type
Definition: privatizer.hpp:53
camp::decay< T > value_type
Definition: privatizer.hpp:52