DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 BackendName>
221  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
222  auto get_native() const -> typename interop<BackendName, context>::type {
223  return reinterpret_cast<typename interop<BackendName, context>::type>(
224  getNative());
225  }
226 
227 private:
229  context(std::shared_ptr<detail::context_impl> Impl);
230 
231  pi_native_handle getNative() const;
232 
233  std::shared_ptr<detail::context_impl> impl;
234  template <class Obj>
235  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
236 
237  template <class T>
238  friend
239  typename detail::add_pointer_t<typename decltype(T::impl)::element_type>
240  detail::getRawSyclObjImpl(const T &SyclObject);
241 
242  template <class T>
243  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
244 };
245 
246 } // namespace sycl
247 } // __SYCL_INLINE_NAMESPACE(cl)
248 
249 namespace std {
250 template <> struct hash<cl::sycl::context> {
251  size_t operator()(const cl::sycl::context &Context) const {
252  return hash<std::shared_ptr<cl::sycl::detail::context_impl>>()(
254  }
255 };
256 } // namespace std
cl::sycl::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:191
cl::sycl::backend
backend
Definition: backend_types.hpp:21
property_list.hpp
type
cl::sycl::info::device
device
Definition: info_desc.hpp:49
cl::sycl::info::param_traits
Definition: info_desc.hpp:297
cl::sycl::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:69
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:199
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:25
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:34
cl::sycl::detail::usm::free
void free(void *Ptr, const context &Ctxt)
Definition: usm_impl.cpp:132
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
cl::sycl::interop
Definition: backend_types.hpp:35
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:72
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::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:182
backend_types.hpp
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:33
std
Definition: accessor.hpp:2358
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:251
exception_list.hpp
info_desc.hpp
common.hpp
cl::sycl::info::platform
platform
Definition: info_desc.hpp:29
cl::sycl::info::context
context
Definition: info_desc.hpp:40
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