mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Add output_multiplex.
This allows an arbitrary number of output_formats to be wrapped up into a single object. This output format just forwards all calls to its children.
This commit is contained in:
@@ -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
|
||||
|
||||
53
nvbench/output_multiplex.cu
Normal file
53
nvbench/output_multiplex.cu
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <nvbench/output_multiplex.cuh>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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
|
||||
36
nvbench/output_multiplex.cuh
Normal file
36
nvbench/output_multiplex.cuh
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <nvbench/output_format.cuh>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
/*!
|
||||
* An nvbench::output_format that just forwards calls to other `output_format`s.
|
||||
*/
|
||||
struct output_multiplex : nvbench::output_format
|
||||
{
|
||||
|
||||
output_multiplex();
|
||||
|
||||
template <typename Format, typename... Ts>
|
||||
Format &emplace(Ts &&...ts)
|
||||
{
|
||||
m_formats.push_back(std::make_unique<Format>(std::forward<Ts>(ts)...));
|
||||
return static_cast<Format &>(*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<std::unique_ptr<nvbench::output_format>> m_formats;
|
||||
};
|
||||
|
||||
} // namespace nvbench
|
||||
Reference in New Issue
Block a user