| 25 | } |
| 26 | |
| 27 | int main(int argc, char *argv[]) |
| 28 | { |
| 29 | perf_parse_args(argc, argv); |
| 30 | std::cout << "size: " << PERF_N << std::endl; |
| 31 | |
| 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 | std::vector<int> h1(PERF_N); |
| 38 | std::vector<int> h2(PERF_N); |
| 39 | std::generate(h1.begin(), h1.end(), rand_int); |
| 40 | std::generate(h2.begin(), h2.end(), rand_int); |
| 41 | |
| 42 | // create vector on the device and copy the data |
| 43 | boost::compute::vector<int> d1(PERF_N, context); |
| 44 | boost::compute::vector<int> d2(PERF_N, context); |
| 45 | boost::compute::copy(h1.begin(), h1.end(), d1.begin(), queue); |
| 46 | boost::compute::copy(h2.begin(), h2.end(), d2.begin(), queue); |
| 47 | |
| 48 | int product = 0; |
| 49 | perf_timer t; |
| 50 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ |
| 51 | t.start(); |
| 52 | product = boost::compute::inner_product( |
| 53 | d1.begin(), d1.end(), d2.begin(), int(0), queue |
| 54 | ); |
| 55 | queue.finish(); |
| 56 | t.stop(); |
| 57 | } |
| 58 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; |
| 59 | |
| 60 | // verify product is correct |
| 61 | int host_product = std::inner_product( |
| 62 | h1.begin(), h1.end(), h2.begin(), int(0) |
| 63 | ); |
| 64 | if(product != host_product){ |
| 65 | std::cout << "ERROR: " |
| 66 | << "device_product (" << product << ") " |
| 67 | << "!= " |
| 68 | << "host_product (" << host_product << ")" |
| 69 | << std::endl; |
| 70 | return -1; |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
nothing calls this directly
no test coverage detected