OpenFPM  5.2.0
Project that contain the implementation of distributed structures
SupportBuilder.cuh
1 //
2 // Created by Serhii
3 //
4 
5 #ifndef OPENFPM_PDATA_SUPPORTBUILDER_CUH
6 #define OPENFPM_PDATA_SUPPORTBUILDER_CUH
7 
8 #include <Space/Shape/Point.hpp>
9 #include <Vector/vector_dist.hpp>
10 #include <utility>
11 #include "SupportBuilder.hpp"
12 
13 
14 template<unsigned int dim, typename T, typename particles_type, typename CellList_type, typename supportSize_type>
15 __global__ void gatherSupportSize_gpu(
17  CellList_type cellList,
18  supportSize_type supportSize,
19  T rCut)
20 {
21  auto p = GET_PARTICLE(particles);
23 
24  size_t N = 0;
25  auto Np = cellList.getNNIteratorBox(cellList.getCell(pos));
26  while (Np.isNext())
27  {
28  auto q = Np.get(); ++Np;
29 
30  if (p == q) continue;
31  if (pos.distance(particles.getPos(q)) < rCut) ++N;
32  }
33 
34  supportSize.get(p) = N;
35 }
36 
37 
38 template<unsigned int dim, typename T, typename particles_type, typename CellList_type, typename supportKey_type>
39 __global__ void assembleSupport_gpu(
41  CellList_type cellList,
42  supportKey_type supportSize,
43  supportKey_type supportKeys1D,
44  T rCut)
45 {
46  auto p = GET_PARTICLE(particles);
48 
49  size_t supportKeysSize = supportSize.get(p+1)-supportSize.get(p);
50  size_t* supportKeys = &((size_t*)supportKeys1D.getPointer())[supportSize.get(p)];
51 
52  size_t N = 0;
53  auto Np = cellList.getNNIteratorBox(cellList.getCell(pos));
54  while (Np.isNext())
55  {
56  auto q = Np.get(); ++Np;
57 
58  if (p == q) continue;
59  if (pos.distance(particles.getPos(q)) < rCut) supportKeys[N++] = q;
60  }
61 }
62 
63 
64 template<typename vector_type>
66 {
67 private:
68  vector_type &domain;
69  typename vector_type::stype rCut;
70 
71 public:
72  SupportBuilderGPU(vector_type &domain, typename vector_type::stype rCut)
73  : domain(domain), rCut(rCut) {}
74 
75  void getSupport(
76  size_t N,
78  openfpm::vector_custd<size_t>& supportKeys1D,
79  size_t& maxSupport,
80  size_t& supportKeysTotalN)
81  {
82  domain.hostToDevicePos();
83  auto it = domain.getDomainIteratorGPU(512);
85  auto NN = domain.getCellListGPU(rCut);
86  domain.updateCellListGPU(NN);
87 
88  // +1 to allow getting size from cumulative sum: "size[i+1] - size[i]"
89  kerOffsets.resize(N+1);
90  gatherSupportSize_gpu<vector_type::dims><<<it.wthr,it.thr>>>(domain.toKernel(), NN.toKernel(), kerOffsets.toKernel(), rCut);
91  kerOffsets.template deviceToHost();
92 
93  supportKeysTotalN = 0; maxSupport = 0;
94 
95  for (size_t i = 0; i < N; ++i) {
96  size_t sz = kerOffsets.get(i);
97  kerOffsets.get(i) = supportKeysTotalN;
98  supportKeysTotalN += sz;
99  if (maxSupport < sz) maxSupport = sz;
100  }
101  kerOffsets.get(N) = supportKeysTotalN;
102 
103  supportKeys1D.resize(supportKeysTotalN);
104  kerOffsets.template hostToDevice();
105  assembleSupport_gpu<vector_type::dims><<<it.wthr,it.thr>>>(domain.toKernel(), NN.toKernel(), kerOffsets.toKernel(), supportKeys1D.toKernel(), rCut);
106  supportKeys1D.template deviceToHost();
107  }
108 };
109 
110 
111 #endif //OPENFPM_PDATA_SUPPORTBUILDER_CUH
Class for FAST cell list implementation.
Definition: CellList.hpp:558
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:28
__device__ __host__ T distance(const Point< dim, T > &q) const
It calculate the distance between 2 points.
Definition: Point.hpp:265
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:204
Distributed vector.
auto getPos(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.