Skip to content

Commit

Permalink
Refactor names
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Apr 12, 2022
1 parent 5b000e8 commit ba8356f
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 85 deletions.
22 changes: 11 additions & 11 deletions examples/custom_iteration_spaces.cu
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct under_diag final : nvbench::user_axis_space
mutable std::size_t y_pos = 0;
mutable std::size_t x_start = 0;

nvbench::detail::axis_space_iterator do_iter(axes_info info) const
nvbench::detail::axis_space_iterator do_get_iterator(axes_info info) const
{
// generate our increment function
auto adv_func = [&, info](std::size_t &inc_index,
Expand Down Expand Up @@ -136,17 +136,17 @@ struct under_diag final : nvbench::user_axis_space
diag_under);
}

std::size_t do_size(const axes_info &info) const
std::size_t do_get_size(const axes_info &info) const
{
return ((info[0].size * (info[1].size + 1)) / 2);
}

std::size_t do_valid_count(const axes_info &info) const
std::size_t do_get_active_count(const axes_info &info) const
{
return ((info[0].size * (info[1].size + 1)) / 2);
}

std::unique_ptr<nvbench::axis_space_base> do_clone() const
std::unique_ptr<nvbench::iteration_space_base> do_clone() const
{
return std::make_unique<under_diag>(*this);
}
Expand All @@ -155,7 +155,7 @@ struct under_diag final : nvbench::user_axis_space
NVBENCH_BENCH(copy_sweep_grid_shape)
.set_name("user_copy_sweep_grid_shape")
.add_user_iteration_axes(
[](auto... args) -> std::unique_ptr<nvbench::axis_space_base> {
[](auto... args) -> std::unique_ptr<nvbench::iteration_space_base> {
return std::make_unique<under_diag>(args...);
},
nvbench::int64_axis("BlockSize", {64, 128, 256, 512, 1024}),
Expand All @@ -175,7 +175,7 @@ struct gauss final : nvbench::user_axis_space
std::move(output_indices))
{}

nvbench::detail::axis_space_iterator do_iter(axes_info info) const
nvbench::detail::axis_space_iterator do_get_iterator(axes_info info) const
{
const double mid_point = static_cast<double>((info[0].size / 2));

Expand Down Expand Up @@ -206,14 +206,14 @@ struct gauss final : nvbench::user_axis_space
gauss_func);
}

std::size_t do_size(const axes_info &info) const { return info[0].size; }
std::size_t do_get_size(const axes_info &info) const { return info[0].size; }

std::size_t do_valid_count(const axes_info &info) const
std::size_t do_get_active_count(const axes_info &info) const
{
return info[0].size;
}

