2#define BOOST_TEST_DYN_LINK
3#include <boost/test/unit_test.hpp>
4#include "Space/Shape/Box.hpp"
5#include "Vector/map_vector.hpp"
6#include "NN/CellList/cuda/CellList_gpu.hpp"
7#define DISABLE_MPI_WRITTERS
8#include "VTKWriter/VTKWriter.hpp"
10template<
typename vector_pos_type,
typename vector_prop_type>
11__global__
void test_launch(vector_pos_type set_points, vector_prop_type
prop,
Box<3,float> domain)
13 int p = threadIdx.x + blockIdx.x * blockDim.x;
15 if (p >= set_points.size())
19 pos[0] = set_points.template get<0>(p)[0];
20 pos[1] = set_points.template get<0>(p)[1];
21 pos[2] = set_points.template get<0>(p)[1];
23 float scalar =
prop.template get<0>(p);
27 v[0] =
prop.template get<1>(p)[0];
28 v[1] =
prop.template get<1>(p)[1];
29 v[2] =
prop.template get<1>(p)[2];
32template<
typename gr
id_type>
37 float scalar =
grid.template get<0>(key);
41 v[0] =
grid.template get<1>(key)[0];
42 v[1] =
grid.template get<1>(key)[1];
43 v[2] =
grid.template get<1>(key)[2];
45 printf(
"Grid point %d %d %d scalar: %f vector: %f %f %f \n",(
int)key.get(0),(
int)key.get(1),(
int)key.get(2),scalar,v[0],v[1],v[2]);
48__global__
void test_launch_cuda_native(
float * scalar,
float * vector,
int sxy,
int sx ,
int sy ,
int sz ,
int stride)
52 id[0] = threadIdx.x + blockIdx.x * blockDim.x;
53 id[1] = threadIdx.y + blockIdx.y * blockDim.y;
54 id[2] = threadIdx.z + blockIdx.z * blockDim.z;
56 if (
id[0] >= sx) {
return;}
57 if (
id[1] >= sy) {
return;}
58 if (
id[2] >= sz) {
return;}
60 float s = scalar[
id[2]*sxy+
id[1]*sx+
id[0]];
64 v[0] = vector[
id[2]*sxy+
id[1]*sx+
id[0] + 0*stride];
65 v[1] = vector[
id[2]*sxy+
id[1]*sx+
id[0] + 1*stride];
66 v[2] = vector[
id[2]*sxy+
id[1]*sx+
id[0] + 2*stride];
68 printf(
"Grid point from CUDA %d %d %d scalar: %f vector: %f %f %f \n",
id[0],
id[1],
id[2],s,v[0],v[1],v[2]);
71constexpr int NN_num = 4;
103BOOST_AUTO_TEST_SUITE( grid_gpu_func_interp )
105BOOST_AUTO_TEST_CASE (gpu_p2m)
113 for (
size_t i = 0 ; i < 100 ; i++)
115 pos.template get<0>(i)[0] = (float)rand() / RAND_MAX;
116 pos.template get<0>(i)[1] = (float)rand() / RAND_MAX;
117 pos.template get<0>(i)[2] = (float)rand() / RAND_MAX;
119 prop.template get<0>(i) = 5.0;
120 prop.template get<1>(i)[0] = 3.0;
121 prop.template get<1>(i)[1] = 4.0;
122 prop.template get<1>(i)[2] = 5.0;
125 pos.template hostToDevice<0>();
126 prop.template hostToDevice<0,1>();
130 auto ite = pos.getGPUIterator();
132 test_launch<<<ite.wthr,ite.thr>>>(pos.toKernel(),
prop.toKernel(),domain);
136 grid.resize({10,10,10});
138 auto it =
grid.getIterator();
144 grid.template get<0>(key) = key.get(0) + key.get(1) + key.get(2);
145 grid.template get<1>(key)[0] = key.get(0);
146 grid.template get<1>(key)[1] = key.get(1);
147 grid.template get<1>(key)[2] = key.get(2);
155 auto ite_g =
grid.getGPUIterator(start,stop);
157 grid.template hostToDevice<0,1>();
163 test_launch_cuda_native<<<
ite_g.wthr,
ite_g.thr>>>((
float *)
grid.template getDeviceBuffer<0>(),(
float *)
grid.template getDeviceBuffer<1>(),100,10,10,10,
grid.size());
170 pos_sort.resize(pos.
size());
171 prop_sort.resize(
prop.size());
173 size_t g_m = pos.
size();
177 const size_t (& sz)[3] =
grid.getGrid().getSize();
179 CellList_gpu<3,float,CudaMemory,shift_only<3,float>> cl(domain,sz,2);
181 cl.template construct(pos,pos_sort,
prop,prop_sort,context,g_m);
186 auto ite_gpu = getGPUIterator_impl(cl.getGrid(),start_c,stop_c);
195 VECTOR_POINTS> vtk_writer;
196 vtk_writer.add(pos,
prop,pos.
size());
199 prp_names.add(
"scalar");
200 prp_names.add(
"vector");
202 file_type ft = file_type::ASCII;
204 pos.template deviceToHost<0>();
205 prop.template deviceToHost<0,1>();
208 vtk_writer.write(
"particles.vtk",prp_names,
"particles",ft);
211BOOST_AUTO_TEST_CASE (gpu_m2p)
216BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This is a distributed grid.
grid_key_dx is the key to access any element in the grid
Implementation of 1-D std::vector like structure.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...