RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
WorkStruct.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_PATTERN_WORKGROUP_WorkStruct_HPP
21 #define RAJA_PATTERN_WORKGROUP_WorkStruct_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <utility>
26 #include <cstddef>
27 
29 
30 namespace RAJA
31 {
32 
33 namespace detail
34 {
35 
39 template<size_t size, typename Dispatcher_T>
40 struct WorkStruct;
41 
48 template<typename Dispatcher_T>
50 
51 template<size_t size,
52  Platform platform,
53  typename dispatch_policy,
54  typename DispatcherID,
55  typename... CallArgs>
56 struct WorkStruct<
57  size,
58  Dispatcher<platform, dispatch_policy, DispatcherID, CallArgs...>>
59 {
61  Dispatcher<platform, dispatch_policy, DispatcherID, CallArgs...>;
62 
63  // construct a WorkStruct with a value of type holder from the args and
64  // check a variety of constraints at compile time
65  template<typename holder, typename... holder_ctor_args>
66  static RAJA_INLINE void construct(void* ptr,
67  const dispatcher_type* dispatcher,
68  holder_ctor_args&&... ctor_args)
69  {
70  using true_value_type = WorkStruct<sizeof(holder), dispatcher_type>;
71  using value_type = GenericWorkStruct<dispatcher_type>;
72 
73  static_assert(sizeof(holder) <= sizeof(true_value_type::obj),
74  "holder must fit in WorkStruct::obj");
75  static_assert(std::is_standard_layout<true_value_type>::value,
76  "WorkStruct must be a standard layout type");
77  static_assert(std::is_standard_layout<value_type>::value,
78  "GenericWorkStruct must be a standard layout type");
79  static_assert(
80  offsetof(value_type, obj) == offsetof(true_value_type, obj),
81  "WorkStruct and GenericWorkStruct must have obj at the same offset");
82  static_assert(sizeof(value_type) <= sizeof(true_value_type),
83  "WorkStruct must not be smaller than GenericWorkStruct");
84  true_value_type* value_ptr = static_cast<true_value_type*>(ptr);
85 
86  value_ptr->dispatcher = dispatcher;
87  value_ptr->invoke = dispatcher->invoke;
88  new (&value_ptr->obj) holder(std::forward<holder_ctor_args>(ctor_args)...);
89  }
90 
91  // move construct in dst from the value in src and destroy the value in src
92  static RAJA_INLINE void move_destroy(WorkStruct* value_dst,
93  WorkStruct* value_src)
94  {
95  value_dst->dispatcher = value_src->dispatcher;
96  value_dst->invoke = value_src->invoke;
97  value_dst->dispatcher->move_construct_destroy(&value_dst->obj,
98  &value_src->obj);
99  }
100 
101  // destroy the value ptr
102  static RAJA_INLINE void destroy(WorkStruct* value_ptr)
103  {
104  value_ptr->dispatcher->destroy(&value_ptr->obj);
105  }
106 
107  // invoke the call operator of the value ptr with args
108  static RAJA_INLINE void host_call(const WorkStruct* value_ptr,
109  CallArgs... args)
110  {
111  value_ptr->invoke(&value_ptr->obj, std::forward<CallArgs>(args)...);
112  }
113 
115  // invoke the call operator of the value ptr with args
116  static RAJA_DEVICE RAJA_INLINE void device_call(const WorkStruct* value_ptr,
117  CallArgs... args)
118  {
119  value_ptr->invoke(&value_ptr->obj, std::forward<CallArgs>(args)...);
120  }
121 
123  typename dispatcher_type::invoker_type invoke;
124  typename std::aligned_storage<size, RAJA_MAX_ALIGN>::type obj;
125 };
126 
127 } // namespace detail
128 
129 } // namespace RAJA
130 
131 #endif // closing endif for header file include guard
#define RAJA_DEVICE
Definition: macros.hpp:66
Args args
Definition: WorkRunner.hpp:212
Definition: AlignedRangeIndexSetBuilders.cpp:35
Header file providing RAJA Dispatcher for workgroup.
Definition: Dispatcher.hpp:85
static RAJA_INLINE void host_call(const WorkStruct *value_ptr, CallArgs... args)
Definition: WorkStruct.hpp:108
std::aligned_storage< size, RAJA_MAX_ALIGN >::type obj
Definition: WorkStruct.hpp:124
static RAJA_DEVICE RAJA_INLINE void device_call(const WorkStruct *value_ptr, CallArgs... args)
Definition: WorkStruct.hpp:116
static RAJA_INLINE void construct(void *ptr, const dispatcher_type *dispatcher, holder_ctor_args &&... ctor_args)
Definition: WorkStruct.hpp:66
static RAJA_INLINE void destroy(WorkStruct *value_ptr)
Definition: WorkStruct.hpp:102
static RAJA_INLINE void move_destroy(WorkStruct *value_dst, WorkStruct *value_src)
Definition: WorkStruct.hpp:92
Definition: WorkStruct.hpp:40