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 <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
12 #include <sycl/id.hpp> // for id
13 #include <sycl/range.hpp> // for range
14 
15 namespace sycl {
16 inline namespace _V1 {
17 
22 template <int Dimensions = 1> class nd_range {
23 public:
24  static constexpr int dimensions = Dimensions;
25 
26 private:
27  range<Dimensions> globalSize;
28  range<Dimensions> localSize;
29  id<Dimensions> offset;
30  static_assert(Dimensions >= 1 && Dimensions <= 3,
31  "nd_range can only be 1, 2, or 3 Dimensional.");
32 
33 public:
34  __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020")
35  nd_range(range<Dimensions> globalSize, range<Dimensions> localSize,
36  id<Dimensions> offset)
37  : globalSize(globalSize), localSize(localSize), offset(offset) {}
38 
40  : globalSize(globalSize), localSize(localSize), offset(id<Dimensions>()) {
41  }
42 
43  range<Dimensions> get_global_range() const { return globalSize; }
44 
45  range<Dimensions> get_local_range() const { return localSize; }
46 
47  range<Dimensions> get_group_range() const { return globalSize / localSize; }
48 
49  __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020")
50  id<Dimensions> get_offset() const { return offset; }
51 
52  // Common special member functions for by-value semantics
53  nd_range(const nd_range<Dimensions> &rhs) = default;
54  nd_range(nd_range<Dimensions> &&rhs) = default;
57  nd_range() = default;
58 
59  // Common member functions for by-value semantics
60  bool operator==(const nd_range<Dimensions> &rhs) const {
61  return (rhs.globalSize == this->globalSize) &&
62  (rhs.localSize == this->localSize) && (rhs.offset == this->offset);
63  }
64 
65  bool operator!=(const nd_range<Dimensions> &rhs) const {
66  return !(*this == rhs);
67  }
68 };
69 
70 } // namespace _V1
71 } // namespace sycl
A unique identifier of an item in an index space.
Definition: id.hpp:36
Defines the iteration domain of both the work-groups and the overall dispatch.
Definition: nd_range.hpp:22
nd_range< Dimensions > & operator=(nd_range< Dimensions > &&rhs)=default
bool operator==(const nd_range< Dimensions > &rhs) const
Definition: nd_range.hpp:60
range< Dimensions > get_global_range() const
Definition: nd_range.hpp:43
range< Dimensions > get_local_range() const
Definition: nd_range.hpp:45
nd_range(const nd_range< Dimensions > &rhs)=default
id< Dimensions > get_offset() const
Definition: nd_range.hpp:50
nd_range(range< Dimensions > globalSize, range< Dimensions > localSize)
Definition: nd_range.hpp:39
nd_range(nd_range< Dimensions > &&rhs)=default
static constexpr int dimensions
Definition: nd_range.hpp:24
nd_range< Dimensions > & operator=(const nd_range< Dimensions > &rhs)=default
range< Dimensions > get_group_range() const
Definition: nd_range.hpp:47
bool operator!=(const nd_range< Dimensions > &rhs) const
Definition: nd_range.hpp:65
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
Definition: accessor.hpp:3233
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:94
Definition: access.hpp:18