Add float64_axis.

This commit is contained in:
Allison Vacanti
2020-12-22 16:38:05 -05:00
parent 65eadda1c1
commit 1e5fe88c9b
5 changed files with 99 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
set(srcs
axis_base.cu
float64_axis.cu
type_axis.cu
int64_axis.cu
)

17
nvbench/float64_axis.cu Normal file
View File

@@ -0,0 +1,17 @@
#include <nvbench/float64_axis.cuh>
#include <fmt/format.h>
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

38
nvbench/float64_axis.cuh Normal file
View File

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

View File

@@ -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 "$<TARGET_FILE:${test_target}>")
add_test(NAME ${test_name} COMMAND "$<TARGET_FILE:${test_name}>")
endforeach()

View File

@@ -1,4 +1,40 @@
//
// Created by allie on 12/22/2020.
//
#include <nvbench/float64_axis.cuh>
#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();
}