Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ bool context_impl::hasDevice(
return false;
}

DeviceImplPtr
context_impl::findMatchingDeviceImpl(RT::PiDevice &DevicePI) const {
for (device D : MDevices)
if (getSyclObjImpl(D)->getHandleRef() == DevicePI)
return getSyclObjImpl(D);

return nullptr;
}

pi_native_handle context_impl::getNative() const {
auto Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Expand Down
4 changes: 4 additions & 0 deletions sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class context_impl {
/// Returns true if and only if context contains the given device.
bool hasDevice(std::shared_ptr<detail::device_impl> Device) const;

/// Given a PiDevice, returns the matching shared_ptr<device_impl>
/// within this context. May return nullptr if no match discovered.
DeviceImplPtr findMatchingDeviceImpl(RT::PiDevice &DevicePI) const;

/// Gets the native handle of the SYCL context.
///
/// \return a native handle.
Expand Down
13 changes: 8 additions & 5 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ class queue_impl {

MQueues.push_back(pi::cast<RT::PiQueue>(PiQueue));

RT::PiDevice Device{};
RT::PiDevice DevicePI{};
const detail::plugin &Plugin = getPlugin();
// TODO catch an exception and put it to list of asynchronous exceptions
Plugin.call<PiApiKind::piQueueGetInfo>(MQueues[0], PI_QUEUE_INFO_DEVICE,
sizeof(Device), &Device, nullptr);
MDevice =
DeviceImplPtr(new device_impl(Device, Context->getPlatformImpl()));
Plugin.call<PiApiKind::piQueueGetInfo>(
MQueues[0], PI_QUEUE_INFO_DEVICE, sizeof(DevicePI), &DevicePI, nullptr);
MDevice = MContext->findMatchingDeviceImpl(DevicePI);
if (MDevice == nullptr)
throw sycl::exception(
make_error_code(errc::invalid),
"Device provided by native Queue not found in Context.");
}

~queue_impl() {
Expand Down