Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(BENCHMARKS
erase_remove
exclusive_scan
fill
find
find_end
includes
inner_product
Expand Down Expand Up @@ -70,6 +71,7 @@ endforeach()
set(STL_BENCHMARKS
stl_accumulate
stl_count
stl_find
stl_find_end
stl_includes
stl_inner_product
Expand Down Expand Up @@ -118,6 +120,7 @@ if(${BOOST_COMPUTE_HAVE_CUDA})
thrust_accumulate
thrust_count
thrust_exclusive_scan
thrust_find
thrust_inner_product
thrust_merge
thrust_partial_sum
Expand Down
2 changes: 2 additions & 0 deletions perf/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def run_benchmark(name, sizes, vs=[]):
"accumulate",
"count",
"exclusive_scan",
"find",
"inner_product",
"merge",
"partial_sum",
Expand All @@ -136,6 +137,7 @@ def run_benchmark(name, sizes, vs=[]):
"stl": [
"accumulate",
"count",
"find",
"find_end",
"includes",
"inner_product",
Expand Down
88 changes: 88 additions & 0 deletions perf/perf_find.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//

#include <algorithm>
#include <iostream>
#include <vector>

#include <boost/compute/system.hpp>
#include <boost/compute/algorithm/find.hpp>
#include <boost/compute/container/vector.hpp>

#include "perf.hpp"

// Max integer that can be generated by rand_int() function.
int rand_int_max = 25;

int rand_int()
{
return static_cast<int>((rand() / double(RAND_MAX)) * rand_int_max);
}

int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;

// setup context and queue for the default device
boost::compute::device device = boost::compute::system::default_device();
boost::compute::context context(device);
boost::compute::command_queue queue(context, device);
std::cout << "device: " << device.name() << std::endl;

// create vector of random numbers on the host
std::vector<int> host_vector(PERF_N);
std::generate(host_vector.begin(), host_vector.end(), rand_int);

// create vector on the device and copy the data
boost::compute::vector<int> device_vector(PERF_N, context);
boost::compute::copy(
host_vector.begin(),
host_vector.end(),
device_vector.begin(),
queue
);

// trying to find element that isn't in vector (worst-case scenario)
int wanted = rand_int_max + 1;

// device iterator
boost::compute::vector<int>::iterator device_result_it;

perf_timer t;
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
t.start();
device_result_it = boost::compute::find(device_vector.begin(),
device_vector.end(),
wanted,
queue);
queue.finish();
t.stop();
}
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;

// verify if found index is correct by comparing it with std::find() result
size_t host_result_index = std::distance(host_vector.begin(),
std::find(host_vector.begin(),
host_vector.end(),
wanted));
size_t device_result_index = device_result_it.get_index();

if(device_result_index != host_result_index){
std::cout << "ERROR: "
<< "device_result_index (" << device_result_index << ") "
<< "!= "
<< "host_result_index (" << host_result_index << ")"
<< std::endl;
return -1;
}

return 0;
}
58 changes: 58 additions & 0 deletions perf/perf_stl_find.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//

#include <algorithm>
#include <iostream>
#include <vector>

#include "perf.hpp"

// Max integer that can be generated by rand_int() function.
int rand_int_max = 25;

int rand_int()
{
return static_cast<int>((rand() / double(RAND_MAX)) * rand_int_max);
}

int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;

// create vector of random numbers on the host
std::vector<int> host_vector(PERF_N);
std::generate(host_vector.begin(), host_vector.end(), rand_int);

// trying to find element that isn't in vector (worst-case scenario)
int wanted = rand_int_max + 1;

// result
std::vector<int>::iterator host_result_it;

perf_timer t;
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
t.start();
host_result_it = std::find(host_vector.begin(), host_vector.end(), wanted);
t.stop();
}
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;

// verify
if(host_result_it != host_vector.end()){
std::cout << "ERROR: "
<< "host_result_iterator != "
<< "host_vector.end()"
<< std::endl;
return -1;
}

return 0;
}
65 changes: 65 additions & 0 deletions perf/perf_thrust_find.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//

#include <algorithm>
#include <iostream>
#include <vector>

#include <thrust/find.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>

#include "perf.hpp"

// Max integer that can be generated by rand_int() function.
int rand_int_max = 25;

int rand_int()
{
return static_cast<int>((rand() / double(RAND_MAX)) * rand_int_max);
}

int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;

// create vector of random numbers on the host
thrust::host_vector<int> host_vector(PERF_N);
thrust::generate(host_vector.begin(), host_vector.end(), rand_int);

thrust::device_vector<int> v = host_vector;

// trying to find element that isn't in vector (worst-case scenario)
int wanted = rand_int_max + 1;

// result
thrust::device_vector<int>::iterator device_result_it;

perf_timer t;
for(size_t trial = 0; trial < PERF_TRIALS; trial++){
t.start();
device_result_it = thrust::find(v.begin(), v.end(), wanted);
cudaDeviceSynchronize();
t.stop();
}
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;

// verify
if(device_result_it != v.end()){
std::cout << "ERROR: "
<< "device_result_iterator != "
<< "v.end()"
<< std::endl;
return -1;
}

return 0;
}