DPC++ Runtime
Runtime libraries for oneAPI DPC++
interop_handle.cpp
Go to the documentation of this file.
1 //==------------ interop_handle.cpp --- SYCL interop handle ----------------==//
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 
10 #include <detail/backend_impl.hpp>
11 #include <detail/context_impl.hpp>
12 #include <detail/device_impl.hpp>
13 #include <detail/queue_impl.hpp>
14 #include <sycl/exception.hpp>
15 #include <sycl/interop_handle.hpp>
16 
17 #include <algorithm>
18 
19 namespace sycl {
21 
22 backend interop_handle::get_backend() const noexcept {
23  return detail::getImplBackend(MQueue);
24 }
25 
26 pi_native_handle interop_handle::getNativeMem(detail::Requirement *Req) const {
27  auto Iter = std::find_if(std::begin(MMemObjs), std::end(MMemObjs),
28  [=](ReqToMem Elem) { return (Elem.first == Req); });
29 
30  if (Iter == std::end(MMemObjs)) {
31  throw invalid_object_error("Invalid memory object used inside interop",
32  PI_ERROR_INVALID_MEM_OBJECT);
33  }
34 
35  auto Plugin = MQueue->getPlugin();
36  pi_native_handle Handle;
37  Plugin.call<detail::PiApiKind::piextMemGetNativeHandle>(Iter->second,
38  &Handle);
39  return Handle;
40 }
41 
42 pi_native_handle interop_handle::getNativeDevice() const {
43  return MDevice->getNative();
44 }
45 
46 pi_native_handle interop_handle::getNativeContext() const {
47  return MContext->getNative();
48 }
49 
50 pi_native_handle interop_handle::getNativeQueue() const {
51  return MQueue->getNative();
52 }
53 
54 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
55 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
backend getImplBackend(const T &Impl)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
uintptr_t pi_native_handle
Definition: pi.h:109
pi_result piextMemGetNativeHandle(pi_mem mem, pi_native_handle *nativeHandle)
Gets the native handle of a PI mem object.