diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt index c3c3c87..3edf6ab 100644 --- a/nvbench/CMakeLists.txt +++ b/nvbench/CMakeLists.txt @@ -13,6 +13,7 @@ set(srcs markdown_format.cu named_values.cu option_parser.cu + output_multiplex.cu runner.cu state.cu string_axis.cu diff --git a/nvbench/output_multiplex.cu b/nvbench/output_multiplex.cu new file mode 100644 index 0000000..f2fc1f4 --- /dev/null +++ b/nvbench/output_multiplex.cu @@ -0,0 +1,53 @@ +#include + +#include + +namespace nvbench +{ + +output_multiplex::output_multiplex() + : output_format(std::cerr) // Nothing should write to this. +{} + +void output_multiplex::do_print_device_info() +{ + for (auto &format_ptr : m_formats) + { + format_ptr->print_device_info(); + } +} + +void output_multiplex::do_print_log_preamble() +{ + for (auto &format_ptr : m_formats) + { + format_ptr->print_log_preamble(); + } +} + +void output_multiplex::do_print_log_epilogue() +{ + for (auto &format_ptr : m_formats) + { + format_ptr->print_log_epilogue(); + } +} + +void output_multiplex::do_print_benchmark_list(const benchmark_vector &benches) +{ + for (auto &format_ptr : m_formats) + { + format_ptr->print_benchmark_list(benches); + } +} + +void output_multiplex::do_print_benchmark_results( + const benchmark_vector &benches) +{ + for (auto &format_ptr : m_formats) + { + format_ptr->print_benchmark_results(benches); + } +} + +} // namespace nvbench diff --git a/nvbench/output_multiplex.cuh b/nvbench/output_multiplex.cuh new file mode 100644 index 0000000..25549bb --- /dev/null +++ b/nvbench/output_multiplex.cuh @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include +#include + +namespace nvbench +{ + +/*! + * An nvbench::output_format that just forwards calls to other `output_format`s. + */ +struct output_multiplex : nvbench::output_format +{ + + output_multiplex(); + + template + Format &emplace(Ts &&...ts) + { + m_formats.push_back(std::make_unique(std::forward(ts)...)); + return static_cast(*m_formats.back()); + } + +private: + void do_print_device_info(); + void do_print_log_preamble(); + void do_print_log_epilogue(); + void do_print_benchmark_list(const benchmark_vector &benches); + void do_print_benchmark_results(const benchmark_vector &benches); + + std::vector> m_formats; +}; + +} // namespace nvbench