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

Function main

perf/perf_partial_sum.cpp:27–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

perf_parse_argsFunction · 0.85
generateFunction · 0.85
copyFunction · 0.85
partial_sumFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
min_timeMethod · 0.80
nameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
finishMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected