Fixes for multidevice/gcc.

- Allow devices to be cleared during benchmark definition.
- Fix various demangling bugs.
This commit is contained in:
Allison Vacanti
2021-02-15 21:26:21 -05:00
parent 8897490a6d
commit bb871094c3
7 changed files with 41 additions and 16 deletions

View File

@@ -30,7 +30,7 @@ std::unique_ptr<benchmark_base> benchmark_base::clone() const
return std::move(result);
}
void benchmark_base::set_devices(std::vector<int> device_ids)
benchmark_base &benchmark_base::set_devices(std::vector<int> device_ids)
{
std::vector<device_info> devices;
devices.reserve(device_ids.size());
@@ -38,12 +38,12 @@ void benchmark_base::set_devices(std::vector<int> device_ids)
{
devices.emplace_back(dev_id);
}
this->set_devices(std::move(devices));
return this->set_devices(std::move(devices));
}
void benchmark_base::add_device(int device_id)
benchmark_base &benchmark_base::add_device(int device_id)
{
this->add_device(device_info{device_id});
return this->add_device(device_info{device_id});
}
} // namespace nvbench

View File

@@ -81,18 +81,26 @@ struct benchmark_base
return *this;
}
void set_devices(std::vector<int> device_ids);
benchmark_base &set_devices(std::vector<int> device_ids);
void set_devices(std::vector<nvbench::device_info> devices)
benchmark_base &set_devices(std::vector<nvbench::device_info> devices)
{
m_devices = std::move(devices);
return *this;
}
void add_device(int device_id);
benchmark_base &clear_devices()
{
m_devices.clear();
return *this;
}
void add_device(nvbench::device_info device)
benchmark_base &add_device(int device_id);
benchmark_base &add_device(nvbench::device_info device)
{
m_devices.push_back(std::move(device));
return *this;
}
[[nodiscard]] const std::vector<nvbench::device_info> &get_devices() const

View File

@@ -1,5 +1,7 @@
#pragma once
#include <nvbench/benchmark_base.cuh>
#include <nvbench/detail/state_generator.cuh>
#include <stdexcept>

View File

@@ -1,7 +1,5 @@
#include <nvbench/type_strings.cuh>
#include <cstdlib>
#include <memory>
#include <string>
#if defined(__GNUC__) || defined(__clang__)
@@ -10,16 +8,28 @@
#ifdef NVBENCH_CXXABI_DEMANGLE
#include <cxxabi.h>
#endif
#include <cstdlib>
#include <memory>
namespace
{
struct free_wrapper
{
void operator()(void* ptr) { std::free(ptr); }
};
} // end namespace
#endif // NVBENCH_CXXABI_DEMANGLE
namespace nvbench::detail
{
std::string nvbench::detail::demangle(const std::string &str)
std::string demangle(const std::string &str)
{
#ifdef NVBENCH_CXXABI_DEMANGLE
std::unique_ptr<char, std::free> demangled =
abi::__cxx_demangle(str.c_str(), nullptr, nullptr, nullptr);
std::unique_ptr<char, free_wrapper> demangled{
abi::__cxa_demangle(str.c_str(), nullptr, nullptr, nullptr)};
return std::string(demangled.get());
#else
return str;

View File

@@ -222,6 +222,7 @@ void test_run()
// More exhaustive testing is in runner.cu. This just tests that the
// runner is called.
no_types_bench bench;
bench.set_devices(std::vector<int>{});
ASSERT(bench.get_states().empty());
bench.run();
ASSERT(bench.get_states().size() == 1);
@@ -230,6 +231,7 @@ void test_run()
void test_clone()
{
lots_of_types_bench bench;
bench.set_devices(std::vector<int>{});
bench.set_type_axes_names({"Integer", "Float", "Other"});
bench.add_string_axis("Strings", {"string a", "string b", "string c"});
bench.add_int64_power_of_two_axis("I64 POT Axis", {10, 20});

View File

@@ -10,7 +10,7 @@
//==============================================================================
// Declare a couple benchmarks for testing:
void DummyBench(nvbench::state &state) { state.skip("Skipping for testing."); }
NVBENCH_CREATE(DummyBench);
NVBENCH_CREATE(DummyBench).clear_devices();
using Ts = nvbench::type_list<void, nvbench::int8_t, nvbench::uint8_t>;
using Us = nvbench::type_list<bool, nvbench::float32_t, nvbench::float64_t>;
@@ -25,7 +25,8 @@ NVBENCH_CREATE_TEMPLATE(TestBench, NVBENCH_TYPE_AXES(Ts, Us))
.add_int64_axis("Ints", {42})
.add_int64_power_of_two_axis("PO2s", {3})
.add_float64_axis("Floats", {3.14})
.add_string_axis("Strings", {"S1"});
.add_string_axis("Strings", {"S1"})
.clear_devices();
//==============================================================================
namespace

View File

@@ -69,6 +69,7 @@ void test_empty()
using runner_type = nvbench::runner<benchmark_type>;
benchmark_type bench;
bench.set_devices(std::vector<int>{});
runner_type runner{bench};
runner.generate_states();
@@ -85,6 +86,7 @@ void test_non_types()
using runner_type = nvbench::runner<benchmark_type>;
benchmark_type bench;
bench.set_devices(std::vector<int>{});
bench.add_int64_axis("Int", {1, 2, 3});
bench.add_float64_axis("Float", {11.0, 12.0, 13.0});
bench.add_string_axis("String", {"One", "Two", "Three"});