From 1e5fe88c9bb255ebf4ddbcc8630f0e0b10afc2f4 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Tue, 22 Dec 2020 16:38:05 -0500 Subject: [PATCH] Add float64_axis. --- nvbench/CMakeLists.txt | 1 + nvbench/float64_axis.cu | 17 ++++++++++++++++ nvbench/float64_axis.cuh | 38 ++++++++++++++++++++++++++++++++++++ testing/CMakeLists.txt | 5 ++++- testing/float64_axis.cu | 42 +++++++++++++++++++++++++++++++++++++--- 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 nvbench/float64_axis.cu create mode 100644 nvbench/float64_axis.cuh diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt index 85e440b..0ca3a35 100644 --- a/nvbench/CMakeLists.txt +++ b/nvbench/CMakeLists.txt @@ -1,5 +1,6 @@ set(srcs axis_base.cu + float64_axis.cu type_axis.cu int64_axis.cu ) diff --git a/nvbench/float64_axis.cu b/nvbench/float64_axis.cu new file mode 100644 index 0000000..a83af98 --- /dev/null +++ b/nvbench/float64_axis.cu @@ -0,0 +1,17 @@ +#include + +#include + +namespace nvbench +{ + +float64_axis::~float64_axis() = default; + +std::string float64_axis::do_get_input_string(std::size_t i) const +{ + return fmt::to_string(m_values[i]); +} + +std::string float64_axis::do_get_description(std::size_t i) const { return {}; } + +} // namespace nvbench diff --git a/nvbench/float64_axis.cuh b/nvbench/float64_axis.cuh new file mode 100644 index 0000000..76dccbd --- /dev/null +++ b/nvbench/float64_axis.cuh @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include + +#include + +namespace nvbench +{ + +struct float64_axis final : public axis_base +{ + explicit float64_axis(std::string name) + : axis_base{std::move(name), axis_type::float64} + , m_values{} + {} + + ~float64_axis() final; + + void set_inputs(std::vector inputs) + { + m_values = std::move(inputs); + } + [[nodiscard]] nvbench::float64_t get_value(std::size_t i) const + { + return m_values[i]; + } + +private: + std::size_t do_get_size() const final { return m_values.size(); } + std::string do_get_input_string(std::size_t i) const final; + std::string do_get_description(std::size_t i) const final; + + std::vector m_values; +}; + +} // namespace nvbench diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 2a8f462..5c7eb78 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -1,9 +1,12 @@ set(test_srcs int64_axis.cu + float64_axis.cu type_axis.cu type_list.cu ) +enable_testing() + foreach(test_src IN LISTS test_srcs) get_filename_component(test_name "${test_src}" NAME_WLE) string(PREPEND test_name "nvbench.test.") @@ -11,5 +14,5 @@ foreach(test_src IN LISTS test_srcs) target_include_directories(${test_name} PRIVATE "${CMAKE_CURRENT_LIST_DIR}") target_link_libraries(${test_name} PRIVATE nvbench fmt) set_target_properties(${test_name} PROPERTIES COMPILE_FEATURES cuda_std_17) - add_test(NAME ${test_name} COMMAND "$") + add_test(NAME ${test_name} COMMAND "$") endforeach() diff --git a/testing/float64_axis.cu b/testing/float64_axis.cu index 674afd0..3f58095 100644 --- a/testing/float64_axis.cu +++ b/testing/float64_axis.cu @@ -1,4 +1,40 @@ -// -// Created by allie on 12/22/2020. -// +#include +#include "test_asserts.cuh" + +void test_empty() +{ + nvbench::float64_axis axis("Empty"); + ASSERT(axis.get_name() == "Empty"); + ASSERT(axis.get_type() == nvbench::axis_type::float64); + ASSERT(axis.get_size() == 0); + + axis.set_inputs({}); + + ASSERT(axis.get_size() == 0); +} + +void test_basic() +{ + nvbench::float64_axis axis("Basic"); + ASSERT(axis.get_name() == "Basic"); + + axis.set_inputs({-100.3, 0., 2064.15}); + + ASSERT(axis.get_size() == 3); + ASSERT(axis.get_value(0) == -100.3); + ASSERT(axis.get_input_string(0) == "-100.3"); + ASSERT(axis.get_description(0) == ""); + ASSERT(axis.get_value(1) == 0.); + ASSERT(axis.get_input_string(1) == "0"); + ASSERT(axis.get_description(1) == ""); + ASSERT(axis.get_value(2) == 2064.15); + ASSERT(axis.get_input_string(2) == "2064.15"); + ASSERT(axis.get_description(2) == ""); +} + +int main() +{ + test_empty(); + test_basic(); +}