OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
11constexpr 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
29template<typename vector_dist_ker>
30struct 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
57template<unsigned int dim,
58 typename St,
59 typename prop,
60 template<typename> class layout_base = memory_traits_inte>
61class 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
74public:
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
179 __device__ __host__ inline auto getPosOrig(int vec_key) -> decltype(v_pos.template get<0>(vec_key))
180 {
181 return v_pos.template get<0>(vec_key);
182 }
183
193 __device__ __host__ inline auto getPosOrig(const vect_dist_key_dx & vec_key) -> decltype(v_pos.template get<0>(vec_key.getKey()))
194 {
195 return v_pos.template get<0>(vec_key.getKey());
196 }
197
207 __device__ __host__ inline auto getPosOrig(int vec_key) const -> decltype(v_pos.template get<0>(vec_key))
208 {
209 return v_pos.template get<0>(vec_key);
210 }
211
221 __device__ __host__ inline auto getPosOrig(const vect_dist_key_dx & vec_key) const -> decltype(v_pos.template get<0>(vec_key.getKey()))
222 {
223 return v_pos.template get<0>(vec_key.getKey());
224 }
225
236 template<unsigned int id> __device__ __host__ inline auto getProp(int vec_key) -> decltype(v_prp.template get<id>(vec_key))
237 {
238 return v_prp.template get<id>(vec_key);
239 }
240
251 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()))
252 {
253 return v_prp.template get<id>(vec_key.getKey());
254 }
255
266 template<unsigned int id> __device__ __host__ inline auto getProp(int vec_key) const -> decltype(v_prp.template get<id>(vec_key))
267 {
268 return v_prp.template get<id>(vec_key);
269 }
270
281 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()))
282 {
283 return v_prp.template get<id>(vec_key.getKey());
284 }
285
293 {
294 return v_pos;
295 }
296
302 __device__ openfpm::vector_gpu_ker<prop,memory_traits_inte> & getPropVector()
303 {
304 return v_prp;
305 }
306
307 __host__ vector_dist_iterator getDomainIterator() const
308 {
309 std::cout << __FILE__ << ":" << __LINE__ << " error getDomainIterator used on a vector_dist_ker object is not allowed" << std::endl;
310
311 return vector_dist_iterator(0,0);
312 }
313
319 __host__ ite_gpu<1> getDomainIteratorGPU(size_t n_thr = default_kernel_wg_threads_) const
320 {
321 return v_pos.getGPUIteratorTo(g_m,n_thr);
322 }
323
329 __host__ bool operator==(const vector_dist_ker & v)
330 {
331 if (v.v_pos.template getPointer<0>() != v_pos.template getPointer<0>())
332 {return false;}
333
334 check_vector_dist_kernels<openfpm::vector_gpu_ker<prop,memory_traits_inte>> cv(this->v_prp,v.v_prp);
335
336 cv.check = true;
337
338 // Do the same for the properties
339 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,prop::max_prop> >(cv);
340
341 return cv.check;
342 }
343
349 __host__ bool isSubset() const
350 {
351 return false;
352 }
353
354#ifdef SE_CLASS1
355
361 pointer_check check_device_pointer(void * ptr)
362 {
363 pointer_check pc;
364
365 pc.match = false;
366
367 // we check the position vector and the property vector
368 pc = v_pos.check_device_pointer(ptr);
369
370 if (pc.match == true)
371 {
372 pc.match_str = std::string("Particle index overflow in position (v_pos): ") + "\n" + pc.match_str;
373 return pc;
374 }
375
376 pc = v_prp.check_device_pointer(ptr);
377 if (pc.match == true)
378 {
379 pc.match_str = std::string("Particle index overflow in properties (v_prp): ") + "\n" + pc.match_str;
380 return pc;
381 }
382
383 return pc;
384 }
385
386#endif
387};
388
389// This is a tranformation node for vector_distributed for the algorithm toKernel_tranform
390template<template <typename> class layout_base, typename T>
391struct toKernel_transform<layout_base,T,2>
392{
393 typedef typename apply_transform<layout_base,typename T::value_type>::type aggr;
394
395 typedef vector_dist_ker<T::dims,typename T::stype,aggr,layout_base> type;
396};
397
398#endif
399
400#endif /* VECTOR_DIST_GPU_HPP_ */
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
Grid key for a distributed grid.
Iterator that Iterate across particle indexes.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Transform the boost::fusion::vector into memory specification (memory_traits)
grid interface available when on gpu
ite_gpu< 1 > getGPUIteratorTo(size_t stop, size_t n_thr=default_kernel_wg_threads_) const
Get an iterator for the GPU.
__device__ __host__ unsigned int size() const
Return the size of the vector.
std::string match_str
match string
bool match
Indicate if the pointer match.