| 20 | #include "perf.hpp" |
| 21 | |
| 22 | int main(int argc, char *argv[]) |
| 23 | { |
| 24 | perf_parse_args(argc, argv); |
| 25 | |
| 26 | std::cout << "size: " << PERF_N << std::endl; |
| 27 | |
| 28 | boost::compute::device device = boost::compute::system::default_device(); |
| 29 | boost::compute::context context(device); |
| 30 | boost::compute::command_queue queue(context, device); |
| 31 | std::cout << "device: " << device.name() << std::endl; |
| 32 | |
| 33 | std::vector<int> v1 = generate_random_vector<int>(std::floor(PERF_N / 2.0)); |
| 34 | std::vector<int> v2 = generate_random_vector<int>(std::ceil(PERF_N / 2.0)); |
| 35 | std::vector<int> v3(PERF_N); |
| 36 | |
| 37 | std::sort(v1.begin(), v1.end()); |
| 38 | std::sort(v2.begin(), v2.end()); |
| 39 | |
| 40 | boost::compute::vector<int> gpu_v1(v1.begin(), v1.end(), queue); |
| 41 | boost::compute::vector<int> gpu_v2(v2.begin(), v2.end(), queue); |
| 42 | boost::compute::vector<int> gpu_v3(PERF_N, context); |
| 43 | |
| 44 | perf_timer t; |
| 45 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ |
| 46 | t.start(); |
| 47 | boost::compute::merge(gpu_v1.begin(), gpu_v1.end(), |
| 48 | gpu_v2.begin(), gpu_v2.end(), |
| 49 | gpu_v3.begin(), |
| 50 | queue |
| 51 | ); |
| 52 | queue.finish(); |
| 53 | t.stop(); |
| 54 | } |
| 55 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; |
| 56 | |
| 57 | std::vector<int> check_v3(PERF_N); |
| 58 | boost::compute::copy(gpu_v3.begin(), gpu_v3.end(), check_v3.begin(), queue); |
| 59 | queue.finish(); |
| 60 | |
| 61 | std::merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin()); |
| 62 | bool ok = std::equal(check_v3.begin(), check_v3.end(), v3.begin()); |
| 63 | if(!ok){ |
| 64 | std::cerr << "ERROR: merged ranges different" << std::endl; |
| 65 | return -1; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
nothing calls this directly
no test coverage detected