From e57f1ecf4cceb3ee893a820615fb10996d2f0f5f Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk <21087696+oleksandr-pavlyk@users.noreply.github.com> Date: Fri, 5 Dec 2025 19:32:55 -0600 Subject: [PATCH] Introduce nvbench::stop_runner_loop exception. If application throws it, runner loop is stopped and other pending benchmark instances are skipped --- nvbench/runner.cuh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/nvbench/runner.cuh b/nvbench/runner.cuh index 2c4176f..c3cc283 100644 --- a/nvbench/runner.cuh +++ b/nvbench/runner.cuh @@ -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 { @@ -88,7 +95,8 @@ private: [&self = *this, &states = m_benchmark.m_states, &type_config_index, &device]( auto type_config_wrapper) { // Get current type_config: - using type_config = typename decltype(type_config_wrapper)::type; + 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) @@ -99,13 +107,21 @@ private: self.run_state_prologue(cur_state); try { - auto kernel_generator_copy = self.m_kernel_generator; - kernel_generator_copy(cur_state, type_config{}); - if (cur_state.is_skipped()) + if (!skip_remaining) + { + auto kernel_generator_copy = self.m_kernel_generator; + kernel_generator_copy(cur_state, type_config{}); + } + 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);