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 {
18 inline namespace _V1 {
19 namespace ext::oneapi::cuda {
20 
21 // Implementation of ext_oneapi_cuda::make<device>
22 inline __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
24 }
25 
26 // Implementation of cuda::has_native_event
27 inline __SYCL_EXPORT bool has_native_event(event sycl_event) {
28  if (sycl_event.get_backend() == backend::ext_oneapi_cuda)
29  return get_native<backend::ext_oneapi_cuda>(sycl_event) != nullptr;
30 
31  return false;
32 }
33 
34 } // namespace ext::oneapi::cuda
35 
36 // CUDA context specialization
37 template <>
38 inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C)
40  // create a vector to be returned
42 
43  // get the native CUDA context from the SYCL object
44  auto native = reinterpret_cast<
46  C.getNative());
47  ret.push_back(native);
48 
49  return ret;
50 }
51 
52 // Specialisation of interop_handles get_native_context
53 template <>
55 interop_handle::get_native_context<backend::ext_oneapi_cuda>() const {
56 #ifndef __SYCL_DEVICE_ONLY__
57  return std::vector{reinterpret_cast<CUcontext>(getNativeContext())};
58 #else
59  // we believe this won't be ever called on device side
60  return {};
61 #endif
62 }
63 
64 // CUDA device specialization
65 template <>
66 inline device make_device<backend::ext_oneapi_cuda>(
69  for (auto &dev : devs) {
70  if (dev.get_backend() == backend::ext_oneapi_cuda &&
71  BackendObject == get_native<backend::ext_oneapi_cuda>(dev)) {
72  return dev;
73  }
74  }
75  pi_native_handle NativeHandle = static_cast<pi_native_handle>(BackendObject);
76  return ext::oneapi::cuda::make_device(NativeHandle);
77 }
78 
79 // CUDA event specialization
80 template <>
81 inline event make_event<backend::ext_oneapi_cuda>(
83  const context &TargetContext) {
84  return detail::make_event(detail::pi::cast<pi_native_handle>(BackendObject),
85  TargetContext, true,
86  /*Backend*/ backend::ext_oneapi_cuda);
87 }
88 
89 // CUDA queue specialization
90 template <>
91 inline queue make_queue<backend::ext_oneapi_cuda>(
93  const context &TargetContext, const async_handler Handler) {
94  int32_t nativeHandleDesc = 0;
95  const property_list &PropList{};
96  return detail::make_queue(detail::pi::cast<pi_native_handle>(BackendObject),
97  nativeHandleDesc, TargetContext, nullptr, true,
98  PropList, Handler,
99  /*Backend*/ backend::ext_oneapi_cuda);
100 }
101 
102 } // namespace _V1
103 } // namespace sycl
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:31
sycl::_V1::detail::make_queue
queue make_queue(pi_native_handle NativeHandle, int32_t nativeHandleDesc, const context &TargetContext, const device *TargetDevice, bool KeepOwnership, const property_list &PropList, const async_handler &Handler, backend Backend)
Definition: backend.cpp:107
context.hpp
sycl
Definition: access.hpp:18
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:44
sycl::_V1::info::device_type::gpu
@ gpu
sycl::_V1::backend::ext_oneapi_cuda
@ ext_oneapi_cuda
CUcontext
struct CUctx_st * CUcontext
Definition: backend_traits_cuda.hpp:25
sycl::_V1::backend_input_t
typename backend_traits< Backend >::template input_type< SyclType > backend_input_t
Definition: backend.hpp:83
sycl::_V1::ext::oneapi::cuda::has_native_event
bool has_native_event(event sycl_event)
Definition: cuda.hpp:27
backend_traits_cuda.hpp
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:119
sycl::_V1::event::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: event.cpp:105
sycl::_V1::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:87
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:59
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:198
sycl::_V1::device::get_devices
static std::vector< device > get_devices(info::device_type deviceType=info::device_type::all)
Query available SYCL devices.
Definition: device.cpp:52
__simd_abi
Definition: simd.hpp:718
backend.hpp
sycl::_V1::async_handler
std::function< void(sycl::exception_list)> async_handler
Definition: async_handler.hpp:19
sycl::_V1::ext::oneapi::cuda::make_device
device make_device(pi_native_handle NativeHandle)
Definition: cuda.hpp:22
sycl::_V1::detail::make_event
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:141
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51