Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 62 lines (47 sloc) 1.824 kb
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
1 #include <unittest/unittest.h>
2 #include <thrust/pair.h>
3 #include <thrust/transform.h>
212f30b @wnbell replaced thrust::experimental::inclusive_segmented_scan with thrust::inc...
wnbell authored
4 #include <thrust/scan.h>
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
5
6 struct make_pair_functor
7 {
8 template<typename T1, typename T2>
9 __host__ __device__
10 thrust::pair<T1,T2> operator()(const T1 &x, const T2 &y)
11 {
12 return thrust::make_pair(x,y);
13 } // end operator()()
14 }; // end make_pair_functor
15
16
17 struct add_pairs
18 {
19 template <typename Pair1, typename Pair2>
20 __host__ __device__
21 Pair1 operator()(const Pair1 &x, const Pair2 &y)
22 {
23 return thrust::make_pair(x.first + y.first, x.second + y.second);
24 } // end operator()
25 }; // end add_pairs
26
27
28 template <typename T>
29 struct TestPairScanByKey
30 {
31 void operator()(const size_t n)
32 {
33 typedef thrust::pair<T,T> P;
34
35 thrust::host_vector<T> h_p1 = unittest::random_integers<T>(n);
36 thrust::host_vector<T> h_p2 = unittest::random_integers<T>(n);
37 thrust::host_vector<P> h_pairs(n);
38
39 // zip up pairs on the host
40 thrust::transform(h_p1.begin(), h_p1.end(), h_p2.begin(), h_pairs.begin(), make_pair_functor());
41
42 thrust::device_vector<T> d_p1 = h_p1;
43 thrust::device_vector<T> d_p2 = h_p2;
44 thrust::device_vector<P> d_pairs = h_pairs;
45
90d3687 @wnbell removed unnecessary test instantiations to reduce test time and memory c...
wnbell authored
46 thrust::host_vector<T> h_keys = unittest::random_integers<bool>(n);
47 thrust::device_vector<T> d_keys = h_keys;
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
48
49 P init = thrust::make_pair(13,13);
50
51 // scan on the host
212f30b @wnbell replaced thrust::experimental::inclusive_segmented_scan with thrust::inc...
wnbell authored
52 thrust::exclusive_scan_by_key(h_keys.begin(), h_keys.end(), h_pairs.begin(), h_pairs.begin(), init, thrust::equal_to<T>(), add_pairs());
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
53
54 // scan on the device
212f30b @wnbell replaced thrust::experimental::inclusive_segmented_scan with thrust::inc...
wnbell authored
55 thrust::exclusive_scan_by_key(d_keys.begin(), d_keys.end(), d_pairs.begin(), d_pairs.begin(), init, thrust::equal_to<T>(), add_pairs());
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
56
57 ASSERT_EQUAL_QUIET(h_pairs, d_pairs);
58 }
59 };
90d3687 @wnbell removed unnecessary test instantiations to reduce test time and memory c...
wnbell authored
60 VariableUnitTest<TestPairScanByKey, unittest::type_list<char,short,int> > TestPairScanByKeyInstance;
8c7ee46 @wnbell split large unittest files into several pieces to lower peak memory cons...
wnbell authored
61
Something went wrong with that request. Please try again.