Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension of Nd range #1449

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Match the current specification draft. Use public types internally.
  • Loading branch information
akukanov committed Sep 3, 2024
commit b7a093fe9a0b256749e497ef7f74ce0bc1f062dc
30 changes: 15 additions & 15 deletions include/oneapi/tbb/blocked_rangeNd.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,25 @@ class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {
//! Type of a value.
using value_type = Value;

//! Helper type to construct range with N tbb::blocked_range<value_type> objects.
template<std::size_t>
//! Type of a dimension range.
using dim_range_type = tbb::blocked_range<value_type>;
akukanov marked this conversation as resolved.
Show resolved Hide resolved

//! Type for the size of a range.
using size_type = dim_range_type::size_type;

blocked_rangeNd_impl() = delete;

//! Constructs N-dimensional range over N half-open intervals each represented as tbb::blocked_range<Value>.
blocked_rangeNd_impl(const dim_range_type<Is>&... args) : my_dims{ {args...} } {}
blocked_rangeNd_impl(const enumerated_t<dim_range_type, Is>&... args) : my_dims{ {args...} } {}

blocked_rangeNd_impl(
Value size[N],
typename tbb::blocked_range<value_type>::size_type grainsize = 1
):
my_dims { dim_range_type<Is>(0, size[Is], grainsize)... } {}
blocked_rangeNd_impl(value_type size[N], size_type grainsize = 1) :
my_dims { dim_range_type(0, size[Is], grainsize)... } {}

//! Dimensionality of a range.
static constexpr unsigned int dim_count() { return N; }

//! Range in certain dimension.
const tbb::blocked_range<value_type>& dim(unsigned int dimension) const {
const dim_range_type& dim(unsigned int dimension) const {
__TBB_ASSERT(dimension < N, "out of bound");
return my_dims[dimension];
}
Expand All @@ -87,14 +86,14 @@ class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {

//! True if at least one dimension is empty.
bool empty() const {
return std::any_of(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& d) {
return std::any_of(my_dims.begin(), my_dims.end(), [](const dim_range_type& d) {
return d.empty();
});
}

//! True if at least one dimension is divisible.
bool is_divisible() const {
return std::any_of(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& d) {
return std::any_of(my_dims.begin(), my_dims.end(), [](const dim_range_type& d) {
return d.is_divisible();
});
}
Expand All @@ -111,20 +110,21 @@ class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {
static_assert(N != 0, "zero dimensional blocked_rangeNd can't be constructed");

//! Ranges in each dimension.
std::array<tbb::blocked_range<value_type>, N> my_dims;
std::array<dim_range_type, N> my_dims;

template<typename split_type>
void do_split(blocked_rangeNd_impl& r, split_type proportion) {
static_assert((std::is_same<split_type, split>::value || std::is_same<split_type, proportional_split>::value), "type of split object is incorrect");
static_assert((std::is_same<split_type, split>::value || std::is_same<split_type, proportional_split>::value),
"type of split object is incorrect");
__TBB_ASSERT(r.is_divisible(), "can't split not divisible range");

auto my_it = std::max_element(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& first, const tbb::blocked_range<value_type>& second) {
auto my_it = std::max_element(my_dims.begin(), my_dims.end(), [](const dim_range_type& first, const dim_range_type& second) {
return (first.size() * second.grainsize() < second.size() * first.grainsize());
});

auto r_it = r.my_dims.begin() + (my_it - my_dims.begin());

my_it->my_begin = tbb::blocked_range<value_type>::do_split(*r_it, proportion);
my_it->my_begin = dim_range_type::do_split(*r_it, proportion);

// (!(my_it->my_begin < r_it->my_end) && !(r_it->my_end < my_it->my_begin)) equals to
// (my_it->my_begin == r_it->my_end), but we can't use operator== due to Value concept
Expand Down
3 changes: 3 additions & 0 deletions include/oneapi/tbb/detail/_template_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ using make_index_sequence = typename make_index_sequence_impl<N>::type;

#endif /* __TBB_CPP14_INTEGER_SEQUENCE_PRESENT */

template<typename T, std::size_t>
using enumerated_t = T;

#if __TBB_CPP17_LOGICAL_OPERATIONS_PRESENT
using std::conjunction;
using std::disjunction;
Expand Down
Loading