• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 //[copy_data_example
12 
13 #include <vector>
14 
15 #include <boost/compute/algorithm/copy.hpp>
16 #include <boost/compute/container/vector.hpp>
17 
18 namespace compute = boost::compute;
19 
main()20 int main()
21 {
22     // get default device and setup context
23     compute::device device = compute::system::default_device();
24     compute::context context(device);
25     compute::command_queue queue(context, device);
26 
27     // create data array on host
28     int host_data[] = { 1, 3, 5, 7, 9 };
29 
30     // create vector on device
31     compute::vector<int> device_vector(5, context);
32 
33     // copy from host to device
34     compute::copy(
35         host_data, host_data + 5, device_vector.begin(), queue
36     );
37 
38     // create vector on host
39     std::vector<int> host_vector(5);
40 
41     // copy data back to host
42     compute::copy(
43         device_vector.begin(), device_vector.end(), host_vector.begin(), queue
44     );
45 
46     return 0;
47 }
48 
49 //]
50