Introduce nvbench::stop_runner_loop exception. If application throws it, runner loop is stopped and other pending benchmark instances are skipped

This commit is contained in:
Oleksandr Pavlyk
2025-12-05 19:32:55 -06:00
parent c286199adc
commit e57f1ecf4c

View File

@@ -27,6 +27,13 @@
namespace nvbench
{
struct stop_runner_loop : std::runtime_error
{
// ask compiler to generate all constructor signatures
// that are defined for the base class
using std::runtime_error::runtime_error;
};
// Non-templated code goes here to reduce instantiation costs:
struct runner_base
{
@@ -89,6 +96,7 @@ private:
auto type_config_wrapper) {
// Get current type_config:
using type_config = typename decltype(type_config_wrapper)::type;
bool skip_remaining = false;
// Find states with the current device / type_config
for (nvbench::state &cur_state : states)
@@ -98,14 +106,22 @@ private:
{
self.run_state_prologue(cur_state);
try
{
if (!skip_remaining)
{
auto kernel_generator_copy = self.m_kernel_generator;
kernel_generator_copy(cur_state, type_config{});
if (cur_state.is_skipped())
}
if (skip_remaining || cur_state.is_skipped())
{
self.print_skip_notification(cur_state);
}
}
catch (nvbench::stop_runner_loop &e)
{
skip_remaining = true;
self.handle_sampling_exception(e, cur_state);
}
catch (std::exception &e)
{
self.handle_sampling_exception(e, cur_state);