Skip to content

Commit

Permalink
more elegant printing of rate
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhammond committed Oct 20, 2023
1 parent f6607c0 commit c7d6861
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Cxx11/prk_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ namespace prk {
return __builtin_pow(x,n);
}

template <typename T>
void print_flop_rate_time(T name, double rate, double time)
{
const auto d = std::log10(rate);
const int shifts[6] = { 15, 12, 9, 6, 3, 0 };
const char prefix[6] = { 'P', 'T', 'G', 'M', 'K', ' ' };
for ( int r=0; r<6; r++ ) {
const auto shift = shifts[r];
if (d > shift) {
std::cout << name
<< " Rate (" << prefix[r] << "F/s): " << std::pow(1.0,-shift) * rate
<< " Avg time (s): " << time << std::endl;
break;
}
}
}

} // namespace prk

#endif /* PRK_UTIL_H */
4 changes: 1 addition & 3 deletions Cxx11/xgemm-cublas.cu
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ void run(const cublasHandle_t & h, int iterations, int order)
auto pname = (is_fp64 ? "FP64" :
(is_fp32 ? "FP32" :
(is_fp16 ? "FP16" : "Unknown FP type")));
std::cout << pname
<< " Rate (MF/s): " << 1.0e-6 * nflops/avgtime
<< " Avg time (s): " << avgtime << std::endl;
prk::print_flop_rate_time(pname, nflops/avgtime, avgtime);
} else {
std::cout << "Reference checksum = " << reference << "\n"
<< "Residuum = " << residuum << std::endl;
Expand Down

0 comments on commit c7d6861

Please sign in to comment.