mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Merge pull request #130 from senior-zero/enh-main/github/json-list
Introduce machine-readable version of --list
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
// Used to initialize input data:
|
||||
#include <thrust/sequence.h>
|
||||
|
||||
// Used to run the benchmark on a CUDA stream
|
||||
#include <thrust/execution_policy.h>
|
||||
|
||||
// `sequence_bench` measures the execution time of `thrust::sequence`. Since
|
||||
// algorithms in `thrust::` implicitly sync the CUDA device, the
|
||||
// `nvbench::exec_tag::sync` must be passed to `state.exec(...)`.
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
// Thrust simplifies memory management, etc:
|
||||
#include <thrust/copy.h>
|
||||
#include <thrust/execution_policy.h>
|
||||
#include <thrust/device_vector.h>
|
||||
#include <thrust/sequence.h>
|
||||
|
||||
|
||||
@@ -436,4 +436,66 @@ void json_printer::do_print_benchmark_results(const benchmark_vector &benches)
|
||||
m_ostream << root.dump(2) << "\n";
|
||||
}
|
||||
|
||||
void json_printer::do_print_benchmark_list(const benchmark_vector &benches)
|
||||
{
|
||||
if (benches.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::ordered_json root;
|
||||
auto &benchmarks = root["benchmarks"];
|
||||
|
||||
for (const auto &bench_ptr : benches)
|
||||
{
|
||||
const auto bench_index = benchmarks.size();
|
||||
auto &bench = benchmarks.emplace_back();
|
||||
|
||||
bench["name"] = bench_ptr->get_name();
|
||||
bench["index"] = bench_index;
|
||||
|
||||
// We have to ensure that the axes are represented as an array, not an
|
||||
// nil object when there are no axes.
|
||||
auto &axes = bench["axes"] = nlohmann::json::array();
|
||||
|
||||
for (const auto &axis_ptr : bench_ptr->get_axes().get_axes())
|
||||
{
|
||||
auto &axis = axes.emplace_back();
|
||||
|
||||
axis["name"] = axis_ptr->get_name();
|
||||
axis["type"] = axis_ptr->get_type_as_string();
|
||||
axis["flags"] = axis_ptr->get_flags_as_string();
|
||||
|
||||
auto &values = axis["values"];
|
||||
const auto axis_size = axis_ptr->get_size();
|
||||
for (std::size_t i = 0; i < axis_size; ++i)
|
||||
{
|
||||
auto &value = values.emplace_back();
|
||||
value["input_string"] = axis_ptr->get_input_string(i);
|
||||
value["description"] = axis_ptr->get_description(i);
|
||||
|
||||
switch (axis_ptr->get_type())
|
||||
{
|
||||
case nvbench::axis_type::int64:
|
||||
value["value"] = static_cast<int64_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
case nvbench::axis_type::float64:
|
||||
value["value"] = static_cast<float64_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
case nvbench::axis_type::string:
|
||||
value["value"] = static_cast<string_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} // end switch (axis type)
|
||||
} // end foreach axis value
|
||||
}
|
||||
} // end foreach bench
|
||||
|
||||
m_ostream << root.dump(2) << "\n";
|
||||
}
|
||||
|
||||
} // namespace nvbench
|
||||
|
||||
@@ -68,6 +68,7 @@ protected:
|
||||
const std::string &hint,
|
||||
const std::vector<nvbench::float64_t> &data) override;
|
||||
void do_print_benchmark_results(const benchmark_vector &benches) override;
|
||||
void do_print_benchmark_list(const benchmark_vector &) override;
|
||||
|
||||
bool m_enable_binary_output{false};
|
||||
std::size_t m_num_jsonbin_files{};
|
||||
|
||||
@@ -399,7 +399,14 @@ void option_parser::parse_range(option_parser::arg_iterator_t first,
|
||||
}
|
||||
else if (arg == "--list" || arg == "-l")
|
||||
{
|
||||
this->print_list();
|
||||
nvbench::markdown_printer printer{std::cout};
|
||||
this->print_list(printer);
|
||||
std::exit(0);
|
||||
}
|
||||
else if (arg == "--jsonlist" || arg == "-l")
|
||||
{
|
||||
nvbench::json_printer printer{std::cout};
|
||||
this->print_list(printer);
|
||||
std::exit(0);
|
||||
}
|
||||
else if (arg == "--persistence-mode" || arg == "--pm")
|
||||
@@ -580,12 +587,9 @@ void option_parser::print_version() const
|
||||
NVBENCH_GIT_VERSION);
|
||||
}
|
||||
|
||||
void option_parser::print_list() const
|
||||
void option_parser::print_list(printer_base& printer) const
|
||||
{
|
||||
const auto &bench_mgr = nvbench::benchmark_manager::get();
|
||||
|
||||
nvbench::markdown_printer printer{std::cout};
|
||||
printer.print_device_info();
|
||||
printer.print_benchmark_list(bench_mgr.get_benchmarks());
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
std::ostream &printer_spec_to_ostream(const std::string &spec);
|
||||
|
||||
void print_version() const;
|
||||
void print_list() const;
|
||||
void print_list(printer_base& printer) const;
|
||||
void print_help() const;
|
||||
void print_help_axis() const;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -191,7 +192,12 @@ protected:
|
||||
const std::string &,
|
||||
const std::string &,
|
||||
const std::vector<nvbench::float64_t> &){};
|
||||
virtual void do_print_benchmark_list(const benchmark_vector &) {}
|
||||
|
||||
virtual void do_print_benchmark_list(const benchmark_vector &)
|
||||
{
|
||||
throw std::runtime_error{"nvbench::do_print_benchmark_list is not supported by this printer."};
|
||||
}
|
||||
|
||||
virtual void do_print_benchmark_results(const benchmark_vector &) {}
|
||||
|
||||
virtual void do_set_completed_state_count(std::size_t states);
|
||||
|
||||
Reference in New Issue
Block a user