mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-20 06:48:53 +00:00
remove need for output_indices
This commit is contained in:
@@ -74,7 +74,7 @@ NVBENCH_BENCH(copy_sweep_grid_shape)
|
||||
// Zipped iteration of BlockSize and NumBlocks axes.
|
||||
// Will generate only 4 invocations of copy_sweep_grid_shape
|
||||
NVBENCH_BENCH(copy_sweep_grid_shape)
|
||||
.set_name("tied_copy_sweep_grid_shape")
|
||||
.set_name("zipped_copy_sweep_grid_shape")
|
||||
.add_zip_axes(nvbench::int64_axis{"BlockSize", {32, 64, 128, 256}},
|
||||
nvbench::int64_axis{"NumBlocks", {1024, 512, 256, 128}});
|
||||
|
||||
@@ -89,10 +89,8 @@ NVBENCH_BENCH(copy_sweep_grid_shape)
|
||||
//
|
||||
struct under_diag final : nvbench::user_axis_space
|
||||
{
|
||||
under_diag(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices),
|
||||
std::move(output_indices))
|
||||
under_diag(std::vector<std::size_t> input_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices))
|
||||
{}
|
||||
|
||||
mutable std::size_t x_pos = 0;
|
||||
@@ -116,17 +114,16 @@ struct under_diag final : nvbench::user_axis_space
|
||||
};
|
||||
|
||||
// our update function
|
||||
std::vector<std::size_t> locs = m_output_indices;
|
||||
auto diag_under =
|
||||
[&, locs, info](std::size_t,
|
||||
std::vector<nvbench::detail::axis_index> &indices) {
|
||||
[&, info](std::size_t,
|
||||
std::vector<nvbench::detail::axis_index> &indices) {
|
||||
nvbench::detail::axis_index temp = info[0];
|
||||
temp.index = x_pos;
|
||||
indices[locs[0]] = temp;
|
||||
indices.push_back(std::move(temp));
|
||||
|
||||
temp = info[1];
|
||||
temp.index = y_pos;
|
||||
indices[locs[1]] = temp;
|
||||
temp = info[1];
|
||||
temp.index = y_pos;
|
||||
indices.push_back(std::move(temp));
|
||||
};
|
||||
|
||||
const size_t iteration_length = ((info[0].size * (info[1].size + 1)) / 2);
|
||||
@@ -169,10 +166,8 @@ NVBENCH_BENCH(copy_sweep_grid_shape)
|
||||
struct gauss final : nvbench::user_axis_space
|
||||
{
|
||||
|
||||
gauss(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices),
|
||||
std::move(output_indices))
|
||||
gauss(std::vector<std::size_t> input_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices))
|
||||
{}
|
||||
|
||||
nvbench::detail::axis_space_iterator do_get_iterator(axes_info info) const
|
||||
@@ -193,12 +188,11 @@ struct gauss final : nvbench::user_axis_space
|
||||
}
|
||||
|
||||
// our update function
|
||||
std::vector<std::size_t> locs = m_output_indices;
|
||||
auto gauss_func = [=](std::size_t index,
|
||||
auto gauss_func = [=](std::size_t index,
|
||||
std::vector<nvbench::detail::axis_index> &indices) {
|
||||
nvbench::detail::axis_index temp = info[0];
|
||||
temp.index = gauss_indices[index];
|
||||
indices[locs[0]] = temp;
|
||||
indices.push_back(std::move(temp));
|
||||
};
|
||||
|
||||
return nvbench::detail::axis_space_iterator(1,
|
||||
|
||||
@@ -160,7 +160,7 @@ axes_metadata::axes_metadata(nvbench::type_list<TypeAxes...>)
|
||||
const std::size_t type_axis_index = axes.size();
|
||||
|
||||
spaces.push_back(
|
||||
std::make_unique<linear_axis_space>(type_axis_index, type_axis_index));
|
||||
std::make_unique<linear_axis_space>(type_axis_index));
|
||||
|
||||
// Note:
|
||||
// The word "type" appears 6 times in the next line.
|
||||
|
||||
@@ -137,8 +137,7 @@ void axes_metadata::add_string_axis(std::string name,
|
||||
void axes_metadata::add_axis(const axis_base &axis)
|
||||
{
|
||||
m_value_space.push_back(
|
||||
std::make_unique<linear_axis_space>(m_axes.size(),
|
||||
m_axes.size() - m_type_axe_count));
|
||||
std::make_unique<linear_axis_space>(m_axes.size()));
|
||||
m_axes.push_back(axis.clone());
|
||||
}
|
||||
|
||||
@@ -152,11 +151,7 @@ void axes_metadata::add_zip_space(std::size_t first_index, std::size_t count)
|
||||
|
||||
// compute the numeric indice for each name we have
|
||||
std::vector<std::size_t> input_indices(count);
|
||||
std::vector<std::size_t> output_indices(count);
|
||||
std::iota(input_indices.begin(), input_indices.end(), first_index);
|
||||
std::iota(input_indices.begin(),
|
||||
input_indices.end(),
|
||||
first_index - m_type_axe_count);
|
||||
|
||||
const auto expected_size = m_axes[input_indices[0]]->get_size();
|
||||
for (auto i : input_indices)
|
||||
@@ -174,8 +169,7 @@ void axes_metadata::add_zip_space(std::size_t first_index, std::size_t count)
|
||||
}
|
||||
|
||||
// add the new tied iteration space
|
||||
auto tied = std::make_unique<zip_axis_space>(std::move(input_indices),
|
||||
std::move(output_indices));
|
||||
auto tied = std::make_unique<zip_axis_space>(std::move(input_indices));
|
||||
m_value_space.push_back(std::move(tied));
|
||||
}
|
||||
|
||||
@@ -186,11 +180,7 @@ void axes_metadata::add_user_iteration_space(
|
||||
{
|
||||
// compute the numeric indice for each name we have
|
||||
std::vector<std::size_t> input_indices(count);
|
||||
std::vector<std::size_t> output_indices(count);
|
||||
std::iota(input_indices.begin(), input_indices.end(), first_index);
|
||||
std::iota(input_indices.begin(),
|
||||
input_indices.end(),
|
||||
first_index - m_type_axe_count);
|
||||
|
||||
for (auto i : input_indices)
|
||||
{
|
||||
@@ -201,7 +191,7 @@ void axes_metadata::add_user_iteration_space(
|
||||
m_axes[i]->get_name());
|
||||
}
|
||||
|
||||
auto user_func = make(std::move(input_indices), std::move(output_indices));
|
||||
auto user_func = make(std::move(input_indices));
|
||||
m_value_space.push_back(std::move(user_func));
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ struct state_iterator
|
||||
void next();
|
||||
|
||||
std::vector<axis_space_iterator> m_space;
|
||||
std::size_t m_axes_count = 0;
|
||||
std::size_t m_axes_count = 0;
|
||||
std::size_t m_current_space = 0;
|
||||
std::size_t m_current_iteration = 0;
|
||||
std::size_t m_max_iteration = 1;
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace nvbench::detail
|
||||
{
|
||||
// state_iterator ==============================================================
|
||||
|
||||
void state_iterator::add_iteration_space(const nvbench::detail::axis_space_iterator &iter)
|
||||
void state_iterator::add_iteration_space(
|
||||
const nvbench::detail::axis_space_iterator &iter)
|
||||
{
|
||||
m_axes_count += iter.m_number_of_axes;
|
||||
m_max_iteration *= iter.m_iteration_size;
|
||||
@@ -55,11 +56,13 @@ void state_iterator::init()
|
||||
|
||||
[[nodiscard]] std::vector<axis_index> state_iterator::get_current_indices() const
|
||||
{
|
||||
std::vector<axis_index> indices(m_axes_count);
|
||||
std::vector<axis_index> indices;
|
||||
indices.reserve(m_axes_count);
|
||||
for (auto &m : m_space)
|
||||
{
|
||||
m.update_indices(indices);
|
||||
}
|
||||
// verify length
|
||||
return indices;
|
||||
}
|
||||
|
||||
@@ -138,6 +141,7 @@ void state_generator::build_axis_configs()
|
||||
axis.get_input_string(axis_info.index));
|
||||
}
|
||||
}
|
||||
|
||||
for (vi.init(); vi.iter_valid(); vi.next())
|
||||
{
|
||||
auto &config = m_non_type_axis_configs.emplace_back();
|
||||
|
||||
@@ -67,8 +67,7 @@ struct iteration_space_base
|
||||
* @param[input_indices] recorded indices of each axi from the axes metadata value space
|
||||
* @param[output_indices] requested indices of each axi for output when iterating the type+value space
|
||||
*/
|
||||
iteration_space_base(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices);
|
||||
iteration_space_base(std::vector<std::size_t> input_indices);
|
||||
virtual ~iteration_space_base();
|
||||
|
||||
[[nodiscard]] std::unique_ptr<iteration_space_base> clone() const;
|
||||
@@ -102,7 +101,6 @@ struct iteration_space_base
|
||||
|
||||
protected:
|
||||
std::vector<std::size_t> m_input_indices;
|
||||
std::vector<std::size_t> m_output_indices;
|
||||
|
||||
virtual std::unique_ptr<iteration_space_base> do_clone() const = 0;
|
||||
virtual detail::axis_space_iterator do_get_iterator(axes_info info) const = 0;
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
iteration_space_base::iteration_space_base(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
iteration_space_base::iteration_space_base(std::vector<std::size_t> input_indices)
|
||||
: m_input_indices(std::move(input_indices))
|
||||
, m_output_indices(std::move(output_indices))
|
||||
{}
|
||||
|
||||
iteration_space_base::~iteration_space_base() = default;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace nvbench
|
||||
*/
|
||||
struct linear_axis_space final : iteration_space_base
|
||||
{
|
||||
linear_axis_space(std::size_t in, std::size_t out);
|
||||
linear_axis_space(std::size_t in);
|
||||
~linear_axis_space();
|
||||
|
||||
std::unique_ptr<iteration_space_base> do_clone() const override;
|
||||
|
||||
@@ -23,20 +23,18 @@
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
linear_axis_space::linear_axis_space(std::size_t in_index,
|
||||
std::size_t out_index)
|
||||
: iteration_space_base({in_index}, {out_index})
|
||||
linear_axis_space::linear_axis_space(std::size_t in_index)
|
||||
: iteration_space_base({in_index})
|
||||
{}
|
||||
|
||||
linear_axis_space::~linear_axis_space() = default;
|
||||
|
||||
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,
|
||||
std::vector<detail::axis_index> &indices) {
|
||||
indices[loc] = info[0];
|
||||
indices[loc].index = inc_index;
|
||||
indices.push_back(info[0]);
|
||||
indices.back().index = inc_index;
|
||||
};
|
||||
|
||||
return detail::axis_space_iterator(1, info[0].size, update_func);
|
||||
|
||||
@@ -35,47 +35,43 @@ namespace nvbench
|
||||
*
|
||||
* struct every_third final : nvbench::user_axis_space
|
||||
* {
|
||||
* every_third(std::vector<std::size_t> input_indices,
|
||||
* std::vector<std::size_t> output_indices)
|
||||
* : nvbench::user_axis_space(std::move(input_indices),
|
||||
* std::move(output_indices))
|
||||
* every_third(std::vector<std::size_t> input_indices)
|
||||
* : nvbench::user_axis_space(std::move(input_indices))
|
||||
* {}
|
||||
*
|
||||
* nvbench::detail::axis_space_iterator do_get_iterator(axes_info info) const
|
||||
* {
|
||||
* // our increment function
|
||||
* auto adv_func = [&, info](std::size_t &inc_index, std::size_t len) -> bool {
|
||||
* inc_index += 3;
|
||||
* return inc_index >= len;
|
||||
* auto adv_func = [&, info](std::size_t &inc_index, std::size_t len) ->
|
||||
* bool { inc_index += 3; return inc_index >= len;
|
||||
* };
|
||||
*
|
||||
* // our update function
|
||||
* std::vector<std::size_t> locs = m_output_indices;
|
||||
* auto update_func = [=](std::size_t inc_index,
|
||||
* std::vector<detail::axis_index> &indices) {
|
||||
* std::vector<axis_index> &indices) {
|
||||
* for (std::size_t i = 0; i < info.size(); ++i)
|
||||
* {
|
||||
* detail::axis_index temp = info[i];
|
||||
* temp.index = inc_index;
|
||||
* indices[locs[i]] = temp;
|
||||
* indices.push_back(std::move(temp));
|
||||
* }
|
||||
* };
|
||||
* return detail::axis_space_iterator(locs.size(), (info[0].size/3), adv_func, update_func);
|
||||
* return detail::axis_space_iterator(locs.size(), (info[0].size/3),
|
||||
* adv_func, update_func);
|
||||
* }
|
||||
*
|
||||
* std::size_t do_get_size(const axes_info &info) const { return (info[0].size/3); }
|
||||
* std::size_t do_get_size(const axes_info &info) const { return
|
||||
* (info[0].size/3); }
|
||||
* ...
|
||||
*
|
||||
*/
|
||||
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(std::vector<std::size_t> input_indices);
|
||||
~user_axis_space();
|
||||
};
|
||||
|
||||
using make_user_space_signature =
|
||||
std::unique_ptr<iteration_space_base>(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices);
|
||||
std::unique_ptr<iteration_space_base>(std::vector<std::size_t> input_indices);
|
||||
|
||||
} // namespace nvbench
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
user_axis_space::user_axis_space(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
: iteration_space_base(std::move(input_indices), std::move(output_indices))
|
||||
user_axis_space::user_axis_space(std::vector<std::size_t> input_indices)
|
||||
: iteration_space_base(std::move(input_indices))
|
||||
{}
|
||||
user_axis_space::~user_axis_space() = default;
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace nvbench
|
||||
*/
|
||||
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::vector<std::size_t> input_indices);
|
||||
~zip_axis_space();
|
||||
|
||||
std::unique_ptr<iteration_space_base> do_clone() const override;
|
||||
|
||||
@@ -23,27 +23,25 @@
|
||||
namespace nvbench
|
||||
{
|
||||
|
||||
zip_axis_space::zip_axis_space(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
: iteration_space_base(std::move(input_indices), std::move(output_indices))
|
||||
zip_axis_space::zip_axis_space(std::vector<std::size_t> input_indices)
|
||||
: iteration_space_base(std::move(input_indices))
|
||||
{}
|
||||
|
||||
zip_axis_space::~zip_axis_space() = default;
|
||||
|
||||
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,
|
||||
auto update_func = [=](std::size_t inc_index,
|
||||
std::vector<detail::axis_index> &indices) {
|
||||
for (std::size_t i = 0; i < info.size(); ++i)
|
||||
{
|
||||
detail::axis_index temp = info[i];
|
||||
temp.index = inc_index;
|
||||
indices[locs[i]] = temp;
|
||||
indices.push_back(std::move(temp));
|
||||
}
|
||||
};
|
||||
|
||||
return detail::axis_space_iterator(locs.size(), info[0].size, update_func);
|
||||
return detail::axis_space_iterator(info.size(), info[0].size, update_func);
|
||||
}
|
||||
|
||||
std::size_t zip_axis_space::do_get_size(const axes_info &info) const
|
||||
|
||||
@@ -181,10 +181,8 @@ void test_zip_clone()
|
||||
|
||||
struct under_diag final : nvbench::user_axis_space
|
||||
{
|
||||
under_diag(std::vector<std::size_t> input_indices,
|
||||
std::vector<std::size_t> output_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices),
|
||||
std::move(output_indices))
|
||||
under_diag(std::vector<std::size_t> input_indices)
|
||||
: nvbench::user_axis_space(std::move(input_indices))
|
||||
{}
|
||||
|
||||
mutable std::size_t x_pos = 0;
|
||||
@@ -208,17 +206,16 @@ struct under_diag final : nvbench::user_axis_space
|
||||
};
|
||||
|
||||
// our update function
|
||||
std::vector<std::size_t> locs = m_output_indices;
|
||||
auto diag_under =
|
||||
[&, locs, info](std::size_t,
|
||||
std::vector<nvbench::detail::axis_index> &indices) {
|
||||
[&, info](std::size_t,
|
||||
std::vector<nvbench::detail::axis_index> &indices) {
|
||||
nvbench::detail::axis_index temp = info[0];
|
||||
temp.index = x_pos;
|
||||
indices[locs[0]] = temp;
|
||||
indices.push_back(std::move(temp));
|
||||
|
||||
temp = info[1];
|
||||
temp.index = y_pos;
|
||||
indices[locs[1]] = temp;
|
||||
temp = info[1];
|
||||
temp.index = y_pos;
|
||||
indices.push_back(std::move(temp));
|
||||
};
|
||||
|
||||
const size_t iteration_length = ((info[0].size * (info[1].size + 1)) / 2);
|
||||
|
||||
@@ -62,7 +62,7 @@ void test_single_state()
|
||||
std::vector<std::unique_ptr<nvbench::axis_base>> axes;
|
||||
axes.push_back(std::make_unique<nvbench::string_axis>(si));
|
||||
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{0, 0}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{0}.get_iterator(axes));
|
||||
ASSERT(sg.get_number_of_states() == 1);
|
||||
sg.init();
|
||||
ASSERT(sg.iter_valid());
|
||||
@@ -96,10 +96,10 @@ void test_basic()
|
||||
axes.emplace_back(std::make_unique<nvbench::string_axis>(si3));
|
||||
axes.emplace_back(std::make_unique<nvbench::string_axis>(si4));
|
||||
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{0, 0}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{1, 1}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{2, 2}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{3, 3}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{0}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{1}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{2}.get_iterator(axes));
|
||||
sg.add_iteration_space(nvbench::linear_axis_space{3}.get_iterator(axes));
|
||||
|
||||
ASSERT_MSG(sg.get_number_of_states() == (2 * 3 * 3 * 2),
|
||||
"Actual: {} Expected: {}",
|
||||
|
||||
Reference in New Issue
Block a user