OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellList_gpu_ker.cuh
1 #ifndef CELLLIST_GPU_KER_CUH_
2 #define CELLLIST_GPU_KER_CUH_
3 
4 #include "NN/CellList/cuda/CellDecomposer_gpu_ker.cuh"
5 
6 
7 template<unsigned int dim, typename ids_type>
8 class NN_gpu_it
9 {
13 
14  unsigned int p;
15  int neighborCellIndexAct;
16  int cellPositionIndex;
17  unsigned int boxNeighborCellOffset_i;
18  unsigned int neighborPartIndexStart;
19  unsigned int neighborPartIndexStop;
20 
21  inline __device__ void SelectValid()
22  {
23  while (neighborPartIndexStart == neighborPartIndexStop && isNext())
24  {
25  this->nextCell();
26 
27  if (isNext() == false) break;
28 
29  if (cellPositionIndex+this->neighborCellIndexAct+1 >= numPartInCellPrefixSum.size() || cellPositionIndex+this->neighborCellIndexAct < 0)
30  continue;
31 
32  neighborPartIndexStart = numPartInCellPrefixSum.template get<0>(cellPositionIndex+this->neighborCellIndexAct);
33  neighborPartIndexStop = numPartInCellPrefixSum.template get<0>(cellPositionIndex+this->neighborCellIndexAct+1);
34  }
35  }
36 
37 public:
38  inline __device__ NN_gpu_it(
39  const grid_key_dx<dim,ids_type> & cellPosition,
42  const openfpm::vector_gpu_ker<aggregate<int>,memory_traits_inte> & neighborCellOffset,
43  const openfpm::array<ids_type,dim> & numCellDim)
44  : numPartInCellPrefixSum(numPartInCellPrefixSum),
45  sortedToUnsortedIndex(sortedToUnsortedIndex),
46  neighborCellOffset(neighborCellOffset),
47  cellPositionIndex(cid_<dim,ids_type,int>::get_cid(numCellDim,cellPosition)),
48  boxNeighborCellOffset_i(0),
49  p(1),
50  neighborCellIndexAct(neighborCellOffset.template get<0>(0))
51  {
52  neighborPartIndexStart = numPartInCellPrefixSum.template get<0>(cellPositionIndex+neighborCellIndexAct);
53  neighborPartIndexStop = numPartInCellPrefixSum.template get<0>(cellPositionIndex+neighborCellIndexAct+1);
54 
55  SelectValid();
56  }
57 
58  inline __device__ NN_gpu_it(
59  size_t p,
60  const grid_key_dx<dim,ids_type> & cellPosition,
63  const openfpm::vector_gpu_ker<aggregate<int>,memory_traits_inte> & neighborCellOffset,
64  const openfpm::array<ids_type,dim> & numCellDim)
65  : numPartInCellPrefixSum(numPartInCellPrefixSum),
66  sortedToUnsortedIndex(sortedToUnsortedIndex),
67  neighborCellOffset(neighborCellOffset),
68  cellPositionIndex(cid_<dim,ids_type,int>::get_cid(numCellDim,cellPosition)),
69  boxNeighborCellOffset_i(0),
70  p(p),
71  neighborCellIndexAct(neighborCellOffset.template get<0>(0))
72  {
73  neighborPartIndexStart = numPartInCellPrefixSum.template get<0>(cellPositionIndex+neighborCellIndexAct);
74  neighborPartIndexStop = numPartInCellPrefixSum.template get<0>(cellPositionIndex+neighborCellIndexAct+1);
75 
76  SelectValid();
77  }
78 
79  inline __device__ unsigned int get_sort()
80  {
81  return neighborPartIndexStart;
82  }
83 
84  inline __device__ unsigned int get()
85  {
86  return sortedToUnsortedIndex.template get<0>(neighborPartIndexStart);
87  }
88 
89  inline __device__ NN_gpu_it<dim,ids_type> & operator++()
90  {
91  ++neighborPartIndexStart; SelectValid();
92 
93  return *this;
94  }
95 
96  inline __device__ unsigned int get_start(unsigned int ce_id)
97  {
98  return numPartInCellPrefixSum.template get<0>(ce_id);
99  }
100 
101  inline __device__ unsigned int get_cid()
102  {
103  return cellPositionIndex + neighborCellIndexAct;
104  }
105 
106  inline __device__ bool isNext()
107  {
108  return boxNeighborCellOffset_i < neighborCellOffset.size();
109  }
110 
111  __device__ inline void nextCell()
112  {
113  ++boxNeighborCellOffset_i;
114 
115  if (isNext()) neighborCellIndexAct = neighborCellOffset.template get<0>(boxNeighborCellOffset_i);
116  }
117 
118 };
119 
120 
121 template<unsigned int dim, typename T, typename ids_type, typename transform_type, bool is_sparse>
122 class CellList_gpu_ker: public CellDecomposer_gpu_ker<dim,T,ids_type,transform_type>
123 {
126 
129 
132 
135 
138 
141 
143  unsigned int ghostMarker;
144 
145 public:
146 
147  typedef int yes_is_gpu_ker_celllist;
148 
151 
152  __host__ __device__ inline CellList_gpu_ker()
153  :ghostMarker(0)
154  {}
155 
156  __host__ __device__ inline CellList_gpu_ker(
164  openfpm::array<ids_type,dim> & numCellDim,
166  const transform_type & pointTransform,
167  unsigned int ghostMarker,
179  {}
180 
181  inline __device__ NN_gpu_it<dim,ids_type> getNNIteratorRadius(
182  const grid_key_dx<dim,ids_type> & cellPosition)
183  {
185 
186  return ngi;
187  }
188 
189  inline __device__ NN_gpu_it<dim,ids_type> getNNIteratorBox(
190  const grid_key_dx<dim,ids_type> & cellPosition)
191  {
193 
194  return ngi;
195  }
196 
197  inline __device__ NN_gpu_it<dim,ids_type> getNNIteratorBoxSym(
198  size_t p,
199  const grid_key_dx<dim,ids_type> & cellPosition)
200  {
202 
203  return ngi;
204  }
205 
206  inline __device__ openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & getDomainSortIds()
207  {
209  }
210 
211  inline __device__ openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & getSortToNonSort()
212  {
213  return sortedToUnsortedIndex;
214  }
215 
220  inline __device__ unsigned int getNCells() const
221  {
222  return numPartInCellPrefixSum.size() - 1;
223  }
224 
232  inline __device__ unsigned int getNelements(unsigned int cell_id) const
233  {
234  return numPartInCellPrefixSum.template get<0>(cell_id+1) - numPartInCellPrefixSum.template get<0>(cell_id);
235  }
236 
247  inline __device__ unsigned int get(
248  unsigned int cell,
249  unsigned int ele)
250  {
251  unsigned int p_id = numPartInCellPrefixSum.template get<0>(cell) + ele;
252  return sortedToUnsortedIndex.template get<0>(p_id);
253  }
254 
255 
256  inline __device__ unsigned int getGhostMarker()
257  {
258  return ghostMarker;
259  }
260 
261 #ifdef SE_CLASS1
262 
268  pointer_check check_device_pointer(void * ptr)
269  {
270  pointer_check pc;
271 
272  pc = numPartInCellPrefixSum.check_device_pointer(ptr);
273 
274  if (pc.match == true)
275  {
276  pc.match_str = std::string("Cell index overflow (numPartInCellPrefixSum): ") + "\n" + pc.match_str;
277  return pc;
278  }
279 
280  pc = sortedToUnsortedIndex.check_device_pointer(ptr);
281 
282  if (pc.match == true)
283  {
284  pc.match_str = std::string("Particle index overflow (str): ") + "\n" + pc.match_str;
285  return pc;
286  }
287 
288  pc = sortedToSortedIndexNoGhost.check_device_pointer(ptr);
289 
290  if (pc.match == true)
291  {
292  pc.match_str = std::string("Particle index overflow (sortedToSortedIndexNoGhost): ") + "\n" + pc.match_str;
293  return pc;
294  }
295 
296  pc = rcutNeighborCellOffset.check_device_pointer(ptr);
297 
298  if (pc.match == true)
299  {
300  pc.match_str = std::string("Particle index overflow (sortedToSortedIndexNoGhost): ") + "\n" + pc.match_str;
301  return pc;
302  }
303 
304  return pc;
305  }
306 
307 #endif
308 };
309 
310 
311 template<unsigned int dim, typename ids_type>
313 {
314  unsigned int neighborPartIndexStart;
315  unsigned int neighborPartIndexStop;
316  unsigned int neighborCellIndexStart;
317  unsigned int neighborCellIndexStop;
318 
320  const openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & neighborCellCountPrefixSum;
322 
323  __device__ void SelectValid()
324  {
325  while ((neighborPartIndexStart == neighborPartIndexStop) && isNext())
326  {
327  ++neighborCellIndexStart;
328 
329  if (neighborCellIndexStart < neighborCellIndexStop)
330  {
331  neighborPartIndexStart = neighborPartIndexFrom_To.template get<0>(neighborCellIndexStart);
332  neighborPartIndexStop = neighborPartIndexFrom_To.template get<1>(neighborCellIndexStart);
333  }
334  }
335  }
336 
337 public:
338  __device__ NN_gpu_it_sparse(
339  unsigned int cellIndex,
340  const openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & neighborCellCountPrefixSum,
343  : sortedToUnsortedIndex(sortedToUnsortedIndex),
344  neighborCellCountPrefixSum(neighborCellCountPrefixSum),
345  neighborPartIndexFrom_To(neighborPartIndexFrom_To)
346  {
347  if (cellIndex == (unsigned int)-1)
348  {
349  neighborCellIndexStop = neighborCellIndexStart;
350  return;
351  }
352 
353  neighborCellIndexStart = neighborCellCountPrefixSum.template get<0>(cellIndex);
354  neighborCellIndexStop = neighborCellCountPrefixSum.template get<0>(cellIndex + 1);
355 
356  neighborPartIndexStart = neighborPartIndexFrom_To.template get<0>(neighborCellIndexStart);
357  neighborPartIndexStop = neighborPartIndexFrom_To.template get<1>(neighborCellIndexStart);
358 
359  SelectValid();
360  }
361 
362  __device__ unsigned int get_sort()
363  {
364  return neighborPartIndexStart;
365  }
366 
367  __device__ unsigned int get()
368  {
369  return sortedToUnsortedIndex.template get<0>(neighborPartIndexStart);
370  }
371 
372  __device__ NN_gpu_it_sparse<dim,ids_type> & operator++()
373  {
374  ++neighborPartIndexStart; SelectValid();
375 
376  return *this;
377  }
378 
379  inline __device__ bool isNext()
380  {
381  return neighborCellIndexStart < neighborCellIndexStop;
382  }
383 };
384 
385 
386 template<unsigned int dim, typename T, typename ids_type, typename transform_type>
387 class CellList_gpu_ker<dim,T,ids_type,transform_type,true>: public CellDecomposer_gpu_ker<dim,T,ids_type,transform_type>
388 {
391 
394 
397 
400 
403 
405  unsigned int ghostMarker;
406 
407 public:
408 
411 
412  __host__ __device__ inline CellList_gpu_ker(
419  openfpm::array<ids_type,dim> & numCellDim,
421  const transform_type & pointTransform,
422  unsigned int ghostMarker,
426  )
428  neighborCellCountPrefixSum(neighborCellCountPrefixSum),
429  neighborPartIndexFrom_To(neighborPartIndexFrom_To),
432  vecSparseCellIndex_PartIndex(vecSparseCellIndex_PartIndex),
434  {}
435 
436  inline __device__ auto getCell(
437  const Point<dim,T> & xp)
438  const -> decltype(vecSparseCellIndex_PartIndex.get_sparse(0))
439  {
440  unsigned int cell = cid_<dim,ids_type,transform_type>::get_cid(this->get_div_c(),this->get_spacing_c(),this->get_off(),this->get_t(),xp);
441 
442  return vecSparseCellIndex_PartIndex.get_sparse(cell);
443  }
444 
445  inline __device__ NN_gpu_it_sparse<dim,ids_type> getNNIteratorBox(
446  decltype(vecSparseCellIndex_PartIndex.get_sparse(0)) cId)
447  {
448  NN_gpu_it_sparse<dim,ids_type> ngi(cId.id,neighborCellCountPrefixSum,neighborPartIndexFrom_To,sortedToUnsortedIndex);
449 
450  return ngi;
451  }
452 
453 
454  inline __device__ openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & getDomainSortIds()
455  {
457  }
458 
459  inline __device__ openfpm::vector_gpu_ker<aggregate<unsigned int>,memory_traits_inte> & getSortToNonSort()
460  {
461  return sortedToUnsortedIndex;
462  }
463 
464 
465  inline __device__ unsigned int getGhostMarker()
466  {
467  return ghostMarker;
468  }
469 
470 #ifdef SE_CLASS1
471 
477  pointer_check check_device_pointer(void * ptr)
478  {
479  pointer_check pc;
480 
481  pc = neighborCellCountPrefixSum.check_device_pointer(ptr);
482 
483  if (pc.match == true)
484  {
485  pc.match_str = std::string("Cell index overflow (starts): ") + "\n" + pc.match_str;
486  return pc;
487  }
488 
489  pc = neighborPartIndexFrom_To.check_device_pointer(ptr);
490 
491  if (pc.match == true)
492  {
493  pc.match_str = std::string("Cell particle buffer overflow (neighborPartIndexFrom_To): ") + "\n" + pc.match_str;
494  return pc;
495  }
496 
497  pc = sortedToUnsortedIndex.check_device_pointer(ptr);
498 
499  if (pc.match == true)
500  {
501  pc.match_str = std::string("Particle index overflow (str): ") + "\n" + pc.match_str;
502  return pc;
503  }
504 
505  pc = sortedToSortedIndexNoGhost.check_device_pointer(ptr);
506 
507  if (pc.match == true)
508  {
509  pc.match_str = std::string("Particle index overflow (sortedToSortedIndexNoGhost): ") + "\n" + pc.match_str;
510  return pc;
511  }
512 
513  return pc;
514  }
515 
516 #endif
517 };
518 
519 
520 #endif /* CELLLIST_GPU_KER_CUH_ */
This class represent an N-dimensional box.
Definition: Box.hpp:60
Box< dim, T > cellListSpaceBox
Unit box of the Cell list.
openfpm::array< ids_type, dim > cellPadDim
cell offset
openfpm::array< T, dim > unitCellP2
Spacing.
transform_type pointTransform
transformation
Point< dim, long int > cellShift
cellShift
grid_sm< dim, void > cellListGrid
Grid structure of the Cell list.
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > sortedToUnsortedIndex
Sorted to non sorted ids conversion.
int yes_has_check_device_pointer
Indicate this structure has a function to check the device pointer.
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > neighborCellCountPrefixSum
starting point for each cell
openfpm::vector_sparse_gpu_ker< aggregate< unsigned int >, int, memory_traits_inte > vecSparseCellIndex_PartIndex
Set of cells sparse.
openfpm::vector_gpu_ker< aggregate< unsigned int, unsigned int >, memory_traits_inte > neighborPartIndexFrom_To
starting point for each cell
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > sortedToSortedIndexNoGhost
Domain particles ids.
__device__ unsigned int getNCells() const
Get the number of cells this cell-list contain.
int yes_has_check_device_pointer
Indicate this structure has a function to check the device pointer.
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > numPartInCellPrefixSum
starting point for each cell
unsigned int ghostMarker
Ghost particle marker.
__device__ unsigned int get(unsigned int cell, unsigned int ele)
Get an element in the cell.
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > sortedToSortedIndexNoGhost
Domain particles ids.
openfpm::vector_gpu_ker< aggregate< int >, memory_traits_inte > boxNeighborCellOffsetSym
Box cells.
openfpm::vector_gpu_ker< aggregate< int >, memory_traits_inte > rcutNeighborCellOffset
radius cells
openfpm::vector_gpu_ker< aggregate< int >, memory_traits_inte > boxNeighborCellOffset
Box cells.
openfpm::vector_gpu_ker< aggregate< unsigned int >, memory_traits_inte > sortedToUnsortedIndex
Sorted to non sorted ids conversion.
__device__ unsigned int getNelements(unsigned int cell_id) const
Return the number of elements in the cell.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:19
__device__ openfpm::sparse_index< Ti > get_sparse(Ti id) const
Get the sparse index.
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...
Definition: aggregate.hpp:221
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:84
grid interface available when on 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.