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 ur_native_handle_t
27 interop_handle::getNativeMem(detail::Requirement *Req) const {
28  auto Iter = std::find_if(std::begin(MMemObjs), std::end(MMemObjs),
29  [=](ReqToMem Elem) { return (Elem.first == Req); });
30 
31  if (Iter == std::end(MMemObjs)) {
33  "Invalid memory object used inside interop");
34  }
35 
36  auto Plugin = MQueue->getPlugin();
37  ur_native_handle_t Handle;
38  Plugin->call(urMemGetNativeHandle, Iter->second, MDevice->getHandleRef(),
39  &Handle);
40  return Handle;
41 }
42 
43 ur_native_handle_t interop_handle::getNativeDevice() const {
44  return MDevice->getNative();
45 }
46 
47 ur_native_handle_t interop_handle::getNativeContext() const {
48  return MContext->getNative();
49 }
50 
51 ur_native_handle_t
52 interop_handle::getNativeQueue(int32_t &NativeHandleDesc) const {
53  return MQueue->getNative(NativeHandleDesc);
54 }
55 
56 } // namespace _V1
57 } // namespace sycl
backend get_backend() const noexcept
Returns a backend associated with the queue associated with this interop_handle.
backend getImplBackend(const T &Impl)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:65
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324