std::unique_ptr<axis_space_base> do_clone() const
std::unique_ptr<iteration_space_base> do_clone() const
{
return std::make_unique<gauss>(*this);
}
Expand All @@ -232,12 +232,12 @@ void dual_float64_axis(nvbench::state &state)
}
NVBENCH_BENCH(dual_float64_axis)
.add_user_iteration_axes(
[](auto... args) -> std::unique_ptr<nvbench::axis_space_base> {
[](auto... args) -> std::unique_ptr<nvbench::iteration_space_base> {
return std::make_unique<gauss>(args...);
},
nvbench::float64_axis("Duration_A", nvbench::range(0., 1e-4, 1e-5)))
.add_user_iteration_axes(
[](auto... args) -> std::unique_ptr<nvbench::axis_space_base> {
[](auto... args) -> std::unique_ptr<nvbench::iteration_space_base> {
return std::make_unique<gauss>(args...);
},
nvbench::float64_axis("Duration_B", nvbench::range(0., 1e-4, 1e-5)));
12 changes: 6 additions & 6 deletions nvbench/axes_metadata.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace nvbench
struct axes_metadata
{
using axes_type = std::vector<std::unique_ptr<nvbench::axis_base>>;
using axes_iteration_space =
std::vector<std::unique_ptr<nvbench::axis_space_base>>;
using iteration_space_type =
std::vector<std::unique_ptr<nvbench::iteration_space_base>>;

template <typename... TypeAxes>
explicit axes_metadata(nvbench::type_list<TypeAxes...>);
Expand Down Expand Up @@ -86,11 +86,11 @@ struct axes_metadata
user_iteration_axes(std::function<nvbench::make_user_space_signature> make,
std::vector<std::string> names);

[[nodiscard]] const axes_iteration_space &get_type_iteration_space() const
[[nodiscard]] const iteration_space_type &get_type_iteration_space() const
{
return m_type_space;
}
[[nodiscard]] const axes_iteration_space &get_value_iteration_space() const
[[nodiscard]] const iteration_space_type &get_value_iteration_space() const
{
return m_value_space;
}
Expand Down Expand Up @@ -131,8 +131,8 @@ struct axes_metadata
private:
axes_type m_axes;
std::size_t m_type_axe_count = 0;
axes_iteration_space m_type_space;
axes_iteration_space m_value_space;
iteration_space_type m_type_space;
iteration_space_type m_value_space;
};

template <typename... TypeAxes>
Expand Down
6 changes: 3 additions & 3 deletions nvbench/axes_metadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ get_axes_indices(std::size_t type_axe_count,
}

void reset_iteration_space(
nvbench::axes_metadata::axes_iteration_space &all_spaces,
nvbench::axes_metadata::iteration_space_type &all_spaces,
const std::vector<std::size_t> &indices_to_remove)
{
// 1. Find all spaces indices that
nvbench::axes_metadata::axes_iteration_space reset_space;
nvbench::axes_metadata::axes_iteration_space to_filter;
nvbench::axes_metadata::iteration_space_type reset_space;
nvbench::axes_metadata::iteration_space_type to_filter;
for (auto &space : all_spaces)
{
bool added = false;
Expand Down
48 changes: 24 additions & 24 deletions nvbench/axis_iteration_space.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace nvbench
{

struct axis_space_base
struct iteration_space_base
{
using axes_type = std::vector<std::unique_ptr<nvbench::axis_base>>;
using axes_info = std::vector<detail::axis_index>;
Expand All @@ -32,62 +32,62 @@ struct axis_space_base
nvbench::detail::axis_space_iterator::AdvanceSignature;
using UpdateSignature = nvbench::detail::axis_space_iterator::UpdateSignature;

axis_space_base(std::vector<std::size_t> input_indices,
iteration_space_base(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
virtual ~axis_space_base();
virtual ~iteration_space_base();

[[nodiscard]] std::unique_ptr<axis_space_base> clone() const;
[[nodiscard]] std::vector<std::unique_ptr<axis_space_base>>
[[nodiscard]] std::unique_ptr<iteration_space_base> clone() const;
[[nodiscard]] std::vector<std::unique_ptr<iteration_space_base>>
clone_as_linear() const;

[[nodiscard]] detail::axis_space_iterator iter(const axes_type &axes) const;
[[nodiscard]] std::size_t size(const axes_type &axes) const;
[[nodiscard]] std::size_t valid_count(const axes_type &axes) const;
[[nodiscard]] detail::axis_space_iterator get_iterator(const axes_type &axes) const;
[[nodiscard]] std::size_t get_size(const axes_type &axes) const;
[[nodiscard]] std::size_t get_active_count(const axes_type &axes) const;

[[nodiscard]] bool contains(std::size_t input_index) const;

protected:
std::vector<std::size_t> m_input_indices;
std::vector<std::size_t> m_output_indices;

virtual std::unique_ptr<axis_space_base> do_clone() const = 0;
virtual detail::axis_space_iterator do_iter(axes_info info) const = 0;
virtual std::size_t do_size(const axes_info &info) const = 0;
virtual std::size_t do_valid_count(const axes_info &info) const = 0;
virtual std::unique_ptr<iteration_space_base> do_clone() const = 0;
virtual detail::axis_space_iterator do_get_iterator(axes_info info) const = 0;
virtual std::size_t do_get_size(const axes_info &info) const = 0;
virtual std::size_t do_get_active_count(const axes_info &info) const = 0;
};

struct linear_axis_space final : axis_space_base
struct linear_axis_space final : iteration_space_base
{
linear_axis_space(std::size_t in, std::size_t out);
~linear_axis_space();

std::unique_ptr<axis_space_base> do_clone() const override;
detail::axis_space_iterator do_iter(axes_info info) const override;
std::size_t do_size(const axes_info &info) const override;
std::size_t do_valid_count(const axes_info &info) const override;
std::unique_ptr<iteration_space_base> do_clone() const override;
detail::axis_space_iterator do_get_iterator(axes_info info) const override;
std::size_t do_get_size(const axes_info &info) const override;
std::size_t do_get_active_count(const axes_info &info) const override;
};

struct zip_axis_space final : axis_space_base
struct zip_axis_space final : iteration_space_base
{
zip_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~zip_axis_space();

std::unique_ptr<axis_space_base> do_clone() const override;
detail::axis_space_iterator do_iter(axes_info info) const override;
std::size_t do_size(const axes_info &info) const override;
std::size_t do_valid_count(const axes_info &info) const override;
std::unique_ptr<iteration_space_base> do_clone() const override;
detail::axis_space_iterator do_get_iterator(axes_info info) const override;
std::size_t do_get_size(const axes_info &info) const override;
std::size_t do_get_active_count(const axes_info &info) const override;
};

struct user_axis_space : axis_space_base
struct user_axis_space : iteration_space_base
{
user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~user_axis_space();
};

using make_user_space_signature =
std::unique_ptr<axis_space_base>(std::vector<std::size_t> input_indices,
std::unique_ptr<iteration_space_base>(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);

} // namespace nvbench
54 changes: 27 additions & 27 deletions nvbench/axis_iteration_space.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
namespace nvbench
{

axis_space_base::axis_space_base(std::vector<std::size_t> input_indices,
iteration_space_base::iteration_space_base(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices)
: m_input_indices(std::move(input_indices))
, m_output_indices(std::move(output_indices))
{}

axis_space_base::~axis_space_base() = default;
iteration_space_base::~iteration_space_base() = default;

std::unique_ptr<axis_space_base> axis_space_base::clone() const
std::unique_ptr<iteration_space_base> iteration_space_base::clone() const
{
auto clone = this->do_clone();
return clone;
}

std::vector<std::unique_ptr<axis_space_base>>
axis_space_base::clone_as_linear() const
std::vector<std::unique_ptr<iteration_space_base>>
iteration_space_base::clone_as_linear() const
{
std::vector<std::unique_ptr<axis_space_base>> clones;
std::vector<std::unique_ptr<iteration_space_base>> clones;
clones.reserve(m_input_indices.size());

for (std::size_t i = 0; i < m_input_indices.size(); ++i)
Expand All @@ -55,11 +55,11 @@ axis_space_base::clone_as_linear() const

namespace
{
nvbench::axis_space_base::axes_info
get_axes_info(const nvbench::axis_space_base::axes_type &axes,
nvbench::iteration_space_base::axes_info
get_axes_info(const nvbench::iteration_space_base::axes_type &axes,
const std::vector<std::size_t> &indices)
{
nvbench::axis_space_base::axes_info info;
nvbench::iteration_space_base::axes_info info;
info.reserve(indices.size());
for (auto &n : indices)
{
Expand All @@ -69,22 +69,22 @@ get_axes_info(const nvbench::axis_space_base::axes_type &axes,
}
} // namespace

detail::axis_space_iterator axis_space_base::iter(const axes_type &axes) const
detail::axis_space_iterator iteration_space_base::get_iterator(const axes_type &axes) const
{

return this->do_iter(get_axes_info(axes, m_input_indices));
return this->do_get_iterator(get_axes_info(axes, m_input_indices));
}

std::size_t axis_space_base::size(const axes_type &axes) const
std::size_t iteration_space_base::get_size(const axes_type &axes) const
{
return this->do_size(get_axes_info(axes, m_input_indices));
return this->do_get_size(get_axes_info(axes, m_input_indices));
}
std::size_t axis_space_base::valid_count(const axes_type &axes) const
std::size_t iteration_space_base::get_active_count(const axes_type &axes) const
{
return this->do_valid_count(get_axes_info(axes, m_input_indices));
return this->do_get_active_count(get_axes_info(axes, m_input_indices));
}

bool axis_space_base::contains(std::size_t in_index) const
bool iteration_space_base::contains(std::size_t in_index) const
{
auto iter =
std::find_if(m_input_indices.cbegin(),
Expand All @@ -95,12 +95,12 @@ bool axis_space_base::contains(std::size_t in_index) const

linear_axis_space::linear_axis_space(std::size_t in_index,
std::size_t out_index)
: axis_space_base({in_index}, {out_index})
: iteration_space_base({in_index}, {out_index})
{}

linear_axis_space::~linear_axis_space() = default;

detail::axis_space_iterator linear_axis_space::do_iter(axes_info info) const
detail::axis_space_iterator linear_axis_space::do_get_iterator(axes_info info) const
{
std::size_t loc(m_output_indices[0]);
auto update_func = [=](std::size_t inc_index,
Expand All @@ -112,29 +112,29 @@ detail::axis_space_iterator linear_axis_space::do_iter(axes_info info) const
return detail::make_space_iterator(1, info[0].size, update_func);
}

std::size_t linear_axis_space::do_size(const axes_info &info) const
std::size_t linear_axis_space::do_get_size(const axes_info &info) const
{
return info[0].size;
}

std::size_t linear_axis_space::do_valid_count(const axes_info &info) const
std::size_t linear_axis_space::do_get_active_count(const axes_info &info) const
{
return info[0].active_size;
}

std::unique_ptr<axis_space_base> linear_axis_space::do_clone() const
std::unique_ptr<iteration_space_base> linear_axis_space::do_clone() const
{
return std::make_unique<linear_axis_space>(*this);
}

zip_axis_space::zip_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices)
: axis_space_base(std::move(input_indices), std::move(output_indices))
: iteration_space_base(std::move(input_indices), std::move(output_indices))
{}

zip_axis_space::~zip_axis_space() = default;

detail::axis_space_iterator zip_axis_space::do_iter(axes_info info) const
detail::axis_space_iterator zip_axis_space::do_get_iterator(axes_info info) const
{
std::vector<std::size_t> locs = m_output_indices;
auto update_func = [=](std::size_t inc_index,
Expand All @@ -150,24 +150,24 @@ detail::axis_space_iterator zip_axis_space::do_iter(axes_info info) const
return detail::make_space_iterator(locs.size(), info[0].size, update_func);
}

std::size_t zip_axis_space::do_size(const axes_info &info) const
std::size_t zip_axis_space::do_get_size(const axes_info &info) const
{
return info[0].size;
}

std::size_t zip_axis_space::do_valid_count(const axes_info &info) const
std::size_t zip_axis_space::do_get_active_count(const axes_info &info) const
{
return info[0].active_size;
}

std::unique_ptr<axis_space_base> zip_axis_space::do_clone() const
std::unique_ptr<iteration_space_base> zip_axis_space::do_clone() const
{
return std::make_unique<zip_axis_space>(*this);
}

user_axis_space::user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices)
: axis_space_base(std::move(input_indices), std::move(output_indices))
: iteration_space_base(std::move(input_indices), std::move(output_indices))
{}
user_axis_space::~user_axis_space() = default;

Expand Down
4 changes: 2 additions & 2 deletions nvbench/benchmark_base.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ std::size_t benchmark_base::get_config_count() const
m_axes.get_value_iteration_space().cend(),
std::size_t{1},
std::multiplies<>{},
[&axes](const auto &space) { return space->size(axes); });
[&axes](const auto &space) { return space->get_size(axes); });

const std::size_t type_count = nvbench::detail::transform_reduce(
m_axes.get_type_iteration_space().cbegin(),
m_axes.get_type_iteration_space().cend(),
std::size_t{1},
std::multiplies<>{},
[&axes](const auto &space) { return space->valid_count(axes); });
[&axes](const auto &space) { return space->get_active_count(axes); });

return (value_count * type_count) * std::max(1UL, m_devices.size());
}
Expand Down
Loading

0 comments on commit ba8356f

Please sign in to comment.