| 23 | namespace compute = boost::compute; |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | // get the default device |
| 28 | compute::device gpu = compute::system::default_device(); |
| 29 | |
| 30 | // create context for default device |
| 31 | compute::context context(gpu); |
| 32 | |
| 33 | // create command queue with profiling enabled |
| 34 | compute::command_queue queue( |
| 35 | context, gpu, compute::command_queue::enable_profiling |
| 36 | ); |
| 37 | |
| 38 | // generate random data on the host |
| 39 | std::vector<int> host_vector(16000000); |
| 40 | std::generate(host_vector.begin(), host_vector.end(), rand); |
| 41 | |
| 42 | // create a vector on the device |
| 43 | compute::vector<int> device_vector(host_vector.size(), context); |
| 44 | |
| 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 |
| 48 | ); |
| 49 | |
| 50 | // wait for copy to finish |
| 51 | future.wait(); |
| 52 | |
| 53 | // get elapsed time from event profiling information |
| 54 | boost::chrono::milliseconds duration = |
| 55 | future.get_event().duration<boost::chrono::milliseconds>(); |
| 56 | |
| 57 | // print elapsed time in milliseconds |
| 58 | std::cout << "time: " << duration.count() << " ms" << std::endl; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | //] |