diff --git a/examples/exec_tag_sync.cu b/examples/exec_tag_sync.cu index 0ef4ee7..1366931 100644 --- a/examples/exec_tag_sync.cu +++ b/examples/exec_tag_sync.cu @@ -27,6 +27,9 @@ // Used to initialize input data: #include +// Used to run the benchmark on a CUDA stream +#include + // `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(...)`. diff --git a/examples/exec_tag_timer.cu b/examples/exec_tag_timer.cu index 6aab858..812dda8 100644 --- a/examples/exec_tag_timer.cu +++ b/examples/exec_tag_timer.cu @@ -23,6 +23,7 @@ // Thrust simplifies memory management, etc: #include +#include #include #include diff --git a/nvbench/json_printer.cu b/nvbench/json_printer.cu index ed358ba..6c0e29a 100644 --- a/nvbench/json_printer.cu +++ b/nvbench/json_printer.cu @@ -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(*axis_ptr).get_value(i); + break; + + case nvbench::axis_type::float64: + value["value"] = static_cast(*axis_ptr).get_value(i); + break; + + case nvbench::axis_type::string: + value["value"] = static_cast(*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 diff --git a/nvbench/json_printer.cuh b/nvbench/json_printer.cuh index 394efb0..23875c4 100644 --- a/nvbench/json_printer.cuh +++ b/nvbench/json_printer.cuh @@ -68,6 +68,7 @@ protected: const std::string &hint, const std::vector &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{}; diff --git a/nvbench/option_parser.cu b/nvbench/option_parser.cu index 744479d..3d65fff 100644 --- a/nvbench/option_parser.cu +++ b/nvbench/option_parser.cu @@ -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()); } diff --git a/nvbench/option_parser.cuh b/nvbench/option_parser.cuh index c183764..1f334d6 100644 --- a/nvbench/option_parser.cuh +++ b/nvbench/option_parser.cuh @@ -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; diff --git a/nvbench/printer_base.cuh b/nvbench/printer_base.cuh index 3de8874..3bb20f7 100644 --- a/nvbench/printer_base.cuh +++ b/nvbench/printer_base.cuh @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -191,7 +192,12 @@ protected: const std::string &, const std::string &, const std::vector &){}; - 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);