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

Function main

compute/perf/perf_count.cpp:26–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26int main(int argc, char *argv[])
27{
28 perf_parse_args(argc, argv);
29 std::cout << "size: " << PERF_N << std::endl;
30
31 // setup context and queue for the default device
32 boost::compute::device device = boost::compute::system::default_device();
33 boost::compute::context context(device);
34 boost::compute::command_queue queue(context, device);
35 std::cout << "device: " << device.name() << std::endl;
36
37 // create vector of random numbers on the host
38 std::vector<int> host_vector(PERF_N);
39 std::generate(host_vector.begin(), host_vector.end(), rand_int);
40
41 // create vector on the device and copy the data
42 boost::compute::vector<int> device_vector(PERF_N, context);
43 boost::compute::copy(
44 host_vector.begin(),
45 host_vector.end(),
46 device_vector.begin(),
47 queue
48 );
49
50 size_t count = 0;
51 perf_timer t;
52 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
53 t.start();
54 count = boost::compute::count(
55 device_vector.begin(), device_vector.end(), 4, queue
56 );
57 queue.finish();
58 t.stop();
59 }
60 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
61 std::cout << "count: " << count << std::endl;
62
63 // verify count is correct
64 size_t host_count = std::count(host_vector.begin(),
65 host_vector.end(),
66 4);
67 if(count != host_count){
68 std::cout << "ERROR: "
69 << "device_count (" << count << ") "
70 << "!= "
71 << "host_count (" << host_count << ")"
72 << std::endl;
73 return -1;
74 }
75
76 return 0;
77}

Callers

nothing calls this directly

Calls 11

perf_parse_argsFunction · 0.85
copyFunction · 0.85
countFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
min_timeMethod · 0.80
generateFunction · 0.50
nameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected