mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Base method naming convention
This commit is contained in:
@@ -24,14 +24,14 @@
|
||||
// Thrust vectors simplify memory management:
|
||||
#include <thrust/device_vector.h>
|
||||
|
||||
// Inherit from the stopping_criterion class:
|
||||
class fixed_criterion final : public nvbench::stopping_criterion
|
||||
// Inherit from the stopping_criterion_base class:
|
||||
class fixed_criterion final : public nvbench::stopping_criterion_base
|
||||
{
|
||||
nvbench::int64_t m_num_samples{};
|
||||
|
||||
public:
|
||||
fixed_criterion()
|
||||
: nvbench::stopping_criterion{"fixed", {{"max-samples", nvbench::int64_t{42}}}}
|
||||
: nvbench::stopping_criterion_base{"fixed", {{"max-samples", nvbench::int64_t{42}}}}
|
||||
{}
|
||||
|
||||
// Process new measurements in the `add_measurement()` method:
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace nvbench
|
||||
|
||||
class criterion_manager
|
||||
{
|
||||
std::unordered_map<std::string, std::unique_ptr<nvbench::stopping_criterion>> m_map;
|
||||
std::unordered_map<std::string, std::unique_ptr<nvbench::stopping_criterion_base>> m_map;
|
||||
|
||||
criterion_manager();
|
||||
|
||||
@@ -45,9 +45,9 @@ public:
|
||||
/**
|
||||
* Register a new stopping criterion.
|
||||
*/
|
||||
nvbench::stopping_criterion& add(std::unique_ptr<nvbench::stopping_criterion> criterion);
|
||||
nvbench::stopping_criterion& get_criterion(const std::string& name);
|
||||
const nvbench::stopping_criterion& get_criterion(const std::string& name) const;
|
||||
nvbench::stopping_criterion_base& add(std::unique_ptr<nvbench::stopping_criterion_base> criterion);
|
||||
nvbench::stopping_criterion_base& get_criterion(const std::string& name);
|
||||
const nvbench::stopping_criterion_base& get_criterion(const std::string& name) const;
|
||||
|
||||
using params_description = std::vector<std::pair<std::string, nvbench::named_values::type>>;
|
||||
params_description get_params_description() const;
|
||||
@@ -58,8 +58,8 @@ public:
|
||||
*
|
||||
* See the `custom_criterion.cu` example for usage.
|
||||
*/
|
||||
#define NVBENCH_REGISTER_CRITERION(TYPE) \
|
||||
static nvbench::stopping_criterion& NVBENCH_UNIQUE_IDENTIFIER(TYPE) = \
|
||||
nvbench::criterion_manager::get().add(std::make_unique<TYPE>()) \
|
||||
#define NVBENCH_REGISTER_CRITERION(TYPE) \
|
||||
static nvbench::stopping_criterion_base &NVBENCH_UNIQUE_IDENTIFIER(TYPE) = \
|
||||
nvbench::criterion_manager::get().add(std::make_unique<TYPE>())
|
||||
|
||||
} // namespace nvbench
|
||||
|
||||
@@ -34,7 +34,7 @@ criterion_manager &criterion_manager::get()
|
||||
return registry;
|
||||
}
|
||||
|
||||
stopping_criterion& criterion_manager::get_criterion(const std::string& name)
|
||||
stopping_criterion_base& criterion_manager::get_criterion(const std::string& name)
|
||||
{
|
||||
auto iter = m_map.find(name);
|
||||
if (iter == m_map.end())
|
||||
@@ -44,7 +44,7 @@ stopping_criterion& criterion_manager::get_criterion(const std::string& name)
|
||||
return *iter->second.get();
|
||||
}
|
||||
|
||||
const nvbench::stopping_criterion& criterion_manager::get_criterion(const std::string& name) const
|
||||
const nvbench::stopping_criterion_base& criterion_manager::get_criterion(const std::string& name) const
|
||||
{
|
||||
auto iter = m_map.find(name);
|
||||
if (iter == m_map.end())
|
||||
@@ -54,7 +54,7 @@ const nvbench::stopping_criterion& criterion_manager::get_criterion(const std::s
|
||||
return *iter->second.get();
|
||||
}
|
||||
|
||||
stopping_criterion &criterion_manager::add(std::unique_ptr<stopping_criterion> criterion)
|
||||
stopping_criterion_base &criterion_manager::add(std::unique_ptr<stopping_criterion_base> criterion)
|
||||
{
|
||||
const std::string name = criterion->get_name();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
namespace nvbench::detail
|
||||
{
|
||||
|
||||
class entropy_criterion final : public stopping_criterion
|
||||
class entropy_criterion final : public stopping_criterion_base
|
||||
{
|
||||
// state
|
||||
nvbench::int64_t m_total_samples{};
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace nvbench::detail
|
||||
{
|
||||
|
||||
entropy_criterion::entropy_criterion()
|
||||
: stopping_criterion{"entropy",
|
||||
{{"max-angle", 0.048}, {"min-r2", 0.36}}}
|
||||
: stopping_criterion_base{"entropy", {{"max-angle", 0.048}, {"min-r2", 0.36}}}
|
||||
{
|
||||
m_freq_tracker.reserve(m_entropy_tracker.capacity() * 2);
|
||||
m_probabilities.reserve(m_entropy_tracker.capacity() * 2);
|
||||
|
||||
@@ -87,7 +87,7 @@ protected:
|
||||
nvbench::blocking_kernel m_blocker;
|
||||
|
||||
nvbench::criterion_params m_criterion_params;
|
||||
nvbench::stopping_criterion& m_stopping_criterion;
|
||||
nvbench::stopping_criterion_base& m_stopping_criterion;
|
||||
|
||||
bool m_run_once{false};
|
||||
bool m_no_block{false};
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
namespace nvbench::detail
|
||||
{
|
||||
|
||||
class stdrel_criterion final : public stopping_criterion
|
||||
class stdrel_criterion final : public stopping_criterion_base
|
||||
{
|
||||
// state
|
||||
nvbench::int64_t m_total_samples{};
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace nvbench::detail
|
||||
{
|
||||
|
||||
stdrel_criterion::stdrel_criterion()
|
||||
: stopping_criterion{"stdrel",
|
||||
{{"max-noise", nvbench::detail::compat_max_noise()},
|
||||
{"min-time", nvbench::detail::compat_min_time()}}}
|
||||
: stopping_criterion_base{"stdrel",
|
||||
{{"max-noise", nvbench::detail::compat_max_noise()},
|
||||
{"min-time", nvbench::detail::compat_min_time()}}}
|
||||
{}
|
||||
|
||||
void stdrel_criterion::do_initialize()
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
/**
|
||||
* Stopping criterion interface
|
||||
*/
|
||||
class stopping_criterion
|
||||
class stopping_criterion_base
|
||||
{
|
||||
protected:
|
||||
std::string m_name;
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
* @param name Unique name of the criterion
|
||||
* @param params Default values for all parameters of the criterion
|
||||
*/
|
||||
explicit stopping_criterion(std::string name, criterion_params params)
|
||||
explicit stopping_criterion_base(std::string name, criterion_params params)
|
||||
: m_name{std::move(name)}
|
||||
, m_params{params}
|
||||
{}
|
||||
|
||||
@@ -27,11 +27,11 @@ void test_standard_criteria_exist()
|
||||
ASSERT(nvbench::criterion_manager::get().get_criterion("entropy").get_name() == "entropy");
|
||||
}
|
||||
|
||||
class custom_criterion : public nvbench::stopping_criterion
|
||||
class custom_criterion : public nvbench::stopping_criterion_base
|
||||
{
|
||||
public:
|
||||
custom_criterion()
|
||||
: nvbench::stopping_criterion("custom", nvbench::criterion_params{})
|
||||
: nvbench::stopping_criterion_base("custom", nvbench::criterion_params{})
|
||||
{}
|
||||
|
||||
virtual void add_measurement(nvbench::float64_t /* measurement */) override {}
|
||||
@@ -47,7 +47,7 @@ void test_no_duplicates_are_allowed()
|
||||
bool exception_triggered = false;
|
||||
|
||||
try {
|
||||
nvbench::stopping_criterion& custom = manager.get_criterion("custom");
|
||||
nvbench::stopping_criterion_base& custom = manager.get_criterion("custom");
|
||||
} catch(...) {
|
||||
exception_triggered = true;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ void test_no_duplicates_are_allowed()
|
||||
custom_criterion* custom_raw = custom_ptr.get();
|
||||
ASSERT(&manager.add(std::move(custom_ptr)) == custom_raw);
|
||||
|
||||
nvbench::stopping_criterion& custom = nvbench::criterion_manager::get().get_criterion("custom");
|
||||
nvbench::stopping_criterion_base& custom = nvbench::criterion_manager::get().get_criterion("custom");
|
||||
ASSERT(custom_raw == &custom);
|
||||
|
||||
exception_triggered = false;
|
||||
|
||||
Reference in New Issue
Block a user