DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 
155  std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram> &
157  return MCachedLibPrograms;
158  }
159 
160  KernelProgramCache &getKernelProgramCache() const;
161 
163  bool hasDevice(std::shared_ptr<detail::device_impl> Device) const;
164 
168  pi_native_handle getNative() const;
169 
170 private:
171  async_handler MAsyncHandler;
172  std::vector<device> MDevices;
173  RT::PiContext MContext;
174  PlatformImplPtr MPlatform;
175  property_list MPropList;
176  bool MHostContext;
177  std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>
178  MCachedLibPrograms;
179  mutable KernelProgramCache MKernelProgramCache;
180 };
181 
182 } // namespace detail
183 } // namespace sycl
184 } // __SYCL_INLINE_NAMESPACE(cl)
property_list.hpp
cl::sycl::info::device
device
Definition: info_desc.hpp:50
cl::sycl::info::param_traits
Definition: info_desc.hpp:304
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
detail
Definition: pi_opencl.cpp:86
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:35
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:523
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:89
program_manager.hpp
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:73
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
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::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:148
cl::sycl::detail::context_impl::getCachedLibPrograms
std::map< std::pair< DeviceLibExt, RT::PiDevice >, RT::PiProgram > & getCachedLibPrograms()
In contrast to user programs, which are compiled from user code, library programs come from the SYCL ...
Definition: context_impl.hpp:156
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12