| 27 | } |
| 28 | |
| 29 | int main(int argc, char *argv[]) |
| 30 | { |
| 31 | perf_parse_args(argc, argv); |
| 32 | std::cout << "size: " << PERF_N << std::endl; |
| 33 | |
| 34 | // setup context and queue for the default device |
| 35 | boost::compute::device device = boost::compute::system::default_device(); |
| 36 | boost::compute::context context(device); |
| 37 | boost::compute::command_queue queue(context, device); |
| 38 | std::cout << "device: " << device.name() << std::endl; |
| 39 | |
| 40 | // create vector of random numbers on the host |
| 41 | std::vector<int> host_vector(PERF_N); |
| 42 | std::generate(host_vector.begin(), host_vector.end(), rand_int); |
| 43 | |
| 44 | // create vector on the device and copy the data |
| 45 | boost::compute::vector<int> device_vector(PERF_N, context); |
| 46 | boost::compute::copy( |
| 47 | host_vector.begin(), |
| 48 | host_vector.end(), |
| 49 | device_vector.begin(), |
| 50 | queue |
| 51 | ); |
| 52 | |
| 53 | // trying to find element that isn't in vector (worst-case scenario) |
| 54 | int wanted = rand_int_max + 1; |
| 55 | |
| 56 | // device iterator |
| 57 | boost::compute::vector<int>::iterator device_result_it; |
| 58 | |
| 59 | perf_timer t; |
| 60 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ |
| 61 | t.start(); |
| 62 | device_result_it = boost::compute::find(device_vector.begin(), |
| 63 | device_vector.end(), |
| 64 | wanted, |
| 65 | queue); |
| 66 | queue.finish(); |
| 67 | t.stop(); |
| 68 | } |
| 69 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; |
| 70 | |
| 71 | // verify if found index is correct by comparing it with std::find() result |
| 72 | size_t host_result_index = std::distance(host_vector.begin(), |
| 73 | std::find(host_vector.begin(), |
| 74 | host_vector.end(), |
| 75 | wanted)); |
| 76 | size_t device_result_index = device_result_it.get_index(); |
| 77 | |
| 78 | if(device_result_index != host_result_index){ |
| 79 | std::cout << "ERROR: " |
| 80 | << "device_result_index (" << device_result_index << ") " |
| 81 | << "!= " |
| 82 | << "host_result_index (" << host_result_index << ")" |
| 83 | << std::endl; |
| 84 | return -1; |
| 85 | } |
| 86 |
nothing calls this directly
no test coverage detected