DPC++ Runtime
Runtime libraries for oneAPI DPC++
context.hpp
Go to the documentation of this file.
1 //==---------------- context.hpp - SYCL context ----------------------------==//
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 
12 #include <sycl/detail/cl.h>
13 #include <sycl/detail/common.hpp>
14 #include <sycl/detail/export.hpp>
17 #include <sycl/exception_list.hpp>
18 #include <sycl/info/info_desc.hpp>
19 #include <sycl/property_list.hpp>
20 #include <sycl/stl.hpp>
21 
22 // 4.6.2 Context class
23 
24 namespace sycl {
26 // Forward declarations
27 class device;
28 class platform;
29 namespace detail {
30 class context_impl;
31 }
32 template <backend Backend, class SyclT>
33 auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
34 
39 class __SYCL_EXPORT context {
40 public:
49  explicit context(const property_list &PropList = {});
50 
62  explicit context(const async_handler &AsyncHandler,
63  const property_list &PropList = {});
64 
74  explicit context(const device &Device, const property_list &PropList = {});
75 
88  explicit context(const device &Device, async_handler AsyncHandler,
89  const property_list &PropList = {});
90 
100  explicit context(const platform &Platform,
101  const property_list &PropList = {});
102 
115  explicit context(const platform &Platform, async_handler AsyncHandler,
116  const property_list &PropList = {});
117 
128  explicit context(const std::vector<device> &DeviceList,
129  const property_list &PropList = {});
130 
144  explicit context(const std::vector<device> &DeviceList,
145  async_handler AsyncHandler,
146  const property_list &PropList = {});
147 
156 #ifdef __SYCL_INTERNAL_API
157  context(cl_context ClContext, async_handler AsyncHandler = {});
158 #endif
159 
163  template <typename Param>
164  typename detail::is_context_info_desc<Param>::return_type get_info() const;
165 
166  context(const context &rhs) = default;
167 
168  context(context &&rhs) = default;
169 
170  context &operator=(const context &rhs) = default;
171 
172  context &operator=(context &&rhs) = default;
173 
174  bool operator==(const context &rhs) const { return impl == rhs.impl; }
175 
176  bool operator!=(const context &rhs) const { return !(*this == rhs); }
177 
181  template <typename propertyT> bool has_property() const noexcept;
182 
189  template <typename propertyT> propertyT get_property() const;
190 
196 #ifdef __SYCL_INTERNAL_API
197  cl_context get() const;
198 #endif
199 
204  "is_host() is deprecated as the host device is no longer supported.")
205  bool is_host() const;
206 
210  backend get_backend() const noexcept;
211 
215  platform get_platform() const;
216 
220  std::vector<device> get_devices() const;
221 
222 private:
224  context(std::shared_ptr<detail::context_impl> Impl);
225 
226  pi_native_handle getNative() const;
227 
228  std::shared_ptr<detail::context_impl> impl;
229 
230  template <backend Backend, class SyclT>
231  friend auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
232 
233  template <class Obj>
234  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
235 
236  template <class T>
237  friend
238  typename detail::add_pointer_t<typename decltype(T::impl)::element_type>
239  detail::getRawSyclObjImpl(const T &SyclObject);
240 
241  template <class T>
242  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
243 };
244 
245 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
246 } // namespace sycl
247 
248 namespace std {
249 template <> struct hash<sycl::context> {
250  size_t operator()(const sycl::context &Context) const {
251  return hash<std::shared_ptr<sycl::detail::context_impl>>()(
253  }
254 };
255 } // namespace std
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
property_list.hpp
sycl::_V1::errc::platform
@ platform
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:13
std::hash< sycl::context >::operator()
size_t operator()(const sycl::context &Context) const
Definition: context.hpp:250
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:13
sycl::_V1::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:250
backend_traits.hpp
sycl::_V1::get_native
auto get_native(const SyclT &Obj) -> backend_return_t< Backend, SyclT >
sycl::_V1::ext::oneapi::experimental::detail::get_property
static constexpr std::enable_if_t< HasProperty, typename FindCompileTimePropertyValueType< CTPropertyT, PropertiesT >::type > get_property()
Definition: properties.hpp:65
stl_type_traits.hpp
export.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl.h
Device
@ Device
Definition: usm_allocator.hpp:14
common.hpp
sycl::_V1::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:72
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
sycl::_V1::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:258
sycl::_V1::access::target::device
@ device
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:103
sycl::_V1::detail::is_context_info_desc
Definition: info_desc_helpers.hpp:19
std
Definition: accessor.hpp:3071
info_desc_helpers.hpp
sycl::_V1::async_handler
std::function< void(sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
sycl::_V1::context::operator!=
bool operator!=(const context &rhs) const
Definition: context.hpp:176
exception_list.hpp
sycl::_V1::context::operator==
bool operator==(const context &rhs) const
Definition: context.hpp:174
info_desc.hpp
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
sycl::_V1::detail::add_pointer_t
typename std::add_pointer< T >::type add_pointer_t
Definition: stl_type_traits.hpp:37
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:54
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39