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

Function main

perf/perf_max_element.cpp:26–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26int main(int argc, char *argv[])
27{
28 perf_parse_args(argc, argv);
29 std::cout << "size: " << PERF_N << std::endl;
30
31 // setup context and queue for the default device
32 boost::compute::device device = boost::compute::system::default_device();
33 boost::compute::context context(device);
34 boost::compute::command_queue queue(context, device);
35 std::cout << "device: " << device.name() << std::endl;
36
37 // create vector of random numbers on the host
38 std::vector<int> host_vector(PERF_N);
39 std::generate(host_vector.begin(), host_vector.end(), rand_int);
40
41 // create vector on the device and copy the data
42 boost::compute::vector<int> device_vector(PERF_N, context);
43 boost::compute::copy(
44 host_vector.begin(),
45 host_vector.end(),
46 device_vector.begin(),
47 queue
48 );
49
50 boost::compute::vector<int>::iterator device_max_iter
51 = device_vector.begin();
52
53 perf_timer t;
54 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
55 t.start();
56 device_max_iter = boost::compute::max_element(
57 device_vector.begin(), device_vector.end(), queue
58 );
59 queue.finish();
60 t.stop();
61 }
62
63 int device_max = device_max_iter.read(queue);
64 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
65 std::cout << "max: " << device_max << std::endl;
66
67 // verify max is correct
68 std::vector<int>::iterator host_max_iter
69 = std::max_element(host_vector.begin(), host_vector.end());
70
71 int host_max = *host_max_iter;
72 if(device_max != host_max){
73 std::cout << "ERROR: "
74 << "device_max (" << device_max << ") "
75 << "!= "
76 << "host_max (" << host_max << ")"
77 << std::endl;
78 return -1;
79 }
80
81 size_t host_max_idx = std::distance(host_vector.begin(), host_max_iter);
82 size_t device_max_idx = std::distance(device_vector.begin(), device_max_iter);
83 if(device_max_idx != host_max_idx){

Callers

nothing calls this directly

Calls 12

perf_parse_argsFunction · 0.85
generateFunction · 0.85
copyFunction · 0.85
max_elementFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
min_timeMethod · 0.80
nameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
finishMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected