27 inline namespace _V1 {
43 :
context(Platform.get_devices(), PropList) {}
47 :
context(Platform.get_devices(), AsyncHandler, PropList) {}
55 if (DeviceList.empty()) {
56 throw invalid_parameter_error(
"DeviceList is empty.",
57 PI_ERROR_INVALID_VALUE);
59 auto NonHostDeviceIter = std::find_if_not(
60 DeviceList.begin(), DeviceList.end(), [&](
const device &CurrentDevice) {
61 return detail::getSyclObjImpl(CurrentDevice)->is_host();
63 if (NonHostDeviceIter == DeviceList.end())
64 impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,
67 const device &NonHostDevice = *NonHostDeviceIter;
68 const auto &NonHostPlatform =
70 if (
std::any_of(DeviceList.begin(), DeviceList.end(),
71 [&](
const device &CurrentDevice) {
73 detail::getSyclObjImpl(CurrentDevice)->is_host() ||
74 (detail::getSyclObjImpl(CurrentDevice.get_platform())
75 ->getHandleRef() != NonHostPlatform));
77 throw invalid_parameter_error(
78 "Can't add devices across platforms to a single context.",
79 PI_ERROR_INVALID_DEVICE);
81 impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
86 const auto &Plugin = sycl::detail::pi::getPlugin<backend::opencl>();
87 impl = std::make_shared<detail::context_impl>(
88 detail::pi::cast<sycl::detail::pi::PiContext>(ClContext), AsyncHandler,
92 template <
typename Param>
93 typename detail::is_context_info_desc<Param>::return_type
95 return impl->template get_info<Param>();
98 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
99 template __SYCL_EXPORT ReturnT context::get_info<info::DescType::Desc>() \
102 #include <sycl/info/context_traits.def>
104 #undef __SYCL_PARAM_TRAITS_SPEC
106 template <
typename Param>
109 return impl->get_backend_info<Param>();
112 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \
113 template __SYCL_EXPORT ReturnT \
114 context::get_backend_info<info::DescType::Desc>() const;
116 #include <sycl/info/sycl_backend_traits.def>
118 #undef __SYCL_PARAM_TRAITS_SPEC
120 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
122 __SYCL_EXPORT bool context::has_property<param_type>() const noexcept { \
123 return impl->has_property<param_type>(); \
125 #include <sycl/detail/properties_traits.def>
127 #undef __SYCL_PARAM_TRAITS_SPEC
129 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
131 __SYCL_EXPORT param_type context::get_property<param_type>() const { \
132 return impl->get_property<param_type>(); \
134 #include <sycl/detail/properties_traits.def>
136 #undef __SYCL_PARAM_TRAITS_SPEC
140 bool context::is_host()
const {
141 bool IsHost = impl->is_host();
142 assert(!IsHost &&
"context::is_host should not be called in implementation.");
149 return impl->get_info<info::context::platform>();
153 return impl->get_info<info::context::devices>();
156 context::context(std::shared_ptr<detail::context_impl> Impl) : impl(Impl) {}
The context class represents a SYCL context on which kernel functions may be executed.
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
detail::is_context_info_desc< Param >::return_type get_info() const
Constructs a SYCL context instance from OpenCL cl_context.
context(const property_list &PropList={})
Constructs a SYCL context instance using an instance of default_selector.
platform get_platform() const
Gets platform associated with this SYCL context.
backend get_backend() const noexcept
Returns the backend associated with this context.
detail::is_backend_info_desc< Param >::return_type get_backend_info() const
Queries this SYCL context for SYCL backend-specific information.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
platform get_platform() const
Get associated SYCL platform.
Objects of the property_list class are containers for the SYCL properties.
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
void defaultAsyncHandler(exception_list Exceptions)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
std::function< void(sycl::exception_list)> async_handler
uintptr_t pi_native_handle
bool any_of(const simd_mask< _Tp, _Abi > &) noexcept
_Abi const simd< _Tp, _Abi > & noexcept