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 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ba123a8
Fixed
tobiasweinzierl80 Jul 13, 2024
dda4d20
Adopted copyright dates.
tobiasweinzierl80 Jul 16, 2024
aa1b495
Fixed two bugs
tobiasweinzierl80 Jul 16, 2024
6f67e78
Added the includes as per MR remark
tobiasweinzierl80 Jul 19, 2024
500263f
Work in a review remark from Mike
tobiasweinzierl80 Aug 24, 2024
dc64b51
Rename ndims to dim_count
sasalla23 Aug 27, 2024
714c97e
Implement ctor changes discussed in the spec
sasalla23 Aug 28, 2024
6deb538
Change back from std::vector to std::array to store dimensions
sasalla23 Aug 28, 2024
9b16c5e
Remove unnecessary assertions and mentions of vector
sasalla23 Aug 29, 2024
fc0b698
Revert changed include of blocked_range.h
sasalla23 Aug 30, 2024
dbc9d7a
Revert unnecessary copyright update
akukanov Sep 3, 2024
b7a093f
Match the current specification draft. Use public types internally.
akukanov Sep 3, 2024
fd59a9a
Rename the helper type, add a comment
akukanov Sep 3, 2024
8dd634d
Fix CI errors
akukanov Sep 3, 2024
be3ea4d
Convert to double for size-to-grainsize ratio computation, similar to…
akukanov Sep 3, 2024
89e1935
Add a test for the new constructor
akukanov Sep 3, 2024
e48e6a7
Fix the test
akukanov Sep 3, 2024
81b32b4
Fix the test - 2
akukanov Sep 3, 2024
eb691a4
Fix the test - 3
akukanov Sep 3, 2024
af8c0fb
Fix the constructor to work with a braced-init-list argument
akukanov Sep 5, 2024
39f2ef7
Fix "comparison of integers of different signs"
akukanov Sep 5, 2024
f0df4e6
Satisfy doctest
akukanov Sep 5, 2024
8167c11
Rename to blocked_nd_range
akukanov Oct 10, 2024
b6fb056
Update copyright year
akukanov Oct 10, 2024
5b3d1a5
Correct test traceability tags
akukanov Oct 16, 2024
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
43 changes: 29 additions & 14 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 <vector>
#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,36 @@ 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 begin[N],
Value end[N],
typename tbb::blocked_range<value_type>::size_type grainsize
):
my_dims() {
akukanov marked this conversation as resolved.
Show resolved Hide resolved
for (int d=0; d<N; d++) {
my_dims.push_back( dim_range_type< tbb::blocked_range<value_type>::size_type >( begin[d], end[d], grainsize ) );
}
__TBB_ASSERT(my_dims.size()==N, "range is not properly initialised" );
}

//! Dimensionality of a range.
static constexpr unsigned int ndims() { 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,17 +110,23 @@ 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.
std::array<tbb::blocked_range<value_type>, N> my_dims;
/*! 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.
*/
std::vector<tbb::blocked_range<value_type>> my_dims;
akukanov marked this conversation as resolved.
Show resolved Hide resolved

template<typename split_type>
void do_split(blocked_rangeNd_impl& r, split_type proportion) {
Expand Down Expand Up @@ -144,4 +160,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
1 change: 0 additions & 1 deletion 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
Loading