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

Function main

perf/perf_reduce_by_key.cpp:47–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45} UniqueKey;
46
47int main(int argc, char *argv[])
48{
49 perf_parse_args(argc, argv);
50
51 std::cout << "size: " << PERF_N << std::endl;
52
53 // setup context and queue for the default device
54 boost::compute::device device = boost::compute::system::default_device();
55 boost::compute::context context(device);
56 boost::compute::command_queue queue(context, device);
57 std::cout << "device: " << device.name() << std::endl;
58
59 // create vector of keys and random values
60 std::vector<int> host_keys(PERF_N);
61 std::vector<int> host_values(PERF_N);
62 std::generate(host_keys.begin(), host_keys.end(), UniqueKey);
63 std::generate(host_values.begin(), host_values.end(), rand_int);
64
65 // create vectors for keys and values on the device and copy the data
66 boost::compute::vector<int> device_keys(PERF_N, context);
67 boost::compute::vector<int> device_values(PERF_N,context);
68 boost::compute::copy(
69 host_keys.begin(),
70 host_keys.end(),
71 device_keys.begin(),
72 queue
73 );
74 boost::compute::copy(
75 host_values.begin(),
76 host_values.end(),
77 device_values.begin(),
78 queue
79 );
80
81 // vectors for the results
82 boost::compute::vector<int> device_keys_results(PERF_N, context);
83 boost::compute::vector<int> device_values_results(PERF_N,context);
84
85 typedef boost::compute::vector<int>::iterator iterType;
86 std::pair<iterType, iterType> result(
87 device_keys_results.begin(),
88 device_values_results.begin()
89 );
90
91 // reduce by key
92 perf_timer t;
93 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
94 t.start();
95 result = boost::compute::reduce_by_key(device_keys.begin(),
96 device_keys.end(),
97 device_values.begin(),
98 device_keys_results.begin(),
99 device_values_results.begin(),
100 queue);
101 t.stop();
102 }
103 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
104

Callers

nothing calls this directly

Calls 10

perf_parse_argsFunction · 0.85
generateFunction · 0.85
copyFunction · 0.85
reduce_by_keyFunction · 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