]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/example/time_copy.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@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 //---------------------------------------------------------------------------//
17 #include <boost/compute/event.hpp>
18 #include <boost/compute/system.hpp>
19 #include <boost/compute/algorithm/copy.hpp>
20 #include <boost/compute/async/future.hpp>
21 #include <boost/compute/container/vector.hpp>
23 namespace compute
= boost::compute
;
27 // get the default device
28 compute::device gpu
= compute::system::default_device();
30 // create context for default device
31 compute::context
context(gpu
);
33 // create command queue with profiling enabled
34 compute::command_queue
queue(
35 context
, gpu
, compute::command_queue::enable_profiling
38 // generate random data on the host
39 std::vector
<int> host_vector(16000000);
40 std::generate(host_vector
.begin(), host_vector
.end(), rand
);
42 // create a vector on the device
43 compute::vector
<int> device_vector(host_vector
.size(), context
);
45 // copy data from the host to the device
46 compute::future
<void> future
= compute::copy_async(
47 host_vector
.begin(), host_vector
.end(), device_vector
.begin(), queue
50 // wait for copy to finish
53 // get elapsed time from event profiling information
54 boost::chrono::milliseconds duration
=
55 future
.get_event().duration
<boost::chrono::milliseconds
>();
57 // print elapsed time in milliseconds
58 std::cout
<< "time: " << duration
.count() << " ms" << std::endl
;