DPC++ Runtime
Runtime libraries for oneAPI DPC++
cuda.hpp
Go to the documentation of this file.
1 //==--------- cuda.hpp - SYCL CUDA backend ---------------------------------==//
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 
9 #pragma once
10 
11 #include <sycl/backend.hpp>
12 #include <sycl/context.hpp>
14 
15 #include <vector>
16 
17 namespace sycl {
19 namespace ext {
20 namespace oneapi {
21 namespace cuda {
22 
23 // Implementation of ext_oneapi_cuda::make<device>
24 inline __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
25  return sycl::detail::make_device(NativeHandle, backend::ext_oneapi_cuda);
26 }
27 
28 // Implementation of cuda::has_native_event
29 inline __SYCL_EXPORT bool has_native_event(event sycl_event) {
30  if (sycl_event.get_backend() == backend::ext_oneapi_cuda)
31  return get_native<backend::ext_oneapi_cuda>(sycl_event) != nullptr;
32 
33  return false;
34 }
35 
36 } // namespace cuda
37 } // namespace oneapi
38 } // namespace ext
39 
40 // CUDA context specialization
41 template <>
42 inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C)
44  // create a vector to be returned
46 
47  // get the native CUDA context from the SYCL object
48  auto native = reinterpret_cast<
50  C.getNative());
51  ret.push_back(native);
52 
53  return ret;
54 }
55 
56 // Specialisation of interop_handles get_native_context
57 template <>
58 inline backend_return_t<backend::ext_oneapi_cuda, context>
59 interop_handle::get_native_context<backend::ext_oneapi_cuda>() const {
60 #ifndef __SYCL_DEVICE_ONLY__
61  return std::vector{reinterpret_cast<CUcontext>(getNativeContext())};
62 #else
63  // we believe this won't be ever called on device side
64  return {};
65 #endif
66 }
67 
68 // CUDA device specialization
69 template <>
70 inline device make_device<backend::ext_oneapi_cuda>(
72  pi_native_handle NativeHandle = static_cast<pi_native_handle>(BackendObject);
73  return ext::oneapi::cuda::make_device(NativeHandle);
74 }
75 
76 // CUDA event specialization
77 template <>
78 inline event make_event<backend::ext_oneapi_cuda>(
80  const context &TargetContext) {
81  return detail::make_event(detail::pi::cast<pi_native_handle>(BackendObject),
82  TargetContext, true,
83  /*Backend*/ backend::ext_oneapi_cuda);
84 }
85 
86 // CUDA queue specialization
87 template <>
88 inline queue make_queue<backend::ext_oneapi_cuda>(
90  const context &TargetContext, const async_handler Handler) {
91  return detail::make_queue(detail::pi::cast<pi_native_handle>(BackendObject),
92  TargetContext, nullptr, true, Handler,
93  /*Backend*/ backend::ext_oneapi_cuda);
94 }
95 
96 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
97 } // namespace sycl
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:13
context.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:13
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:38
CUcontext
struct CUctx_st * CUcontext
Definition: backend_traits_cuda.hpp:26
sycl::_V1::backend_input_t
typename backend_traits< Backend >::template input_type< SyclType > backend_input_t
Definition: backend.hpp:68
sycl::_V1::opencl::make_queue
queue make_queue(const context &Context, pi_native_handle InteropHandle)
Definition: opencl.cpp:41
sycl::_V1::ext::oneapi::cuda::has_native_event
bool has_native_event(event sycl_event)
Definition: cuda.hpp:29
backend_traits_cuda.hpp
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:86
sycl::_V1::event::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: event.cpp:99
sycl::_V1::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:72
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:103
__simd_abi
Definition: simd.hpp:718
backend.hpp
sycl::_V1::async_handler
std::function< void(sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
sycl::_V1::ext::oneapi::cuda::make_device
device make_device(pi_native_handle NativeHandle)
Definition: cuda.hpp:24
sycl::_V1::detail::make_event
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:112
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39