DPC++ Runtime
Runtime libraries for oneAPI DPC++
context_impl.hpp
Go to the documentation of this file.
1 //==---------------- context_impl.hpp - SYCL context ------------*- C++-*---==//
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
12 #include <CL/sycl/detail/pi.hpp>
16 #include <CL/sycl/stl.hpp>
17 #include <detail/device_impl.hpp>
19 #include <detail/platform_impl.hpp>
21 
22 #include <map>
23 #include <memory>
24 
26 namespace sycl {
27 // Forward declaration
28 class device;
29 namespace detail {
30 using PlatformImplPtr = std::shared_ptr<detail::platform_impl>;
31 class context_impl {
32 public:
42  context_impl(const device &Device, async_handler AsyncHandler,
43  const property_list &PropList);
44 
57  context_impl(const std::vector<cl::sycl::device> DeviceList,
58  async_handler AsyncHandler, const property_list &PropList);
59 
70  const plugin &Plugin);
71 
72  ~context_impl();
73 
77  template <typename propertyT> bool has_property() const {
78  return MPropList.has_property<propertyT>();
79  }
80 
87  template <typename propertyT> propertyT get_property() const {
88  return MPropList.get_property<propertyT>();
89  }
90 
94  cl_context get() const;
95 
99  bool is_host() const;
100 
104  const async_handler &get_async_handler() const;
105 
107  const plugin &getPlugin() const { return MPlatform->getPlugin(); }
108 
110  PlatformImplPtr getPlatformImpl() const { return MPlatform; }
111 
115  template <info::context param>
117  get_info() const;
118 
127  RT::PiContext &getHandleRef();
128 
137  const RT::PiContext &getHandleRef() const;
138 
141  const std::vector<device> &getDevices() const { return MDevices; }
142 
143  using CachedLibProgramsT =
144  std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>;
145 
160  return {MCachedLibPrograms, MCachedLibProgramsMutex};
161  }
162 
163  KernelProgramCache &getKernelProgramCache() const;
164 
166  bool hasDevice(std::shared_ptr<detail::device_impl> Device) const;
167 
171  pi_native_handle getNative() const;
172 
173  // Returns true if buffer_location property is supported by devices
174  bool isBufferLocationSupported() const;
175 
176  enum PropertySupport { NotSupported = 0, Supported = 1, NotChecked = 2 };
177 
178 private:
179  async_handler MAsyncHandler;
180  std::vector<device> MDevices;
181  RT::PiContext MContext;
182  PlatformImplPtr MPlatform;
183  property_list MPropList;
184  bool MHostContext;
185  CachedLibProgramsT MCachedLibPrograms;
186  std::mutex MCachedLibProgramsMutex;
187  mutable KernelProgramCache MKernelProgramCache;
188  mutable PropertySupport MSupportBufferLocationByDevices;
189 };
190 
191 } // namespace detail
192 } // namespace sycl
193 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::Locked
Represents a reference to value with appropriate lock acquired.
Definition: locked.hpp:24
property_list.hpp
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::detail::KernelProgramCache
Definition: kernel_program_cache.hpp:31
stl.hpp
kernel_program_cache.hpp
os_util.hpp
cl::sycl::detail::context_impl::get_property
propertyT get_property() const
Gets the specified property of this context_impl.
Definition: context_impl.hpp:87
sycl
Definition: invoke_simd.hpp:68
device_impl.hpp
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::detail::context_impl::getPlatformImpl
PlatformImplPtr getPlatformImpl() const
Definition: context_impl.hpp:110
cl::sycl::detail::context_impl::has_property
bool has_property() const
Checks if this context_impl has a property of type propertyT.
Definition: context_impl.hpp:77
cl::sycl::detail::pi::PiContext
::pi_context PiContext
Definition: pi.hpp:106
pi.hpp
platform_impl.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:36
cl::sycl::detail::context_impl::PropertySupport
PropertySupport
Definition: context_impl.hpp:176
Device
@ Device
Definition: usm_allocator.hpp:14
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::context_impl
Definition: context_impl.hpp:31
_pi_program
Implementation of PI Program on CUDA Module object.
Definition: pi_cuda.hpp:718
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
program_manager.hpp
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:98
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::context_impl::getDevices
const std::vector< device > & getDevices() const
Unlike ‘get_info<info::context::devices>’, this function returns a reference.
Definition: context_impl.hpp:141
cl::sycl::detail::PlatformImplPtr
std::shared_ptr< detail::platform_impl > PlatformImplPtr
Definition: context_impl.hpp:30
cl::sycl::detail::context_impl::acquireCachedLibPrograms
Locked< CachedLibProgramsT > acquireCachedLibPrograms()
In contrast to user programs, which are compiled from user code, library programs come from the SYCL ...
Definition: context_impl.hpp:159
exception_list.hpp
info_desc.hpp
cl::sycl::detail::context_impl::getPlugin
const plugin & getPlugin() const
Definition: context_impl.hpp:107
common.hpp
cl::sycl::info::device
device
Definition: info_desc.hpp:53
cl::sycl::async_handler
std::function< void(cl::sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
_pi_context
PI context mapping to a CUDA context object.
Definition: pi_cuda.hpp:159
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12