Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions sycl/include/sycl/detail/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ template <int dimensions = 1> class array {
return result;
}

size_t get(int dimension) const {
size_t get(int dimension) const noexcept {
check_dimension(dimension);
return common_array[dimension];
}

size_t &operator[](int dimension) {
size_t &operator[](int dimension) noexcept {
check_dimension(dimension);
return common_array[dimension];
}

size_t operator[](int dimension) const {
size_t operator[](int dimension) const noexcept {
check_dimension(dimension);
return common_array[dimension];
}
Expand Down
51 changes: 32 additions & 19 deletions sycl/include/sycl/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
/* The following constructor is only available in the range class
specialization where: Dimensions==1 */
template <int N = Dimensions>
range(typename std::enable_if_t<(N == 1), size_t> dim0) : base(dim0) {}
range(typename std::enable_if_t<(N == 1), size_t> dim0) noexcept
: base(dim0) {}

/* The following constructor is only available in the range class
specialization where: Dimensions==2 */
template <int N = Dimensions>
range(typename std::enable_if_t<(N == 2), size_t> dim0, size_t dim1)
range(typename std::enable_if_t<(N == 2), size_t> dim0, size_t dim1) noexcept
: base(dim0, dim1) {}

/* The following constructor is only available in the range class
specialization where: Dimensions==3 */
template <int N = Dimensions>
range(typename std::enable_if_t<(N == 3), size_t> dim0, size_t dim1,
size_t dim2)
size_t dim2) noexcept
: base(dim0, dim1, dim2) {}

size_t size() const {
size_t size() const noexcept {
size_t size = 1;
for (int i = 0; i < Dimensions; ++i) {
size *= this->common_array[i];
Expand All @@ -64,15 +65,17 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
}

range(const range<Dimensions> &rhs) = default;
range(range<Dimensions> &&rhs) = default;
range(range<Dimensions> &&rhs) noexcept = default;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC SYCL 2020 doesn't require these functions (for by-value semantics) to be noexcept.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right.. I thought that I should apply good practice here to add noexcept for move functions so they could benefit from moves. standard library usually moves types only if they have noexcept move constructor / operator, but now I properly understand that this type is designed to be passed by value and as such this noexcept should bring little to no improvement, so I will most likely remove it from here

range<Dimensions> &operator=(const range<Dimensions> &rhs) = default;
range<Dimensions> &operator=(range<Dimensions> &&rhs) = default;
range() = default;
range<Dimensions> &operator=(range<Dimensions> &&rhs) noexcept = default;
range() noexcept = default;

~range() noexcept = default;

// OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >=
#define __SYCL_GEN_OPT_BASE(op) \
friend range<Dimensions> operator op(const range<Dimensions> &lhs, \
const range<Dimensions> &rhs) { \
friend range<Dimensions> operator op( \
const range<Dimensions> &lhs, const range<Dimensions> &rhs) noexcept { \
range<Dimensions> result(lhs); \
for (int i = 0; i < Dimensions; ++i) { \
result.common_array[i] = lhs.common_array[i] op rhs.common_array[i]; \
Expand All @@ -86,7 +89,7 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
__SYCL_GEN_OPT_BASE(op) \
template <typename T> \
friend IntegralType<T, range<Dimensions>> operator op( \
const range<Dimensions> &lhs, const T &rhs) { \
const range<Dimensions> &lhs, const T &rhs) noexcept { \
range<Dimensions> result(lhs); \
for (int i = 0; i < Dimensions; ++i) { \
result.common_array[i] = lhs.common_array[i] op rhs; \
Expand All @@ -95,14 +98,15 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
} \
template <typename T> \
friend IntegralType<T, range<Dimensions>> operator op( \
const T &lhs, const range<Dimensions> &rhs) { \
const T &lhs, const range<Dimensions> &rhs) noexcept { \
range<Dimensions> result(rhs); \
for (int i = 0; i < Dimensions; ++i) { \
result.common_array[i] = lhs op rhs.common_array[i]; \
} \
return result; \
}
#else

#define __SYCL_GEN_OPT(op) \
__SYCL_GEN_OPT_BASE(op) \
friend range<Dimensions> operator op(const range<Dimensions> &lhs, \
Expand Down Expand Up @@ -145,8 +149,8 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {

// OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=
#define __SYCL_GEN_OPT(op) \
friend range<Dimensions> &operator op(range<Dimensions> &lhs, \
const range<Dimensions> &rhs) { \
friend range<Dimensions> &operator op( \
range<Dimensions> &lhs, const range<Dimensions> &rhs) noexcept { \
for (int i = 0; i < Dimensions; ++i) { \
lhs.common_array[i] op rhs[i]; \
} \
Expand All @@ -158,6 +162,14 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
lhs.common_array[i] op rhs; \
} \
return lhs; \
} \
template <typename T> \
friend IntegralType<T, range<Dimensions>> operator op( \
range<Dimensions> &lhs, const T &rhs) noexcept { \
for (int i = 0; i < Dimensions; ++i) { \
lhs.common_array[i] op rhs; \
} \
return lhs; \
}

__SYCL_GEN_OPT(+=)
Expand All @@ -175,7 +187,8 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {

// OP is unary +, -
#define __SYCL_GEN_OPT(op) \
friend range<Dimensions> operator op(const range<Dimensions> &rhs) { \
friend range<Dimensions> operator op( \
const range<Dimensions> &rhs) noexcept { \
range<Dimensions> result(rhs); \
for (int i = 0; i < Dimensions; ++i) { \
result.common_array[i] = (op rhs.common_array[i]); \
Expand All @@ -190,7 +203,7 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {

// OP is prefix ++, --
#define __SYCL_GEN_OPT(op) \
friend range<Dimensions> &operator op(range<Dimensions> &rhs) { \
friend range<Dimensions> &operator op(range<Dimensions> &rhs) noexcept { \
for (int i = 0; i < Dimensions; ++i) { \
op rhs.common_array[i]; \
} \
Expand All @@ -204,7 +217,7 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {

// OP is postfix ++, --
#define __SYCL_GEN_OPT(op) \
friend range<Dimensions> operator op(range<Dimensions> &lhs, int) { \
friend range<Dimensions> operator op(range<Dimensions> &lhs, int) noexcept { \
range<Dimensions> old_lhs(lhs); \
for (int i = 0; i < Dimensions; ++i) { \
op lhs.common_array[i]; \
Expand All @@ -226,9 +239,9 @@ template <int Dimensions = 1> class range : public detail::array<Dimensions> {
};

#ifdef __cpp_deduction_guides
range(size_t)->range<1>;
range(size_t, size_t)->range<2>;
range(size_t, size_t, size_t)->range<3>;
range(size_t) -> range<1>;
range(size_t, size_t) -> range<2>;
range(size_t, size_t, size_t) -> range<3>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

automatic change from my clang-format, I think it adheres to coding style rules of the repository

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok, let's update this. In general try to use git clang-format HEAD~ after you've created a commit. It'll only format your changes then.

#endif

} // namespace _V1
Expand Down
Loading