| 174 | vector.push_back(int2_(8, -5), queue); |
| 175 | |
| 176 | BOOST_COMPUTE_FUNCTION(bool, compare_second, (const int2_ a, const int2_ b), |
| 177 | { |
| 178 | return a.y < b.y; |
| 179 | }); |
| 180 | |
| 181 | boost::compute::vector<int2_>::iterator min_iter = |
| 182 | boost::compute::min_element( |
| 183 | vector.begin(), vector.end(), compare_second, queue |
| 184 | ); |
| 185 | BOOST_CHECK(min_iter == vector.begin() + 1); |
| 186 | BOOST_CHECK_EQUAL(*min_iter, int2_(2, -100)); |
| 187 | |
| 188 | boost::compute::vector<int2_>::iterator max_iter = |
| 189 | boost::compute::max_element( |
| 190 | vector.begin(), vector.end(), compare_second, queue |
| 191 | ); |
| 192 | BOOST_CHECK(max_iter == vector.begin() + 2); |
| 193 | BOOST_CHECK_EQUAL(*max_iter, int2_(3, 30)); |
| 194 | |
| 195 | // find_extrama_on_cpu |
| 196 | |
| 197 | // make sure find_extrama_on_cpu is used, no serial_find_extrema |
| 198 | std::string cache_key = |
| 199 | "__boost_find_extrema_cpu_8"; |
| 200 | boost::shared_ptr<bc::detail::parameter_cache> parameters = |
| 201 | bc::detail::parameter_cache::get_global_cache(device); |
| 202 | |
| 203 | // save |
| 204 | uint_ map_copy_threshold = |
| 205 | parameters->get(cache_key, "serial_find_extrema_threshold", 0); |
| 206 | // force find_extrama_on_cpu |
| 207 | parameters->set(cache_key, "serial_find_extrema_threshold", 16); |
| 208 | |
| 209 | min_iter = boost::compute::detail::find_extrema_on_cpu( |
| 210 | vector.begin(), vector.end(), compare_second, true /* find minimum */, queue |
| 211 | ); |
| 212 | BOOST_CHECK(min_iter == vector.begin() + 1); |
| 213 | BOOST_CHECK_EQUAL(*min_iter, int2_(2, -100)); |
| 214 | |
| 215 | max_iter = boost::compute::detail::find_extrema_on_cpu( |
| 216 | vector.begin(), vector.end(), compare_second, false /* find minimum */, queue |
| 217 | ); |
| 218 | BOOST_CHECK(max_iter == vector.begin() + 2); |
| 219 | BOOST_CHECK_EQUAL(*max_iter, int2_(3, 30)); |
| 220 | |
| 221 | // restore |
| 222 | parameters->set(cache_key, "serial_find_extrema_threshold", map_copy_threshold); |
| 223 | |
| 224 | if(is_apple_cpu_device(device)) { |
| 225 | std::cerr |
| 226 | << "skipping all further tests due to Apple platform" |
| 227 | << " behavior when local memory is used on a CPU device" |
| 228 | << std::endl; |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | // find_extrama_with_reduce |
| 233 | min_iter = boost::compute::detail::find_extrema_with_reduce( |
no test coverage detected