2#define BOOST_TEST_DYN_LINK
5#include <boost/test/unit_test.hpp>
6#include "Grid/grid_dist_id.hpp"
9BOOST_AUTO_TEST_SUITE( sgrid_gpu_test_suite )
11template<
unsigned int p>
14 template<
typename SparseGr
idGpu_type,
typename ite_type>
15 __device__
void operator()(SparseGridGpu_type & sg, ite_type & ite,
float c)
17 GRID_ID_2_GLOBAL(ite);
21 if (inactive ==
false)
22 {sg.template insert<p>(key) = c + keyg.get(0) + keyg.get(1);}
26 sg.flush_block_insert();
32template<
unsigned int p>
35 template<
typename SparseGr
idGpu_type,
typename ite_type>
36 __device__
void operator()(SparseGridGpu_type & sg, ite_type & ite,
float c)
38 GRID_ID_3_GLOBAL(ite);
42 if (inactive ==
false)
43 {sg.template insert<p>(key) = c + keyg.get(0) + keyg.get(1) + keyg.get(2);}
47 sg.flush_block_insert();
52BOOST_AUTO_TEST_CASE( sgrid_gpu_test_base )
54 size_t sz[2] = {17,17};
61 sgrid_dist_id_gpu<2,float,aggregate<float>> gdist(sz,domain,g,bc);
63 gdist.template setBackgroundValue<0>(666);
68 auto it = gdist.getGridIterator(box.getKP1(),box.getKP2());
74 gdist.template iterateGridGPU<insert_kernel2D<0>>(it,c);
75 gdist.template flush<smax_<0>>(flush_type::FLUSH_ON_DEVICE);
77 gdist.template deviceToHost<0>();
82 auto it = gdist.getGridIterator(box2.getKP1(),box2.getKP2());
86 auto p = it.get_dist();
89 if (p2.get(0) == box.getLow(0) && p2.get(1) == box.getLow(1))
91 BOOST_REQUIRE_EQUAL(gdist.template get<0>(p), 7.0);
95 BOOST_REQUIRE_EQUAL(gdist.template get<0>(p), 666.0);
108 auto it3 = gdist.getGridIterator(box3.getKP1(),box3.getKP2());
110 gdist.template iterateGridGPU<insert_kernel2D<0>>(it3,c);
111 gdist.template flush<smax_<0>>(flush_type::FLUSH_ON_DEVICE);
112 gdist.template deviceToHost<0>();
117 auto it = gdist.getGridIterator(box2.getKP1(),box2.getKP2());
121 auto p = it.get_dist();
126 if (box.isInside(p2_))
128 BOOST_REQUIRE_EQUAL(gdist.template get<0>(p), 7.0);
130 else if (box3.isInside(p2_))
132 float tst = c + p2.get(0) + p2.get(1);
134 BOOST_REQUIRE_EQUAL(gdist.template get<0>(p), tst);
138 BOOST_REQUIRE_EQUAL(gdist.template get<0>(p), 666.0);
147BOOST_AUTO_TEST_CASE( sgrid_gpu_test_output )
149 auto & v_cl = create_vcluster();
151 if (v_cl.size() > 3){
return;}
153 size_t sz[2] = {17,17};
160 sgrid_dist_id_gpu<2,float,aggregate<float>> gdist(sz,domain,g,bc);
162 gdist.template setBackgroundValue<0>(666);
167 auto it = gdist.getGridIterator(box.getKP1(),box.getKP2());
173 gdist.template iterateGridGPU<insert_kernel2D<0>>(it,c);
174 gdist.template flush<smax_<0>>(flush_type::FLUSH_ON_DEVICE);
176 gdist.template deviceToHost<0>();
178 gdist.write(
"sgrid_gpu_output");
180 std::string file_test(
"sgrid_gpu_output_" + std::to_string(v_cl.size()) +
"_" + std::to_string(v_cl.rank()) +
".vtk");
181 std::string file(
"sgrid_gpu_output_" + std::to_string(v_cl.rank()) +
".vtk");
184 bool test = compare(file,
"test_data/" + file_test);
186 BOOST_REQUIRE_EQUAL(
true,test);
190template<
typename gr
id,
typename box_type>
191void check_sgrid(
grid & gdist2, box_type & box,
float c)
195 auto it2 = gdist2.getDomainIterator();
201 auto key = it2.getGKey(p);
203 auto p_xp1 = p.move(0,1);
204 auto p_xm1 = p.move(0,-1);
205 auto p_yp1 = p.move(1,1);
206 auto p_ym1 = p.move(1,-1);
208 auto key_xp1 = key.move(0,1);
209 auto key_xm1 = key.move(0,-1);
210 auto key_yp1 = key.move(1,1);
211 auto key_ym1 = key.move(1,-1);
213 if (box.isInside(key_xp1.toPoint()))
215 match &= gdist2.template get<0>(p_xp1) == c + key_xp1.get(0) + key_xp1.get(1);
219 std::cout << gdist2.template get<0>(p_xp1) <<
" " << c + key_xp1.get(0) + key_xp1.get(1) << std::endl;
220 std::cout <<
"1 " << key_xp1.to_string() <<
" " << p_xp1.getKey().toPoint().to_string() <<
" " << &gdist2.template get<0>(p_xp1) << std::endl;
225 if (box.isInside(key_xm1.toPoint()))
227 match &= gdist2.template get<0>(p_xm1) == c + key_xm1.get(0) + key_xm1.get(1);
231 std::cout << gdist2.template get<0>(p_xm1) <<
" " << c + key_xm1.get(0) + key_xm1.get(1) << std::endl;
232 std::cout <<
"2 " << key_xm1.to_string() << std::endl;
237 if (box.isInside(key_yp1.toPoint()))
239 match &= gdist2.template get<0>(p_yp1) == c + key_yp1.get(0) + key_yp1.get(1);
243 std::cout << gdist2.template get<0>(p_yp1) <<
" " << c + key_yp1.get(0) + key_yp1.get(1) << std::endl;
244 std::cout <<
"3 " << key_yp1.to_string() << std::endl;
249 if (box.isInside(key_ym1.toPoint()))
251 match &= gdist2.template get<0>(p_ym1) == c + key_ym1.get(0) + key_ym1.get(1);
255 std::cout << gdist2.template get<0>(p_ym1) <<
" " << c + key_ym1.get(0) + key_ym1.get(1) << std::endl;
256 std::cout <<
"4 " << key_ym1.to_string() << std::endl;
266 auto & v_cl = create_vcluster();
271 BOOST_REQUIRE_EQUAL(match,
true);
272 BOOST_REQUIRE_EQUAL(n_point,350*350);
275template<
typename gr
id,
typename box_type>
276void check_sgrid_no_ghost(
grid & gdist2, box_type & box,
float c)
280 auto it2 = gdist2.getDomainIterator();
286 auto key = it2.getGKey(p);
288 match &= gdist2.template get<0>(p) == c + key.get(0) + key.get(1);
292 std::cout << gdist2.template get<0>(p) <<
" " << c + key.get(0) + key.get(1) << std::endl;
293 std::cout <<
"1 " << key.to_string() <<
" " << p.getKey().toPoint().to_string() <<
" " << &gdist2.template get<0>(p) << std::endl;
302 auto & v_cl = create_vcluster();
307 BOOST_REQUIRE_EQUAL(match,
true);
308 BOOST_REQUIRE_EQUAL(n_point,350*350);
311BOOST_AUTO_TEST_CASE( sgrid_gpu_test_load_from_file )
313 auto & v_cl = create_vcluster();
317 if (v_cl.size() > 8){
return;}
319 size_t sz[2] = {370,370};
332 sgrid_dist_id_gpu<2,float,aggregate<float,float>> gdist2(sz,domain,g,bc);
334 gdist2.load(
"test_data/sgrid_gpu_output_hdf5");
335 gdist2.deviceToHost<0,1>();
336 check_sgrid_no_ghost(gdist2,box,c);
337 gdist2.template hostToDevice<0>();
338 gdist2.template ghost_get<0,1>(RUN_ON_DEVICE);
340 gdist2.deviceToHost<0,1>();
341 check_sgrid(gdist2,box,c);
344BOOST_AUTO_TEST_CASE( sgrid_gpu_test_save_and_load )
346 auto & v_cl = create_vcluster();
348 if (v_cl.size() > 3){
return;}
350 size_t sz[2] = {370,370};
357 sgrid_dist_id_gpu<2,float,aggregate<float,float>> gdist(sz,domain,g,bc);
359 gdist.template setBackgroundValue<0>(666);
364 auto it = gdist.getGridIterator(box.getKP1(),box.getKP2());
372 gdist.addPoints(box.getKP1(),box.getKP2(),[] __device__ (
int i,
int j)
376 [c] __device__ (InsertBlockT & data,
int i,
int j)
378 data.template get<0>() = c + i + j;
379 data.template get<1>() = c + 1000 + i + j;
383 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
385 gdist.template deviceToHost<0>();
386 gdist.save(
"sgrid_gpu_output_hdf5");
387 gdist.write(
"sgrid_conf");
391 sgrid_dist_id_gpu<2,float,aggregate<float,float>> gdist2(sz,domain,g,bc);
393 gdist2.load(
"sgrid_gpu_output_hdf5");
394 gdist2.deviceToHost<0,1>();
395 check_sgrid_no_ghost(gdist2,box,c);
396 gdist2.template hostToDevice<0>();
397 gdist2.template ghost_get<0,1>(RUN_ON_DEVICE);
399 gdist2.deviceToHost<0,1>();
400 gdist.deviceToHost<0,1>();
401 check_sgrid(gdist2,box,c);
404void sgrid_ghost_get(
size_t (& sz)[2],
size_t (& sz2)[2])
412 sgrid_dist_id_gpu<2,float,aggregate<float>> gdist(sz,domain,g,bc);
414 gdist.template setBackgroundValue<0>(666);
419 auto it = gdist.getGridIterator(box.getKP1(),box.getKP2());
425 gdist.template iterateGridGPU<insert_kernel2D<0>>(it,c);
426 gdist.template flush<smax_<0>>(flush_type::FLUSH_ON_DEVICE);
428 gdist.template deviceToHost<0>();
430 gdist.template ghost_get<0>(RUN_ON_DEVICE);
432 gdist.template deviceToHost<0>();
436 auto it2 = gdist.getDomainIterator();
444 auto key = it2.getGKey(p);
446 auto p_xp1 = p.move(0,1);
447 auto p_xm1 = p.move(0,-1);
448 auto p_yp1 = p.move(1,1);
449 auto p_ym1 = p.move(1,-1);
451 auto key_xp1 = key.move(0,1);
452 auto key_xm1 = key.move(0,-1);
453 auto key_yp1 = key.move(1,1);
454 auto key_ym1 = key.move(1,-1);
456 if (box.isInside(key_xp1.toPoint()))
458 match &= gdist.template get<0>(p_xp1) == c + key_xp1.get(0) + key_xp1.get(1);
462 std::cout << gdist.template get<0>(p_xp1) <<
" " << c + key_xp1.get(0) + key_xp1.get(1) << std::endl;
467 if (box.isInside(key_xm1.toPoint()))
469 match &= gdist.template get<0>(p_xm1) == c + key_xm1.get(0) + key_xm1.get(1);
473 std::cout << gdist.template get<0>(p_xm1) <<
" " << c + key_xm1.get(0) + key_xm1.get(1) << std::endl;
478 if (box.isInside(key_yp1.toPoint()))
480 match &= gdist.template get<0>(p_yp1) == c + key_yp1.get(0) + key_yp1.get(1);
484 std::cout << gdist.template get<0>(p_yp1) <<
" " << c + key_yp1.get(0) + key_yp1.get(1) << std::endl;
489 if (box.isInside(key_ym1.toPoint()))
491 match &= gdist.template get<0>(p_ym1) == c + key_ym1.get(0) + key_ym1.get(1);
495 std::cout << gdist.template get<0>(p_ym1) <<
" " << c + key_ym1.get(0) + key_ym1.get(1) << std::endl;
503 BOOST_REQUIRE_EQUAL(match,
true);
506BOOST_AUTO_TEST_CASE( sgrid_gpu_test_ghost_get )
508 size_t sz[2] = {17,17};
509 size_t sz6[2] = {15,15};
510 sgrid_ghost_get(sz,sz6);
514 size_t sz2[2] = {170,170};
515 size_t sz3[2] = {15,15};
516 sgrid_ghost_get(sz2,sz3);
518 size_t sz4[2] = {168,168};
519 sgrid_ghost_get(sz2,sz4);
522BOOST_AUTO_TEST_CASE( sgrid_gpu_app_point_test_no_box )
524 size_t sz[3] = {75,75,75};
531 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
533 gdist.template setBackgroundValue<0>(666);
534 gdist.template setBackgroundValue<1>(666);
535 gdist.template setBackgroundValue<2>(666);
536 gdist.template setBackgroundValue<3>(666);
551 *(
int *)cmem.getPointer() = 0.0;
555 int * cnt = (
int *)cmem.getDevicePointer();
557 gdist.addPoints([cnt] __device__ (
int i,
int j,
int k)
563 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
565 data.template get<0>() = c + i + j;
566 data.template get<1>() = c + 1000 + i + j;
570 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
571 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
575 int cnt_host = *(
int *)cmem.getPointer();
577 auto & v_cl = create_vcluster();
582 BOOST_REQUIRE_EQUAL(cnt_host,75*75*75);
586BOOST_AUTO_TEST_CASE( sgrid_gpu_app_point_test )
588 size_t sz[3] = {75,75,75};
595 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
597 gdist.template setBackgroundValue<0>(666);
598 gdist.template setBackgroundValue<1>(666);
599 gdist.template setBackgroundValue<2>(666);
600 gdist.template setBackgroundValue<3>(666);
617 *(
int *)cmem.getPointer() = 0.0;
623 int * cnt = (
int *)cmem.getDevicePointer();
628 gdist.addPoints(bx.getKP1(),bx.getKP2(),
629 [cnt,cnt_out,bx] __device__ (
int i,
int j,
int k)
637 atomicAdd(cnt_out,1);
642 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
644 data.template get<0>() = c + i + j;
645 data.template get<1>() = c + 1000 + i + j;
649 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
650 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
655 int cnt_host = *(
int *)cmem.getPointer();
656 int cnt_host_out = *(
int *)cmem_out.
getPointer();
658 auto & v_cl = create_vcluster();
660 v_cl.sum(cnt_host_out);
664 BOOST_REQUIRE_EQUAL(cnt_host_out,0);
665 BOOST_REQUIRE_EQUAL(cnt_host,bx.getVolumeKey());
669BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv2_test )
671 size_t sz[2] = {164,164};
678 sgrid_dist_id_gpu<2,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
680 gdist.template setBackgroundValue<0>(666);
681 gdist.template setBackgroundValue<1>(666);
682 gdist.template setBackgroundValue<2>(666);
683 gdist.template setBackgroundValue<3>(666);
695 gdist.addPoints(box.getKP1(),box.getKP2(),
696 [] __device__ (
int i,
int j)
700 [c] __device__ (InsertBlockT & data,
int i,
int j)
702 data.template get<0>() = c + i + j;
703 data.template get<1>() = c + 1000 + i + j;
707 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
708 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
713 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
715 gdist.template conv2<0,1,2,3,1>({2,2},{(
int)sz[0]-2,(
int)sz[1]-2},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j){
716 u_out = u(i+1,j) - u(i-1,j) + u(i,j+1) - u(i,j-1);
717 v_out = v(i+1,j) - v(i-1,j) + v(i,j+1) - v(i,j-1);
720 gdist.deviceToHost<0,1,2,3>();
724 auto it3 = gdist.getSubDomainIterator({2,2},{(
int)sz[0]-2,(
int)sz[1]-2});
732 auto p_xp1 = p.move(0,1);
733 auto p_xm1 = p.move(0,-1);
734 auto p_yp1 = p.move(1,1);
735 auto p_ym1 = p.move(1,-1);
737 float sub1 = gdist.template get<2>(p);
738 float sub2 = gdist.template get<3>(p);
740 if (sub1 != 4.0 || sub2 != 4.0)
742 std::cout << sub1 <<
" " << sub2 << std::endl;
743 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
744 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
752 BOOST_REQUIRE_EQUAL(match,
true);
756BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv2_test_3d )
759 size_t sz[3] = {20,20,20};
761 size_t sz[3] = {60,60,60};
769 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
771 gdist.template setBackgroundValue<0>(666);
772 gdist.template setBackgroundValue<1>(666);
773 gdist.template setBackgroundValue<2>(666);
774 gdist.template setBackgroundValue<3>(666);
786 gdist.addPoints(box.getKP1(),box.getKP2(),
787 [] __device__ (
int i,
int j,
int k)
791 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
793 data.template get<0>() = c + i + j + k;
794 data.template get<1>() = c + 1000 + i + j + k;
798 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
800 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
802 for (
int i = 0 ; i < 10 ; i++)
804 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
809 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
811 gdist.template conv2<0,1,2,3,1>({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
812 u_out = u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1);
813 v_out = v(i+1,j,k) - v(i-1,j,k) + v(i,j+1,k) - v(i,j-1,k) + v(i,j,k+1) - v(i,j,k-1);
816 gdist.deviceToHost<0,1,2,3>();
820 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2});
828 auto p_xp1 = p.move(0,1);
829 auto p_xm1 = p.move(0,-1);
830 auto p_yp1 = p.move(1,1);
831 auto p_ym1 = p.move(1,-1);
832 auto p_zp1 = p.move(2,1);
833 auto p_zm1 = p.move(2,-1);
835 float sub1 = gdist.template get<2>(p);
836 float sub2 = gdist.template get<3>(p);
838 if (sub1 != 6.0 || sub2 != 6.0)
840 std::cout << sub1 <<
" " << sub2 << std::endl;
841 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
842 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
850 BOOST_REQUIRE_EQUAL(match,
true);
853BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv_cross_block_test_3d )
856 size_t sz[3] = {20,20,20};
858 size_t sz[3] = {60,60,60};
866 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
868 gdist.template setBackgroundValue<0>(666);
869 gdist.template setBackgroundValue<1>(666);
870 gdist.template setBackgroundValue<2>(666);
871 gdist.template setBackgroundValue<3>(666);
883 gdist.addPoints(box.getKP1(),box.getKP2(),
884 [] __device__ (
int i,
int j,
int k)
888 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
890 data.template get<0>() = c + i + j + k;
891 data.template get<1>() = c + 1000 + i + j + k;
895 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
897 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
899 for (
int i = 0 ; i < 10 ; i++)
901 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
906 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
908 gdist.template conv_cross_b<0,1,1>({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2},[] __device__ (CpBlockType & u,
auto & block,
int offset,
int i,
int j,
int k){
909 return u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1) + block.template get<0>()[offset];
912 gdist.deviceToHost<0,1,2,3>();
916 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2});
924 auto p_xp1 = p.move(0,1);
925 auto p_xm1 = p.move(0,-1);
926 auto p_yp1 = p.move(1,1);
927 auto p_ym1 = p.move(1,-1);
928 auto p_zp1 = p.move(2,1);
929 auto p_zm1 = p.move(2,-1);
931 float sub1 = gdist.template get<1>(p);
933 if (sub1 != 6.0 + gdist.template get<0>(p))
935 std::cout << sub1 << std::endl;
936 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
937 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
945 BOOST_REQUIRE_EQUAL(match,
true);
948BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv2_b_test_3d )
951 size_t sz[3] = {20,20,20};
953 size_t sz[3] = {60,60,60};
961 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
963 gdist.template setBackgroundValue<0>(666);
964 gdist.template setBackgroundValue<1>(666);
965 gdist.template setBackgroundValue<2>(666);
966 gdist.template setBackgroundValue<3>(666);
978 gdist.addPoints(box.getKP1(),box.getKP2(),
979 [] __device__ (
int i,
int j,
int k)
983 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
985 data.template get<0>() = c + i + j + k;
986 data.template get<1>() = c + 1000 + i + j + k;
990 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
992 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
994 for (
int i = 0 ; i < 10 ; i++)
996 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1001 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
1003 gdist.template conv2_b<0,1,2,3,1>({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
auto & block,
int offset,
int i,
int j,
int k){
1004 u_out = u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1) + block.template get<0>()[offset];
1005 v_out = v(i+1,j,k) - v(i-1,j,k) + v(i,j+1,k) - v(i,j-1,k) + v(i,j,k+1) - v(i,j,k-1) + block.template get<1>()[offset];
1008 gdist.deviceToHost<0,1,2,3>();
1012 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2});
1016 while (it3.isNext())
1020 auto p_xp1 = p.move(0,1);
1021 auto p_xm1 = p.move(0,-1);
1022 auto p_yp1 = p.move(1,1);
1023 auto p_ym1 = p.move(1,-1);
1024 auto p_zp1 = p.move(2,1);
1025 auto p_zm1 = p.move(2,-1);
1027 float sub1 = gdist.template get<2>(p) ;
1028 float sub2 = gdist.template get<3>(p);
1030 if (sub1 != 6.0 + gdist.template get<0>(p) || sub2 != 6.0 + gdist.template get<1>(p))
1032 std::cout << sub1 <<
" " << sub2 << std::endl;
1033 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
1034 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
1042 BOOST_REQUIRE_EQUAL(match,
true);
1045BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv3_b_test_3d )
1048 size_t sz[3] = {20,20,20};
1050 size_t sz[3] = {60,60,60};
1058 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float,float,float>> gdist(sz,domain,g,bc);
1060 gdist.template setBackgroundValue<0>(666);
1061 gdist.template setBackgroundValue<1>(666);
1062 gdist.template setBackgroundValue<2>(666);
1063 gdist.template setBackgroundValue<3>(666);
1064 gdist.template setBackgroundValue<4>(666);
1065 gdist.template setBackgroundValue<5>(666);
1077 gdist.addPoints(box.getKP1(),box.getKP2(),
1078 [] __device__ (
int i,
int j,
int k)
1082 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
1084 data.template get<0>() = c + i + j + k;
1085 data.template get<1>() = c + 1000 + i + j + k;
1086 data.template get<2>() = c + 10000 + i + j + k;
1090 gdist.template flush<smax_<0>,
smax_<1>,
smax_<2>>(flush_type::FLUSH_ON_DEVICE);
1092 gdist.template ghost_get<0,1,2>(RUN_ON_DEVICE);
1094 for (
int i = 0 ; i < 10 ; i++)
1096 gdist.template ghost_get<0,1,2>(RUN_ON_DEVICE);
1101 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
1103 gdist.template conv3_b<0,1,2,3,4,5,1>({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2},[] __device__ (
float & u_out,
float & v_out,
float & m_out, CpBlockType & u, CpBlockType & v , CpBlockType & m,
auto & block,
int offset,
int i,
int j,
int k){
1104 u_out = u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1) + block.template get<0>()[offset];
1105 v_out = v(i+1,j,k) - v(i-1,j,k) + v(i,j+1,k) - v(i,j-1,k) + v(i,j,k+1) - v(i,j,k-1) + block.template get<1>()[offset];
1106 m_out = m(i+1,j,k) - m(i-1,j,k) + m(i,j+1,k) - m(i,j-1,k) + m(i,j,k+1) - m(i,j,k-1) + block.template get<2>()[offset];
1109 gdist.deviceToHost<0,1,2,3,4,5>();
1113 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-2,(
int)sz[1]-2,(
int)sz[2]-2});
1117 while (it3.isNext())
1121 auto p_xp1 = p.move(0,1);
1122 auto p_xm1 = p.move(0,-1);
1123 auto p_yp1 = p.move(1,1);
1124 auto p_ym1 = p.move(1,-1);
1125 auto p_zp1 = p.move(2,1);
1126 auto p_zm1 = p.move(2,-1);
1128 float sub1 = gdist.template get<3>(p);
1129 float sub2 = gdist.template get<4>(p);
1130 float sub3 = gdist.template get<5>(p);
1132 if (sub1 != 6.0 + gdist.template get<0>(p) || sub2 != 6.0 + gdist.template get<1>(p) || sub3 != 6.0 + gdist.template get<2>(p))
1134 std::cout << sub1 <<
" " << sub2 <<
" " << sub3 << std::endl;
1135 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
1136 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
1137 std::cout << gdist.template get<2>(p_xp1) <<
" " << gdist.template get<2>(p_xm1) << std::endl;
1145 BOOST_REQUIRE_EQUAL(match,
true);
1148BOOST_AUTO_TEST_CASE( sgrid_gpu_test_ghost_point_remove )
1150 size_t sz[3] = {60,60,60};
1157 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
1159 gdist.template setBackgroundValue<0>(666);
1160 gdist.template setBackgroundValue<1>(666);
1161 gdist.template setBackgroundValue<2>(666);
1162 gdist.template setBackgroundValue<3>(666);
1174 gdist.addPoints(box.getKP1(),box.getKP2(),
1175 [] __device__ (
int i,
int j,
int k)
1179 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
1181 data.template get<0>() = c + i + j + k;
1182 data.template get<1>() = c + 1000 + i + j + k;
1186 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
1188 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1192 gdist.removePoints(bxR);
1196 gdist.removePoints(bxT);
1200 gdist.removePoints(bxD);
1202 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1204 for (
int i = 0 ; i < 10 ; i++)
1206 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1211 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
1213 gdist.template conv2<0,1,2,3,1>({2,2,2},{(
int)sz[0]-3,(
int)sz[1]-3,(
int)sz[2]-3},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1214 u_out = u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1);
1215 v_out = v(i+1,j,k) - v(i-1,j,k) + v(i,j+1,k) - v(i,j-1,k) + v(i,j,k+1) - v(i,j,k-1);
1218 gdist.deviceToHost<0,1,2,3>();
1222 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-3,(
int)sz[1]-3,(
int)sz[2]-3});
1226 while (it3.isNext())
1230 auto p_xp1 = p.move(0,1);
1231 auto p_xm1 = p.move(0,-1);
1232 auto p_yp1 = p.move(1,1);
1233 auto p_ym1 = p.move(1,-1);
1234 auto p_zp1 = p.move(2,1);
1235 auto p_zm1 = p.move(2,-1);
1237 float sub1 = gdist.template get<2>(p);
1238 float sub2 = gdist.template get<3>(p);
1240 if (sub1 != 6.0 || sub2 != 6.0)
1242 std::cout << sub1 <<
" " << sub2 << std::endl;
1243 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
1244 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
1252 BOOST_REQUIRE_EQUAL(match,
true);
1254 gdist.template deviceToHost<0,1,2,3>();
1256 auto it4 = gdist.getDomainGhostIterator();
1261 while (it4.isNext())
1266 auto gkey = it4.getGKey(p);
1268 if (bin.isInside(gkey.toPoint()) ==
false)
1274 BOOST_REQUIRE_EQUAL(match,
true);
1277BOOST_AUTO_TEST_CASE( sgrid_gpu_test_skip_labelling )
1279 size_t sz[3] = {60,60,60};
1286 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
1288 gdist.template setBackgroundValue<0>(666);
1289 gdist.template setBackgroundValue<1>(666);
1290 gdist.template setBackgroundValue<2>(666);
1291 gdist.template setBackgroundValue<3>(666);
1303 gdist.addPoints(box.getKP1(),box.getKP2(),
1304 [] __device__ (
int i,
int j,
int k)
1308 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
1310 data.template get<0>() = c + i + j + k;
1311 data.template get<1>() = c + 1000 + i + j + k;
1315 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
1317 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1321 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
1323 gdist.template conv2<0,1,0,1,1>({0,0,0},{(
int)sz[0]-1,(
int)sz[1]-1,(
int)sz[2]-1},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1328 gdist.template ghost_get<0,1>(RUN_ON_DEVICE | SKIP_LABELLING);
1330 gdist.template conv2<0,1,0,1,1>({0,0,0},{(
int)sz[0]-1,(
int)sz[1]-1,(
int)sz[2]-1},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1335 gdist.template ghost_get<0,1>(RUN_ON_DEVICE | SKIP_LABELLING);
1337 gdist.template conv2<0,1,0,1,1>({0,0,0},{(
int)sz[0]-1,(
int)sz[1]-1,(
int)sz[2]-1},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1342 gdist.template ghost_get<0,1>(RUN_ON_DEVICE | SKIP_LABELLING);
1344 gdist.template conv2<0,1,2,3,1>({2,2,2},{(
int)sz[0]-3,(
int)sz[1]-3,(
int)sz[2]-3},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1345 u_out = u(i+1,j,k) - u(i-1,j,k) + u(i,j+1,k) - u(i,j-1,k) + u(i,j,k+1) - u(i,j,k-1);
1346 v_out = v(i+1,j,k) - v(i-1,j,k) + v(i,j+1,k) - v(i,j-1,k) + v(i,j,k+1) - v(i,j,k-1);
1350 gdist.deviceToHost<0,1,2,3>();
1354 auto it3 = gdist.getSubDomainIterator({2,2,2},{(
int)sz[0]-3,(
int)sz[1]-3,(
int)sz[2]-3});
1358 while (it3.isNext())
1362 auto p_xp1 = p.move(0,1);
1363 auto p_xm1 = p.move(0,-1);
1364 auto p_yp1 = p.move(1,1);
1365 auto p_ym1 = p.move(1,-1);
1366 auto p_zp1 = p.move(2,1);
1367 auto p_zm1 = p.move(2,-1);
1369 float sub1 = gdist.template get<2>(p);
1370 float sub2 = gdist.template get<3>(p);
1372 if (sub1 != 6.0*10.0 || sub2 != 6.0*10.0)
1374 std::cout << sub1 <<
" " << sub2 << std::endl;
1375 std::cout << gdist.template get<0>(p_xp1) <<
" " << gdist.template get<0>(p_xm1) << std::endl;
1376 std::cout << gdist.template get<1>(p_xp1) <<
" " << gdist.template get<1>(p_xm1) << std::endl;
1384 BOOST_REQUIRE_EQUAL(match,
true);
1387BOOST_AUTO_TEST_CASE( sgrid_gpu_test_conv_background )
1389 size_t sz[3] = {60,60,60};
1396 sgrid_dist_id_gpu<3,float,aggregate<float,float,float,float>> gdist(sz,domain,g,bc);
1398 gdist.template setBackgroundValue<0>(666);
1399 gdist.template setBackgroundValue<1>(666);
1400 gdist.template setBackgroundValue<2>(666);
1401 gdist.template setBackgroundValue<3>(666);
1413 gdist.addPoints(box.getKP1(),box.getKP2(),
1414 [] __device__ (
int i,
int j,
int k)
1416 return (i == 30 && j == 30 && k == 30);
1418 [c] __device__ (InsertBlockT & data,
int i,
int j,
int k)
1420 data.template get<0>() = 0;
1421 data.template get<1>() = 0;
1425 gdist.template flush<smax_<0>,
smax_<1>>(flush_type::FLUSH_ON_DEVICE);
1427 gdist.template ghost_get<0,1>(RUN_ON_DEVICE);
1431 typedef typename GetCpBlockType<
decltype(gdist),0,1>::type CpBlockType;
1433 gdist.template conv2<0,1,2,3,1>({0,0,0},{(
int)sz[0]-1,(
int)sz[1]-1,(
int)sz[2]-1},[] __device__ (
float & u_out,
float & v_out, CpBlockType & u, CpBlockType & v,
int i,
int j,
int k){
1434 u_out = u(i+1,j,k) + u(i,j+1,k) + u(i,j,k+1);
1435 v_out = v(i+1,j,k) + v(i,j+1,k) + v(i,j,k+1);
1438 gdist.deviceToHost<0,1,2,3>();
1442 auto it3 = gdist.getDomainIterator();
1448 while (it3.isNext())
1452 float sub1 = gdist.template get<2>(p);
1453 float sub2 = gdist.template get<3>(p);
1455 if (sub1 != 3*666.0 || sub2 != 3*666.0)
1457 std::cout << sub1 <<
" " << sub2 << std::endl;
1467 BOOST_REQUIRE(count == 0 || count == 1);
1468 BOOST_REQUIRE_EQUAL(match,
true);
1471BOOST_AUTO_TEST_CASE( grid_dense_to_sparse_conversion )
1489 auto it = g_dist.getDomainIterator();
1494 auto gkey = it.getGKey(p);
1496 g_dist.template getProp<0>(p) = gkey.get(0) + gkey.get(1) + gkey.get(2);
1497 g_dist.template getProp<1>(p) = 3.0*gkey.get(0) + gkey.get(1) + gkey.get(2);
1502 sgrid_dist_id_gpu<3,float,aggregate<float,float>> sgdist(g_dist.getDecomposition(),sz,g);
1507 auto gkey = it.getGKey(p);
1509 sgdist.template insertFlush<0>(p) = g_dist.template get<0>(p);
1520 auto gkey = it.getGKey(p);
1522 check &= sgdist.template getProp<0>(p) == g_dist.template get<0>(p);
1527 BOOST_REQUIRE_EQUAL(check,
true);
1530BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
virtual void * getDevicePointer()
get a readable pointer with the data
virtual void deviceToHost()
Move memory from device to host.
virtual void hostToDevice()
Move memory from host to device.
virtual void * getPointer()
get a readable pointer with the data
virtual bool allocate(size_t sz)
allocate memory
This class implement the point shape in an N-dimensional space.
This is a distributed grid.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
get the type of the insertBlock
get the type of the block