5#ifndef OPENFPM_PDATA_SPARSEGRIDGPU_TESTKERNELS_CUH
6#define OPENFPM_PDATA_SPARSEGRIDGPU_TESTKERNELS_CUH
10template<
unsigned int dim,
unsigned int p_src,
unsigned int p_dst>
17 static constexpr unsigned int supportRadius = 1;
19 template<
typename SparseGr
idT,
typename DataBlockWrapperT>
20 static inline __device__
void stencil(
21 SparseGridT & sparseGrid,
22 const unsigned int dataBlockId,
26 DataBlockWrapperT & dataBlockLoad,
27 DataBlockWrapperT & dataBlockStore,
28 unsigned char curMask)
30 if (curMask == mask_sparse::EXIST_AND_PADDING)
32 dataBlockStore.template get<p_dst>()[offset] = pointCoord.
get(0);
37template<
unsigned int dim,
unsigned int p_src,
unsigned int p_dst,
typename ScalarT =
float>
44 static constexpr unsigned int supportRadius = 1;
46 template<
typename SparseGr
idT,
typename DataBlockWrapperT>
47 static inline __device__
void stencil(
48 SparseGridT & sparseGrid,
49 const unsigned int dataBlockId,
53 DataBlockWrapperT & dataBlockLoad,
54 DataBlockWrapperT & dataBlockStore,
55 unsigned char curMask,
56 ScalarT minX, ScalarT maxX, ScalarT minValue, ScalarT maxValue)
58 if (curMask == mask_sparse::EXIST_AND_PADDING)
60 const ScalarT x = pointCoord.
get(0);
62 auto value = maxValue * (x - minX) / (maxX - minX - 1);
71 dataBlockStore.template get<p_dst>()[offset] = value;
75 template <
typename SparseGr
idT,
typename CtxT>
76 static inline void __host__ flush(SparseGridT & sparseGrid, CtxT & ctx)
84template<
unsigned int p,
typename SparseGr
idType,
typename ValueType>
85__global__
void insertSphere(SparseGridType sparseGrid,
grid_key_dx<2,int> start,
float r1,
float r2, ValueType value)
87 constexpr unsigned int pMask = SparseGridType::pMask;
88 typedef BlockTypeOf<typename SparseGridType::AggregateType, p> BlockT;
89 typedef BlockTypeOf<typename SparseGridType::AggregateType, pMask> MaskBlockT;
91 typedef typename SparseGridType::indexT_ idType;
94 blockIdx.x + start.
get(0) / sparseGrid.getBlockEdgeSize(),
95 blockIdx.y + start.
get(1) / sparseGrid.getBlockEdgeSize()
98 unsigned int offset = threadIdx.x;
100 __shared__
bool is_block_empty;
102 if (threadIdx.x == 0 && threadIdx.y == 0)
103 {is_block_empty =
true;}
107 auto blockId = sparseGrid.getBlockLinId(blk);
110 keyg = sparseGrid.getGlobalCoord(blk,offset);
112 float radius = sqrt( (
float)
113 (keyg.
get(0) - (start.
get(0) + gridDim.x/2*SparseGridType::blockEdgeSize_))
114 * (keyg.
get(0) - (start.
get(0) + gridDim.x/2*SparseGridType::blockEdgeSize_))
115 + (keyg.
get(1) - (start.
get(1) + gridDim.y/2*SparseGridType::blockEdgeSize_))
116 * (keyg.
get(1) - (start.
get(1) + gridDim.y/2*SparseGridType::blockEdgeSize_)) );
118 bool is_active = radius < r1 && radius > r2;
120 if (is_active ==
true)
122 is_block_empty =
false;
127 if (is_block_empty ==
false)
129 auto ec = sparseGrid.insertBlock(blockId);
131 if ( is_active ==
true)
133 ec.template get<p>()[offset] = value;
140 sparseGrid.flush_block_insert();
143template<
unsigned int p,
typename SparseGr
idType,
typename ValueType>
144__global__
void insertSphere3D(SparseGridType sparseGrid,
grid_key_dx<3,int> start,
float r1,
float r2, ValueType value)
146 constexpr unsigned int pMask = SparseGridType::pMask;
147 typedef BlockTypeOf<typename SparseGridType::AggregateType, p> BlockT;
148 typedef BlockTypeOf<typename SparseGridType::AggregateType, pMask> MaskBlockT;
150 typedef typename SparseGridType::indexT_ idType;
153 blockIdx.x + start.
get(0) / sparseGrid.getBlockEdgeSize(),
154 blockIdx.y + start.
get(1) / sparseGrid.getBlockEdgeSize(),
155 blockIdx.z + start.
get(2) / sparseGrid.getBlockEdgeSize()});
157 unsigned int offset = threadIdx.x;
159 __shared__
bool is_block_empty;
161 if (threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0)
162 {is_block_empty =
true;}
166 auto blockId = sparseGrid.getBlockLinId(blk);
169 keyg = sparseGrid.getGlobalCoord(blk,offset);
171 const long int x = (
long int)keyg.
get(0) - (start.
get(0) + gridDim.x / 2 * SparseGridType::blockEdgeSize_);
172 const long int y = (
long int)keyg.
get(1) - (start.
get(1) + gridDim.y / 2 * SparseGridType::blockEdgeSize_);
173 const long int z = (
long int)keyg.
get(2) - (start.
get(2) + gridDim.z / 2 * SparseGridType::blockEdgeSize_);
175 float radius = sqrt((
float) (x*x + y*y + z*z));
177 bool is_active = radius < r1 && radius >= r2;
179 if (is_active ==
true)
181 is_block_empty =
false;
186 if (is_block_empty ==
false)
188 auto ec = sparseGrid.insertBlock(blockId);
190 if ( is_active ==
true)
192 ec.template get<p>()[offset] = value;
199 sparseGrid.flush_block_insert();
202template<
unsigned int p,
typename SparseGr
idType,
typename ValueType>
203__global__
void insertSphere3D_radius(SparseGridType sparseGrid,
grid_key_dx<3,int> start,
float r1,
float r2, ValueType value)
205 constexpr unsigned int pMask = SparseGridType::pMask;
206 typedef BlockTypeOf<typename SparseGridType::AggregateType, p> BlockT;
207 typedef BlockTypeOf<typename SparseGridType::AggregateType, pMask> MaskBlockT;
209 typedef typename SparseGridType::indexT_ idType;
212 blockIdx.x + start.
get(0) / sparseGrid.getBlockEdgeSize(),
213 blockIdx.y + start.
get(1) / sparseGrid.getBlockEdgeSize(),
214 blockIdx.z + start.
get(2) / sparseGrid.getBlockEdgeSize()});
216 unsigned int offset = threadIdx.x;
218 __shared__
bool is_block_empty;
220 if (threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0)
221 {is_block_empty =
true;}
225 auto blockId = sparseGrid.getBlockLinId(blk);
228 keyg = sparseGrid.getGlobalCoord(blk,offset);
230 const long int x = (
long int)keyg.
get(0) - (start.
get(0) + gridDim.x / 2 * SparseGridType::blockEdgeSize_);
231 const long int y = (
long int)keyg.
get(1) - (start.
get(1) + gridDim.y / 2 * SparseGridType::blockEdgeSize_);
232 const long int z = (
long int)keyg.
get(2) - (start.
get(2) + gridDim.z / 2 * SparseGridType::blockEdgeSize_);
234 float radius = sqrt((
float) (x*x + y*y + z*z));
236 bool is_active = radius < r1 && radius > r2;
238 if (is_active ==
true)
240 is_block_empty =
false;
245 if (is_block_empty ==
false)
247 auto ec = sparseGrid.insertBlock(blockId);
249 if ( is_active ==
true)
251 ec.template get<p>()[offset] = x+y+z;
258 sparseGrid.flush_block_insert();
261template<
unsigned int p,
typename SparseGr
idType,
typename ValueType>
262__global__
void insertSphere3D_radiusV(SparseGridType sparseGrid,
grid_key_dx<3,int> start,
float r1,
float r2, ValueType value)
264 constexpr unsigned int pMask = SparseGridType::pMask;
265 typedef BlockTypeOf<typename SparseGridType::AggregateType, p> BlockT;
266 typedef BlockTypeOf<typename SparseGridType::AggregateType, pMask> MaskBlockT;
268 typedef typename SparseGridType::indexT_ idType;
271 blockIdx.x + start.
get(0) / sparseGrid.getBlockEdgeSize(),
272 blockIdx.y + start.
get(1) / sparseGrid.getBlockEdgeSize(),
273 blockIdx.z + start.
get(2) / sparseGrid.getBlockEdgeSize()});
275 unsigned int offset = threadIdx.x;
277 __shared__
bool is_block_empty;
279 if (threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0)
280 {is_block_empty =
true;}
284 auto blockId = sparseGrid.getBlockLinId(blk);
287 keyg = sparseGrid.getGlobalCoord(blk,offset);
289 const long int x = (
long int)keyg.
get(0) - (start.
get(0) + gridDim.x / 2 * SparseGridType::blockEdgeSize_);
290 const long int y = (
long int)keyg.
get(1) - (start.
get(1) + gridDim.y / 2 * SparseGridType::blockEdgeSize_);
291 const long int z = (
long int)keyg.
get(2) - (start.
get(2) + gridDim.z / 2 * SparseGridType::blockEdgeSize_);
293 float radius = sqrt((
float) (x*x + y*y + z*z));
295 bool is_active = radius < r1 && radius > r2;
297 if (is_active ==
true)
299 is_block_empty =
false;
304 if (is_block_empty ==
false)
306 auto ec = sparseGrid.insertBlock(blockId);
308 if ( is_active ==
true)
310 ec.template get<p>()[offset] = x+y+z;
311 ec.template get<p+1>()[0][offset] = x;
312 ec.template get<p+1>()[1][offset] = y;
313 ec.template get<p+1>()[2][offset] = z;
320 sparseGrid.flush_block_insert();
323template<
unsigned int p,
typename SparseGr
idType,
typename ValueType>
324__global__
void removeSphere3D_even_radiusV(SparseGridType sparseGrid,
grid_key_dx<3,int> start,
float r1,
float r2, ValueType value)
326 constexpr unsigned int pMask = SparseGridType::pMask;
327 typedef BlockTypeOf<typename SparseGridType::AggregateType, p> BlockT;
328 typedef BlockTypeOf<typename SparseGridType::AggregateType, pMask> MaskBlockT;
330 typedef typename SparseGridType::indexT_ idType;
333 blockIdx.x + start.
get(0) / sparseGrid.getBlockEdgeSize(),
334 blockIdx.y + start.
get(1) / sparseGrid.getBlockEdgeSize(),
335 blockIdx.z + start.
get(2) / sparseGrid.getBlockEdgeSize()});
337 unsigned int offset = threadIdx.x;
339 auto blockId = sparseGrid.getBlockLinId(blk);
342 keyg = sparseGrid.getGlobalCoord(blk,offset);
344 const long int x = (
long int)keyg.
get(0) - (start.
get(0) + gridDim.x / 2 * SparseGridType::blockEdgeSize_);
345 const long int y = (
long int)keyg.
get(1) - (start.
get(1) + gridDim.y / 2 * SparseGridType::blockEdgeSize_);
346 const long int z = (
long int)keyg.
get(2) - (start.
get(2) + gridDim.z / 2 * SparseGridType::blockEdgeSize_);
348 float radius = sqrt((
float) (x*x + y*y + z*z));
350 bool is_active = radius < r1 && radius > r2 && (keyg.
get(0) + keyg.
get(1) + keyg.
get(2)) % 2 == 0;
352 if (is_active ==
true)
354 sparseGrid.remove(keyg);
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data