Base method naming convention

This commit is contained in:
Georgy Evtushenko
2024-01-11 10:41:11 -08:00
parent 182c77e4f4
commit dacbee127c
10 changed files with 26 additions and 27 deletions

View File

@@ -24,14 +24,14 @@
// Thrust vectors simplify memory management: // Thrust vectors simplify memory management:
#include <thrust/device_vector.h> #include <thrust/device_vector.h>
// Inherit from the stopping_criterion class: // Inherit from the stopping_criterion_base class:
class fixed_criterion final : public nvbench::stopping_criterion class fixed_criterion final : public nvbench::stopping_criterion_base
{ {
nvbench::int64_t m_num_samples{}; nvbench::int64_t m_num_samples{};
public: public:
fixed_criterion() 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: // Process new measurements in the `add_measurement()` method:

View File

@@ -32,7 +32,7 @@ namespace nvbench
class criterion_manager 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(); criterion_manager();
@@ -45,9 +45,9 @@ public:
/** /**
* Register a new stopping criterion. * Register a new stopping criterion.
*/ */
nvbench::stopping_criterion& add(std::unique_ptr<nvbench::stopping_criterion> criterion); nvbench::stopping_criterion_base& add(std::unique_ptr<nvbench::stopping_criterion_base> criterion);
nvbench::stopping_criterion& get_criterion(const std::string& name); nvbench::stopping_criterion_base& get_criterion(const std::string& name);
const nvbench::stopping_criterion& get_criterion(const std::string& name) const; 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>>; using params_description = std::vector<std::pair<std::string, nvbench::named_values::type>>;
params_description get_params_description() const; params_description get_params_description() const;
@@ -58,8 +58,8 @@ public:
* *
* See the `custom_criterion.cu` example for usage. * See the `custom_criterion.cu` example for usage.
*/ */
#define NVBENCH_REGISTER_CRITERION(TYPE) \ #define NVBENCH_REGISTER_CRITERION(TYPE) \
static nvbench::stopping_criterion& NVBENCH_UNIQUE_IDENTIFIER(TYPE) = \ static nvbench::stopping_criterion_base &NVBENCH_UNIQUE_IDENTIFIER(TYPE) = \
nvbench::criterion_manager::get().add(std::make_unique<TYPE>()) \ nvbench::criterion_manager::get().add(std::make_unique<TYPE>())
} // namespace nvbench } // namespace nvbench

View File

@@ -34,7 +34,7 @@ criterion_manager &criterion_manager::get()
return registry; 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); auto iter = m_map.find(name);
if (iter == m_map.end()) if (iter == m_map.end())
@@ -44,7 +44,7 @@ stopping_criterion& criterion_manager::get_criterion(const std::string& name)
return *iter->second.get(); 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); auto iter = m_map.find(name);
if (iter == m_map.end()) if (iter == m_map.end())
@@ -54,7 +54,7 @@ const nvbench::stopping_criterion& criterion_manager::get_criterion(const std::s
return *iter->second.get(); 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(); const std::string name = criterion->get_name();

View File

@@ -27,7 +27,7 @@
namespace nvbench::detail namespace nvbench::detail
{ {
class entropy_criterion final : public stopping_criterion class entropy_criterion final : public stopping_criterion_base
{ {
// state // state
nvbench::int64_t m_total_samples{}; nvbench::int64_t m_total_samples{};

View File

@@ -26,8 +26,7 @@ namespace nvbench::detail
{ {
entropy_criterion::entropy_criterion() entropy_criterion::entropy_criterion()
: stopping_criterion{"entropy", : stopping_criterion_base{"entropy", {{"max-angle", 0.048}, {"min-r2", 0.36}}}
{{"max-angle", 0.048}, {"min-r2", 0.36}}}
{ {
m_freq_tracker.reserve(m_entropy_tracker.capacity() * 2); m_freq_tracker.reserve(m_entropy_tracker.capacity() * 2);
m_probabilities.reserve(m_entropy_tracker.capacity() * 2); m_probabilities.reserve(m_entropy_tracker.capacity() * 2);

View File

@@ -87,7 +87,7 @@ protected:
nvbench::blocking_kernel m_blocker; nvbench::blocking_kernel m_blocker;
nvbench::criterion_params m_criterion_params; 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_run_once{false};
bool m_no_block{false}; bool m_no_block{false};

View File

@@ -27,7 +27,7 @@
namespace nvbench::detail namespace nvbench::detail
{ {
class stdrel_criterion final : public stopping_criterion class stdrel_criterion final : public stopping_criterion_base
{ {
// state // state
nvbench::int64_t m_total_samples{}; nvbench::int64_t m_total_samples{};

View File

@@ -22,9 +22,9 @@ namespace nvbench::detail
{ {
stdrel_criterion::stdrel_criterion() stdrel_criterion::stdrel_criterion()
: stopping_criterion{"stdrel", : stopping_criterion_base{"stdrel",
{{"max-noise", nvbench::detail::compat_max_noise()}, {{"max-noise", nvbench::detail::compat_max_noise()},
{"min-time", nvbench::detail::compat_min_time()}}} {"min-time", nvbench::detail::compat_min_time()}}}
{} {}
void stdrel_criterion::do_initialize() void stdrel_criterion::do_initialize()

View File

@@ -70,7 +70,7 @@ public:
/** /**
* Stopping criterion interface * Stopping criterion interface
*/ */
class stopping_criterion class stopping_criterion_base
{ {
protected: protected:
std::string m_name; std::string m_name;
@@ -81,7 +81,7 @@ public:
* @param name Unique name of the criterion * @param name Unique name of the criterion
* @param params Default values for all parameters 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_name{std::move(name)}
, m_params{params} , m_params{params}
{} {}

View File

@@ -27,11 +27,11 @@ void test_standard_criteria_exist()
ASSERT(nvbench::criterion_manager::get().get_criterion("entropy").get_name() == "entropy"); 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: public:
custom_criterion() 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 {} virtual void add_measurement(nvbench::float64_t /* measurement */) override {}
@@ -47,7 +47,7 @@ void test_no_duplicates_are_allowed()
bool exception_triggered = false; bool exception_triggered = false;
try { try {
nvbench::stopping_criterion& custom = manager.get_criterion("custom"); nvbench::stopping_criterion_base& custom = manager.get_criterion("custom");
} catch(...) { } catch(...) {
exception_triggered = true; exception_triggered = true;
} }
@@ -57,7 +57,7 @@ void test_no_duplicates_are_allowed()
custom_criterion* custom_raw = custom_ptr.get(); custom_criterion* custom_raw = custom_ptr.get();
ASSERT(&manager.add(std::move(custom_ptr)) == custom_raw); 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); ASSERT(custom_raw == &custom);
exception_triggered = false; exception_triggered = false;