-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][CUDA] Add experimental context and device interop #6202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c6e32c2
[SYCL][CUDA] Add context interop specialization
npmiller 91b5d61
[SYCL] Unify interop implementations
npmiller 04886c3
Merge commit 'c6e32c228c97ef1c5ef11108377112e6f27ef39a' into cuda_exp…
2dd2f6f
Merge commit '91b5d61551170e4e4fdf3b1f5fab4950e2d49d8d' into cuda_exp…
736b5c0
Add experimental cuda interop with ctx and device
6948ab8
Update based on feedback
ebe0bb6
Add retain to ContextCreateWithNativeHandle
f2c57b1
Add ownership to cuda _pi_context
094a7fb
Update based on feedback
6825691
Update cuda_piContextRelease branches and adjust comments
e057f07
Merge branch 'sycl' of https://github.com/AidanBeltonS/llvm into cuda…
8367bd0
Change pi error code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
sycl/include/sycl/ext/oneapi/experimental/backend/backend_traits_cuda.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
//===------- backend_traits_cuda.hpp - Backend traits for CUDA ---*-C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the specializations of the sycl::detail::interop, | ||
// sycl::detail::BackendInput and sycl::detail::BackendReturn class templates | ||
// for the CUDA backend but there is no sycl::detail::InteropFeatureSupportMap | ||
// specialization for the CUDA backend. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <CL/sycl/accessor.hpp> | ||
#include <CL/sycl/context.hpp> | ||
#include <CL/sycl/detail/backend_traits.hpp> | ||
#include <CL/sycl/device.hpp> | ||
#include <CL/sycl/event.hpp> | ||
#include <CL/sycl/kernel_bundle.hpp> | ||
#include <CL/sycl/queue.hpp> | ||
|
||
#include <vector> | ||
|
||
typedef int CUdevice; | ||
typedef struct CUctx_st *CUcontext; | ||
typedef struct CUstream_st *CUstream; | ||
typedef struct CUevent_st *CUevent; | ||
typedef struct CUmod_st *CUmodule; | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
namespace detail { | ||
|
||
// TODO the interops for context, device, event, platform and program | ||
// may be removed after removing the deprecated 'get_native()' methods | ||
// from the corresponding classes. The interop<backend, queue> specialization | ||
// is also used in the get_queue() method of the deprecated class | ||
// interop_handler and also can be removed after API cleanup. | ||
template <> struct interop<backend::ext_oneapi_cuda, context> { | ||
using type = CUcontext; | ||
}; | ||
|
||
template <> struct interop<backend::ext_oneapi_cuda, device> { | ||
using type = CUdevice; | ||
}; | ||
|
||
template <> struct interop<backend::ext_oneapi_cuda, event> { | ||
using type = CUevent; | ||
}; | ||
|
||
template <> struct interop<backend::ext_oneapi_cuda, queue> { | ||
using type = CUstream; | ||
}; | ||
|
||
template <> struct interop<backend::ext_oneapi_cuda, platform> { | ||
using type = std::vector<CUdevice>; | ||
}; | ||
|
||
#ifdef __SYCL_INTERNAL_API | ||
template <> struct interop<backend::ext_oneapi_cuda, program> { | ||
using type = CUmodule; | ||
}; | ||
#endif | ||
|
||
template <typename DataT, int Dimensions, typename AllocatorT> | ||
struct BackendInput<backend::ext_oneapi_cuda, | ||
buffer<DataT, Dimensions, AllocatorT>> { | ||
using type = DataT *; | ||
}; | ||
|
||
template <typename DataT, int Dimensions, typename AllocatorT> | ||
struct BackendReturn<backend::ext_oneapi_cuda, | ||
buffer<DataT, Dimensions, AllocatorT>> { | ||
using type = DataT *; | ||
}; | ||
|
||
template <> struct BackendInput<backend::ext_oneapi_cuda, context> { | ||
using type = CUcontext; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, context> { | ||
using type = std::vector<CUcontext>; | ||
}; | ||
|
||
template <> struct BackendInput<backend::ext_oneapi_cuda, device> { | ||
using type = CUdevice; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, device> { | ||
using type = CUdevice; | ||
}; | ||
|
||
template <> struct BackendInput<backend::ext_oneapi_cuda, event> { | ||
using type = CUevent; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, event> { | ||
using type = CUevent; | ||
}; | ||
|
||
template <> struct BackendInput<backend::ext_oneapi_cuda, queue> { | ||
using type = CUstream; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, queue> { | ||
using type = CUstream; | ||
}; | ||
|
||
template <> struct BackendInput<backend::ext_oneapi_cuda, platform> { | ||
using type = std::vector<CUdevice>; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, platform> { | ||
using type = std::vector<CUdevice>; | ||
}; | ||
|
||
#ifdef __SYCL_INTERNAL_API | ||
template <> struct BackendInput<backend::ext_oneapi_cuda, program> { | ||
using type = CUmodule; | ||
}; | ||
|
||
template <> struct BackendReturn<backend::ext_oneapi_cuda, program> { | ||
using type = CUmodule; | ||
}; | ||
#endif | ||
|
||
template <> struct InteropFeatureSupportMap<backend::ext_oneapi_cuda> { | ||
static constexpr bool MakePlatform = false; | ||
static constexpr bool MakeDevice = true; | ||
static constexpr bool MakeContext = true; | ||
static constexpr bool MakeQueue = false; | ||
static constexpr bool MakeEvent = false; | ||
static constexpr bool MakeBuffer = false; | ||
static constexpr bool MakeKernel = false; | ||
static constexpr bool MakeKernelBundle = false; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) |
75 changes: 75 additions & 0 deletions
75
sycl/include/sycl/ext/oneapi/experimental/backend/cuda.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//==--------- cuda.hpp - SYCL CUDA backend ---------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <CL/sycl/backend.hpp> | ||
#include <CL/sycl/context.hpp> | ||
|
||
#include <vector> | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
namespace ext { | ||
namespace oneapi { | ||
namespace cuda { | ||
|
||
// Implementation of ext_oneapi_cuda::make<device> | ||
inline __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) { | ||
return sycl::detail::make_device(NativeHandle, backend::ext_oneapi_cuda); | ||
} | ||
|
||
} // namespace cuda | ||
} // namespace oneapi | ||
} // namespace ext | ||
|
||
// CUDA context specialization | ||
template <> | ||
inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C) | ||
-> backend_return_t<backend::ext_oneapi_cuda, context> { | ||
// create a vector to be returned | ||
backend_return_t<backend::ext_oneapi_cuda, context> ret; | ||
|
||
// get the native CUDA context from the SYCL object | ||
auto native = reinterpret_cast< | ||
backend_return_t<backend::ext_oneapi_cuda, context>::value_type>( | ||
C.getNative()); | ||
ret.push_back(native); | ||
|
||
return ret; | ||
} | ||
|
||
// Specialisation of non-free context get_native | ||
template <> | ||
inline backend_return_t<backend::ext_oneapi_cuda, context> | ||
context::get_native<backend::ext_oneapi_cuda>() const { | ||
return sycl::get_native<backend::ext_oneapi_cuda, context>(*this); | ||
} | ||
|
||
// Specialisation of interop_handles get_native_context | ||
template <> | ||
inline backend_return_t<backend::ext_oneapi_cuda, context> | ||
interop_handle::get_native_context<backend::ext_oneapi_cuda>() const { | ||
#ifndef __SYCL_DEVICE_ONLY__ | ||
return std::vector{reinterpret_cast<CUcontext>(getNativeContext())}; | ||
#else | ||
// we believe this won't be ever called on device side | ||
return {}; | ||
#endif | ||
} | ||
|
||
// CUDA device specialization | ||
template <> | ||
inline device make_device<backend::ext_oneapi_cuda>( | ||
const backend_input_t<backend::ext_oneapi_cuda, device> &BackendObject) { | ||
pi_native_handle NativeHandle = static_cast<pi_native_handle>(BackendObject); | ||
return ext::oneapi::cuda::make_device(NativeHandle); | ||
} | ||
|
||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.