Skip to content

Commit

Permalink
added option to perform arbitrary number of runs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkstoyanov committed Feb 12, 2025
1 parent fd20c64 commit c9daa1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
15 changes: 12 additions & 3 deletions benchmarks/speed3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ void benchmark_fft(std::array<int,3> size_fft, std::deque<std::string> const &ar

// Print results
if(me==0){
t_max = t_max / (2.0 * ntest);
double const fftsize = static_cast<double>(world.count());
double const floprate = 5.0 * batch_size * fftsize * std::log(fftsize) * 1e-9 / std::log(2.0) / t_max;
double const fftsize = static_cast<double>(world.count());

double floprate = 0.0;
if (ntest > 0) { // something was tested
t_max /= (2.0 * ntest); // time per test, 2 transforms forward/backward
floprate = 5.0 * batch_size * fftsize * std::log(fftsize) * 1e-9 / std::log(2.0) / t_max;
} else {
t_max = 0.0; // nothing was tested
}

long long mem_usage = static_cast<long long>(fft.size_inbox()) + static_cast<long long>(fft.size_outbox())
+ static_cast<long long>(fft.size_workspace());
mem_usage *= sizeof(output_type);
Expand All @@ -232,6 +239,7 @@ void benchmark_fft(std::array<int,3> size_fft, std::deque<std::string> const &ar
for(int i=0; i<5; i++)
print_proc_grid(i);
cout << "\n";
cout << "Num runs: " << ntest << '\n';
cout << "Time per run: " << t_max << " (s)\n";
cout << "Performance: " << floprate << " GFlops/s\n";
cout << "Memory usage: " << mem_usage << "MB/rank\n";
Expand Down Expand Up @@ -351,6 +359,7 @@ int main(int argc, char *argv[]){
-r2c_dir dir: specifies the r2c direction for the r2c tests, dir must be 0 1 or 2
-mps: for the cufft backend and multiple gpus, associate the mpi ranks with different cuda devices
-nX: number of times to repeat the run, accepted variants are -n5 (default), -n1, -n10, -n50
-nrunsXYZ: same as -n but allows for a custom number, XYZ must be a non-negative integer, e.g., -nruns17
)help2";

Expand Down
27 changes: 23 additions & 4 deletions test/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ bool has_option(std::deque<std::string> const &args, std::string const &opt){
return false;
}
//! \brief Takes the three arguments after \b opt and converts them to an array of ints, throws runtime_error if no arguments or cannot convert.
std::array<int, 3> get_grid(std::deque<std::string> const &args, std::string const &opt){
inline std::array<int, 3> get_grid(std::deque<std::string> const &args, std::string const &opt){
auto iopt = args.begin();
while(iopt != args.end()){
if (*iopt == opt){ // found the argument, take the next three entries
Expand All @@ -374,7 +374,7 @@ std::array<int, 3> get_grid(std::deque<std::string> const &args, std::string con
throw std::runtime_error(opt + " not found");
}

int get_int_arg(std::string const &name, std::deque<std::string> const &args, int default_value = -1){
inline int get_int_arg(std::string const &name, std::deque<std::string> const &args, int default_value = -1){
auto iopt = args.begin();
while(iopt != args.end()){
if (*iopt == name){
Expand All @@ -388,8 +388,27 @@ int get_int_arg(std::string const &name, std::deque<std::string> const &args, in
}
return default_value;
}

int nruns(std::deque<std::string> const &args){
//! returns the number of runs selected in the args
inline int nruns(std::deque<std::string> const &args){
for(auto &s : args) {
std::string::size_type nr = s.find("-nruns");
if (nr != 0)
continue;
// found a string with -nruns, get the number
int num = 0;
try {
num = std::stoi(s.substr(6));
} catch(std::invalid_argument &) {
std::cerr << "cannot convert '" << s.substr(6) << "' to 'int'\n";
throw;
} catch(std::out_of_range &) {
std::cerr << "provided integer '" << s.substr(6) << "' is too large\n";
throw;
}
if (num < 0)
throw std::runtime_error("the number of of runs has to be non-negative");
return num;
}
for(auto &s : args)
if (s == "-n1")
return 1;
Expand Down

0 comments on commit c9daa1e

Please sign in to comment.