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

Function main

example/time_copy.cpp:25–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace compute = boost::compute;
24
25int 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//]

Callers

nothing calls this directly

Calls 8

copy_asyncFunction · 0.85
generateFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
waitMethod · 0.45
get_eventMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected