| 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 | // setup context and queue for the default device |
| 33 | boost::compute::device device = boost::compute::system::default_device(); |
| 34 | boost::compute::context context(device); |
| 35 | boost::compute::command_queue queue(context, device); |
| 36 | std::cout << "device: " << device.name() << std::endl; |
| 37 | |
| 38 | // create vectors of random numbers on the host |
| 39 | std::vector<int> v1(std::floor(PERF_N / 2.0)); |
| 40 | std::vector<int> v2(std::ceil(PERF_N / 2.0)); |
| 41 | std::generate(v1.begin(), v1.end(), rand_int); |
| 42 | std::generate(v2.begin(), v2.end(), rand_int); |
| 43 | std::sort(v1.begin(), v1.end()); |
| 44 | std::sort(v2.begin(), v2.end()); |
| 45 | |
| 46 | // create vectors on the device and copy the data |
| 47 | boost::compute::vector<int> gpu_v1(std::floor(PERF_N / 2.0), context); |
| 48 | boost::compute::vector<int> gpu_v2(std::ceil(PERF_N / 2.0), context); |
| 49 | |
| 50 | boost::compute::copy( |
| 51 | v1.begin(), v1.end(), gpu_v1.begin(), queue |
| 52 | ); |
| 53 | boost::compute::copy( |
| 54 | v2.begin(), v2.end(), gpu_v2.begin(), queue |
| 55 | ); |
| 56 | |
| 57 | boost::compute::vector<int> gpu_v3(PERF_N, context); |
| 58 | boost::compute::vector<int>::iterator gpu_v3_end; |
| 59 | |
| 60 | perf_timer t; |
| 61 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ |
| 62 | t.start(); |
| 63 | gpu_v3_end = boost::compute::set_difference( |
| 64 | gpu_v1.begin(), gpu_v1.end(), |
| 65 | gpu_v2.begin(), gpu_v2.end(), |
| 66 | gpu_v3.begin(), queue |
| 67 | ); |
| 68 | queue.finish(); |
| 69 | t.stop(); |
| 70 | } |
| 71 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; |
| 72 | std::cout << "size: " << std::distance(gpu_v3.begin(), gpu_v3_end) << std::endl; |
| 73 | |
| 74 | return 0; |
| 75 | } |
nothing calls this directly
no test coverage detected