9#define BOOST_GPU_ENABLED __host__ __device__
10#include "util/cuda_launch.hpp"
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
16#include "util/cuda_util.hpp"
17#include "Vector/map_vector.hpp"
19template<
typename vector_vector_type,
typename vector_out_type>
20__global__
void vv_test_size(vector_vector_type vvt, vector_out_type out)
22 int p = threadIdx.x + blockIdx.x * blockDim.x;
24 if (p >= vvt.size())
return;
26 out.template get<0>(p) = vvt.template get<0>(p).size();
29template<
typename vector_vector_type,
typename vector_out_type>
30__global__
void vv_test_pointer(vector_vector_type vvt, vector_out_type out)
32 int p = threadIdx.x + blockIdx.x * blockDim.x;
34 if (p >= vvt.size())
return;
36 out.template get<0>(p) = (size_t)vvt.template get<0>(p).template getPointer<0>();
37 out.template get<1>(p) = (size_t)vvt.template get<0>(p).template getPointer<1>();
40template<
typename vector_vector_type,
typename vector_out_type>
41__global__
void vv_test_data_get(vector_vector_type vvt, vector_out_type out,
int i_sz)
43 int p = threadIdx.x + blockIdx.x * blockDim.x;
45 if (p >= out.size())
return;
50 out.template get<0>(p)[0] = (size_t)vvt.template get<0>(id1).template get<0>(id2)[0];
51 out.template get<0>(p)[1] = (size_t)vvt.template get<0>(id1).template get<0>(id2)[1];
52 out.template get<0>(p)[2] = (size_t)vvt.template get<0>(id1).template get<0>(id2)[2];
54 out.template get<1>(p)[0] = (size_t)vvt.template get<0>(id1).template get<1>(id2)[0];
55 out.template get<1>(p)[1] = (size_t)vvt.template get<0>(id1).template get<1>(id2)[1];
56 out.template get<1>(p)[2] = (size_t)vvt.template get<0>(id1).template get<1>(id2)[2];
59BOOST_AUTO_TEST_SUITE( vector_cuda_tests )
63BOOST_AUTO_TEST_CASE ( test_vector_of_vector_gpu )
69 vb_int_proc.resize_no_device(5);
74 for (
size_t i = 0 ; i< vb_int_proc.
size() ; i++)
76 vb_int_proc.template get<0>(i).resize(7);
78 for (
size_t j = 0 ; j < vb_int_proc.template get<0>(i).
size() ; j++)
80 for (
size_t k = 0 ; k < 3 ; k++)
82 vb_int_proc.template get<0>(i).template get<0>(j)[k] = i+j+k;
83 vb_int_proc.template get<0>(i).template get<1>(j)[k] = 100+i+j+k;
87 vb_int_proc.template get<0>(i).template hostToDevice<0,1>();
88 ptr_dev.get(i).first = vb_int_proc.template get<0>(i).template getDeviceBuffer<0>();
89 ptr_dev.get(i).second = vb_int_proc.template get<0>(i).template getDeviceBuffer<1>();
92 vb_int_proc.template hostToDevice<0>();
95 out.resize(vb_int_proc.
size());
97 auto ite = vb_int_proc.getGPUIterator();
99 CUDA_LAUNCH_DIM3((vv_test_size<
decltype(vb_int_proc.toKernel()),
decltype(out.toKernel())>),ite.wthr,ite.thr,vb_int_proc.toKernel(),out.toKernel());
101 out.deviceToHost<0>();
103 for (
size_t i = 0 ; i < out.
size() ; i++)
105 BOOST_REQUIRE_EQUAL(out.template get<0>(i),7);
109 out_pointer.resize(vb_int_proc.
size());
111 CUDA_LAUNCH_DIM3((vv_test_pointer<
decltype(vb_int_proc.toKernel()),
decltype(out_pointer.toKernel())>),ite.wthr,ite.thr,vb_int_proc.toKernel(),out_pointer.toKernel());
113 out_pointer.deviceToHost<0,1>();
115 for (
size_t i = 0 ; i < out_pointer.
size() ; i++)
117 BOOST_REQUIRE_EQUAL((
size_t)out_pointer.template get<0>(i),(
size_t)ptr_dev.get(i).first);
118 BOOST_REQUIRE_EQUAL((
size_t)out_pointer.template get<1>(i),(
size_t)ptr_dev.get(i).second);
122 out_data.resize(vb_int_proc.
size()*7);
124 auto ite2 = out_data.getGPUIterator();
126 CUDA_LAUNCH_DIM3((vv_test_data_get<
decltype(vb_int_proc.toKernel()),
decltype(out_data.toKernel())>),ite2.wthr,ite2.thr,vb_int_proc.toKernel(),out_data.toKernel(),7);
128 out_data.template deviceToHost<0,1>();
132 for (
size_t p = 0 ; p < out_data.
size() ; p++)
137 BOOST_REQUIRE_EQUAL(out_data.template get<0>(p)[0],vb_int_proc.template get<0>(id1).template get<0>(id2)[0] );
138 BOOST_REQUIRE_EQUAL(out_data.template get<0>(p)[1],vb_int_proc.template get<0>(id1).template get<0>(id2)[1] );
139 BOOST_REQUIRE_EQUAL(out_data.template get<0>(p)[2],vb_int_proc.template get<0>(id1).template get<0>(id2)[2] );
141 BOOST_REQUIRE_EQUAL(out_data.template get<1>(p)[0],vb_int_proc.template get<0>(id1).template get<1>(id2)[0] );
142 BOOST_REQUIRE_EQUAL(out_data.template get<1>(p)[1],vb_int_proc.template get<0>(id1).template get<1>(id2)[1] );
143 BOOST_REQUIRE_EQUAL(out_data.template get<1>(p)[2],vb_int_proc.template get<0>(id1).template get<1>(id2)[2] );
147BOOST_AUTO_TEST_SUITE_END()
Implementation of 1-D std::vector like structure.
Transform the boost::fusion::vector into memory specification (memory_traits)