45 :
context(Platform.get_devices(), PropList) {}
49 :
context(Platform.get_devices(), AsyncHandler, PropList) {}
57 if (DeviceList.empty()) {
58 throw invalid_parameter_error(
"DeviceList is empty.",
59 PI_ERROR_INVALID_VALUE);
61 auto NonHostDeviceIter = std::find_if_not(
62 DeviceList.begin(), DeviceList.end(), [&](
const device &CurrentDevice) {
63 return detail::getSyclObjImpl(CurrentDevice)->is_host();
65 if (NonHostDeviceIter == DeviceList.end())
66 impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,
69 const device &NonHostDevice = *NonHostDeviceIter;
70 const auto &NonHostPlatform =
72 if (
std::any_of(DeviceList.begin(), DeviceList.end(),
73 [&](
const device &CurrentDevice) {
75 detail::getSyclObjImpl(CurrentDevice)->is_host() ||
76 (detail::getSyclObjImpl(CurrentDevice.get_platform())
77 ->getHandleRef() != NonHostPlatform));
79 throw invalid_parameter_error(
80 "Can't add devices across platforms to a single context.",
81 PI_ERROR_INVALID_DEVICE);
83 impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
88 const auto &Plugin = RT::getPlugin<backend::opencl>();
89 impl = std::make_shared<detail::context_impl>(
90 detail::pi::cast<detail::RT::PiContext>(ClContext), AsyncHandler, Plugin);
93 template <
typename Param>
94 typename detail::is_context_info_desc<Param>::return_type
96 return impl->template get_info<Param>();
99 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
100 template __SYCL_EXPORT ReturnT context::get_info<info::DescType::Desc>() \
103 #include <sycl/info/context_traits.def>
105 #undef __SYCL_PARAM_TRAITS_SPEC
107 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
109 __SYCL_EXPORT bool context::has_property<param_type>() const noexcept { \
110 return impl->has_property<param_type>(); \
112 #include <sycl/detail/properties_traits.def>
114 #undef __SYCL_PARAM_TRAITS_SPEC
116 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
118 __SYCL_EXPORT param_type context::get_property<param_type>() const { \
119 return impl->get_property<param_type>(); \
121 #include <sycl/detail/properties_traits.def>
123 #undef __SYCL_PARAM_TRAITS_SPEC
127 bool context::is_host()
const {
128 bool IsHost = impl->is_host();
129 assert(!IsHost &&
"context::is_host should not be called in implementation.");
136 return impl->get_info<info::context::platform>();
140 return impl->get_info<info::context::devices>();
143 context::context(std::shared_ptr<detail::context_impl> Impl) : impl(Impl) {}