OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_kernel.hpp
1 /*
2  * vector_dist_gpu.hpp
3  *
4  * Created on: Jul 28, 2018
5  * Author: i-bird
6  */
7 
8 #ifndef VECTOR_DIST_GPU_HPP_
9 #define VECTOR_DIST_GPU_HPP_
10 
11 constexpr unsigned int POS_PROP = (unsigned int)-1;
12 
13 #ifdef CUDA_GPU
14 
15 #define GET_PARTICLE(vd) blockDim.x*blockIdx.x + threadIdx.x; if (blockDim.x*blockIdx.x + threadIdx.x >= static_cast<unsigned int>(vd.size_local())) {return;};
16 #define GET_PARTICLE_SORT(p,NN) if (blockDim.x*blockIdx.x + threadIdx.x >= NN.get_g_m()) {return;}\
17  else{p = NN.getDomainSortIds().template get<0>(blockDim.x*blockIdx.x + threadIdx.x);}
18 
19 
20 #define GET_PARTICLE_BY_ID(p,ids) if (blockDim.x*blockIdx.x + threadIdx.x >= ids.size()) {return;}\
21  else{p = ids.template get<0>(blockDim.x*blockIdx.x + threadIdx.x);}
22 
29 template<typename vector_dist_ker>
30 struct check_vector_dist_kernels
31 {
33  const vector_dist_ker & o1;
35  const vector_dist_ker & o2;
36 
37  bool check;
38 
45  inline check_vector_dist_kernels(const vector_dist_ker & o1, const vector_dist_ker & o2)
46  :o1(o1),o2(o2),check(false)
47  {};
48 
50  template<typename T>
51  __device__ __host__ inline void operator()(T& t)
52  {
53  check &= o1.template getPointer<T::value>() == o2.template getPointer<T::value>();
54  }
55 };
56 
57 template<unsigned int dim,
58  typename St,
59  typename prop,
60  template<typename> class layout_base = memory_traits_inte>
61 class vector_dist_ker
62 {
64  int g_m = 0;
65 
68  mutable openfpm::vector_gpu_ker<Point<dim,St>,layout_base> v_pos;
69 
73 
74 public:
75 
77  typedef St stype;
78 
80  static const unsigned int dims = dim;
81 
83  typedef int vector_kernel;
84 
86  typedef int yes_has_check_device_pointer;
87 
89  typedef prop value_type;
90 
91  vector_dist_ker()
92  :g_m(0)
93  {}
94 
95  vector_dist_ker(int g_m, const openfpm::vector_gpu_ker<Point<dim,St>,layout_base> & v_pos,
96  const openfpm::vector_gpu_ker<typename apply_transform<layout_base,prop>::type,layout_base> & v_prp)
97  :g_m(g_m),v_pos(v_pos),v_prp(v_prp)
98  {}
99 
105  __device__ __host__ int size_local() const {return g_m;}
106 
112  __device__ __host__ int size() const {return v_pos.size();}
113 
123  __device__ __host__ inline auto getPos(int vec_key) -> decltype(v_pos.template get<0>(vec_key))
124  {
125  return v_pos.template get<0>(vec_key);
126  }
127 
137  __device__ __host__ inline auto getPos(const vect_dist_key_dx & vec_key) -> decltype(v_pos.template get<0>(vec_key.getKey()))
138  {
139  return v_pos.template get<0>(vec_key.getKey());
140  }
141 
151  __device__ __host__ inline auto getPos(int vec_key) const -> decltype(v_pos.template get<0>(vec_key))
152  {
153  return v_pos.template get<0>(vec_key);
154  }
155 
165  __device__ __host__ inline auto getPos(const vect_dist_key_dx & vec_key) const -> decltype(v_pos.template get<0>(vec_key.getKey()))
166  {
167  return v_pos.template get<0>(vec_key.getKey());
168  }
169 
180  template<unsigned int id> __device__ __host__ inline auto getProp(int vec_key) -> decltype(v_prp.template get<id>(vec_key))
181  {
182  return v_prp.template get<id>(vec_key);
183  }
184 
195  template<unsigned int id> __device__ __host__ inline auto getProp(const vect_dist_key_dx & vec_key) -> decltype(v_prp.template get<id>(vec_key.getKey()))
196  {
197  return v_prp.template get<id>(vec_key.getKey());
198  }
199 
210  template<unsigned int id> __device__ __host__ inline auto getProp(int vec_key) const -> decltype(v_prp.template get<id>(vec_key))
211  {
212  return v_prp.template get<id>(vec_key);
213  }
214 
225  template<unsigned int id> __device__ __host__ inline auto getProp(const vect_dist_key_dx & vec_key) const -> decltype(v_prp.template get<id>(vec_key.getKey()))
226  {
227  return v_prp.template get<id>(vec_key.getKey());
228  }
229 
236  __device__ openfpm::vector_gpu_ker<Point<dim,St>,memory_traits_inte> & getPosVector()
237  {
238  return v_pos;
239  }
240 
246  __device__ openfpm::vector_gpu_ker<prop,memory_traits_inte> & getPropVector()
247  {
248  return v_prp;
249  }
250 
251  __host__ vector_dist_iterator getDomainIterator() const
252  {
253  std::cout << __FILE__ << ":" << __LINE__ << " error getDomainIterator used on a vector_dist_ker object is not allowed" << std::endl;
254 
255  return vector_dist_iterator(0,0);
256  }
257 
263  __host__ ite_gpu<1> getDomainIteratorGPU(size_t n_thr = default_kernel_wg_threads_) const
264  {
265  return v_pos.getGPUIteratorTo(g_m,n_thr);
266  }
267 
273  __host__ bool operator==(const vector_dist_ker & v)
274  {
275  if (v.v_pos.template getPointer<0>() != v_pos.template getPointer<0>())
276  {return false;}
277 
278  check_vector_dist_kernels<openfpm::vector_gpu_ker<prop,memory_traits_inte>> cv(this->v_prp,v.v_prp);
279 
280  cv.check = true;
281 
282  // Do the same for the properties
283  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,prop::max_prop> >(cv);
284 
285  return cv.check;
286  }
287 
293  __host__ bool isSubset() const
294  {
295  return false;
296  }
297 
298 #ifdef SE_CLASS1
299 
305  pointer_check check_device_pointer(void * ptr)
306  {
307  pointer_check pc;
308 
309  pc.match = false;
310 
311  // we check the position vector and the property vector
312  pc = v_pos.check_device_pointer(ptr);
313 
314  if (pc.match == true)
315  {
316  pc.match_str = std::string("Particle index overflow in position (v_pos): ") + "\n" + pc.match_str;
317  return pc;
318  }
319 
320  pc = v_prp.check_device_pointer(ptr);
321  if (pc.match == true)
322  {
323  pc.match_str = std::string("Particle index overflow in properties (v_prp): ") + "\n" + pc.match_str;
324  return pc;
325  }
326 
327  return pc;
328  }
329 
330 #endif
331 };
332 
333 // This is a tranformation node for vector_distributed for the algorithm toKernel_tranform
334 template<template <typename> class layout_base, typename T>
335 struct toKernel_transform<layout_base,T,2>
336 {
337  typedef typename apply_transform<layout_base,typename T::value_type>::type aggr;
338 
339  typedef vector_dist_ker<T::dims,typename T::stype,aggr,layout_base> type;
340 };
341 
342 #endif
343 
344 #endif /* VECTOR_DIST_GPU_HPP_ */
bool match
Indicate if the pointer match.
grid interface available when on gpu
Iterator that Iterate across particle indexes.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
Grid key for a distributed grid.
ite_gpu< 1 > getGPUIteratorTo(size_t stop, size_t n_thr=default_kernel_wg_threads_) const
Get an iterator for the GPU.
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:83
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
__device__ __host__ unsigned int size() const
Return the size of the vector.
std::string match_str
match string