Skip to content

Commit 0ab1d5f

Browse files
committed
Add reverse_copy benchmarks
1 parent aa15cd6 commit 0ab1d5f

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

perf/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(BENCHMARKS
4141
partition_point
4242
prev_permutation
4343
reverse
44+
reverse_copy
4445
rotate
4546
rotate_copy
4647
host_sort
@@ -80,6 +81,7 @@ set(STL_BENCHMARKS
8081
stl_partition
8182
stl_prev_permutation
8283
stl_reverse
84+
stl_reverse_copy
8385
stl_rotate
8486
stl_rotate_copy
8587
stl_saxpy
@@ -123,6 +125,7 @@ if(${BOOST_COMPUTE_HAVE_CUDA})
123125
thrust_partial_sum
124126
thrust_partition
125127
thrust_reverse
128+
thrust_reverse_copy
126129
thrust_rotate
127130
thrust_saxpy
128131
thrust_set_difference

perf/perf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def run_benchmark(name, sizes, vs=[]):
123123
"partial_sum",
124124
"partition",
125125
"reverse",
126+
"reverse_copy",
126127
"rotate",
127128
"saxpy",
128129
"sort",
@@ -149,6 +150,7 @@ def run_benchmark(name, sizes, vs=[]):
149150
"partition_point",
150151
"prev_permutation",
151152
"reverse",
153+
"reverse_copy",
152154
"rotate",
153155
"rotate_copy",
154156
"saxpy",

perf/perf_reverse_copy.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://kylelutz.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
#include <algorithm>
12+
#include <iostream>
13+
#include <numeric>
14+
#include <vector>
15+
16+
#include <boost/compute/system.hpp>
17+
#include <boost/compute/algorithm/reverse_copy.hpp>
18+
#include <boost/compute/container/vector.hpp>
19+
20+
#include "perf.hpp"
21+
22+
int rand_int()
23+
{
24+
return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
25+
}
26+
27+
int main(int argc, char *argv[])
28+
{
29+
perf_parse_args(argc, argv);
30+
std::cout << "size: " << PERF_N << std::endl;
31+
32+
// setup context and queue for the default device
33+
boost::compute::device device = boost::compute::system::default_device();
34+
boost::compute::context context(device);
35+
boost::compute::command_queue queue(context, device);
36+
std::cout << "device: " << device.name() << std::endl;
37+
38+
// create vector of random numbers on the host
39+
std::vector<int> host_vector(PERF_N);
40+
std::generate(host_vector.begin(), host_vector.end(), rand_int);
41+
42+
// create vector on the device and copy the data
43+
boost::compute::vector<int> device_vector(PERF_N, context);
44+
boost::compute::copy(
45+
host_vector.begin(), host_vector.end(), device_vector.begin(), queue
46+
);
47+
48+
// create vector on the device for reversed data
49+
boost::compute::vector<int> device_reversed_vector(PERF_N, context);
50+
51+
perf_timer t;
52+
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
53+
t.start();
54+
boost::compute::reverse_copy(
55+
device_vector.begin(), device_vector.end(),
56+
device_reversed_vector.begin(),
57+
queue
58+
);
59+
queue.finish();
60+
t.stop();
61+
}
62+
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
63+
64+
return 0;
65+
}

perf/perf_stl_reverse_copy.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://kylelutz.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
#include <algorithm>
12+
#include <iostream>
13+
#include <numeric>
14+
#include <vector>
15+
16+
#include "perf.hpp"
17+
18+
int rand_int()
19+
{
20+
return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
21+
}
22+
23+
int main(int argc, char *argv[])
24+
{
25+
perf_parse_args(argc, argv);
26+
std::cout << "size: " << PERF_N << std::endl;
27+
28+
// create vector of random numbers on the host
29+
std::vector<int> host_vector(PERF_N);
30+
std::generate(host_vector.begin(), host_vector.end(), rand_int);
31+
32+
// create vector for reversed data
33+
std::vector<int> host_reversed_vector(PERF_N);
34+
35+
perf_timer t;
36+
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
37+
t.start();
38+
std::reverse_copy(host_vector.begin(), host_vector.end(),
39+
host_reversed_vector.begin());
40+
t.stop();
41+
}
42+
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
43+
44+
return 0;
45+
}

perf/perf_thrust_reverse_copy.cu

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://kylelutz.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
#include <algorithm>
12+
#include <cstdlib>
13+
14+
#include <thrust/copy.h>
15+
#include <thrust/device_vector.h>
16+
#include <thrust/generate.h>
17+
#include <thrust/host_vector.h>
18+
#include <thrust/reverse.h>
19+
20+
#include "perf.hpp"
21+
22+
int main(int argc, char *argv[])
23+
{
24+
perf_parse_args(argc, argv);
25+
26+
std::cout << "size: " << PERF_N << std::endl;
27+
thrust::host_vector<int> h_vec = generate_random_vector<int>(PERF_N);
28+
29+
// transfer data to the device
30+
thrust::device_vector<int> d_vec;
31+
d_vec = h_vec;
32+
33+
// device vector for reversed data
34+
thrust::device_vector<int> d_reversed_vec(PERF_N);
35+
36+
perf_timer t;
37+
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
38+
t.start();
39+
thrust::reverse_copy(d_vec.begin(), d_vec.end(), d_reversed_vec.begin());
40+
cudaDeviceSynchronize();
41+
t.stop();
42+
}
43+
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)