| 14 | #include <cmath> |
| 15 | |
| 16 | static bool progress(unsigned iter_curr, af::timer t, double time_total) { |
| 17 | static unsigned iter_prev = 0; |
| 18 | static double time_prev = 0; |
| 19 | static double max_rate = 0; |
| 20 | |
| 21 | af::sync(); |
| 22 | double time_curr = af::timer::stop(t); |
| 23 | |
| 24 | if ((time_curr - time_prev) < 1) return true; |
| 25 | |
| 26 | double rate = (iter_curr - iter_prev) / (time_curr - time_prev); |
| 27 | printf(" iterations per second: %.0f (progress %.0f%%)\n", rate, |
| 28 | 100.0f * time_curr / time_total); |
| 29 | |
| 30 | max_rate = std::max(max_rate, rate); |
| 31 | |
| 32 | iter_prev = iter_curr; |
| 33 | time_prev = time_curr; |
| 34 | |
| 35 | if (time_curr < time_total) return true; |
| 36 | |
| 37 | printf(" ### %f iterations per second (max)\n", max_rate); |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | #endif |