mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Formatting updates.
This commit is contained in:
@@ -17,22 +17,19 @@
|
||||
*/
|
||||
|
||||
#include <nvbench/axes_metadata.cuh>
|
||||
|
||||
#include <nvbench/type_list.cuh>
|
||||
#include <nvbench/type_strings.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
using int_list = nvbench::type_list<nvbench::int8_t,
|
||||
nvbench::int16_t,
|
||||
nvbench::int32_t,
|
||||
nvbench::int64_t>;
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
using int_list =
|
||||
nvbench::type_list<nvbench::int8_t, nvbench::int16_t, nvbench::int32_t, nvbench::int64_t>;
|
||||
|
||||
using float_list = nvbench::type_list<nvbench::float32_t, nvbench::float64_t>;
|
||||
|
||||
@@ -110,7 +107,6 @@ void test_default_type_axes_names()
|
||||
ASSERT(axes.get_type_axis(4).get_name() == "T4");
|
||||
ASSERT(axes.get_type_axis(4).get_axis_index() == 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_type_axes()
|
||||
@@ -138,8 +134,7 @@ void test_type_axes()
|
||||
fmt::format_to(std::back_inserter(buffer),
|
||||
" - {}{}\n",
|
||||
input_string,
|
||||
description.empty() ? ""
|
||||
: fmt::format(" ({})", description));
|
||||
description.empty() ? "" : fmt::format(" ({})", description));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,9 +152,8 @@ Axis: Other
|
||||
)expected";
|
||||
|
||||
const std::string test = fmt::to_string(buffer);
|
||||
const auto diff =
|
||||
std::mismatch(ref.cbegin(), ref.cend(), test.cbegin(), test.cend());
|
||||
const auto idx = static_cast<std::size_t>(diff.second - test.cbegin());
|
||||
const auto diff = std::mismatch(ref.cbegin(), ref.cend(), test.cbegin(), test.cend());
|
||||
const auto idx = static_cast<std::size_t>(diff.second - test.cbegin());
|
||||
ASSERT_MSG(test == ref,
|
||||
"Differs at character {}.\n"
|
||||
"Expected:\n\"{}\"\n\n"
|
||||
@@ -189,9 +183,7 @@ void test_float64_axes()
|
||||
void test_int64_axes()
|
||||
{
|
||||
nvbench::axes_metadata axes;
|
||||
axes.add_int64_axis("I64 Axis",
|
||||
{10, 11, 12, 13, 14},
|
||||
nvbench::int64_axis_flags::none);
|
||||
axes.add_int64_axis("I64 Axis", {10, 11, 12, 13, 14}, nvbench::int64_axis_flags::none);
|
||||
ASSERT(axes.get_axes().size() == 1);
|
||||
const auto &axis = axes.get_int64_axis("I64 Axis");
|
||||
ASSERT(axis.get_size() == 5);
|
||||
@@ -205,9 +197,7 @@ void test_int64_axes()
|
||||
void test_int64_power_of_two_axes()
|
||||
{
|
||||
nvbench::axes_metadata axes;
|
||||
axes.add_int64_axis("I64 POT Axis",
|
||||
{1, 2, 3, 4, 5},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
axes.add_int64_axis("I64 POT Axis", {1, 2, 3, 4, 5}, nvbench::int64_axis_flags::power_of_two);
|
||||
ASSERT(axes.get_axes().size() == 1);
|
||||
const auto &axis = axes.get_int64_axis("I64 POT Axis");
|
||||
ASSERT(axis.get_size() == 5);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
#include <nvbench/benchmark.cuh>
|
||||
|
||||
#include <nvbench/callable.cuh>
|
||||
#include <nvbench/named_values.cuh>
|
||||
#include <nvbench/state.cuh>
|
||||
@@ -25,8 +24,6 @@
|
||||
#include <nvbench/type_strings.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -34,6 +31,8 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> sort(std::vector<T> &&vec)
|
||||
{
|
||||
@@ -61,34 +60,26 @@ void no_op_generator(nvbench::state &state)
|
||||
NVBENCH_DEFINE_CALLABLE(no_op_generator, no_op_callable);
|
||||
|
||||
template <typename Integer, typename Float, typename Other>
|
||||
void template_no_op_generator(nvbench::state &state,
|
||||
nvbench::type_list<Integer, Float, Other>)
|
||||
void template_no_op_generator(nvbench::state &state, nvbench::type_list<Integer, Float, Other>)
|
||||
{
|
||||
ASSERT(nvbench::type_strings<Integer>::input_string() ==
|
||||
state.get_string("Integer"));
|
||||
ASSERT(nvbench::type_strings<Float>::input_string() ==
|
||||
state.get_string("Float"));
|
||||
ASSERT(nvbench::type_strings<Other>::input_string() ==
|
||||
state.get_string("Other"));
|
||||
ASSERT(nvbench::type_strings<Integer>::input_string() == state.get_string("Integer"));
|
||||
ASSERT(nvbench::type_strings<Float>::input_string() == state.get_string("Float"));
|
||||
ASSERT(nvbench::type_strings<Other>::input_string() == state.get_string("Other"));
|
||||
|
||||
// Enum params using non-templated version:
|
||||
no_op_generator(state);
|
||||
}
|
||||
NVBENCH_DEFINE_CALLABLE_TEMPLATE(template_no_op_generator,
|
||||
template_no_op_callable);
|
||||
NVBENCH_DEFINE_CALLABLE_TEMPLATE(template_no_op_generator, template_no_op_callable);
|
||||
|
||||
using int_list = nvbench::type_list<nvbench::int8_t,
|
||||
nvbench::int16_t,
|
||||
nvbench::int32_t,
|
||||
nvbench::int64_t>;
|
||||
using int_list =
|
||||
nvbench::type_list<nvbench::int8_t, nvbench::int16_t, nvbench::int32_t, nvbench::int64_t>;
|
||||
|
||||
using float_list = nvbench::type_list<nvbench::float32_t, nvbench::float64_t>;
|
||||
|
||||
using misc_list = nvbench::type_list<bool, void>;
|
||||
|
||||
using lots_of_types_bench =
|
||||
nvbench::benchmark<template_no_op_callable,
|
||||
nvbench::type_list<int_list, float_list, misc_list>>;
|
||||
nvbench::benchmark<template_no_op_callable, nvbench::type_list<int_list, float_list, misc_list>>;
|
||||
|
||||
using no_types_bench = nvbench::benchmark<no_op_callable>;
|
||||
|
||||
@@ -110,8 +101,7 @@ void test_type_axes()
|
||||
fmt::format_to(std::back_inserter(buffer),
|
||||
" - {}{}\n",
|
||||
input_string,
|
||||
description.empty() ? ""
|
||||
: fmt::format(" ({})", description));
|
||||
description.empty() ? "" : fmt::format(" ({})", description));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,9 +290,7 @@ void test_get_config_count()
|
||||
|
||||
auto const num_devices = bench.get_devices().size();
|
||||
|
||||
ASSERT_MSG(bench.get_config_count() == 72 * num_devices,
|
||||
"Got {}",
|
||||
bench.get_config_count());
|
||||
ASSERT_MSG(bench.get_config_count() == 72 * num_devices, "Got {}", bench.get_config_count());
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
#include <nvbench/cpu_timer.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
@@ -16,17 +16,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/create.cuh>
|
||||
|
||||
#include <nvbench/benchmark.cuh>
|
||||
#include <nvbench/callable.cuh>
|
||||
#include <nvbench/create.cuh>
|
||||
#include <nvbench/state.cuh>
|
||||
#include <nvbench/type_list.cuh>
|
||||
#include <nvbench/type_strings.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -34,6 +31,8 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> sort(std::vector<T> &&vec)
|
||||
{
|
||||
@@ -72,15 +71,11 @@ using misc_types = nvbench::type_list<bool, void>;
|
||||
using type_axes = nvbench::type_list<float_types, int_types, misc_types>;
|
||||
|
||||
template <typename FloatT, typename IntT, typename MiscT>
|
||||
void template_no_op_generator(nvbench::state &state,
|
||||
nvbench::type_list<FloatT, IntT, MiscT>)
|
||||
void template_no_op_generator(nvbench::state &state, nvbench::type_list<FloatT, IntT, MiscT>)
|
||||
{
|
||||
ASSERT(nvbench::type_strings<FloatT>::input_string() ==
|
||||
state.get_string("FloatT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() ==
|
||||
state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() ==
|
||||
state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<FloatT>::input_string() == state.get_string("FloatT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() == state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() == state.get_string("IntT"));
|
||||
|
||||
// Enum params using non-templated version:
|
||||
no_op_generator(state);
|
||||
@@ -116,8 +111,7 @@ std::string run_and_get_state_string(nvbench::benchmark_base &bench,
|
||||
|
||||
void validate_default_name()
|
||||
{
|
||||
auto bench =
|
||||
nvbench::benchmark_manager::get().get_benchmark("no_op_generator").clone();
|
||||
auto bench = nvbench::benchmark_manager::get().get_benchmark("no_op_generator").clone();
|
||||
|
||||
const std::string ref = "Params:\n";
|
||||
|
||||
@@ -127,8 +121,7 @@ void validate_default_name()
|
||||
|
||||
void validate_custom_name()
|
||||
{
|
||||
auto bench =
|
||||
nvbench::benchmark_manager::get().get_benchmark("Custom Name").clone();
|
||||
auto bench = nvbench::benchmark_manager::get().get_benchmark("Custom Name").clone();
|
||||
|
||||
const std::string ref = "Params:\n";
|
||||
|
||||
@@ -138,8 +131,7 @@ void validate_custom_name()
|
||||
|
||||
void validate_no_types()
|
||||
{
|
||||
auto bench =
|
||||
nvbench::benchmark_manager::get().get_benchmark("No Types").clone();
|
||||
auto bench = nvbench::benchmark_manager::get().get_benchmark("No Types").clone();
|
||||
|
||||
const std::string ref = R"expected(Params: Float: 11 Int: 1 String: One
|
||||
Params: Float: 11 Int: 2 String: One
|
||||
@@ -176,8 +168,7 @@ Params: Float: 13 Int: 3 String: Three
|
||||
|
||||
void validate_only_types()
|
||||
{
|
||||
auto bench =
|
||||
nvbench::benchmark_manager::get().get_benchmark("Oops, All Types!").clone();
|
||||
auto bench = nvbench::benchmark_manager::get().get_benchmark("Oops, All Types!").clone();
|
||||
|
||||
const std::string ref = R"expected(Params: FloatT: F32 IntT: I32 MiscT: bool
|
||||
Params: FloatT: F32 IntT: I32 MiscT: void
|
||||
@@ -195,8 +186,7 @@ Params: FloatT: F64 IntT: I64 MiscT: void
|
||||
|
||||
void validate_all_axes()
|
||||
{
|
||||
auto bench =
|
||||
nvbench::benchmark_manager::get().get_benchmark("All The Axes").clone();
|
||||
auto bench = nvbench::benchmark_manager::get().get_benchmark("All The Axes").clone();
|
||||
|
||||
const std::string ref =
|
||||
R"expected(Params: Float: 11 FloatT: F32 Int: 1 IntT: I32 MiscT: bool String: One
|
||||
|
||||
@@ -42,27 +42,34 @@ protected:
|
||||
|
||||
void test_no_duplicates_are_allowed()
|
||||
{
|
||||
nvbench::criterion_manager& manager = nvbench::criterion_manager::get();
|
||||
bool exception_triggered = false;
|
||||
nvbench::criterion_manager &manager = nvbench::criterion_manager::get();
|
||||
bool exception_triggered = false;
|
||||
|
||||
try {
|
||||
[[maybe_unused]] nvbench::stopping_criterion_base& _ = manager.get_criterion("custom");
|
||||
} catch(...) {
|
||||
try
|
||||
{
|
||||
[[maybe_unused]] nvbench::stopping_criterion_base &_ = manager.get_criterion("custom");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
exception_triggered = true;
|
||||
}
|
||||
ASSERT(exception_triggered);
|
||||
|
||||
std::unique_ptr<custom_criterion> custom_ptr = std::make_unique<custom_criterion>();
|
||||
custom_criterion* custom_raw = custom_ptr.get();
|
||||
custom_criterion *custom_raw = custom_ptr.get();
|
||||
ASSERT(&manager.add(std::move(custom_ptr)) == custom_raw);
|
||||
|
||||
nvbench::stopping_criterion_base& custom = nvbench::criterion_manager::get().get_criterion("custom");
|
||||
nvbench::stopping_criterion_base &custom =
|
||||
nvbench::criterion_manager::get().get_criterion("custom");
|
||||
ASSERT(custom_raw == &custom);
|
||||
|
||||
exception_triggered = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
manager.add(std::make_unique<custom_criterion>());
|
||||
} catch(...) {
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
exception_triggered = true;
|
||||
}
|
||||
ASSERT(exception_triggered);
|
||||
|
||||
@@ -60,4 +60,3 @@ int main()
|
||||
test_compat_overwrite();
|
||||
test_overwrite();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/cuda_timer.cuh>
|
||||
|
||||
#include <nvbench/cuda_stream.cuh>
|
||||
#include <nvbench/cuda_timer.cuh>
|
||||
#include <nvbench/test_kernels.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
void test_basic(cudaStream_t time_stream,
|
||||
cudaStream_t exec_stream,
|
||||
bool expected)
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_basic(cudaStream_t time_stream, cudaStream_t exec_stream, bool expected)
|
||||
{
|
||||
nvbench::cuda_timer timer;
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/cuda_call.cuh>
|
||||
#include <nvbench/nvbench.cuh>
|
||||
#include "nvbench/cuda_call.cuh"
|
||||
|
||||
/******************************************************************************
|
||||
* Install custom parser.
|
||||
@@ -35,7 +35,7 @@
|
||||
// User code to handle a specific argument:
|
||||
void handle_my_custom_arg();
|
||||
|
||||
// NVBench hook for modiifying the command line arguments before parsing:
|
||||
// NVBench hook for modifying the command line arguments before parsing:
|
||||
void custom_arg_handler(std::vector<std::string> &args)
|
||||
{
|
||||
// Handle and remove "--my-custom-arg"
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <nvbench/nvbench.cuh>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
/******************************************************************************
|
||||
* Test having global state that is initialized and finalized via RAII.
|
||||
|
||||
@@ -29,12 +29,10 @@
|
||||
void noisy_bench(nvbench::state &state)
|
||||
{
|
||||
// time, convert ms -> s
|
||||
const auto mean = static_cast<nvbench::float32_t>(state.get_float64("Mean")) /
|
||||
1000.f;
|
||||
const auto mean = static_cast<nvbench::float32_t>(state.get_float64("Mean")) / 1000.f;
|
||||
// rel stdev
|
||||
const auto noise_pct =
|
||||
static_cast<nvbench::float32_t>(state.get_float64("Noise"));
|
||||
const auto noise = noise_pct / 100.f;
|
||||
const auto noise_pct = static_cast<nvbench::float32_t>(state.get_float64("Noise"));
|
||||
const auto noise = noise_pct / 100.f;
|
||||
// abs stdev
|
||||
const auto stdev = noise * mean;
|
||||
|
||||
@@ -53,8 +51,7 @@ void noisy_bench(nvbench::state &state)
|
||||
try
|
||||
{
|
||||
return static_cast<nvbench::float32_t>(
|
||||
state.get_summary("nv/cold/time/gpu/stdev/relative")
|
||||
.get_float64("value"));
|
||||
state.get_summary("nv/cold/time/gpu/stdev/relative").get_float64("value"));
|
||||
}
|
||||
catch (std::invalid_argument &)
|
||||
{
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
#include <nvbench/stopping_criterion.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_const()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ void test_const()
|
||||
nvbench::detail::entropy_criterion criterion;
|
||||
|
||||
criterion.initialize(params);
|
||||
for (int i = 0; i < 6; i++)
|
||||
for (int i = 0; i < 6; i++)
|
||||
{ // nvbench wants at least 5 to compute the standard deviation
|
||||
criterion.add_measurement(42.0);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ void produce_entropy_arch(nvbench::detail::entropy_criterion &criterion)
|
||||
* 2.5, 2.4, 2.2, 2.1, 2.0, 1.9 <-+
|
||||
* 1.8, 1.7, 1.6, 1.6, 1.5, 1.4 |
|
||||
* 1.4, 1.3, 1.3, 1.3, 1.2, 1.2 |
|
||||
* 1.1, 1.1, 1.1, 1.0, 1.0, 1.0 +-- entropy only decreases after 5-th sample,
|
||||
* 1.1, 1.1, 1.1, 1.0, 1.0, 1.0 +-- entropy only decreases after 5-th sample,
|
||||
* 1.0, 0.9, 0.9, 0.9, 0.9, 0.9 | so the slope should be negative
|
||||
* 0.8, 0.8, 0.8, 0.8, 0.8, 0.8 |
|
||||
* 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 <-+
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
#include <nvbench/enum_type_list.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
// If using gcc version < 7, disable some tests to WAR a compiler bug. See NVIDIA/nvbench#39.
|
||||
#if defined(__GNUC__) && __GNUC__ == 7
|
||||
#define USING_GCC_7
|
||||
@@ -102,8 +102,7 @@ NVBENCH_DECLARE_ENUM_TYPE_STRINGS(
|
||||
void test_int()
|
||||
{
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<>, nvbench::type_list<>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<0>,
|
||||
nvbench::type_list<nvbench::enum_type<0>>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<0>, nvbench::type_list<nvbench::enum_type<0>>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<0, 1, 2, 3, 4>,
|
||||
nvbench::type_list<nvbench::enum_type<0>,
|
||||
nvbench::enum_type<1>,
|
||||
@@ -115,42 +114,35 @@ void test_int()
|
||||
void test_scoped_enum()
|
||||
{
|
||||
#ifndef USING_GCC_7
|
||||
ASSERT((
|
||||
std::is_same_v<nvbench::enum_type_list<scoped_enum::val_1>,
|
||||
nvbench::type_list<nvbench::enum_type<scoped_enum::val_1>>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<scoped_enum::val_1>,
|
||||
nvbench::type_list<nvbench::enum_type<scoped_enum::val_1>>>));
|
||||
#endif
|
||||
ASSERT((
|
||||
std::is_same_v<nvbench::enum_type_list<scoped_enum::val_1,
|
||||
scoped_enum::val_2,
|
||||
scoped_enum::val_3>,
|
||||
nvbench::type_list<nvbench::enum_type<scoped_enum::val_1>,
|
||||
nvbench::enum_type<scoped_enum::val_2>,
|
||||
nvbench::enum_type<scoped_enum::val_3>>>));
|
||||
ASSERT((std::is_same_v<
|
||||
nvbench::enum_type_list<scoped_enum::val_1, scoped_enum::val_2, scoped_enum::val_3>,
|
||||
nvbench::type_list<nvbench::enum_type<scoped_enum::val_1>,
|
||||
nvbench::enum_type<scoped_enum::val_2>,
|
||||
nvbench::enum_type<scoped_enum::val_3>>>));
|
||||
}
|
||||
|
||||
void test_unscoped_enum()
|
||||
{
|
||||
#ifndef USING_GCC_7
|
||||
ASSERT(
|
||||
(std::is_same_v<nvbench::enum_type_list<unscoped_val_1>,
|
||||
nvbench::type_list<nvbench::enum_type<unscoped_val_1>>>));
|
||||
ASSERT(
|
||||
(std::is_same_v<
|
||||
nvbench::enum_type_list<unscoped_val_1, unscoped_val_2, unscoped_val_3>,
|
||||
nvbench::type_list<nvbench::enum_type<unscoped_val_1>,
|
||||
nvbench::enum_type<unscoped_val_2>,
|
||||
nvbench::enum_type<unscoped_val_3>>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<unscoped_val_1>,
|
||||
nvbench::type_list<nvbench::enum_type<unscoped_val_1>>>));
|
||||
ASSERT((std::is_same_v<nvbench::enum_type_list<unscoped_val_1, unscoped_val_2, unscoped_val_3>,
|
||||
nvbench::type_list<nvbench::enum_type<unscoped_val_1>,
|
||||
nvbench::enum_type<unscoped_val_2>,
|
||||
nvbench::enum_type<unscoped_val_3>>>));
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_scoped_enum_type_strings()
|
||||
{
|
||||
using values = nvbench::enum_type_list<scoped_enum::val_1,
|
||||
scoped_enum::val_2,
|
||||
scoped_enum::val_3>;
|
||||
using val_1 = nvbench::tl::get<0, values>;
|
||||
using val_2 = nvbench::tl::get<1, values>;
|
||||
using val_3 = nvbench::tl::get<2, values>;
|
||||
using values =
|
||||
nvbench::enum_type_list<scoped_enum::val_1, scoped_enum::val_2, scoped_enum::val_3>;
|
||||
using val_1 = nvbench::tl::get<0, values>;
|
||||
using val_2 = nvbench::tl::get<1, values>;
|
||||
using val_3 = nvbench::tl::get<2, values>;
|
||||
ASSERT((nvbench::type_strings<val_1>::input_string() == "1"));
|
||||
ASSERT((nvbench::type_strings<val_1>::description() == "scoped_enum::val_1"));
|
||||
ASSERT((nvbench::type_strings<val_2>::input_string() == "2"));
|
||||
|
||||
@@ -34,8 +34,7 @@ void test_empty()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::float64_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::float64_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Empty");
|
||||
@@ -62,8 +61,7 @@ void test_basic()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::float64_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::float64_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Basic");
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
#include <nvbench/int64_axis.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
nvbench::int64_axis axis("Empty");
|
||||
@@ -36,8 +36,7 @@ void test_empty()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Empty");
|
||||
@@ -66,8 +65,7 @@ void test_basic()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "BasicAxis");
|
||||
@@ -87,8 +85,7 @@ void test_basic()
|
||||
void test_power_of_two()
|
||||
{
|
||||
nvbench::int64_axis axis{"POTAxis"};
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4}, nvbench::int64_axis_flags::power_of_two);
|
||||
const std::vector<nvbench::int64_t> ref_inputs{0, 1, 2, 3, 7, 6, 5, 4};
|
||||
const std::vector<nvbench::int64_t> ref_values{1, 2, 4, 8, 128, 64, 32, 16};
|
||||
|
||||
@@ -102,14 +99,12 @@ void test_power_of_two()
|
||||
for (size_t i = 0; i < 8; ++i)
|
||||
{
|
||||
ASSERT(axis.get_input_string(i) == fmt::to_string(ref_inputs[i]));
|
||||
ASSERT(axis.get_description(i) ==
|
||||
fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
ASSERT(axis.get_description(i) == fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
}
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::int64_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "POTAxis");
|
||||
@@ -122,8 +117,7 @@ void test_power_of_two()
|
||||
for (size_t i = 0; i < 8; ++i)
|
||||
{
|
||||
ASSERT(clone->get_input_string(i) == fmt::to_string(ref_inputs[i]));
|
||||
ASSERT(clone->get_description(i) ==
|
||||
fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
ASSERT(clone->get_description(i) == fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,8 +244,7 @@ void test_update_none_to_pow2()
|
||||
void test_update_pow2_to_none()
|
||||
{
|
||||
nvbench::int64_axis axis{"TestAxis"};
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4}, nvbench::int64_axis_flags::power_of_two);
|
||||
const std::vector<nvbench::int64_t> ref_inputs{0, 1, 2, 3, 7, 6, 5, 4};
|
||||
const std::vector<nvbench::int64_t> ref_values{1, 2, 4, 8, 128, 64, 32, 16};
|
||||
|
||||
@@ -304,8 +297,7 @@ void test_update_pow2_to_none()
|
||||
for (size_t i = 0; i < 8; ++i)
|
||||
{
|
||||
ASSERT(axis.get_input_string(i) == fmt::to_string(ref_inputs[i]));
|
||||
ASSERT(axis.get_description(i) ==
|
||||
fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
ASSERT(axis.get_description(i) == fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,8 +305,7 @@ void test_update_pow2_to_pow2()
|
||||
{
|
||||
|
||||
nvbench::int64_axis axis{"TestAxis"};
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
axis.set_inputs({0, 1, 2, 3, 7, 6, 5, 4}, nvbench::int64_axis_flags::power_of_two);
|
||||
const std::vector<nvbench::int64_t> ref_inputs{0, 1, 2, 3, 7, 6, 5, 4};
|
||||
const std::vector<nvbench::int64_t> ref_values{1, 2, 4, 8, 128, 64, 32, 16};
|
||||
|
||||
@@ -369,8 +360,7 @@ void test_update_pow2_to_pow2()
|
||||
for (size_t i = 0; i < 8; ++i)
|
||||
{
|
||||
ASSERT(axis.get_input_string(i) == fmt::to_string(ref_inputs[i]));
|
||||
ASSERT(axis.get_description(i) ==
|
||||
fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
ASSERT(axis.get_description(i) == fmt::format("2^{} = {}", ref_inputs[i], ref_values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
#include <nvbench/named_values.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
nvbench::named_values vals;
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/option_parser.cuh>
|
||||
|
||||
#include <nvbench/create.cuh>
|
||||
#include <nvbench/option_parser.cuh>
|
||||
#include <nvbench/type_list.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
//==============================================================================
|
||||
// Declare a couple benchmarks for testing:
|
||||
void DummyBench(nvbench::state &state) { state.skip("Skipping for testing."); }
|
||||
@@ -50,8 +49,7 @@ NVBENCH_BENCH_TYPES(TestBench, NVBENCH_TYPE_AXES(Ts, Us))
|
||||
namespace
|
||||
{
|
||||
|
||||
[[nodiscard]] std::string
|
||||
states_to_string(const std::vector<nvbench::state> &states)
|
||||
[[nodiscard]] std::string states_to_string(const std::vector<nvbench::state> &states)
|
||||
{
|
||||
fmt::memory_buffer buffer;
|
||||
std::string table_format = "| {:^5} | {:^10} | {:^4} | {:^4} | {:^4} "
|
||||
@@ -88,7 +86,7 @@ states_to_string(const std::vector<nvbench::state> &states)
|
||||
|
||||
// Expects the parser to have a single TestBench benchmark. Runs the benchmark
|
||||
// and returns the resulting states.
|
||||
[[nodiscard]] const auto& parser_to_states(nvbench::option_parser &parser)
|
||||
[[nodiscard]] const auto &parser_to_states(nvbench::option_parser &parser)
|
||||
{
|
||||
const auto &benches = parser.get_benchmarks();
|
||||
ASSERT(benches.size() == 1);
|
||||
@@ -267,8 +265,7 @@ void test_int64_axis_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 : 2 : 1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 : 2 : 1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -308,8 +305,7 @@ void test_int64_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 , 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 , 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -323,8 +319,7 @@ void test_int64_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 : 7 : 5 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ ] = [ 2 : 7 : 5 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -369,8 +364,7 @@ void test_int64_axis_pow2_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -384,8 +378,7 @@ void test_int64_axis_pow2_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 7 : 7 : 1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 7 : 7 : 1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -425,8 +418,7 @@ void test_int64_axis_pow2_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 2 , 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 2 , 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -440,8 +432,7 @@ void test_int64_axis_pow2_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 2 : 7 : 5 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ pow2 ] = [ 2 : 7 : 5 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -486,8 +477,7 @@ void test_int64_axis_none_to_pow2_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -501,8 +491,7 @@ void test_int64_axis_none_to_pow2_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 7 : 7 : 1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 7 : 7 : 1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -542,8 +531,7 @@ void test_int64_axis_none_to_pow2_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 2 , 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 2 , 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -557,8 +545,7 @@ void test_int64_axis_none_to_pow2_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 2 : 7 : 5 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Ints [ pow2 ] = [ 2 : 7 : 5 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -617,8 +604,7 @@ void test_int64_axis_pow2_to_none_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 : 2 : 1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 : 2 : 1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -658,8 +644,7 @@ void test_int64_axis_pow2_to_none_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 , 7 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 , 7 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -673,8 +658,7 @@ void test_int64_axis_pow2_to_none_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 : 7 : 5 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " PO2s [ ] = [ 2 : 7 : 5 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -719,8 +703,7 @@ void test_float64_axis_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -734,10 +717,7 @@ void test_float64_axis_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse({"--benchmark",
|
||||
"TestBench",
|
||||
"--axis",
|
||||
" Floats [ ] = [ 3.5 : 3.6 : 1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 : 3.6 : 1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -777,8 +757,7 @@ void test_float64_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 , 4.1 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 , 4.1 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -792,18 +771,14 @@ void test_float64_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse({"--benchmark",
|
||||
"TestBench",
|
||||
"--axis",
|
||||
" Floats [ ] = [ 3.5 : 4.2 : 0.6 ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Floats [ ] = [ 3.5 : 4.2 : 0.6 ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", "Floats=[3.5:4.2:0.6]"});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", "Floats=[3.5:4.2:0.6]"});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -827,8 +802,7 @@ void test_string_axis_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Strings [ ] = fo br "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Strings [ ] = fo br "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -842,8 +816,7 @@ void test_string_axis_single()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Strings [ ] = [ fo br ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Strings [ ] = [ fo br ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -883,8 +856,7 @@ void test_string_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " Strings [ ] = [ fo br , baz ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " Strings [ ] = [ fo br , baz ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -951,8 +923,7 @@ void test_type_axis_multi()
|
||||
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "TestBench", "--axis", " T [ ] = [ U8, void ] "});
|
||||
parser.parse({"--benchmark", "TestBench", "--axis", " T [ ] = [ U8, void ] "});
|
||||
const auto test = parser_to_state_string(parser);
|
||||
ASSERT_MSG(test == ref, "Expected:\n\"{}\"\n\nActual:\n\"{}\"", ref, test);
|
||||
}
|
||||
@@ -1177,9 +1148,8 @@ void test_axis_before_benchmark()
|
||||
void test_min_samples()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench", "--min-samples", "12345"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark", "DummyBench", "--min-samples", "12345"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(states[0].get_min_samples() == 12345);
|
||||
@@ -1188,9 +1158,8 @@ void test_min_samples()
|
||||
void test_min_time()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench", "--min-time", "12345e2"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark", "DummyBench", "--min-time", "12345e2"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(std::abs(states[0].get_min_time() - 12345e2) < 1.);
|
||||
@@ -1199,9 +1168,8 @@ void test_min_time()
|
||||
void test_max_noise()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench", "--max-noise", "50.3"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark", "DummyBench", "--max-noise", "50.3"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(std::abs(states[0].get_max_noise() - 0.503) < 1.e-4);
|
||||
@@ -1210,9 +1178,8 @@ void test_max_noise()
|
||||
void test_skip_time()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench", "--skip-time", "12345e2"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark", "DummyBench", "--skip-time", "12345e2"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(std::abs(states[0].get_skip_time() - 12345e2) < 1.);
|
||||
@@ -1221,9 +1188,8 @@ void test_skip_time()
|
||||
void test_timeout()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench", "--timeout", "12345e2"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark", "DummyBench", "--timeout", "12345e2"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(std::abs(states[0].get_timeout() - 12345e2) < 1.);
|
||||
@@ -1232,12 +1198,15 @@ void test_timeout()
|
||||
void test_stopping_criterion()
|
||||
{
|
||||
nvbench::option_parser parser;
|
||||
parser.parse(
|
||||
{"--benchmark", "DummyBench",
|
||||
"--stopping-criterion", "entropy",
|
||||
"--max-angle", "0.42",
|
||||
"--min-r2", "0.6"});
|
||||
const auto& states = parser_to_states(parser);
|
||||
parser.parse({"--benchmark",
|
||||
"DummyBench",
|
||||
"--stopping-criterion",
|
||||
"entropy",
|
||||
"--max-angle",
|
||||
"0.42",
|
||||
"--min-r2",
|
||||
"0.6"});
|
||||
const auto &states = parser_to_states(parser);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(states[0].get_stopping_criterion() == "entropy");
|
||||
|
||||
@@ -22,12 +22,9 @@
|
||||
|
||||
void test_basic()
|
||||
{
|
||||
ASSERT((nvbench::range(0, 6) ==
|
||||
std::vector<nvbench::int64_t>{0, 1, 2, 3, 4, 5, 6}));
|
||||
ASSERT((nvbench::range(0, 6, 1) ==
|
||||
std::vector<nvbench::int64_t>{0, 1, 2, 3, 4, 5, 6}));
|
||||
ASSERT(
|
||||
(nvbench::range(0, 6, 2) == std::vector<nvbench::int64_t>{0, 2, 4, 6}));
|
||||
ASSERT((nvbench::range(0, 6) == std::vector<nvbench::int64_t>{0, 1, 2, 3, 4, 5, 6}));
|
||||
ASSERT((nvbench::range(0, 6, 1) == std::vector<nvbench::int64_t>{0, 1, 2, 3, 4, 5, 6}));
|
||||
ASSERT((nvbench::range(0, 6, 2) == std::vector<nvbench::int64_t>{0, 2, 4, 6}));
|
||||
ASSERT((nvbench::range(0, 6, 3) == std::vector<nvbench::int64_t>{0, 3, 6}));
|
||||
ASSERT((nvbench::range(0, 6, 4) == std::vector<nvbench::int64_t>{0, 4}));
|
||||
ASSERT((nvbench::range(0, 6, 5) == std::vector<nvbench::int64_t>{0, 5}));
|
||||
@@ -37,26 +34,19 @@ void test_basic()
|
||||
void test_result_type()
|
||||
{
|
||||
// All ints should turn into int64 by default:
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0ll, 1ll)),
|
||||
std::vector<nvbench::int64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0, 1)),
|
||||
std::vector<nvbench::int64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0u, 1u)),
|
||||
std::vector<nvbench::int64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0ll, 1ll)), std::vector<nvbench::int64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0, 1)), std::vector<nvbench::int64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0u, 1u)), std::vector<nvbench::int64_t>>));
|
||||
|
||||
// All floats should turn into float64 by default:
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0., 1.)),
|
||||
std::vector<nvbench::float64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0.f, 1.f)),
|
||||
std::vector<nvbench::float64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0., 1.)), std::vector<nvbench::float64_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range(0.f, 1.f)), std::vector<nvbench::float64_t>>));
|
||||
|
||||
// Other types may be explicitly specified:
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range<nvbench::float32_t,
|
||||
nvbench::float32_t>(0.f, 1.f)),
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range<nvbench::float32_t, nvbench::float32_t>(0.f, 1.f)),
|
||||
std::vector<nvbench::float32_t>>));
|
||||
ASSERT((std::is_same_v<
|
||||
decltype(nvbench::range<nvbench::int32_t, nvbench::int32_t>(0, 1)),
|
||||
std::vector<nvbench::int32_t>>));
|
||||
ASSERT((std::is_same_v<decltype(nvbench::range<nvbench::int32_t, nvbench::int32_t>(0, 1)),
|
||||
std::vector<nvbench::int32_t>>));
|
||||
}
|
||||
|
||||
void test_fp_tolerance()
|
||||
@@ -68,10 +58,8 @@ void test_fp_tolerance()
|
||||
const nvbench::float32_t stride = 1e-4f;
|
||||
for (std::size_t size = 1; size < 1024; ++size)
|
||||
{
|
||||
const nvbench::float32_t end =
|
||||
start + stride * static_cast<nvbench::float32_t>(size - 1);
|
||||
ASSERT_MSG(nvbench::range(start, end, stride).size() == size,
|
||||
"size={}", size);
|
||||
const nvbench::float32_t end = start + stride * static_cast<nvbench::float32_t>(size - 1);
|
||||
ASSERT_MSG(nvbench::range(start, end, stride).size() == size, "size={}", size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
__global__ void multiply5(const int32_t* __restrict__ a, int32_t* __restrict__ b)
|
||||
{
|
||||
const auto id = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
b[id] = 5 * a[id];
|
||||
}
|
||||
__global__ void multiply5(const int32_t *__restrict__ a, int32_t *__restrict__ b)
|
||||
{
|
||||
const auto id = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
b[id] = 5 * a[id];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
multiply5<<<256, 256>>>(nullptr, nullptr);
|
||||
|
||||
try
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
|
||||
#include <nvbench/detail/ring_buffer.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
template <typename T>
|
||||
bool equal(const nvbench::detail::ring_buffer<T> &buffer,
|
||||
const std::vector<T> &reference)
|
||||
bool equal(const nvbench::detail::ring_buffer<T> &buffer, const std::vector<T> &reference)
|
||||
{
|
||||
return std::equal(buffer.begin(), buffer.end(), reference.begin());
|
||||
}
|
||||
|
||||
@@ -16,23 +16,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/runner.cuh>
|
||||
|
||||
#include <nvbench/benchmark.cuh>
|
||||
#include <nvbench/callable.cuh>
|
||||
#include <nvbench/runner.cuh>
|
||||
#include <nvbench/state.cuh>
|
||||
#include <nvbench/type_list.cuh>
|
||||
#include <nvbench/type_strings.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> sort(std::vector<T> &&vec)
|
||||
{
|
||||
@@ -65,21 +64,16 @@ using misc_types = nvbench::type_list<bool, void>;
|
||||
using type_axes = nvbench::type_list<float_types, int_types, misc_types>;
|
||||
|
||||
template <typename FloatT, typename IntT, typename MiscT>
|
||||
void template_no_op_generator(nvbench::state &state,
|
||||
nvbench::type_list<FloatT, IntT, MiscT>)
|
||||
void template_no_op_generator(nvbench::state &state, nvbench::type_list<FloatT, IntT, MiscT>)
|
||||
{
|
||||
ASSERT(nvbench::type_strings<FloatT>::input_string() ==
|
||||
state.get_string("FloatT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() ==
|
||||
state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() ==
|
||||
state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<FloatT>::input_string() == state.get_string("FloatT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() == state.get_string("IntT"));
|
||||
ASSERT(nvbench::type_strings<IntT>::input_string() == state.get_string("IntT"));
|
||||
|
||||
// Enum params using non-templated version:
|
||||
no_op_generator(state);
|
||||
}
|
||||
NVBENCH_DEFINE_CALLABLE_TEMPLATE(template_no_op_generator,
|
||||
template_no_op_callable);
|
||||
NVBENCH_DEFINE_CALLABLE_TEMPLATE(template_no_op_generator, template_no_op_callable);
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/state.cuh>
|
||||
|
||||
#include <nvbench/benchmark.cuh>
|
||||
#include <nvbench/callable.cuh>
|
||||
#include <nvbench/state.cuh>
|
||||
#include <nvbench/summary.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
@@ -43,8 +42,7 @@ struct state_tester : public nvbench::state
|
||||
void set_param(std::string name, T &&value)
|
||||
{
|
||||
this->state::m_axis_values.set_value(std::move(name),
|
||||
nvbench::named_values::value_type{
|
||||
std::forward<T>(value)});
|
||||
nvbench::named_values::value_type{std::forward<T>(value)});
|
||||
}
|
||||
};
|
||||
} // namespace nvbench::detail
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <nvbench/detail/state_generator.cuh>
|
||||
|
||||
#include <nvbench/axes_metadata.cuh>
|
||||
#include <nvbench/axis_base.cuh>
|
||||
#include <nvbench/benchmark.cuh>
|
||||
#include <nvbench/callable.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
#include <nvbench/detail/state_generator.cuh>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
// Mock up a benchmark for testing:
|
||||
void dummy_generator(nvbench::state &) {}
|
||||
NVBENCH_DEFINE_CALLABLE(dummy_generator, dummy_callable);
|
||||
@@ -37,7 +36,7 @@ using ints = nvbench::type_list<nvbench::int32_t, nvbench::int64_t>;
|
||||
using misc = nvbench::type_list<void, bool>;
|
||||
using type_axes = nvbench::type_list<floats, ints, misc>;
|
||||
template <typename F, typename I, typename M>
|
||||
void template_generator(nvbench::state &, nvbench::type_list<F, I, M>){};
|
||||
void template_generator(nvbench::state &, nvbench::type_list<F, I, M>) {};
|
||||
NVBENCH_DEFINE_CALLABLE_TEMPLATE(template_generator, template_callable);
|
||||
using template_bench = nvbench::benchmark<template_callable, type_axes>;
|
||||
|
||||
@@ -151,20 +150,16 @@ void test_create()
|
||||
bench.set_devices(std::vector<int>{});
|
||||
bench.add_float64_axis("Radians", {3.14, 6.28});
|
||||
bench.add_int64_axis("VecSize", {2, 3, 4}, nvbench::int64_axis_flags::none);
|
||||
bench.add_int64_axis("NumInputs",
|
||||
{10, 15, 20},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_int64_axis("NumInputs", {10, 15, 20}, nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_string_axis("Strategy", {"Recursive", "Iterative"});
|
||||
|
||||
const std::vector<nvbench::state> states =
|
||||
nvbench::detail::state_generator::create(bench);
|
||||
const std::vector<nvbench::state> states = nvbench::detail::state_generator::create(bench);
|
||||
|
||||
// 2 (Radians) * 3 (VecSize) * 3 (NumInputs) * 2 (Strategy) = 36
|
||||
ASSERT(states.size() == 36);
|
||||
|
||||
fmt::memory_buffer buffer;
|
||||
const std::string table_format =
|
||||
"| {:^5} | {:^10} | {:^7} | {:^7} | {:^9} | {:^9} |\n";
|
||||
const std::string table_format = "| {:^5} | {:^10} | {:^7} | {:^7} | {:^9} | {:^9} |\n";
|
||||
|
||||
fmt::format_to(std::back_inserter(buffer), "\n");
|
||||
fmt::format_to(std::back_inserter(buffer),
|
||||
@@ -241,13 +236,10 @@ void test_create_with_types()
|
||||
bench.set_type_axes_names({"Floats", "Ints", "Misc"});
|
||||
bench.add_float64_axis("Radians", {3.14, 6.28});
|
||||
bench.add_int64_axis("VecSize", {2, 3, 4}, nvbench::int64_axis_flags::none);
|
||||
bench.add_int64_axis("NumInputs",
|
||||
{10, 15, 20},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_int64_axis("NumInputs", {10, 15, 20}, nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_string_axis("Strategy", {"Recursive", "Iterative"});
|
||||
|
||||
const std::vector<nvbench::state> states =
|
||||
nvbench::detail::state_generator::create(bench);
|
||||
const std::vector<nvbench::state> states = nvbench::detail::state_generator::create(bench);
|
||||
|
||||
// - 2 (Floats) * 2 (Ints) * 2 (Misc) = 8 total type_configs
|
||||
// - 2 (Radians) * 3 (VecSize) * 3 (NumInputs) * 2 (Strategy) = 36 non_type
|
||||
@@ -591,17 +583,14 @@ void test_create_with_masked_types()
|
||||
bench.set_type_axes_names({"Floats", "Ints", "Misc"});
|
||||
bench.add_float64_axis("Radians", {3.14, 6.28});
|
||||
bench.add_int64_axis("VecSize", {2, 3, 4}, nvbench::int64_axis_flags::none);
|
||||
bench.add_int64_axis("NumInputs",
|
||||
{10, 15, 20},
|
||||
nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_int64_axis("NumInputs", {10, 15, 20}, nvbench::int64_axis_flags::power_of_two);
|
||||
bench.add_string_axis("Strategy", {"Recursive", "Iterative"});
|
||||
|
||||
// Mask out some types:
|
||||
bench.get_axes().get_type_axis("Floats").set_active_inputs({"F32"});
|
||||
bench.get_axes().get_type_axis("Ints").set_active_inputs({"I64"});
|
||||
|
||||
const std::vector<nvbench::state> states =
|
||||
nvbench::detail::state_generator::create(bench);
|
||||
const std::vector<nvbench::state> states = nvbench::detail::state_generator::create(bench);
|
||||
|
||||
fmt::memory_buffer buffer;
|
||||
std::string table_format = "| {:^5} | {:^10} | {:^6} | {:^4} | {:^4} | {:^7} "
|
||||
@@ -728,8 +717,7 @@ void test_devices()
|
||||
bench.add_string_axis("S", {"foo", "bar"});
|
||||
bench.add_int64_axis("I", {2, 4});
|
||||
|
||||
const std::vector<nvbench::state> states =
|
||||
nvbench::detail::state_generator::create(bench);
|
||||
const std::vector<nvbench::state> states = nvbench::detail::state_generator::create(bench);
|
||||
|
||||
// 3 devices * 4 axis configs = 12 total states
|
||||
ASSERT(states.size() == 12);
|
||||
@@ -791,8 +779,7 @@ void test_termination_criteria()
|
||||
bench.set_skip_time(skip_time);
|
||||
bench.set_timeout(timeout);
|
||||
|
||||
const std::vector<nvbench::state> states =
|
||||
nvbench::detail::state_generator::create(bench);
|
||||
const std::vector<nvbench::state> states = nvbench::detail::state_generator::create(bench);
|
||||
|
||||
ASSERT(states.size() == 1);
|
||||
ASSERT(min_samples == states[0].get_min_samples());
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
#include <nvbench/detail/statistics.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
namespace statistics = nvbench::detail::statistics;
|
||||
|
||||
void test_mean()
|
||||
{
|
||||
{
|
||||
std::vector<nvbench::float64_t> data{1.0, 2.0, 3.0, 4.0, 5.0};
|
||||
const nvbench::float64_t actual = statistics::compute_mean(std::begin(data), std::end(data));
|
||||
const nvbench::float64_t actual = statistics::compute_mean(std::begin(data), std::end(data));
|
||||
const nvbench::float64_t expected = 3.0;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
@@ -46,7 +46,8 @@ void test_std()
|
||||
{
|
||||
std::vector<nvbench::float64_t> data{1.0, 2.0, 3.0, 4.0, 5.0};
|
||||
const nvbench::float64_t mean = 3.0;
|
||||
const nvbench::float64_t actual = statistics::standard_deviation(std::begin(data), std::end(data), mean);
|
||||
const nvbench::float64_t actual =
|
||||
statistics::standard_deviation(std::begin(data), std::end(data), mean);
|
||||
const nvbench::float64_t expected = 1.581;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
@@ -78,7 +79,8 @@ void test_r2()
|
||||
{
|
||||
std::vector<nvbench::float64_t> ys{1.0, 2.0, 3.0, 4.0, 5.0};
|
||||
auto [slope, intercept] = statistics::compute_linear_regression(std::begin(ys), std::end(ys));
|
||||
const nvbench::float64_t actual = statistics::compute_r2(std::begin(ys), std::end(ys), slope, intercept);
|
||||
const nvbench::float64_t actual =
|
||||
statistics::compute_r2(std::begin(ys), std::end(ys), slope, intercept);
|
||||
const nvbench::float64_t expected = 1.0;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
@@ -95,7 +97,8 @@ void test_r2()
|
||||
|
||||
auto [slope, intercept] = statistics::compute_linear_regression(std::begin(ys), std::end(ys));
|
||||
const nvbench::float64_t expected = 0.675;
|
||||
const nvbench::float64_t actual = statistics::compute_r2(std::begin(ys), std::end(ys), slope, intercept);
|
||||
const nvbench::float64_t actual =
|
||||
statistics::compute_r2(std::begin(ys), std::end(ys), slope, intercept);
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
}
|
||||
@@ -103,17 +106,17 @@ void test_r2()
|
||||
void test_slope_conversion()
|
||||
{
|
||||
{
|
||||
const nvbench::float64_t actual = statistics::slope2deg(0.0);
|
||||
const nvbench::float64_t actual = statistics::slope2deg(0.0);
|
||||
const nvbench::float64_t expected = 0.0;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
{
|
||||
const nvbench::float64_t actual = statistics::slope2deg(1.0);
|
||||
const nvbench::float64_t actual = statistics::slope2deg(1.0);
|
||||
const nvbench::float64_t expected = 45.0;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
{
|
||||
const nvbench::float64_t actual = statistics::slope2deg(5.0);
|
||||
const nvbench::float64_t actual = statistics::slope2deg(5.0);
|
||||
const nvbench::float64_t expected = 78.69;
|
||||
ASSERT(std::abs(actual - expected) < 0.001);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
#include <nvbench/stopping_criterion.cuh>
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_const()
|
||||
{
|
||||
nvbench::criterion_params params;
|
||||
@@ -46,14 +46,14 @@ std::vector<double> generate(double mean, double rel_std_dev, int size)
|
||||
std::mt19937 gen(seed++);
|
||||
std::vector<nvbench::float64_t> v(static_cast<std::size_t>(size));
|
||||
std::normal_distribution<nvbench::float64_t> dist(mean, mean * rel_std_dev);
|
||||
std::generate(v.begin(), v.end(), [&]{ return dist(gen); });
|
||||
std::generate(v.begin(), v.end(), [&] { return dist(gen); });
|
||||
return v;
|
||||
}
|
||||
|
||||
void test_stdrel()
|
||||
{
|
||||
const nvbench::int64_t size = 10;
|
||||
const nvbench::float64_t mean = 42.0;
|
||||
const nvbench::int64_t size = 10;
|
||||
const nvbench::float64_t mean = 42.0;
|
||||
const nvbench::float64_t max_noise = 0.1;
|
||||
|
||||
nvbench::criterion_params params;
|
||||
@@ -62,7 +62,7 @@ void test_stdrel()
|
||||
nvbench::detail::stdrel_criterion criterion;
|
||||
criterion.initialize(params);
|
||||
|
||||
for (nvbench::float64_t measurement: generate(mean, max_noise / 2, size))
|
||||
for (nvbench::float64_t measurement : generate(mean, max_noise / 2, size))
|
||||
{
|
||||
criterion.add_measurement(measurement);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ void test_stdrel()
|
||||
params.set_float64("max-noise", max_noise);
|
||||
criterion.initialize(params);
|
||||
|
||||
for (nvbench::float64_t measurement: generate(mean, max_noise * 2, size))
|
||||
for (nvbench::float64_t measurement : generate(mean, max_noise * 2, size))
|
||||
{
|
||||
criterion.add_measurement(measurement);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ void test_empty()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::string_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::string_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Empty");
|
||||
@@ -61,8 +60,7 @@ void test_basic()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::string_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::string_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Basic");
|
||||
|
||||
@@ -23,55 +23,54 @@
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
|
||||
#define ASSERT(cond) \
|
||||
do \
|
||||
{ \
|
||||
if (cond) \
|
||||
{} \
|
||||
else \
|
||||
{ \
|
||||
fmt::print("{}:{}: Assertion failed ({}).\n", __FILE__, __LINE__, #cond); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
#define ASSERT(cond) \
|
||||
do \
|
||||
{ \
|
||||
if (cond) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
fmt::print("{}:{}: Assertion failed ({}).\n", __FILE__, __LINE__, #cond); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define ASSERT_MSG(cond, fmtstr, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (cond) \
|
||||
{} \
|
||||
else \
|
||||
{ \
|
||||
fmt::print("{}:{}: Test assertion failed ({}) {}\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#cond, \
|
||||
fmt::format(fmtstr, __VA_ARGS__)); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
#define ASSERT_MSG(cond, fmtstr, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (cond) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
fmt::print("{}:{}: Test assertion failed ({}) {}\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#cond, \
|
||||
fmt::format(fmtstr, __VA_ARGS__)); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define ASSERT_THROWS_ANY(expr) \
|
||||
do \
|
||||
{ \
|
||||
bool threw = false; \
|
||||
try \
|
||||
{ \
|
||||
expr; \
|
||||
} \
|
||||
catch (...) \
|
||||
{ \
|
||||
threw = true; \
|
||||
} \
|
||||
if (!threw) \
|
||||
{ \
|
||||
fmt::print("{}:{}: Expression expected exception: '{}'.", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
#define ASSERT_THROWS_ANY(expr) \
|
||||
do \
|
||||
{ \
|
||||
bool threw = false; \
|
||||
try \
|
||||
{ \
|
||||
expr; \
|
||||
} \
|
||||
catch (...) \
|
||||
{ \
|
||||
threw = true; \
|
||||
} \
|
||||
if (!threw) \
|
||||
{ \
|
||||
fmt::print("{}:{}: Expression expected exception: '{}'.", __FILE__, __LINE__, #expr); \
|
||||
std::fflush(stdout); \
|
||||
throw std::runtime_error("Unit test failure."); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
*/
|
||||
|
||||
#include <nvbench/type_axis.cuh>
|
||||
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
nvbench::type_axis axis("Basic", 0);
|
||||
@@ -39,8 +38,7 @@ void test_empty()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::type_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::type_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Basic");
|
||||
@@ -63,8 +61,7 @@ void test_single()
|
||||
|
||||
auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
auto *clone =
|
||||
dynamic_cast<nvbench::type_axis *>(clone_base.get());
|
||||
auto *clone = dynamic_cast<nvbench::type_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Single");
|
||||
@@ -102,8 +99,7 @@ void test_single()
|
||||
void test_several()
|
||||
{
|
||||
nvbench::type_axis axis("Several", 0);
|
||||
axis.set_inputs<
|
||||
nvbench::type_list<nvbench::int32_t, nvbench::float64_t, bool>>();
|
||||
axis.set_inputs<nvbench::type_list<nvbench::int32_t, nvbench::float64_t, bool>>();
|
||||
|
||||
ASSERT(axis.get_name() == "Several");
|
||||
ASSERT(axis.get_size() == 3);
|
||||
@@ -122,8 +118,7 @@ void test_several()
|
||||
|
||||
auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
auto *clone =
|
||||
dynamic_cast<nvbench::type_axis *>(clone_base.get());
|
||||
auto *clone = dynamic_cast<nvbench::type_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_name() == "Several");
|
||||
@@ -177,9 +172,8 @@ void test_several()
|
||||
void test_get_type_index()
|
||||
{
|
||||
nvbench::type_axis axis("GetIndexTest", 0);
|
||||
axis.set_inputs<
|
||||
nvbench::
|
||||
type_list<nvbench::int8_t, nvbench::uint16_t, nvbench::float32_t, bool>>();
|
||||
axis
|
||||
.set_inputs<nvbench::type_list<nvbench::int8_t, nvbench::uint16_t, nvbench::float32_t, bool>>();
|
||||
|
||||
ASSERT(axis.get_type_index("I8") == 0);
|
||||
ASSERT(axis.get_type_index("U16") == 1);
|
||||
@@ -188,8 +182,7 @@ void test_get_type_index()
|
||||
|
||||
const auto clone_base = axis.clone();
|
||||
ASSERT(clone_base.get() != nullptr);
|
||||
const auto *clone =
|
||||
dynamic_cast<const nvbench::type_axis *>(clone_base.get());
|
||||
const auto *clone = dynamic_cast<const nvbench::type_axis *>(clone_base.get());
|
||||
ASSERT(clone != nullptr);
|
||||
|
||||
ASSERT(clone->get_type_index("I8") == 0);
|
||||
|
||||
@@ -17,11 +17,8 @@
|
||||
*/
|
||||
|
||||
#include <nvbench/type_list.cuh>
|
||||
|
||||
#include <nvbench/type_strings.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
@@ -30,6 +27,8 @@
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
// Unique, numbered types for testing type_list functionality.
|
||||
using T0 = std::integral_constant<std::size_t, 0>;
|
||||
using T1 = std::integral_constant<std::size_t, 1>;
|
||||
@@ -80,14 +79,13 @@ struct test_concat
|
||||
|
||||
struct empty_tests
|
||||
{
|
||||
static_assert(
|
||||
std::is_same_v<nvbench::tl::concat<TLEmpty, TLEmpty>, TLEmpty>);
|
||||
static_assert(std::is_same_v<nvbench::tl::concat<TLEmpty, TLEmpty>, TLEmpty>);
|
||||
static_assert(std::is_same_v<nvbench::tl::concat<TLEmpty, TL012>, TL012>);
|
||||
static_assert(std::is_same_v<nvbench::tl::concat<TL012, TLEmpty>, TL012>);
|
||||
};
|
||||
|
||||
static_assert(std::is_same_v<nvbench::tl::concat<TL012, TL765>,
|
||||
nvbench::type_list<T0, T1, T2, T7, T6, T5>>);
|
||||
static_assert(
|
||||
std::is_same_v<nvbench::tl::concat<TL012, TL765>, nvbench::type_list<T0, T1, T2, T7, T6, T5>>);
|
||||
};
|
||||
|
||||
struct test_prepend_each
|
||||
@@ -97,8 +95,7 @@ struct test_prepend_each
|
||||
using T23 = nvbench::type_list<T2, T3>;
|
||||
using TLs = nvbench::type_list<T01, T23>;
|
||||
|
||||
using Expected = nvbench::type_list<nvbench::type_list<T, T0, T1>,
|
||||
nvbench::type_list<T, T2, T3>>;
|
||||
using Expected = nvbench::type_list<nvbench::type_list<T, T0, T1>, nvbench::type_list<T, T2, T3>>;
|
||||
static_assert(std::is_same_v<nvbench::tl::prepend_each<T, TLs>, Expected>);
|
||||
};
|
||||
|
||||
@@ -110,16 +107,12 @@ struct test_empty_cartesian_product
|
||||
|
||||
struct test_single_cartesian_product
|
||||
{
|
||||
using prod_1 =
|
||||
nvbench::tl::cartesian_product<nvbench::type_list<nvbench::type_list<T0>>>;
|
||||
static_assert(
|
||||
std::is_same_v<prod_1, nvbench::type_list<nvbench::type_list<T0>>>);
|
||||
using prod_1 = nvbench::tl::cartesian_product<nvbench::type_list<nvbench::type_list<T0>>>;
|
||||
static_assert(std::is_same_v<prod_1, nvbench::type_list<nvbench::type_list<T0>>>);
|
||||
|
||||
using prod_2 = nvbench::tl::cartesian_product<
|
||||
nvbench::type_list<nvbench::type_list<T0, T1>>>;
|
||||
static_assert(std::is_same_v<prod_2,
|
||||
nvbench::type_list<nvbench::type_list<T0>,
|
||||
nvbench::type_list<T1>>>);
|
||||
using prod_2 = nvbench::tl::cartesian_product<nvbench::type_list<nvbench::type_list<T0, T1>>>;
|
||||
static_assert(
|
||||
std::is_same_v<prod_2, nvbench::type_list<nvbench::type_list<T0>, nvbench::type_list<T1>>>);
|
||||
};
|
||||
|
||||
struct test_cartesian_product
|
||||
|
||||
Reference in New Issue
Block a user