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

Function main

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected