| 21 | namespace compute = boost::compute; |
| 22 | |
| 23 | void test_copy_if_odd(compute::command_queue &queue) |
| 24 | { |
| 25 | // create input and output vectors on the device |
| 26 | const compute::context &context = queue.get_context(); |
| 27 | compute::vector<int> input(PERF_N, context); |
| 28 | compute::vector<int> output(PERF_N, context); |
| 29 | |
| 30 | // generate random numbers between 1 and 10 |
| 31 | compute::default_random_engine rng(queue); |
| 32 | compute::uniform_int_distribution<int> d(1, 10); |
| 33 | d.generate(input.begin(), input.end(), rng, queue); |
| 34 | |
| 35 | BOOST_COMPUTE_FUNCTION(bool, is_odd, (int x), |
| 36 | { |
| 37 | return x & 1; |
| 38 | }); |
| 39 | |
| 40 | perf_timer t; |
| 41 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ |
| 42 | t.start(); |
| 43 | compute::vector<int>::iterator i = compute::copy_if( |
| 44 | input.begin(), input.end(), output.begin(), is_odd, queue |
| 45 | ); |
| 46 | queue.finish(); |
| 47 | t.stop(); |
| 48 | |
| 49 | float ratio = float(std::distance(output.begin(), i)) / PERF_N; |
| 50 | if(PERF_N > 1000 && (ratio < 0.45f || ratio > 0.55f)){ |
| 51 | std::cerr << "error: ratio is " << ratio << std::endl; |
| 52 | std::cerr << "error: ratio should be around 45-55%" << std::endl; |
| 53 | } |
| 54 | } |
| 55 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; |
| 56 | } |
| 57 | |
| 58 | void test_copy_if_in_sphere(compute::command_queue &queue) |
| 59 | { |