OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
tokernel_transformation.hpp
1/*
2 * tokernel_transformation.hpp
3 *
4 * Created on: Aug 29, 2018
5 * Author: i-bird
6 */
7
8#ifndef TOKERNEL_TRANSFORMATION_HPP_
9#define TOKERNEL_TRANSFORMATION_HPP_
10
11#include "data_type/aggregate.hpp"
12
20template<typename Tv>
22{
23 Tv & p;
24
25 inline host_to_dev_all_prp(Tv & p)
26 :p(p)
27 {};
28
30 template<typename T>
31 inline void operator()(T& t) const
32 {
33 p.template hostToDevice<T::value>();
34 }
35};
36
37template<typename T, typename T_ker, typename type_prp, template<typename> class layout_base , int is_vector>
39{
40 template<typename mem_type, typename obj_type> static void transform(mem_type * mem, obj_type & obj, size_t start, size_t stop)
41 {
42 start /= sizeof(type_prp);
43 stop /= sizeof(type_prp);
44
45 // The type of device and the type on host does not match (in general)
46 // So we have to convert before transfer
47
48 T * ptr = static_cast<T *>(obj.get_pointer());
49
50 mem_type tmp;
51
52 tmp.allocate(mem->size());
53
54 T_ker * ptr_tt = static_cast<T_ker *>(tmp.getPointer());
55
56 for(size_t i = start ; i < stop ; i++)
57 {
58 new (&ptr_tt[i]) T_ker();
59 ptr_tt[i] = ptr[i].toKernel();
60 }
61
62 mem->hostToDevice(tmp);
63 }
64
66 template<typename obj_type>
67 static void call(obj_type & obj, size_t start, size_t stop)
68 {
69 T * ptr = static_cast<T *>(obj.get_pointer());
70
71 for(size_t i = start ; i < stop ; i++)
72 {
73 host_to_dev_all_prp<T> hdap(ptr[i]);
74
75 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::value_type::max_prop>>(hdap);
76 }
77 }
78};
79
80template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
81struct call_recursive_host_device_if_vector<T,T_ker,type_prp,layout_base,0>
82{
83 template<typename mem_type,typename obj_type> static void transform(mem_type * mem, obj_type & obj, size_t start, size_t stop)
84 {
85 mem->hostToDevice(start,stop);
86 }
87
89 template<typename obj_type>
90 static void call(obj_type & obj, size_t start, size_t stop) {}
91};
92
93template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
94struct call_recursive_host_device_if_vector<T,T_ker,type_prp,layout_base,3>
95{
96 template<typename mem_type,typename obj_type> static void transform(mem_type * mem, obj_type & obj, size_t start, size_t stop)
97 {
98 // calculate the start and stop elements
99 start /= std::extent<type_prp,0>::value;
100 stop /= std::extent<type_prp,0>::value;
101 size_t sz = mem->size() / std::extent<type_prp,0>::value;
102
103 size_t offset = 0;
104 for (size_t i = 0 ; i < std::extent<type_prp,0>::value ; i++)
105 {
106 mem->hostToDevice(offset+start,offset+stop);
107 offset += sz;
108 }
109 }
110
112 template<typename obj_type>
113 static void call(obj_type & obj, size_t start, size_t stop) {}
114};
115
116template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
117struct call_recursive_host_device_if_vector<T,T_ker,type_prp,layout_base,4>
118{
119 template<typename mem_type,typename obj_type> static void transform(mem_type * mem, obj_type & obj, size_t start, size_t stop)
120 {
121 // calculate the start and stop elements
122 start = start / std::extent<type_prp,0>::value / std::extent<type_prp,1>::value;
123 stop = stop / std::extent<type_prp,0>::value / std::extent<type_prp,1>::value;
124 size_t sz = mem->size() / std::extent<type_prp,0>::value / std::extent<type_prp,1>::value;
125
126 size_t offset = 0;
127 for (size_t i = 0 ; i < std::extent<type_prp,0>::value ; i++)
128 {
129 for (size_t j = 0 ; j < std::extent<type_prp,1>::value ; j++)
130 {
131 mem->hostToDevice(offset+start,offset+stop);
132 offset += sz;
133 }
134 }
135 }
136
138 template<typename obj_type>
139 static void call(obj_type & obj, size_t start, size_t stop) {}
140};
141
186namespace openfpm
187{
188
195 template<typename T, template <typename> class layout_base>
196 struct vector_gpu_ker;
197}
198
199// Definition of the box
200template<unsigned int dim , typename T> class Box;
201
202template<template <typename> class layout_base, typename T, int = is_vector_native<T>::value + 2*is_vector_dist<T>::value + 4*is_gpu_celllist<T>::value >
204
205template<template <typename> class layout_base, typename T, typename ... args>
207{
208 typedef void type;
209};
210
211template<template <typename> class layout_base, typename T, int impl, typename ... args>
213{
215};
216
217template<template <typename> class layout_base, typename T, typename ... args>
218struct apply_trasform_impl<layout_base,T,boost::fusion::vector<args...>>
219{
220 static const int impl = is_aggregate<T>::value + is_Box<T>::value * 2 + is_Point<T>::value * 4;
221
222 typedef typename aggregate_or_known_type<layout_base,T,impl,args...>::type type;
223};
224
225
226template<template <typename> class layout_base,typename T>
228{
229 typedef typename apply_trasform_impl<layout_base,T,typename T::type>::type type;
230};
231
233
234template<template <typename> class layout_base, typename T >
235struct toKernel_transform<layout_base,T,0>
236{
237 typedef T type;
238};
239
240
241template<template <typename> class layout_base, typename T>
242struct toKernel_transform<layout_base,T,1>
243{
244 typedef typename apply_transform<layout_base,typename T::value_type>::type aggr;
245
247};
248
250
251template<unsigned int dim ,typename T> class Point;
252
253template<template <typename> class layout_base,typename T, typename ... args>
254struct aggregate_or_known_type<layout_base,T,2,args ...>
255{
257};
258
259template<template <typename> class layout_base,typename T, typename ... args>
260struct aggregate_or_known_type<layout_base,T,4,args ...>
261{
263};
264
265#endif /* TOKERNEL_TRANSFORMATION_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
convert a type into constant type
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
static void call(obj_type &obj, size_t start, size_t stop)
It is not a vector nothing to do.
static void call(obj_type &obj, size_t start, size_t stop)
It is not a vector nothing to do.
static void call(obj_type &obj, size_t start, size_t stop)
It is not a vector nothing to do.
static void call(obj_type &obj, size_t start, size_t stop)
It is a vector recursively call deviceToHost.
this class is a functor for "for_each" algorithm
void operator()(T &t) const
It call the copy function for each property.
Check this is a gpu or cpu type cell-list.
Definition util.hpp:74
grid interface available when on gpu