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 
18 #include <CL/sycl/stl.hpp>
19 
20 // 4.6.2 Context class
21 
23 namespace sycl {
24 // Forward declarations
25 class device;
26 class platform;
27 namespace detail {
28 class context_impl;
29 }
30 
35 class __SYCL_EXPORT context {
36 public:
45  explicit context(const property_list &PropList = {});
46 
58  explicit context(const async_handler &AsyncHandler,
59  const property_list &PropList = {});
60 
70  explicit context(const device &Device, const property_list &PropList = {});
71 
84  explicit context(const device &Device, async_handler AsyncHandler,
85  const property_list &PropList = {});
86 
96  explicit context(const platform &Platform,
97  const property_list &PropList = {});
98 
111  explicit context(const platform &Platform, async_handler AsyncHandler,
112  const property_list &PropList = {});
113 
124  explicit context(const std::vector<device> &DeviceList,
125  const property_list &PropList = {});
126 
140  explicit context(const std::vector<device> &DeviceList,
141  async_handler AsyncHandler,
142  const property_list &PropList = {});
143 
152 #ifdef __SYCL_INTERNAL_API
153  context(cl_context ClContext, async_handler AsyncHandler = {});
154 #endif
155 
159  template <info::context param>
161  get_info() const;
162 
163  context(const context &rhs) = default;
164 
165  context(context &&rhs) = default;
166 
167  context &operator=(const context &rhs) = default;
168 
169  context &operator=(context &&rhs) = default;
170 
171  bool operator==(const context &rhs) const { return impl == rhs.impl; }
172 
173  bool operator!=(const context &rhs) const { return !(*this == rhs); }
174 
178  template <typename propertyT> bool has_property() const;
179 
186  template <typename propertyT> propertyT get_property() const;
187 
193 #ifdef __SYCL_INTERNAL_API
194  cl_context get() const;
195 #endif
196 
200  bool is_host() const;
201 
205  backend get_backend() const noexcept;
206 
210  platform get_platform() const;
211 
215  std::vector<device> get_devices() const;
216 
220  template <backend Backend>
221  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
222  backend_return_t<Backend, context> get_native() const {
223  return reinterpret_cast<backend_return_t<Backend, context>>(getNative());
224  }
225 
226 private:
228  context(std::shared_ptr<detail::context_impl> Impl);
229 
230  pi_native_handle getNative() const;
231 
232  std::shared_ptr<detail::context_impl> impl;
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 } // namespace sycl
246 } // __SYCL_INLINE_NAMESPACE(cl)
247 
248 namespace std {
249 template <> struct hash<cl::sycl::context> {
250  size_t operator()(const cl::sycl::context &Context) const {
251  return hash<std::shared_ptr<cl::sycl::detail::context_impl>>()(
253  }
254 };
255 } // namespace std
cl::sycl::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:213
cl::sycl::backend
backend
Definition: backend_types.hpp:21
property_list.hpp
cl::sycl::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:68
cl::sycl::info::device
device
Definition: info_desc.hpp:53
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:119
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:221
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
sycl
Definition: invoke_simd.hpp:68
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
backend_traits.hpp
stl_type_traits.hpp
export.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::context::operator!=
bool operator!=(const context &rhs) const
Definition: context.hpp:173
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::add_pointer_t
typename std::add_pointer< T >::type add_pointer_t
Definition: stl_type_traits.hpp:37
cl::sycl::detail::usm::free
void free(void *Ptr, const context &Ctxt, const code_location &CL)
Definition: usm_impl.cpp:181
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
cl::sycl::context::operator==
bool operator==(const context &rhs) const
Definition: context.hpp:171
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
std
Definition: accessor.hpp:2616
cl::sycl::ext::oneapi::experimental::detail::get_property
static constexpr std::enable_if_t< HasProperty, typename FindCompileTimePropertyValueType< CTPropertyT, PropertiesT >::type > get_property()
Definition: properties.hpp:65
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
std::hash< cl::sycl::context >::operator()
size_t operator()(const cl::sycl::context &Context) const
Definition: context.hpp:250
exception_list.hpp
info_desc.hpp
common.hpp
cl::sycl::info::platform
platform
Definition: info_desc.hpp:31
cl::sycl::async_handler
std::function< void(cl::sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12