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 8 commits
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
37 changes: 24 additions & 13 deletions include/oneapi/tbb/blocked_rangeNd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2017-2021 Intel Corporation
Copyright (c) 2017-2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,20 +17,17 @@
#ifndef __TBB_blocked_rangeNd_H
#define __TBB_blocked_rangeNd_H

#if !TBB_PREVIEW_BLOCKED_RANGE_ND
#error Set TBB_PREVIEW_BLOCKED_RANGE_ND to include blocked_rangeNd.h
#endif

#include <algorithm> // std::any_of
#include <array>
#include <cstddef>
#include <type_traits> // std::is_same, std::enable_if

#include "detail/_config.h"
#include "detail/_template_helpers.h" // index_sequence, make_index_sequence
akukanov marked this conversation as resolved.
Show resolved Hide resolved
#include "detail/_namespace_injection.h"
#include "detail/_range_common.h"

#include "blocked_range.h"
#include <oneapi/tbb/blocked_range.h>
akukanov marked this conversation as resolved.
Show resolved Hide resolved

namespace tbb {
namespace detail {
Expand Down Expand Up @@ -60,23 +57,32 @@ class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {
//! Type of a value.
using value_type = Value;

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

public:
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_type_helper<Is>&... args) : my_dims{ {args...} } {}
blocked_rangeNd_impl(const dim_range_type<Is>&... args) : my_dims{ {args...} } {
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
akukanov marked this conversation as resolved.
Show resolved Hide resolved
}

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)... } {
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
}

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

//! Range in certain dimension.
const tbb::blocked_range<value_type>& dim(unsigned int dimension) const {
__TBB_ASSERT(dimension < N, "out of bound");
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
return my_dims[dimension];
}

Expand All @@ -100,16 +106,22 @@ class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {

blocked_rangeNd_impl(blocked_rangeNd_impl& r, proportional_split proportion) : my_dims(r.my_dims) {
do_split(r, proportion);
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
}

blocked_rangeNd_impl(blocked_rangeNd_impl& r, split proportion) : my_dims(r.my_dims) {
do_split(r, proportion);
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
}

private:
static_assert(N != 0, "zero dimensional blocked_rangeNd can't be constructed");

//! Ranges in each dimension.
/*! Ranges in each dimension.
*
* This has to be a vector, as there are situations where we can't
* initialise the entries all in one go.
*/
akukanov marked this conversation as resolved.
Show resolved Hide resolved
std::array<tbb::blocked_range<value_type>, N> my_dims;

template<typename split_type>
Expand Down Expand Up @@ -144,4 +156,3 @@ using detail::d1::blocked_rangeNd;
} // namespace tbb

#endif /* __TBB_blocked_rangeNd_H */

2 changes: 1 addition & 1 deletion include/tbb/blocked_rangeNd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2017-2021 Intel Corporation
Copyright (c) 2017-2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 2 additions & 3 deletions test/conformance/conformance_blocked_rangeNd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! \file conformance_blocked_rangeNd.cpp
//! \brief Test for [preview] functionality

#define TBB_PREVIEW_BLOCKED_RANGE_ND 1
#include "oneapi/tbb/blocked_rangeNd.h"
#include "oneapi/tbb/parallel_for.h"
#include "oneapi/tbb/global_control.h"
Expand Down Expand Up @@ -160,7 +159,7 @@ int MakeInt(int i) { return i; }

template<unsigned int DimAmount>
void SerialTest() {
static_assert((oneapi::tbb::blocked_rangeNd<int, DimAmount>::ndims() == oneapi::tbb::blocked_rangeNd<AbstractValueType, DimAmount>::ndims()),
static_assert((oneapi::tbb::blocked_rangeNd<int, DimAmount>::dim_count() == oneapi::tbb::blocked_rangeNd<AbstractValueType, DimAmount>::dim_count()),
"different amount of dimensions");

using range_t = oneapi::tbb::blocked_rangeNd<AbstractValueType, DimAmount>;
Expand All @@ -171,7 +170,7 @@ void SerialTest() {

utils::AssertSameType(r.is_divisible(), bool());
utils::AssertSameType(r.empty(), bool());
utils::AssertSameType(range_t::ndims(), 0U);
utils::AssertSameType(range_t::dim_count(), 0U);

REQUIRE((r.empty() == utils_t::is_empty(r) && r.empty()));
REQUIRE(r.is_divisible() == utils_t::is_divisible(r));
Expand Down
Loading