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 {
20 inline namespace _V1 {
21 
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;
38  Iter->second, MDevice->getHandleRef(), &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 
51 interop_handle::getNativeQueue(int32_t &NativeHandleDesc) const {
52  return MQueue->getNative(NativeHandleDesc);
53 }
54 
55 } // namespace _V1
56 } // namespace sycl
backend get_backend() const noexcept
Returns a backend associated with the queue associated with this interop_handle.
backend getImplBackend(const T &Impl)
Definition: access.hpp:18
pi_result piextMemGetNativeHandle(pi_mem mem, pi_device dev, pi_native_handle *nativeHandle)
Gets the native handle of a PI mem object.
Definition: pi_cuda.cpp:236
uintptr_t pi_native_handle
Definition: pi.h:226
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324