diff --git a/nvbench/benchmark_base.cxx b/nvbench/benchmark_base.cxx index 06b3a3b..7d6f06f 100644 --- a/nvbench/benchmark_base.cxx +++ b/nvbench/benchmark_base.cxx @@ -20,6 +20,9 @@ #include #include +#include +#include + namespace nvbench { @@ -86,7 +89,8 @@ std::size_t benchmark_base::get_config_count() const return axis_ptr->get_size(); }); - return per_device_count * m_devices.size(); + // Devices will be empty for cpu-only benchmarks. + return per_device_count * std::max(std::size_t(1), m_devices.size()); } benchmark_base &benchmark_base::set_stopping_criterion(std::string criterion) diff --git a/testing/benchmark.cu b/testing/benchmark.cu index dfaf468..f2ad2ea 100644 --- a/testing/benchmark.cu +++ b/testing/benchmark.cu @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include +#include #include #include #include @@ -279,6 +281,7 @@ void test_clone() void test_get_config_count() { lots_of_types_bench bench; + bench.set_devices(nvbench::device_manager::get().get_devices()); bench.set_type_axes_names({"Integer", "Float", "Other"}); bench.get_axes().get_type_axis(0).set_active_inputs({"I16", "I32"}); // 2, 2 bench.get_axes().get_type_axis(1).set_active_inputs({"F32", "F64"}); // 2, 4 @@ -288,9 +291,13 @@ void test_get_config_count() bench.add_string_axis("baz", {"str", "ing"}); // 2, 72 bench.add_string_axis("baz", {"single"}); // 1, 72 - auto const num_devices = bench.get_devices().size(); + auto const num_devices = std::max(std::size_t(1), bench.get_devices().size()); ASSERT_MSG(bench.get_config_count() == 72 * num_devices, "Got {}", bench.get_config_count()); + + // Check that zero devices (e.g. CPU-only) is the same as a single device: + bench.set_devices(std::vector{}); + ASSERT_MSG(bench.get_config_count() == 72, "Got {}", bench.get_config_count()); } int main()