| 32 | |
| 33 | template<class T> |
| 34 | double perf_saxpy(const compute::vector<T>& x, |
| 35 | const compute::vector<T>& y, |
| 36 | const T alpha, |
| 37 | const size_t trials, |
| 38 | compute::command_queue& queue) |
| 39 | { |
| 40 | // create vector on the device to store the result |
| 41 | compute::vector<T> result(x.size(), queue.get_context()); |
| 42 | |
| 43 | perf_timer t; |
| 44 | for(size_t trial = 0; trial < trials; trial++){ |
| 45 | compute::fill(result.begin(), result.end(), T(0), queue); |
| 46 | queue.finish(); |
| 47 | |
| 48 | t.start(); |
| 49 | |
| 50 | using compute::lambda::_1; |
| 51 | using compute::lambda::_2; |
| 52 | |
| 53 | compute::transform( |
| 54 | x.begin(), x.end(), y.begin(), result.begin(), alpha * _1 + _2, queue |
| 55 | ); |
| 56 | |
| 57 | queue.finish(); |
| 58 | t.stop(); |
| 59 | } |
| 60 | |
| 61 | return t.min_time(); |
| 62 | } |
| 63 | |
| 64 | template<class T> |
| 65 | void tune_saxpy(const compute::vector<T>& x, |