Refactor to use NVBENCH_THROW where possible.

This commit is contained in:
Allison Vacanti
2021-12-18 17:40:24 -05:00
parent 9ff857ee29
commit 15edfe2eee
9 changed files with 82 additions and 94 deletions

View File

@@ -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;
}

View File

@@ -18,6 +18,8 @@
#include <nvbench/benchmark_manager.cuh>
#include <nvbench/detail/throw.cuh>
#include <fmt/format.h>
#include <algorithm>
@@ -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;

View File

@@ -16,10 +16,14 @@
* limitations under the License.
*/
#include <nvbench/cupti_profiler.cuh>
#include <nvbench/detail/throw.cuh>
#include <nvbench/device_info.cuh>
#include <cupti_profiler_target.h>
#include <cupti_target.h>
#include <nvbench/cupti_profiler.cuh>
#include <nvbench/device_info.cuh>
#include <nvperf_cuda_host.h>
#include <nvperf_host.h>
#include <nvperf_target.h>
@@ -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<double> 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");
}
}

View File

@@ -19,6 +19,7 @@
#include <nvbench/detail/measure_cold.cuh>
#include <nvbench/benchmark_base.cuh>
#include <nvbench/detail/throw.cuh>
#include <nvbench/device_info.cuh>
#include <nvbench/printer_base.cuh>
#include <nvbench/state.cuh>
@@ -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));
}
}

View File

@@ -19,6 +19,7 @@
#include <nvbench/detail/measure_hot.cuh>
#include <nvbench/benchmark_base.cuh>
#include <nvbench/detail/throw.cuh>
#include <nvbench/device_info.cuh>
#include <nvbench/printer_base.cuh>
#include <nvbench/state.cuh>
@@ -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));
}
}

View File

@@ -18,6 +18,8 @@
#include <nvbench/int64_axis.cuh>
#include <nvbench/detail/throw.cuh>
#include <fmt/format.h>
#include <algorithm>
@@ -45,12 +47,10 @@ void int64_axis::set_inputs(std::vector<int64_t> 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);
};

View File

@@ -18,6 +18,8 @@
#include <nvbench/named_values.cuh>
#include <nvbench/detail/throw.cuh>
#include <fmt/format.h>
#include <algorithm>
@@ -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)

View File

@@ -19,6 +19,7 @@
#include <nvbench/state.cuh>
#include <nvbench/benchmark_base.cuh>
#include <nvbench/detail/throw.cuh>
#include <nvbench/types.cuh>
#include <fmt/color.h>
@@ -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;
}

View File

@@ -18,6 +18,8 @@
#include <nvbench/type_axis.cuh>
#include <nvbench/detail/throw.cuh>
#include <fmt/format.h>
#include <fmt/ranges.h>
@@ -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();