]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/perf/perf_bolt_reduce_by_key.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
15 #include <bolt/cl/copy.h>
16 #include <bolt/cl/device_vector.h>
17 #include <bolt/cl/reduce_by_key.h>
23 return static_cast<int>((rand() / double(RAND_MAX
)) * 25.0);
28 int avgValuesNoPerKey
;
33 avgValuesNoPerKey
= 512;
38 double p
= double(1.0) / static_cast<double>(avgValuesNoPerKey
);
39 if((rand() / double(RAND_MAX
)) <= p
)
45 int main(int argc
, char *argv
[])
47 perf_parse_args(argc
, argv
);
49 std::cout
<< "size: " << PERF_N
<< std::endl
;
51 bolt::cl::control ctrl
= bolt::cl::control::getDefault();
52 ::cl::Device device
= ctrl
.getDevice();
53 std::cout
<< "device: " << device
.getInfo
<CL_DEVICE_NAME
>() << std::endl
;
55 // create vector of keys and random values
56 std::vector
<int> host_keys(PERF_N
);
57 std::vector
<int> host_values(PERF_N
);
58 std::generate(host_keys
.begin(), host_keys
.end(), UniqueKey
);
59 std::generate(host_values
.begin(), host_values
.end(), rand_int
);
61 // create device vectors for data
62 bolt::cl::device_vector
<int> device_keys(PERF_N
);
63 bolt::cl::device_vector
<int> device_values(PERF_N
);
65 // transfer data to the device
66 bolt::cl::copy(host_keys
.begin(), host_keys
.end(), device_keys
.begin());
67 bolt::cl::copy(host_values
.begin(), host_values
.end(), device_values
.begin());
69 // create device vectors for the results
70 bolt::cl::device_vector
<int> device_keys_results(PERF_N
);
71 bolt::cl::device_vector
<int> device_values_results(PERF_N
);
73 typedef bolt::cl::device_vector
<int>::iterator iterType
;
74 bolt::cl::pair
<iterType
, iterType
> result
= {
75 device_keys_results
.begin(),
76 device_values_results
.begin()
80 for(size_t trial
= 0; trial
< PERF_TRIALS
; trial
++){
82 result
= bolt::cl::reduce_by_key(device_keys
.begin(),
84 device_values
.begin(),
85 device_keys_results
.begin(),
86 device_values_results
.begin());
89 std::cout
<< "time: " << t
.min_time() / 1e6
<< " ms" << std::endl
;
91 size_t result_size
= bolt::cl::distance(device_keys_results
.begin(), result
.first
);
92 if(result_size
!= static_cast<size_t>(host_keys
[PERF_N
-1] + 1)){
93 std::cout
<< "ERROR: "
94 << "wrong number of keys"