OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
vector_gpu_unit_tests.cu
1/*
2 * map_vector_cuda_funcs_tests.cu
3 *
4 * Created on: Aug 17, 2018
5 * Author: i-bird
6 */
7
8
9#define BOOST_GPU_ENABLED __host__ __device__
10#include "util/cuda_launch.hpp"
11
12#include "config.h"
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15
16#include "util/cuda_util.hpp"
17#include "Vector/map_vector.hpp"
18
19template<typename vector_vector_type, typename vector_out_type>
20__global__ void vv_test_size(vector_vector_type vvt, vector_out_type out)
21{
22 int p = threadIdx.x + blockIdx.x * blockDim.x;
23
24 if (p >= vvt.size()) return;
25
26 out.template get<0>(p) = vvt.template get<0>(p).size();
27}
28
29template<typename vector_vector_type, typename vector_out_type>
30__global__ void vv_test_pointer(vector_vector_type vvt, vector_out_type out)
31{
32 int p = threadIdx.x + blockIdx.x * blockDim.x;
33
34 if (p >= vvt.size()) return;
35
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>();
38}
39
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)
42{
43 int p = threadIdx.x + blockIdx.x * blockDim.x;
44
45 if (p >= out.size()) return;
46
47 int id1 = p/i_sz;
48 int id2 = p%i_sz;
49
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];
53
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];
57}
58
59BOOST_AUTO_TEST_SUITE( vector_cuda_tests )
60
61
62
63BOOST_AUTO_TEST_CASE ( test_vector_of_vector_gpu )
64{
66
68
69 vb_int_proc.resize_no_device(5);
70
72 ptr_dev.resize(5);
73
74 for (size_t i = 0 ; i< vb_int_proc.size() ; i++)
75 {
76 vb_int_proc.template get<0>(i).resize(7);
77
78 for (size_t j = 0 ; j < vb_int_proc.template get<0>(i).size() ; j++)
79 {
80 for (size_t k = 0 ; k < 3 ; k++)
81 {
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;
84 }
85 }
86
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>();
90 }
91
92 vb_int_proc.template hostToDevice<0>();
93
95 out.resize(vb_int_proc.size());
96
97 auto ite = vb_int_proc.getGPUIterator();
98
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());
100
101 out.deviceToHost<0>();
102
103 for (size_t i = 0 ; i < out.size() ; i++)
104 {
105 BOOST_REQUIRE_EQUAL(out.template get<0>(i),7);
106 }
107
109 out_pointer.resize(vb_int_proc.size());
110
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());
112
113 out_pointer.deviceToHost<0,1>();
114
115 for (size_t i = 0 ; i < out_pointer.size() ; i++)
116 {
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);
119 }
120
122 out_data.resize(vb_int_proc.size()*7);
123
124 auto ite2 = out_data.getGPUIterator();
125
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);
127
128 out_data.template deviceToHost<0,1>();
129
130 size_t i_sz = 7;
131
132 for (size_t p = 0 ; p < out_data.size() ; p++)
133 {
134 int id1 = p/i_sz;
135 int id2 = p%i_sz;
136
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] );
140
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] );
144 }
145}
146
147BOOST_AUTO_TEST_SUITE_END()
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
Transform the boost::fusion::vector into memory specification (memory_traits)