MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / main

Function main

compute/perf/perf_copy_to_device.cpp:17–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <boost/compute.hpp>
16
17int main(int argc, char *argv[])
18{
19 size_t size = 1000;
20 if(argc >= 2){
21 size = boost::lexical_cast<size_t>(argv[1]);
22 }
23
24 boost::compute::device device = boost::compute::system::default_device();
25 boost::compute::context context(device);
26
27 boost::compute::command_queue::properties
28 properties = boost::compute::command_queue::enable_profiling;
29 boost::compute::command_queue queue(context, device, properties);
30
31 std::vector<int> host_vector(size);
32 std::generate(host_vector.begin(), host_vector.end(), rand);
33
34 boost::compute::vector<int> device_vector(host_vector.size(), context);
35
36 boost::compute::future<void> future =
37 boost::compute::copy_async(host_vector.begin(),
38 host_vector.end(),
39 device_vector.begin(),
40 queue);
41
42 // wait for copy to finish
43 future.wait();
44
45 // get elapsed time in nanoseconds
46 size_t elapsed =
47 future.get_event().duration<boost::chrono::nanoseconds>().count();
48
49 std::cout << "time: " << elapsed / 1e6 << " ms" << std::endl;
50
51 float rate = (float(size * sizeof(int)) / elapsed) * 1000.f;
52 std::cout << "rate: " << rate << " MB/s" << std::endl;
53
54 return 0;
55}

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
countMethod · 0.45
get_eventMethod · 0.45

Tested by

no test coverage detected