Skip to content

Commit

Permalink
Simplified main-code for benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
neoblizz committed Jul 25, 2022
1 parent f343eb9 commit ae25951
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
59 changes: 42 additions & 17 deletions benchmarks/spmv/parameters.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,73 @@
#include <cxxopts.hpp>

#include <loops/util/filepath.hxx>
#include <nvbench/nvbench.cuh>

std::string filename;

struct parameters_t {
std::string filename;
bool help = false;
cxxopts::Options options;

/**
* @brief Construct a new parameters object and parse command line arguments.
*
* @param argc Number of command line arguments.
* @param argv Command line arguments.
*/
parameters_t(int argc, char** argv) : options(argv[0], "SPMV Benchmarking") {
options.allow_unrecognised_options();
parameters_t(int argc, char** argv)
: m_options(argv[0], "SPMV Benchmarking"), m_argc(argc) {
m_options.allow_unrecognised_options();
// Add command line options
options.add_options()("h,help", "Print help") // help
m_options.add_options()("h,help", "Print help") // help
("m,market", "Matrix file",
cxxopts::value<std::string>()); // mtx

// Parse command line arguments
auto result = options.parse(argc, argv);
// Parse command line arguments.
auto result = m_options.parse(argc, argv);

// Print help if requested
if (result.count("help")) {
help = true;
std::cout << options.help({""});
m_help = true;
std::cout << m_options.help({""});
std::cout << " [optional nvbench args]" << std::endl << std::endl;
// Do not exit so we also print NVBench help.
} else {
const char* argh[1] = {"-h"};
NVBENCH_MAIN_BODY(1, argh);
}

// Get matrix market file or error if not specified.
else {
if (result.count("market") == 1) {
filename = result["market"].as<std::string>();
if (!loops::is_market(filename)) {
std::cout << options.help({""});
this->m_filename = result["market"].as<std::string>();
filename = m_filename;
if (!loops::is_market(m_filename)) {
std::cout << m_options.help({""});
std::cout << " [optional nvbench args]" << std::endl << std::endl;
std::exit(0);
}

// Remove loops parameters and pass the rest to nvbench.
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--market") == 0 || strcmp(argv[i], "-m") == 0) {
i++;
continue;
}
m_args.push_back(argv[i]);
}

} else {
std::cout << options.help({""});
std::cout << m_options.help({""});
std::cout << " [optional nvbench args]" << std::endl << std::endl;
std::exit(0);
}
}
}

/// Helpers for NVBENCH_MAIN_BODY call.
int nvbench_argc() { return m_argc - 2; }
auto nvbench_argv() { return m_args.data(); }

private:
std::string m_filename;
cxxopts::Options m_options;
std::vector<const char*> m_args;
bool m_help = false;
int m_argc;
};
23 changes: 1 addition & 22 deletions benchmarks/spmv/work_oriented.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <loops/container/container.hxx>
#include <loops/algorithms/spmv/work_oriented.cuh>

#include <nvbench/nvbench.cuh>

#define LOOPS_CUPTI_SUPPORTED 0

using namespace loops;
Expand Down Expand Up @@ -57,24 +55,5 @@ NVBENCH_BENCH_TYPES(work_oriented_bench, NVBENCH_TYPE_AXES(value_types));

int main(int argc, char** argv) {
parameters_t params(argc, argv);
filename = params.filename;

if (params.help) {
// Print NVBench help.
const char* args[1] = {"-h"};
NVBENCH_MAIN_BODY(1, args);
} else {
// Create a new argument array without matrix filename to pass to NVBench.
char* args[argc - 2];
int j = 0;
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--market") == 0 || strcmp(argv[i], "-m") == 0) {
i++;
continue;
}
args[j] = argv[i];
j++;
}
NVBENCH_MAIN_BODY(argc - 2, args);
}
NVBENCH_MAIN_BODY(params.nvbench_argc(), params.nvbench_argv());
}

0 comments on commit ae25951

Please sign in to comment.