Add nvbench::string_axis.

This commit is contained in:
Allison Vacanti
2020-12-22 16:57:42 -05:00
parent 1e5fe88c9b
commit 76f9c9b0d6
5 changed files with 94 additions and 1 deletions

View File

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

10
nvbench/string_axis.cu Normal file
View File

@@ -0,0 +1,10 @@
#include <nvbench/string_axis.cuh>
#include <fmt/format.h>
namespace nvbench
{
string_axis::~string_axis() = default;
} // namespace nvbench

41
nvbench/string_axis.cuh Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
#include <nvbench/axis_base.cuh>
#include <nvbench/types.cuh>
#include <vector>
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<std::string> 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<std::string> m_values;
};
} // namespace nvbench

View File

@@ -3,6 +3,7 @@ set(test_srcs
float64_axis.cu
type_axis.cu
type_list.cu
string_axis.cu
)
enable_testing()

40
testing/string_axis.cu Normal file
View File

@@ -0,0 +1,40 @@
#include <nvbench/string_axis.cuh>
#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();
}