MCPcopy Create free account
hub / github.com/boostorg/compute / main

Function main

perf/perf_is_sorted.cpp:23–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include "perf.hpp"
22
23int main(int argc, char *argv[])
24{
25 perf_parse_args(argc, argv);
26 std::cout << "size: " << PERF_N << std::endl;
27
28 // setup context and queue for the default device
29 boost::compute::device device = boost::compute::system::default_device();
30 boost::compute::context context(device);
31 boost::compute::command_queue queue(context, device);
32 std::cout << "device: " << device.name() << std::endl;
33
34 // create vector of random numbers on the host
35 std::vector<int> host_vector(PERF_N);
36 std::generate(host_vector.begin(), host_vector.end(), rand);
37
38 // create vector on the device and copy the data
39 boost::compute::vector<int> device_vector(PERF_N, context);
40 boost::compute::copy(
41 host_vector.begin(), host_vector.end(), device_vector.begin(), queue
42 );
43
44 // sort and then reverse the random vector
45 boost::compute::sort(device_vector.begin(), device_vector.end(), queue);
46 boost::compute::reverse(device_vector.begin(), device_vector.end(), queue);
47
48 perf_timer t;
49 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
50 t.start();
51 bool sorted = boost::compute::is_sorted(
52 device_vector.begin(), device_vector.end(), queue
53 );
54 queue.finish();
55 t.stop();
56 if(sorted){
57 std::cerr << "ERROR: is_sorted() returned true" << std::endl;
58 }
59 }
60 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
61
62 return 0;
63}

Callers

nothing calls this directly

Calls 13

perf_parse_argsFunction · 0.85
generateFunction · 0.85
copyFunction · 0.85
sortFunction · 0.85
reverseFunction · 0.85
is_sortedFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
min_timeMethod · 0.80
nameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected