mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Add type_axis.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
set(srcs
|
||||
axis_base.cu
|
||||
type_axis.cu
|
||||
int64_axis.cu
|
||||
)
|
||||
|
||||
|
||||
8
nvbench/type_axis.cu
Normal file
8
nvbench/type_axis.cu
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <nvbench/type_axis.cuh>
|
||||
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
type_axis::~type_axis() = default;
|
||||
|
||||
}
|
||||
57
nvbench/type_axis.cuh
Normal file
57
nvbench/type_axis.cuh
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <nvbench/axis_base.cuh>
|
||||
|
||||
#include <nvbench/type_list.cuh>
|
||||
#include <nvbench/type_strings.cuh>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
struct type_axis final : public axis_base
|
||||
{
|
||||
explicit type_axis(std::string name)
|
||||
: axis_base{std::move(name), axis_type::type}
|
||||
, m_input_strings{}
|
||||
, m_descriptions{}
|
||||
{}
|
||||
|
||||
~type_axis() final;
|
||||
|
||||
template <typename TypeList>
|
||||
void set_inputs();
|
||||
|
||||
private:
|
||||
std::size_t do_get_size() const final { return m_input_strings.size(); }
|
||||
std::string do_get_input_string(std::size_t i) const final
|
||||
{
|
||||
return m_input_strings[i];
|
||||
}
|
||||
std::string do_get_description(std::size_t i) const final
|
||||
{
|
||||
return m_descriptions[i];
|
||||
}
|
||||
|
||||
std::vector<std::string> m_input_strings;
|
||||
std::vector<std::string> m_descriptions;
|
||||
};
|
||||
|
||||
template <typename TypeList>
|
||||
void type_axis::set_inputs()
|
||||
{
|
||||
// Need locals for lambda capture...
|
||||
auto &input_strings = m_input_strings;
|
||||
auto &descriptions = m_descriptions;
|
||||
nvbench::tl::foreach<TypeList>(
|
||||
[&input_strings, &descriptions]([[maybe_unused]] auto wrapped_type) {
|
||||
using T = typename decltype(wrapped_type)::type;
|
||||
using Strings = nvbench::type_strings<T>;
|
||||
input_strings.push_back(Strings::input_string());
|
||||
descriptions.push_back(Strings::description());
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace nvbench
|
||||
@@ -1,5 +1,6 @@
|
||||
set(test_srcs
|
||||
int64_axis.cu
|
||||
type_axis.cu
|
||||
type_list.cu
|
||||
)
|
||||
|
||||
|
||||
55
testing/type_axis.cu
Normal file
55
testing/type_axis.cu
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <nvbench/type_axis.cuh>
|
||||
|
||||
#include <nvbench/types.cuh>
|
||||
|
||||
#include "test_asserts.cuh"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
nvbench::type_axis axis("Basic");
|
||||
ASSERT(axis.get_name() == "Basic");
|
||||
ASSERT(axis.get_type() == nvbench::axis_type::type);
|
||||
ASSERT(axis.get_size() == 0);
|
||||
|
||||
axis.set_inputs<nvbench::type_list<>>();
|
||||
|
||||
ASSERT(axis.get_size() == 0);
|
||||
}
|
||||
|
||||
void test_single()
|
||||
{
|
||||
nvbench::type_axis axis("Single");
|
||||
ASSERT(axis.get_name() == "Single");
|
||||
|
||||
axis.set_inputs<nvbench::type_list<nvbench::int32_t>>();
|
||||
|
||||
ASSERT(axis.get_size() == 1);
|
||||
ASSERT(axis.get_input_string(0) == "I32");
|
||||
ASSERT(axis.get_description(0) == "int32_t");
|
||||
}
|
||||
|
||||
void test_several()
|
||||
{
|
||||
nvbench::type_axis axis("Several");
|
||||
ASSERT(axis.get_name() == "Several");
|
||||
|
||||
axis.set_inputs<
|
||||
nvbench::type_list<nvbench::int32_t, nvbench::float64_t, bool>>();
|
||||
|
||||
ASSERT(axis.get_size() == 3);
|
||||
ASSERT(axis.get_input_string(0) == "I32");
|
||||
ASSERT(axis.get_description(0) == "int32_t");
|
||||
ASSERT(axis.get_input_string(1) == "F64");
|
||||
ASSERT(axis.get_description(1) == "double");
|
||||
ASSERT(axis.get_input_string(2) == "bool");
|
||||
ASSERT(axis.get_description(2) == "");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_empty();
|
||||
test_single();
|
||||
test_several();
|
||||
}
|
||||
Reference in New Issue
Block a user