OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
memory_conf.hpp
1/*
2 * memory_conf.hpp
3 *
4 * Created on: Aug 28, 2014
5 * Author: Pietro Incardona
6 */
7
8#ifndef MEMORY_CONF_HPP_
9#define MEMORY_CONF_HPP_
10
11#include "util/variadic_to_vmpl.hpp"
12#include "t_to_memory_c.hpp"
13#include "Vector/vect_isel.hpp"
14#include "Vector/util.hpp"
15#include "util/tokernel_transformation.hpp"
16#include "util/hostDevice_util_funcs.hpp"
17
18constexpr int SOA_layout_IA = 2;
19constexpr int SOA_layout = 1;
20constexpr int AOS_layout = 0;
21
39template<typename Seq>
41{
42 typedef typename v_transform<t_to_memory_c,Seq>::type type;
43};
44
62template<typename Seq>
64{
65 typedef typename v_transform<t_to_memory_c_red,Seq>::type type;
66};
67
68
82template<typename T>
84{
86 typedef typename inter_memc<typename T::type>::type type;
87
89 typedef int yes_is_inte;
90
91 typedef boost::mpl::int_<SOA_layout_IA> type_value;
92
102 template<unsigned int p, typename data_type, typename g1_type, typename key_type>
103 __host__ __device__ static inline auto get(data_type & data_, const g1_type & g1, const key_type & v1) -> decltype(boost::fusion::at_c<p>(data_).mem_r.operator[](g1.LinId(v1)))
104 {
105 return boost::fusion::at_c<p>(data_).mem_r.operator[](g1.LinId(v1));
106 }
107
117 template<unsigned int p, typename data_type, typename g1_type>
118 __host__ __device__ static inline auto get_lin(data_type & data_, const g1_type & g1, size_t lin_id) -> decltype(boost::fusion::at_c<p>(data_).mem_r.operator[](lin_id))
119 {
120 return boost::fusion::at_c<p>(data_).mem_r.operator[](lin_id);
121 }
122
132 template<unsigned int p, typename data_type, typename g1_type, typename key_type>
133 __host__ __device__ static inline auto get_c(const data_type & data_, const g1_type & g1, const key_type & v1) -> decltype(boost::fusion::at_c<p>(data_).mem_r.operator[](g1.LinId(v1)))
134 {
135 return boost::fusion::at_c<p>(data_).mem_r.operator[](g1.LinId(v1));
136 }
137
147 template<unsigned int p, typename data_type, typename g1_type>
148 __host__ __device__ static inline auto get_lin_c(const data_type & data_, const g1_type & g1, size_t lin_id) -> decltype(boost::fusion::at_c<p>(data_).mem_r.operator[](lin_id))
149 {
150 return boost::fusion::at_c<p>(data_).mem_r.operator[](lin_id);
151 }
152
161 template<typename S, typename data_type, unsigned int ... prp>
162 static void hostToDevice(data_type & data_, size_t start, size_t stop)
163 {
164 host_to_device_impl<T,memory_traits_inte,S, prp ...> dth(data_,start,stop);
165
166 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(dth);
167 }
168
177 template<typename data_type, unsigned int ... prp>
178 static void deviceToHost(data_type & data_, size_t start, size_t stop)
179 {
180 device_to_host_start_stop_impl<T, memory_traits_inte, prp ...> dth(data_,start,stop);
181
182 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(dth);
183 }
184};
185
199/*template<typename T>
200struct memory_traits_inte_red
201{
203 typedef typename inter_memc_red<typename T::type>::type type;
204
206 typedef int yes_is_inte;
207};*/
208
213template<typename T, bool is_agg>
215{
217};
218
223template<typename T>
225{
226 typedef void type;
227};
228
241template<typename T>
243{
246
247 typedef int yes_is_tlin;
248
249 typedef boost::mpl::int_<AOS_layout> type_value;
250
261 template<unsigned int p, typename data_type, typename g1_type, typename key_type, typename std::enable_if<!std::is_same<data_type, memory_c<boost::fusion::vector<>, 1, memory>>::value,int>::type = 0>
262 __host__ __device__ static inline auto get(data_type & data_, const g1_type & g1, const key_type & v1) -> decltype(boost::fusion::at_c<p>(data_.mem_r.operator[](g1.LinId(v1)))) &
263 {
264 return boost::fusion::at_c<p>(data_.mem_r.operator[](g1.LinId(v1)));
265 }
266
277 template<unsigned int p, typename data_type, typename g1_type, typename key_type, typename std::enable_if<std::is_same<data_type, memory_c<boost::fusion::vector<>, 1, memory>>::value,int>::type = 0>
278 __host__ __device__ static inline void get(data_type & data_, const g1_type & g1, const key_type & v1) {}
279
290 template<unsigned int p, typename data_type, typename g1_type, typename std::enable_if<!std::is_same<data_type, memory_c<boost::fusion::vector<>, 1, memory>>::value,int>::type = 0>
291 __host__ __device__ static inline auto get_lin(data_type & data_, const g1_type & g1, const size_t lin_id) -> decltype(boost::fusion::at_c<p>(data_.mem_r.operator[](lin_id))) &
292 {
293 return boost::fusion::at_c<p>(data_.mem_r.operator[](lin_id));
294 }
295
306 template<unsigned int p, typename data_type, typename g1_type, typename std::enable_if<std::is_same<data_type, memory_c<boost::fusion::vector<>, 1, memory>>::value,int>::type = 0>
307 __host__ __device__ static inline auto get_lin(data_type & data_, const g1_type & g1, const size_t lin_id) {}
308
318 template<unsigned int p, typename data_type, typename g1_type, typename key_type, typename std::enable_if<!std::is_same<data_type, memory_c<boost::fusion::vector<>, 1, memory>>::value,int>::type = 0>
319 __host__ __device__ static inline auto get_c(const data_type & data_, const g1_type & g1, const key_type & v1) -> decltype(boost::fusion::at_c<p>(data_.mem_r.operator[](g1.LinId(v1)))) &
320 {
321 return boost::fusion::at_c<p>(data_.mem_r.operator[](g1.LinId(v1)));
322 }
323
333 template<unsigned int p, typename data_type, typename g1_type>
334 __host__ __device__ static inline auto get_lin_c(const data_type & data_, const g1_type & g1, const size_t lin_id) -> decltype(boost::fusion::at_c<p>(data_.mem_r.operator[](lin_id))) &
335 {
336 return boost::fusion::at_c<p>(data_.mem_r.operator[](lin_id));
337 }
338
347 template<typename S, typename data_type, unsigned int ... prp>
348 static void hostToDevice(data_type & data_, size_t start, size_t stop)
349 {
350 data_.mem->hostToDevice(start*sizeof(T),(stop+1)*sizeof(T));
351 }
352
361 template<typename data_type, unsigned int ... prp>
362 static void deviceToHost(data_type & data_, size_t start, size_t stop)
363 {
364 data_.mem->deviceToHost(start*sizeof(T),(stop+1)*sizeof(T));
365 }
366};
367
368
370
371template<typename T, typename Sfinae = void>
372struct is_layout_mlin: std::false_type {};
373
374
384template<typename T>
385struct is_layout_mlin<T, typename Void< typename T::yes_is_tlin>::type> : std::true_type
386{};
387
388
389template<typename T, typename Sfinae = void>
390struct is_layout_inte: std::false_type {};
391
392
402template<typename T>
403struct is_layout_inte<T, typename Void< typename T::yes_is_inte>::type> : std::true_type
404{};
405
417template<typename T, unsigned int impl = is_vector<T>::value >
418struct is_multiple_buffer_each_prp: std::false_type
419{};
420
421template<typename T>
422struct is_multiple_buffer_each_prp<T,true>: is_layout_inte<typename T::layout_base_>
423{};
424
425#endif
Void structure.
Definition common.hpp:74
this class is a functor for "for_each" algorithm
this class is a functor for "for_each" algorithm
This class convert a boost::mpl::fusion/vector to a boost::mpl::fusion/vector with memory_c<....
This class convert a boost::mpl::fusion/vector to a boost::mpl::fusion/vector with memory_c interleav...
is_multiple_buffer_each_prp
Transform the boost::fusion::vector into memory specification (memory_traits)
inter_memc< typenameT::type >::type type
for each element in the vector interleave memory_c
__host__ static __device__ auto get_lin(data_type &data_, const g1_type &g1, size_t lin_id) -> decltype(boost::fusion::at_c< p >(data_).mem_r.operator[](lin_id))
Return a reference to the selected element.
__host__ static __device__ auto get_c(const data_type &data_, const g1_type &g1, const key_type &v1) -> decltype(boost::fusion::at_c< p >(data_).mem_r.operator[](g1.LinId(v1)))
Return a reference to the selected element.
__host__ static __device__ auto get_lin_c(const data_type &data_, const g1_type &g1, size_t lin_id) -> decltype(boost::fusion::at_c< p >(data_).mem_r.operator[](lin_id))
Return a reference to the selected element.
static void deviceToHost(data_type &data_, size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host.
int yes_is_inte
indicate that it change the memory layout from the original
__host__ static __device__ auto get(data_type &data_, const g1_type &g1, const key_type &v1) -> decltype(boost::fusion::at_c< p >(data_).mem_r.operator[](g1.LinId(v1)))
Return a reference to the selected element.
static void hostToDevice(data_type &data_, size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host.
Transform the boost::fusion::vector into memory specification (memory_traits)
Transform the boost::fusion::vector into memory specification (memory_traits)
__host__ static __device__ auto get_lin_c(const data_type &data_, const g1_type &g1, const size_t lin_id) -> decltype(boost::fusion::at_c< p >(data_.mem_r.operator[](lin_id))) &
Return a reference to the selected element.
__host__ static __device__ auto get_lin(data_type &data_, const g1_type &g1, const size_t lin_id)
Return a reference to the selected element SFINAE is used to hande CSR graphs, where boost::fusion::a...
__host__ static __device__ void get(data_type &data_, const g1_type &g1, const key_type &v1)
Return a reference to the selected element. SFINAE is used to hande CSR graphs, where boost::fusion::...
__host__ static __device__ auto get_c(const data_type &data_, const g1_type &g1, const key_type &v1) -> decltype(boost::fusion::at_c< p >(data_.mem_r.operator[](g1.LinId(v1)))) &
Return a reference to the selected element.
memory_traits_lin_type< T, openfpm::vect_isel< T >::value==OPENFPM_NATIVE >::type type
for each element in the vector interleave memory_c
__host__ static __device__ auto get_lin(data_type &data_, const g1_type &g1, const size_t lin_id) -> decltype(boost::fusion::at_c< p >(data_.mem_r.operator[](lin_id))) &
Return a reference to the selected element SFINAE is used to hande CSR graphs, where boost::fusion::a...
static void deviceToHost(data_type &data_, size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host.
__host__ static __device__ auto get(data_type &data_, const g1_type &g1, const key_type &v1) -> decltype(boost::fusion::at_c< p >(data_.mem_r.operator[](g1.LinId(v1)))) &
Return a reference to the selected element SFINAE is used to hande CSR graphs, where boost::fusion::a...
static void hostToDevice(data_type &data_, size_t start, size_t stop)
Copy the memory from host to device.
v_transform_impl< H, first, last, exit_::value >::type type
generate the boost::fusion::vector apply H on each term