Skip to content

Commit

Permalink
remove need for make_space_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Aug 31, 2022
1 parent dc7e2b7 commit 5708e6c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/custom_iteration_spaces.cu
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct under_diag final : nvbench::user_axis_space
};

const size_t iteration_length = ((info[0].size * (info[1].size + 1)) / 2);
return nvbench::detail::make_space_iterator(2,
return nvbench::detail::axis_space_iterator(2,
iteration_length,
adv_func,
diag_under);
Expand Down Expand Up @@ -201,7 +201,7 @@ struct gauss final : nvbench::user_axis_space
indices[locs[0]] = temp;
};

return nvbench::detail::make_space_iterator(1,
return nvbench::detail::axis_space_iterator(1,
iteration_length,
gauss_func);
}
Expand Down
46 changes: 20 additions & 26 deletions nvbench/detail/axes_iterator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ struct axis_space_iterator
using UpdateSignature = void(std::size_t index,
std::vector<axis_index> &indices);

axis_space_iterator(
std::size_t axes_count,
std::size_t iter_count,
std::function<axis_space_iterator::AdvanceSignature> &&advance,
std::function<axis_space_iterator::UpdateSignature> &&update)
: m_number_of_axes(axes_count)
, m_iteration_size(iter_count)
, m_advance(std::move(advance))
, m_update(std::move(update))
{}

axis_space_iterator(
std::size_t axes_count,
std::size_t iter_count,
std::function<axis_space_iterator::UpdateSignature> &&update)
: m_number_of_axes(axes_count)
, m_iteration_size(iter_count)
, m_update(std::move(update))
{}

[[nodiscard]] bool inc()
{
return this->m_advance(m_current_index, m_iteration_size);
Expand All @@ -83,31 +103,5 @@ private:
std::size_t m_current_index = 0;
};

inline axis_space_iterator make_space_iterator(
std::size_t axes_count,
std::size_t iter_count,
std::function<axis_space_iterator::AdvanceSignature> &&advance,
std::function<axis_space_iterator::UpdateSignature> &&update)
{
axis_space_iterator iter;
iter.m_number_of_axes = axes_count;
iter.m_iteration_size = iter_count;
iter.m_advance = std::move(advance);
iter.m_update = std::move(update);
return iter;
}

inline axis_space_iterator make_space_iterator(
std::size_t axes_count,
std::size_t iter_count,
std::function<axis_space_iterator::UpdateSignature> &&update)
{
axis_space_iterator iter;
iter.m_number_of_axes = axes_count;
iter.m_iteration_size = iter_count;
iter.m_update = std::move(update);
return iter;
}

} // namespace detail
} // namespace nvbench
4 changes: 2 additions & 2 deletions nvbench/linear_axis_space.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ 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]);
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;
};

return detail::make_space_iterator(1, info[0].size, update_func);
return detail::axis_space_iterator(1, info[0].size, update_func);
}

std::size_t linear_axis_space::do_get_size(const axes_info &info) const
Expand Down
2 changes: 1 addition & 1 deletion nvbench/user_axis_space.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace nvbench
* indices[locs[i]] = temp;
* }
* };
* return detail::make_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); }
Expand Down
2 changes: 1 addition & 1 deletion nvbench/zip_axis_space.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ detail::axis_space_iterator zip_axis_space::do_get_iterator(axes_info info) cons
}
};

return detail::make_space_iterator(locs.size(), info[0].size, update_func);
return detail::axis_space_iterator(locs.size(), info[0].size, update_func);
}

std::size_t zip_axis_space::do_get_size(const axes_info &info) const
Expand Down
2 changes: 1 addition & 1 deletion testing/axes_iteration_space.cu
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct under_diag final : nvbench::user_axis_space
};

const size_t iteration_length = ((info[0].size * (info[1].size + 1)) / 2);
return nvbench::detail::make_space_iterator(2,
return nvbench::detail::axis_space_iterator(2,
iteration_length,
adv_func,
diag_under);
Expand Down

0 comments on commit 5708e6c

Please sign in to comment.