diff --git a/nvbench/axes_metadata.cxx b/nvbench/axes_metadata.cxx index a727dbc..f4154b9 100644 --- a/nvbench/axes_metadata.cxx +++ b/nvbench/axes_metadata.cxx @@ -167,10 +167,7 @@ const nvbench::type_axis &axes_metadata::get_type_axis(std::size_t index) const } } } - throw std::runtime_error(fmt::format("{}:{}: Invalid type axis index: {}.", - __FILE__, - __LINE__, - index)); + NVBENCH_THROW(std::runtime_error, "Invalid type axis index: {}.", index); } nvbench::type_axis &axes_metadata::get_type_axis(std::size_t index) @@ -186,10 +183,7 @@ nvbench::type_axis &axes_metadata::get_type_axis(std::size_t index) } } } - throw std::runtime_error(fmt::format("{}:{}: Invalid type axis index: {}.", - __FILE__, - __LINE__, - index)); + NVBENCH_THROW(std::runtime_error, "Invalid type axis index: {}.", index); } const axis_base &axes_metadata::get_axis(std::string_view name) const @@ -201,8 +195,7 @@ const axis_base &axes_metadata::get_axis(std::string_view name) const if (iter == m_axes.cend()) { - throw std::runtime_error( - fmt::format("{}:{}: Axis '{}' not found.", __FILE__, __LINE__, name)); + NVBENCH_THROW(std::runtime_error, "Axis '{}' not found.", name); } return **iter; @@ -217,8 +210,7 @@ axis_base &axes_metadata::get_axis(std::string_view name) if (iter == m_axes.end()) { - throw std::runtime_error( - fmt::format("{}:{}: Axis '{}' not found.", __FILE__, __LINE__, name)); + NVBENCH_THROW(std::runtime_error, "Axis '{}' not found.", name); } return **iter; @@ -230,13 +222,11 @@ const axis_base &axes_metadata::get_axis(std::string_view name, const auto &axis = this->get_axis(name); if (axis.get_type() != type) { - throw std::runtime_error(fmt::format("{}:{}: Axis '{}' type mismatch " - "(expected {}, actual {}).", - __FILE__, - __LINE__, - name, - type, - axis.get_type())); + NVBENCH_THROW(std::runtime_error, + "Axis '{}' type mismatch (expected {}, actual {}).", + name, + type, + axis.get_type()); } return axis; } @@ -247,13 +237,11 @@ axis_base &axes_metadata::get_axis(std::string_view name, auto &axis = this->get_axis(name); if (axis.get_type() != type) { - throw std::runtime_error(fmt::format("{}:{}: Axis '{}' type mismatch " - "(expected {}, actual {}).", - __FILE__, - __LINE__, - name, - type, - axis.get_type())); + NVBENCH_THROW(std::runtime_error, + "Axis '{}' type mismatch (expected {}, actual {}).", + name, + type, + axis.get_type()); } return axis; } diff --git a/nvbench/benchmark_manager.cxx b/nvbench/benchmark_manager.cxx index bde508e..2a0ca60 100644 --- a/nvbench/benchmark_manager.cxx +++ b/nvbench/benchmark_manager.cxx @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -58,8 +60,7 @@ benchmark_manager::get_benchmark(const std::string &name) const }); if (iter == m_benchmarks.cend()) { - throw std::out_of_range( - fmt::format("{}:{}: No benchmark named '{}'.", name)); + NVBENCH_THROW(std::out_of_range, "No benchmark named '{}'.", name); } return **iter; diff --git a/nvbench/cupti_profiler.cxx b/nvbench/cupti_profiler.cxx index 63f3fbb..a2bd432 100644 --- a/nvbench/cupti_profiler.cxx +++ b/nvbench/cupti_profiler.cxx @@ -16,10 +16,14 @@ * limitations under the License. */ +#include + +#include +#include + #include #include -#include -#include + #include #include #include @@ -41,8 +45,7 @@ void cupti_call(const CUptiResult status) const char *errstr{}; cuptiGetResultString(status, &errstr); - throw std::runtime_error( - fmt::format("CUPTI call returned error: {}\n", errstr)); + NVBENCH_THROW(std::runtime_error, "CUPTI call returned error: {}", errstr); } } @@ -50,8 +53,7 @@ void nvpw_call(const NVPA_Status status) { if (status != NVPA_STATUS_SUCCESS) { - throw std::runtime_error( - fmt::format("NVPW call returned error: {}\n", status)); + NVBENCH_THROW(std::runtime_error, "NVPW call returned error: {}", status); } } @@ -100,9 +102,10 @@ void cupti_profiler::initialize_profiler() { if (!m_device.is_cupti_supported()) { - throw std::runtime_error(fmt::format("Device: {} isn't supported (CC {})", - m_device.get_id(), - m_device.get_sm_version())); + NVBENCH_THROW(std::runtime_error, + "Device: {} isn't supported (CC {})", + m_device.get_id(), + m_device.get_sm_version()); } CUpti_Profiler_Initialize_Params params = { @@ -727,7 +730,9 @@ std::vector cupti_profiler::get_counter_values() if (params.numRanges != 1) { - throw std::runtime_error("Something's gone wrong, one range is expected"); + NVBENCH_THROW(std::runtime_error, + "{}", + "Something's gone wrong, one range is expected"); } } diff --git a/nvbench/detail/measure_cold.cu b/nvbench/detail/measure_cold.cu index 25bcd09..48af61b 100644 --- a/nvbench/detail/measure_cold.cu +++ b/nvbench/detail/measure_cold.cu @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -49,17 +50,15 @@ void measure_cold_base::check() const auto device = m_state.get_device(); if (!device) { - throw std::runtime_error(fmt::format("{}:{}: Device required for `cold` " - "measurement.", - __FILE__, - __LINE__)); + NVBENCH_THROW(std::runtime_error, + "{}", + "Device required for `cold` measurement."); } if (!device->is_active()) { // This means something went wrong higher up. Throw an error. - throw std::runtime_error(fmt::format("{}:{}: Internal error: Current " - "device is not active.", - __FILE__, - __LINE__)); + NVBENCH_THROW(std::runtime_error, + "{}", + "Internal error: Current device is not active."); } } @@ -216,7 +215,7 @@ void measure_cold_base::check_skip_time(nvbench::float64_t warmup_time) m_skip_time * 1e6); m_state.skip(reason); - throw std::runtime_error{std::move(reason)}; + NVBENCH_THROW(std::runtime_error, "{}", std::move(reason)); } } diff --git a/nvbench/detail/measure_hot.cu b/nvbench/detail/measure_hot.cu index 9b57a24..62efb59 100644 --- a/nvbench/detail/measure_hot.cu +++ b/nvbench/detail/measure_hot.cu @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -70,17 +71,15 @@ void measure_hot_base::check() const auto device = m_state.get_device(); if (!device) { - throw std::runtime_error(fmt::format("{}:{}: Device required for `hot` " - "measurement.", - __FILE__, - __LINE__)); + NVBENCH_THROW(std::runtime_error, + "{}", + "Device required for `hot` measurement."); } if (!device->is_active()) { // This means something went wrong higher up. Throw an error. - throw std::runtime_error(fmt::format("{}:{}: Internal error: Current " - "device is not active.", - __FILE__, - __LINE__)); + NVBENCH_THROW(std::runtime_error, + "{}", + "Internal error: Current device is not active."); } } @@ -158,7 +157,7 @@ void measure_hot_base::check_skip_time(nvbench::float64_t warmup_time) m_skip_time * 1e6); m_state.skip(reason); - throw std::runtime_error{std::move(reason)}; + NVBENCH_THROW(std::runtime_error, "{}", std::move(reason)); } } diff --git a/nvbench/int64_axis.cxx b/nvbench/int64_axis.cxx index 37858f5..24ff913 100644 --- a/nvbench/int64_axis.cxx +++ b/nvbench/int64_axis.cxx @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -45,12 +47,10 @@ void int64_axis::set_inputs(std::vector inputs, int64_axis_flags flags) auto conv = [](int64_t in) -> int64_t { if (in < 0 || in >= 64) { - throw std::runtime_error(fmt::format("{}:{}: Input value exceeds valid " - "range for power-of-two mode. " - "Input={} ValidRange=[0, 63]", - __FILE__, - __LINE__, - in)); + NVBENCH_THROW(std::runtime_error, + "Input value exceeds valid range for power-of-two mode. " + "Input={} ValidRange=[0, 63]", + in); } return int64_axis::compute_pow2(in); }; diff --git a/nvbench/named_values.cxx b/nvbench/named_values.cxx index 72fdd5a..cb5b1f2 100644 --- a/nvbench/named_values.cxx +++ b/nvbench/named_values.cxx @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -68,8 +70,7 @@ named_values::get_value(const std::string &name) const [&name](const auto &val) { return val.name == name; }); if (iter == m_storage.cend()) { - throw std::runtime_error( - fmt::format("{}:{}: No value with name '{}'.", __FILE__, __LINE__, name)); + NVBENCH_THROW(std::runtime_error, "No value with name '{}'.", name); } return iter->value; } @@ -91,11 +92,9 @@ named_values::type named_values::get_type(const std::string &name) const { return nvbench::named_values::type::string; } - throw std::runtime_error(fmt::format("{}:{}: Unknown variant type for " - "entry '{}'.", - __FILE__, - __LINE__, - name)); + NVBENCH_THROW(std::runtime_error, + "Unknown variant type for entry '{}'.", + name); }, this->get_value(name)); } @@ -107,12 +106,10 @@ try } catch (std::exception &err) { - throw std::runtime_error(fmt::format("{}:{}: Error looking up int64 value " - "`{}`:\n{}", - __FILE__, - __LINE__, - name, - err.what())); + NVBENCH_THROW(std::runtime_error, + "Error looking up int64 value `{}`:\n{}", + name, + err.what()); } nvbench::float64_t named_values::get_float64(const std::string &name) const @@ -122,12 +119,10 @@ try } catch (std::exception &err) { - throw std::runtime_error(fmt::format("{}:{}: Error looking up float64 value " - "`{}`:\n{}", - __FILE__, - __LINE__, - name, - err.what())); + NVBENCH_THROW(std::runtime_error, + "Error looking up float64 value `{}`:\n{}", + name, + err.what()); } const std::string &named_values::get_string(const std::string &name) const @@ -137,12 +132,10 @@ try } catch (std::exception &err) { - throw std::runtime_error(fmt::format("{}:{}: Error looking up string value " - "`{}`:\n{}", - __FILE__, - __LINE__, - name, - err.what())); + NVBENCH_THROW(std::runtime_error, + "Error looking up string value `{}`:\n{}", + name, + err.what()); } void named_values::set_int64(std::string name, nvbench::int64_t value) diff --git a/nvbench/state.cxx b/nvbench/state.cxx index db2ab6d..8a1af3a 100644 --- a/nvbench/state.cxx +++ b/nvbench/state.cxx @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -127,8 +128,7 @@ const summary &state::get_summary(std::string_view name) const [&name](const auto &s) { return s.get_name() == name; }); if (iter == m_summaries.cend()) { - throw std::runtime_error( - fmt::format("{}:{}: No summary named '{}'.", __FILE__, __LINE__, name)); + NVBENCH_THROW(std::runtime_error, "No summary named '{}'.", name); } return *iter; } @@ -140,8 +140,7 @@ summary &state::get_summary(std::string_view name) [&name](auto &s) { return s.get_name() == name; }); if (iter == m_summaries.end()) { - throw std::runtime_error( - fmt::format("{}:{}: No summary named '{}'.", __FILE__, __LINE__, name)); + NVBENCH_THROW(std::runtime_error, "No summary named '{}'.", name); } return *iter; } diff --git a/nvbench/type_axis.cxx b/nvbench/type_axis.cxx index 8677de9..bca3533 100644 --- a/nvbench/type_axis.cxx +++ b/nvbench/type_axis.cxx @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -56,10 +58,12 @@ std::size_t type_axis::get_type_index(const std::string &input_string) const std::find(m_input_strings.cbegin(), m_input_strings.cend(), input_string); if (it == m_input_strings.end()) { - throw std::runtime_error( - fmt::format("{}:{}: Invalid input string '{}' for type_axis `{}`.\n" + NVBENCH_THROW(std::runtime_error, + "Invalid input string '{}' for type_axis `{}`.\n" "Valid input strings: {}", - __FILE__, __LINE__, input_string, this->get_name(), m_input_strings)); + input_string, + this->get_name(), + m_input_strings); } return it - m_input_strings.cbegin();