DPC++ Runtime
Runtime libraries for oneAPI DPC++
nd_range.hpp
Go to the documentation of this file.
1 //==-------- nd_range.hpp --- SYCL iteration nd_range ----------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <stdexcept>
12 #include <sycl/id.hpp>
13 #include <sycl/range.hpp>
14 #include <type_traits>
15 
16 namespace sycl {
18 
23 template <int dimensions = 1> class nd_range {
24  range<dimensions> globalSize;
25  range<dimensions> localSize;
26  id<dimensions> offset;
27  static_assert(dimensions >= 1 && dimensions <= 3,
28  "nd_range can only be 1, 2, or 3 dimensional.");
29 
30 public:
31  __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020")
32  nd_range(range<dimensions> globalSize, range<dimensions> localSize,
33  id<dimensions> offset)
34  : globalSize(globalSize), localSize(localSize), offset(offset) {}
35 
37  : globalSize(globalSize), localSize(localSize), offset(id<dimensions>()) {
38  }
39 
40  range<dimensions> get_global_range() const { return globalSize; }
41 
42  range<dimensions> get_local_range() const { return localSize; }
43 
44  range<dimensions> get_group_range() const { return globalSize / localSize; }
45 
46  __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020")
47  id<dimensions> get_offset() const { return offset; }
48 
49  // Common special member functions for by-value semantics
50  nd_range(const nd_range<dimensions> &rhs) = default;
51  nd_range(nd_range<dimensions> &&rhs) = default;
54  nd_range() = default;
55 
56  // Common member functions for by-value semantics
57  bool operator==(const nd_range<dimensions> &rhs) const {
58  return (rhs.globalSize == this->globalSize) &&
59  (rhs.localSize == this->localSize) && (rhs.offset == this->offset);
60  }
61 
62  bool operator!=(const nd_range<dimensions> &rhs) const {
63  return !(*this == rhs);
64  }
65 };
66 
67 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
68 } // namespace sycl
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:96
sycl::_V1::nd_range::get_group_range
range< dimensions > get_group_range() const
Definition: nd_range.hpp:44
sycl::_V1::nd_range::nd_range
nd_range(range< dimensions > globalSize, range< dimensions > localSize)
Definition: nd_range.hpp:36
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::nd_range::operator==
bool operator==(const nd_range< dimensions > &rhs) const
Definition: nd_range.hpp:57
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::id
A unique identifier of an item in an index space.
Definition: array.hpp:17
id.hpp
sycl::_V1::range
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: buffer.hpp:28
sycl::_V1::ext::oneapi::experimental::operator=
annotated_arg & operator=(annotated_arg &)=default
range.hpp
sycl::_V1::nd_range::get_global_range
range< dimensions > get_global_range() const
Definition: nd_range.hpp:40
sycl::_V1::nd_range
Defines the iteration domain of both the work-groups and the overall dispatch.
Definition: uniform.hpp:36
sycl::_V1::nd_range::get_local_range
range< dimensions > get_local_range() const
Definition: nd_range.hpp:42
sycl::_V1::nd_range::operator!=
bool operator!=(const nd_range< dimensions > &rhs) const
Definition: nd_range.hpp:62
sycl::_V1::errc::nd_range
@ nd_range
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:57