DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 <CL/sycl/id.hpp>
12 #include <CL/sycl/range.hpp>
13 #include <stdexcept>
14 #include <type_traits>
15 
17 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;
52  nd_range<dimensions> &operator=(const nd_range<dimensions> &rhs) = default;
53  nd_range<dimensions> &operator=(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 } // namespace sycl
68 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::nd_range
Defines the iteration domain of both the work-groups and the overall dispatch.
Definition: nd_range.hpp:23
cl::sycl::nd_range::nd_range
nd_range(range< dimensions > globalSize, range< dimensions > localSize)
Definition: nd_range.hpp:36
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:56
cl::sycl::nd_range::operator!=
bool operator!=(const nd_range< dimensions > &rhs) const
Definition: nd_range.hpp:62
cl::sycl::id
A unique identifier of an item in an index space.
Definition: array.hpp:17
cl::sycl::nd_range::get_group_range
range< dimensions > get_group_range() const
Definition: nd_range.hpp:44
cl::sycl::nd_range::operator==
bool operator==(const nd_range< dimensions > &rhs) const
Definition: nd_range.hpp:57
id.hpp
cl::sycl::range
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: buffer.hpp:24
range.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::nd_range::get_global_range
range< dimensions > get_global_range() const
Definition: nd_range.hpp:40
cl::sycl::nd_range::get_local_range
range< dimensions > get_local_range() const
Definition: nd_range.hpp:42
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12