| 63 | |
| 64 | template<class T> |
| 65 | void tune_saxpy(const compute::vector<T>& x, |
| 66 | const compute::vector<T>& y, |
| 67 | const T alpha, |
| 68 | const size_t trials, |
| 69 | compute::command_queue& queue) |
| 70 | { |
| 71 | boost::shared_ptr<compute::detail::parameter_cache> |
| 72 | params = compute::detail::parameter_cache::get_global_cache(queue.get_device()); |
| 73 | |
| 74 | const std::string cache_key = |
| 75 | std::string("__boost_copy_kernel_") + boost::lexical_cast<std::string>(sizeof(T)); |
| 76 | |
| 77 | const compute::uint_ tpbs[] = { 4, 8, 16, 32, 64, 128, 256, 512, 1024 }; |
| 78 | const compute::uint_ vpts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; |
| 79 | |
| 80 | double min_time = (std::numeric_limits<double>::max)(); |
| 81 | compute::uint_ best_tpb = 0; |
| 82 | compute::uint_ best_vpt = 0; |
| 83 | |
| 84 | for(size_t i = 0; i < sizeof(tpbs) / sizeof(*tpbs); i++){ |
| 85 | params->set(cache_key, "tpb", tpbs[i]); |
| 86 | for(size_t j = 0; j < sizeof(vpts) / sizeof(*vpts); j++){ |
| 87 | params->set(cache_key, "vpt", vpts[j]); |
| 88 | |
| 89 | try { |
| 90 | const double t = perf_saxpy(x, y, alpha, trials, queue); |
| 91 | if(t < min_time){ |
| 92 | best_tpb = tpbs[i]; |
| 93 | best_vpt = vpts[j]; |
| 94 | min_time = t; |
| 95 | } |
| 96 | } |
| 97 | catch(compute::opencl_error&){ |
| 98 | // invalid parameters for this device, skip |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // store optimal parameters |
| 104 | params->set(cache_key, "tpb", best_tpb); |
| 105 | params->set(cache_key, "vpt", best_vpt); |
| 106 | } |
| 107 | |
| 108 | int main(int argc, char *argv[]) |
| 109 | { |
no test coverage detected