diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt index 0ca3a35..53535a1 100644 --- a/nvbench/CMakeLists.txt +++ b/nvbench/CMakeLists.txt @@ -1,8 +1,9 @@ set(srcs axis_base.cu float64_axis.cu - type_axis.cu int64_axis.cu + type_axis.cu + string_axis.cu ) # TODO shared may be a good idea to reduce compilation overhead for large diff --git a/nvbench/string_axis.cu b/nvbench/string_axis.cu new file mode 100644 index 0000000..c37116f --- /dev/null +++ b/nvbench/string_axis.cu @@ -0,0 +1,10 @@ +#include + +#include + +namespace nvbench +{ + +string_axis::~string_axis() = default; + +} // namespace nvbench diff --git a/nvbench/string_axis.cuh b/nvbench/string_axis.cuh new file mode 100644 index 0000000..895c509 --- /dev/null +++ b/nvbench/string_axis.cuh @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include + +#include + +namespace nvbench +{ + +struct string_axis final : public axis_base +{ + explicit string_axis(std::string name) + : axis_base{std::move(name), axis_type::string} + , m_values{} + {} + + ~string_axis() final; + + void set_inputs(std::vector inputs) + { + m_values = std::move(inputs); + } + [[nodiscard]] const std::string &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 + { + return m_values[i]; + } + std::string do_get_description(std::size_t i) const final { return {}; } + + std::vector m_values; +}; + +} // namespace nvbench diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 5c7eb78..fb1d3c2 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -3,6 +3,7 @@ set(test_srcs float64_axis.cu type_axis.cu type_list.cu + string_axis.cu ) enable_testing() diff --git a/testing/string_axis.cu b/testing/string_axis.cu new file mode 100644 index 0000000..61eb212 --- /dev/null +++ b/testing/string_axis.cu @@ -0,0 +1,40 @@ +#include + +#include "test_asserts.cuh" + +void test_empty() +{ + nvbench::string_axis axis("Empty"); + ASSERT(axis.get_name() == "Empty"); + ASSERT(axis.get_type() == nvbench::axis_type::string); + ASSERT(axis.get_size() == 0); + + axis.set_inputs({}); + + ASSERT(axis.get_size() == 0); +} + +void test_basic() +{ + nvbench::string_axis axis("Basic"); + ASSERT(axis.get_name() == "Basic"); + + axis.set_inputs({"String 1", "String 2", "String 3"}); + + ASSERT(axis.get_size() == 3); + ASSERT(axis.get_value(0) == "String 1"); + ASSERT(axis.get_input_string(0) == "String 1"); + ASSERT(axis.get_description(0) == ""); + ASSERT(axis.get_value(1) == "String 2"); + ASSERT(axis.get_input_string(1) == "String 2"); + ASSERT(axis.get_description(1) == ""); + ASSERT(axis.get_value(2) == "String 3"); + ASSERT(axis.get_input_string(2) == "String 3"); + ASSERT(axis.get_description(2) == ""); +} + +int main() +{ + test_empty(); + test_basic(); +}