Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct BufferInterop<backend::opencl, DataT, Dimensions, AllocatorT> {
}
};

#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
template <backend BackendName, typename DataT, int Dimensions,
typename AllocatorT>
auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
Expand All @@ -115,6 +116,7 @@ auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
PI_ERROR_INVALID_OPERATION);
return Obj.template getNative<BackendName>();
}
#endif
} // namespace detail

template <backend BackendName, class SyclObjectT>
Expand Down Expand Up @@ -147,6 +149,7 @@ auto get_native(const buffer<DataT, Dimensions, AllocatorT> &Obj)
return detail::get_native_buffer<BackendName>(Obj);
}

#if SYCL_BACKEND_OPENCL
template <>
inline backend_return_t<backend::opencl, event>
get_native<backend::opencl, event>(const event &Obj) {
Expand All @@ -164,6 +167,23 @@ get_native<backend::opencl, event>(const event &Obj) {
}
return ReturnValue;
}
#endif

#if SYCL_EXT_ONEAPI_BACKEND_CUDA
template <>
inline backend_return_t<backend::ext_oneapi_cuda, device>
get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
}
// CUDA uses a 32-bit int instead of an opaque pointer like other backends,
// so we need a specialization with static_cast instead of reinterpret_cast.
return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>>(
Obj.getNative());
}
#endif

// Native handle of an accessor should be accessed through interop_handler
template <backend BackendName, typename DataT, int Dimensions,
Expand Down
14 changes: 0 additions & 14 deletions sycl/include/sycl/ext/oneapi/experimental/backend/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ inline device make_device<backend::ext_oneapi_cuda>(
return ext::oneapi::cuda::make_device(NativeHandle);
}

template <>
backend_return_t<backend::ext_oneapi_cuda, device>
get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
}
// CUDA uses a 32-bit int instead of an opaque pointer like other backends,
// so we need a specialization with static_cast instead of reinterpret_cast.
return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>>(
Obj.getNative());
}

// CUDA event specialization
template <>
inline event make_event<backend::ext_oneapi_cuda>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// REQUIRES: cuda
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API %s -o %t.out
//
/// Also test the experimental CUDA interop interface
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -DSYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL %s -o %t.out
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API -DSYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL %s -o %t.out
// expected-no-diagnostics

// Test for experimental CUDA interop API
// Test for legacy and experimental CUDA interop API

#define SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL 1
#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
#include <sycl/ext/oneapi/experimental/backend/cuda.hpp>
#endif

#include <sycl/sycl.hpp>

using namespace sycl;
Expand Down Expand Up @@ -73,6 +79,7 @@ int main() {
// behavior of these template functions is defined by the SYCL backend
// specification document.

#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
backend_input_t<backend::ext_oneapi_cuda, device> InteropDeviceInput{
cu_device};
device InteropDevice =
Expand All @@ -85,6 +92,7 @@ int main() {
event InteropEvent = make_event<backend::ext_oneapi_cuda>(cu_event, Context);

queue InteropQueue = make_queue<backend::ext_oneapi_cuda>(cu_queue, Context);
#endif

return 0;
}