ComPPare 1.0.0
|
OutputContext class template to hold output parameters and manage implementations. More...
#include <comppare.hpp>
Classes | |
struct | Impl |
Internal container representing one registered implementation. More... | |
Public Member Functions | |
template<typename... Ins> | |
OutputContext (Ins &&...ins) | |
Construct a new OutputContext. | |
OutputContext (const OutputContext &other)=delete | |
Deleted copy constructor. | |
OutputContext & | operator= (const OutputContext &other)=delete |
Deleted copy assignment operator. | |
OutputContext (OutputContext &&other)=delete | |
Deleted move constructor. | |
OutputContext & | operator= (OutputContext &&other)=delete |
Deleted move assignment operator. | |
template<typename F > requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...> | |
Impl & | set_reference (std::string name, F &&f) |
Set a reference implementation. | |
template<typename F > requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...> | |
Impl & | add (std::string name, F &&f) |
Add a new implementation to the comparison framework. | |
const OutPtr | get_reference_output () const |
Get the reference output by pointer. | |
const OutPtr | get_output (const size_t idx) const |
Get the output for a specific implementation by pointer. | |
const OutPtr | get_output (const std::string_view name) const |
Get the output for a specific implementation by name. | |
void | get_reference_output (outtype_t< OutputSpecs > *...outs) const |
Copies the reference output into provided pointer to variables. | |
void | get_output (const size_t idx, outtype_t< OutputSpecs > *...outs) const |
Copies the outputs of a specific implementation by index into provided pointer to variables. | |
void | get_output (const std::string_view name, outtype_t< OutputSpecs > *...outs) const |
Copies the outputs of a specific implementation by name into provided pointer to variables. | |
void | run (int argc=0, char **argv=nullptr) |
Runs the comparison for all added implementations. | |
Private Types | |
template<typename S > | |
using | outtype_t = typename outspec< S >::outtype_t |
Extracts the value type from a outspec. | |
template<typename S > | |
using | pol_t = typename outspec< S >::policy_t |
Extracts the policy type from a outspec. | |
using | Func = std::function< void(const std::decay_t< Inputs > &..., outtype_t< OutputSpecs > &...)> |
Alias for the function signature of a user-provided implementation. | |
using | InTup = std::tuple< std::decay_t< Inputs >... > |
Tuple type holding all input arguments. | |
using | OutTup = std::tuple< outtype_t< OutputSpecs >... > |
Tuple type holding all output values (one element per outspec). | |
using | PolicyTup = std::tuple< pol_t< OutputSpecs >... > |
Tuple type holding the error/policy object associated with each output outspec. | |
using | OutPtr = std::shared_ptr< OutTup > |
Shared pointer to an output tuple. | |
Private Member Functions | |
void | register_plugin (const std::shared_ptr< plugin::Plugin< InTup, OutTup > > &p) |
Register a plugin for the output context. | |
void | print_header () const |
Print the header for the output table. | |
void | compute_errors (PolicyTup &errs, const OutTup &test, const OutTup &ref) |
Compute the error metrics for each output specification. | |
bool | any_fail (const PolicyTup &errs) const |
Check if any of the error policies indicate a failure. | |
void | print_metrics (const PolicyTup &errs) const |
Print the metrics for each output specification. | |
OutPtr | get_output_by_index_ (const size_t idx) const |
Get the output by index. | |
OutPtr | get_output_by_name_ (const std::string_view name) const |
Get the output by implementation name. | |
void | unpack_output_ (const OutTup &outtup, outtype_t< OutputSpecs > *...outs) const |
Unpack the output tuple into the provided output pointers. | |
Static Private Member Functions | |
template<std::size_t I> | |
static constexpr std::size_t | spec_metric_count () |
Get the implementation details for a specific implementation index. | |
template<std::size_t I> | |
static constexpr std::string_view | spec_metric_name (std::size_t m) |
Get the name of a specific metric for a specific implementation index. | |
Private Attributes | |
InTup | inputs_ |
Tuple instance storing all current input arguments. | |
std::vector< OutPtr > | outputs_ |
Storage for reference and comparison outputs. | |
PolicyTup | policies_ref_ |
Tuple of policy objects for the reference outputs. | |
std::shared_ptr< plugin::Plugin< InTup, OutTup > > | plugin_ |
Shared pointer to the plugin instance. | |
std::vector< Impl > | impls_ |
Vector to hold all implementations. | |
Static Private Attributes | |
static constexpr size_t | NUM_OUT = sizeof...(OutputSpecs) |
Number of output specifications. | |
static constexpr int | PRINT_COL_WIDTH = 20 |
Set the width of the print columns. | |
OutputContext class template to hold output parameters and manage implementations.
OutputSpecs |
|
private |
Alias for the function signature of a user-provided implementation.
The function must take all input arguments by const reference, and all output arguments by non-const reference. The framework invokes this function to compare multiple implementations on the same input.
Example signature:
|
private |
Tuple type holding all input arguments.
|
private |
Shared pointer to an output tuple.
Used to manage lifetime of output results across multiple implementations.
|
private |
Tuple type holding all output values (one element per outspec).
|
private |
Extracts the value type from a outspec.
S | The output outspec type. |
|
private |
Extracts the policy type from a outspec.
S | The output outspec type. |
|
private |
Tuple type holding the error/policy object associated with each output outspec.
|
inlineexplicit |
Construct a new OutputContext.
Ins | The types of the input arguments |
ins | The input arguments |
This constructor initializes the OutputContext with the provided input arguments. The inputs are perfectly forwarded to allow for move and copy semantics.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inline |
Add a new implementation to the comparison framework.
F | The type of the function |
name | The name of the implementation |
f | The function to execute |
This function adds a new implementation to the comparison framework. The function will be run and compared against the reference implementation.
|
inlineprivate |
Check if any of the error policies indicate a failure.
errs | The tuple of error policies to check. |
|
inlineprivate |
Compute the error metrics for each output specification.
errs | The tuple of error policies. |
test | The test output. |
ref | The reference output. |
|
inline |
Get the output for a specific implementation by pointer.
idx | The index of the implementation |
This function returns a shared pointer to the output of the implementation at the specified index.
|
inline |
Copies the outputs of a specific implementation by index into provided pointer to variables.
outs | One pointer per output element. Each pointer must point to writable storage of the corresponding output type. |
Internally, this looks up the output tuple at the specified index, and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple
directly.
|
inline |
Get the output for a specific implementation by name.
name | The name of the implementation |
This function returns a shared pointer to the output of the implementation with the specified name.
|
inline |
Copies the outputs of a specific implementation by name into provided pointer to variables.
outs | One pointer per output element. Each pointer must point to writable storage of the corresponding output type. |
Internally, this looks up the output tuple at the specified name, and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple
directly.
|
inlineprivate |
Get the output by index.
idx | The index of the output. |
|
inlineprivate |
Get the output by implementation name.
name | The name of the implementation. |
|
inline |
Get the reference output by pointer.
This function returns a shared pointer to the output of the reference implementation.
|
inline |
Copies the reference output into provided pointer to variables.
outs | One pointer per output element. Each pointer must point to writable storage of the corresponding output type. |
Internally, this looks up the output tuple at index 0 (the reference), and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple
directly.
|
delete |
Deleted copy assignment operator.
|
delete |
Deleted move assignment operator.
|
inlineprivate |
Print the header for the output table.
This includes the framework title, number of implementations, warmup iterations, and benchmark iterations. It also prints the column headers for the output table. The metric headers are printed dynamically based on the number of output specs.
|
inlineprivate |
Print the metrics for each output specification.
errs | The tuple of error policies containing the metrics to print. |
|
inlineprivate |
Register a plugin for the output context.
p | The shared pointer to the plugin to register. |
|
inline |
Runs the comparison for all added implementations.
argc | Number of command line arguments |
argv | Array of command line arguments |
|
inline |
Set a reference implementation.
F | The type of the function |
name | The name of the implementation |
f | The function to execute |
This function sets a reference implementation to the comparison framework. The reference implementation is always the first one added and is used as the baseline for comparison.
|
inlinestaticconstexprprivate |
Get the implementation details for a specific implementation index.
I | The implementation index. |
|
inlinestaticconstexprprivate |
Get the name of a specific metric for a specific implementation index.
I | The implementation index. |
m | The metric index of the output policy. |
|
inlineprivate |
Unpack the output tuple into the provided output pointers.
outtup | The output tuple to unpack. |
outs | The output pointers to fill. |
|
private |
Vector to hold all implementations.
This vector is used to store all the different implementations of the operation being benchmarked.
|
private |
Tuple instance storing all current input arguments.
|
staticconstexprprivate |
Number of output specifications.
This is equal to the number of outputs of a function.
|
private |
Storage for reference and comparison outputs.
Each implementation’s outputs are stored here as shared pointer to tuples. The first implementation is treated as the reference.
|
private |
Shared pointer to the plugin instance.
This pointer is used to store the plugin instance and ensure only one plugin is registered. It is shared across all implementations within the output context.
|
private |
Tuple of policy objects for the reference outputs.
Each policy governs how the corresponding output is validated
|
staticconstexprprivate |
Set the width of the print columns.