Skip to content

[SYCL] Remove deprecated interop interfaces #13306

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
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
5 changes: 3 additions & 2 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle,
backend Backend);
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle,
const async_handler &Handler,
backend Backend);
backend Backend, bool KeepOwnership,
const std::vector<device> &DeviceList = {});
__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle,
int32_t nativeHandleDesc,
const context &TargetContext,
Expand Down Expand Up @@ -334,7 +335,7 @@ make_context(
&BackendObject,
const async_handler &Handler = {}) {
return detail::make_context(detail::pi::cast<pi_native_handle>(BackendObject),
Handler, Backend);
Handler, Backend, false /* KeepOwnership */);
}

template <backend Backend>
Expand Down
44 changes: 0 additions & 44 deletions sycl/include/sycl/backend/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,10 @@
namespace sycl {
inline namespace _V1 {
namespace opencl {
// Implementation of various "make" functions resides in SYCL RT because
// creating SYCL objects requires knowing details not accessible here.
// Note that they take opaque pi_native_handle that real OpenCL handles
// are casted to.
//
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
__SYCL_EXPORT device make_device(pi_native_handle NativeHandle);
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle);
__SYCL_EXPORT queue make_queue(const context &Context,
pi_native_handle InteropHandle);

__SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,
const std::string &Extension);
__SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice,
const std::string &Extension);

// Construction of SYCL platform.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, platform>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
T make(typename detail::interop<backend::opencl, T>::type Interop) {
return make_platform(detail::pi::cast<pi_native_handle>(Interop));
}

// Construction of SYCL device.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, device>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
T make(typename detail::interop<backend::opencl, T>::type Interop) {
return make_device(detail::pi::cast<pi_native_handle>(Interop));
}

// Construction of SYCL context.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, context>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
T make(typename detail::interop<backend::opencl, T>::type Interop) {
return make_context(detail::pi::cast<pi_native_handle>(Interop));
}

// Construction of SYCL queue.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, queue>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function")
T make(const context &Context,
typename detail::interop<backend::opencl, T>::type Interop) {
return make_queue(Context, detail::pi::cast<pi_native_handle>(Interop));
}
} // namespace opencl
} // namespace _V1
} // namespace sycl
100 changes: 20 additions & 80 deletions sycl/include/sycl/ext/oneapi/backend/level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,88 +41,27 @@

namespace sycl {
inline namespace _V1 {
namespace ext::oneapi::level_zero {
// Implementation of various "make" functions resides in libsycl.so and thus
// their interface needs to be backend agnostic.
// TODO: remove/merge with similar functions in sycl::detail
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
namespace ext::oneapi::level_zero::detail {
__SYCL_EXPORT device make_device(const platform &Platform,
pi_native_handle NativeHandle);
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
pi_native_handle NativeHandle,
bool keep_ownership = false);
__SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
pi_native_handle InteropHandle,
bool IsImmCmdList, bool keep_ownership,
const property_list &Properties);
__SYCL_EXPORT event make_event(const context &Context,
pi_native_handle InteropHandle,
bool keep_ownership = false);

// Construction of SYCL platform.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, platform>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
T make(typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
Interop) {
return make_platform(reinterpret_cast<pi_native_handle>(Interop));
}

// Construction of SYCL device.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, device>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
T make(const platform &Platform,
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
Interop) {
return make_device(Platform, reinterpret_cast<pi_native_handle>(Interop));
}

/// Construction of SYCL context.
/// \param DeviceList is a vector of devices which must be encapsulated by
/// created SYCL context. Provided devices and native context handle must
/// be associated with the same platform.
/// \param Interop is a Level Zero native context handle.
/// \param Ownership (optional) specifies who will assume ownership of the
/// native context handle. Default is that SYCL RT does, so it destroys
/// the native handle when the created SYCL object goes out of life.
///
template <typename T, std::enable_if_t<std::is_same_v<T, context>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
T make(const std::vector<device> &DeviceList,
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
Interop,
ownership Ownership = ownership::transfer) {
return make_context(DeviceList,
sycl::detail::pi::cast<pi_native_handle>(Interop),
Ownership == ownership::keep);
}

// Construction of SYCL event.
template <typename T,
typename std::enable_if_t<std::is_same_v<T, event>> * = nullptr>
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function")
T make(const context &Context,
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
Interop,
ownership Ownership = ownership::transfer) {
return make_event(Context, reinterpret_cast<pi_native_handle>(Interop),
Ownership == ownership::keep);
}

} // namespace ext::oneapi::level_zero
} // namespace ext::oneapi::level_zero::detail

// Specialization of sycl::make_context for Level-Zero backend.
template <>
inline context make_context<backend::ext_oneapi_level_zero>(
const backend_input_t<backend::ext_oneapi_level_zero, context>
&BackendObject,
const async_handler &Handler) {
(void)Handler;
return ext::oneapi::level_zero::make_context(
BackendObject.DeviceList,
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep);

const std::vector<device> &DeviceList = BackendObject.DeviceList;
pi_native_handle NativeHandle =
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle);
bool KeepOwnership =
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep;

return sycl::detail::make_context(NativeHandle, Handler,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously Handler was ignored - see

return detail::createSyclObjFromImpl<context>(
std::make_shared<context_impl>(PiContext, detail::defaultAsyncHandler,
Plugin, DeviceList, !KeepOwnership));
, this PR starts using it instead of defaultAsyncHandler.

backend::ext_oneapi_level_zero,
KeepOwnership, DeviceList);
}

namespace detail {
Expand Down Expand Up @@ -191,7 +130,6 @@ template <>
inline queue make_queue<backend::ext_oneapi_level_zero>(
const backend_input_t<backend::ext_oneapi_level_zero, queue> &BackendObject,
const context &TargetContext, const async_handler Handler) {
(void)Handler;
const device Device = device{BackendObject.Device};
bool IsImmCmdList = std::holds_alternative<ze_command_list_handle_t>(
BackendObject.NativeHandle);
Expand All @@ -202,10 +140,11 @@ inline queue make_queue<backend::ext_oneapi_level_zero>(
: reinterpret_cast<pi_native_handle>(
*(std::get_if<ze_command_queue_handle_t>(
&BackendObject.NativeHandle)));
return ext::oneapi::level_zero::make_queue(
TargetContext, Device, Handle, IsImmCmdList,

return sycl::detail::make_queue(
Handle, IsImmCmdList, TargetContext, &Device,
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
BackendObject.Properties);
BackendObject.Properties, Handler, backend::ext_oneapi_level_zero);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, we were using async_handler from the TargetContext, see

return detail::make_queue(
NativeHandle, IsImmCmdList, Context, &Device, KeepOwnership, Properties,
ContextImpl->get_async_handler(), backend::ext_oneapi_level_zero);
. I'm updating to use the provided Handler, although I'm not sure about the consequences of that change. Regardless, using provided Handler instead of doing something completely different looks like a right thing to do for this interface.

}

// Specialization of sycl::get_native for Level-Zero backend.
Expand All @@ -227,10 +166,11 @@ template <>
inline event make_event<backend::ext_oneapi_level_zero>(
const backend_input_t<backend::ext_oneapi_level_zero, event> &BackendObject,
const context &TargetContext) {
return ext::oneapi::level_zero::make_event(
TargetContext,
return sycl::detail::make_event(
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep);
TargetContext,
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
backend::ext_oneapi_level_zero);
}

// Specialization of sycl::make_kernel_bundle for Level-Zero backend.
Expand Down
14 changes: 10 additions & 4 deletions sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle,

__SYCL_EXPORT context make_context(pi_native_handle NativeHandle,
const async_handler &Handler,
backend Backend) {
backend Backend, bool KeepOwnership,
const std::vector<device> &DeviceList) {
const auto &Plugin = getPlugin(Backend);

pi::PiContext PiContext = nullptr;
std::vector<pi_device> DeviceHandles;
for (auto Dev : DeviceList) {
DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
}
Plugin->call<PiApiKind::piextContextCreateWithNativeHandle>(
NativeHandle, 0, nullptr, false, &PiContext);
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), false,
&PiContext);
// Construct the SYCL context from PI context.
return detail::createSyclObjFromImpl<context>(
std::make_shared<context_impl>(PiContext, Handler, Plugin));
return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
PiContext, Handler, Plugin, DeviceList, !KeepOwnership));
}

__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle,
Expand Down
56 changes: 3 additions & 53 deletions sycl/source/backend/level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@

namespace sycl {
inline namespace _V1 {
namespace ext::oneapi::level_zero {
using namespace detail;
namespace ext::oneapi::level_zero::detail {
using namespace sycl::detail;

//----------------------------------------------------------------------------
// Implementation of level_zero::make<platform>
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
return detail::make_platform(NativeHandle, backend::ext_oneapi_level_zero);
}

//----------------------------------------------------------------------------
// Implementation of level_zero::make<device>
__SYCL_EXPORT device make_device(const platform &Platform,
pi_native_handle NativeHandle) {
const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
Expand All @@ -39,48 +31,6 @@ __SYCL_EXPORT device make_device(const platform &Platform,
PlatformImpl->getOrMakeDeviceImpl(PiDevice, PlatformImpl));
}

//----------------------------------------------------------------------------
// Implementation of level_zero::make<context>
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
pi_native_handle NativeHandle,
bool KeepOwnership) {
const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
// Create PI context first.
pi_context PiContext;
std::vector<pi_device> DeviceHandles;
for (auto Dev : DeviceList) {
DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
}
Plugin->call<PiApiKind::piextContextCreateWithNativeHandle>(
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
&PiContext);
// Construct the SYCL context from PI context.
return detail::createSyclObjFromImpl<context>(
std::make_shared<context_impl>(PiContext, detail::defaultAsyncHandler,
Plugin, DeviceList, !KeepOwnership));
}

//----------------------------------------------------------------------------
// Implementation of level_zero::make<queue>
__SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
pi_native_handle NativeHandle, bool IsImmCmdList,
bool KeepOwnership,
const property_list &Properties) {
const auto &ContextImpl = getSyclObjImpl(Context);
return detail::make_queue(
NativeHandle, IsImmCmdList, Context, &Device, KeepOwnership, Properties,
ContextImpl->get_async_handler(), backend::ext_oneapi_level_zero);
}

//----------------------------------------------------------------------------
// Implementation of level_zero::make<event>
__SYCL_EXPORT event make_event(const context &Context,
pi_native_handle NativeHandle,
bool KeepOwnership) {
return detail::make_event(NativeHandle, Context, KeepOwnership,
backend::ext_oneapi_level_zero);
}

} // namespace ext::oneapi::level_zero
} // namespace ext::oneapi::level_zero::detail
} // namespace _V1
} // namespace sycl
28 changes: 0 additions & 28 deletions sycl/source/backend/opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,6 @@ inline namespace _V1 {
namespace opencl {
using namespace detail;

//----------------------------------------------------------------------------
// Implementation of opencl::make<platform>
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
return detail::make_platform(NativeHandle, backend::opencl);
}

//----------------------------------------------------------------------------
// Implementation of opencl::make<device>
__SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
return detail::make_device(NativeHandle, backend::opencl);
}

//----------------------------------------------------------------------------
// Implementation of opencl::make<context>
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle) {
return detail::make_context(NativeHandle, detail::defaultAsyncHandler,
backend::opencl);
}

//----------------------------------------------------------------------------
// Implementation of opencl::make<queue>
__SYCL_EXPORT queue make_queue(const context &Context,
pi_native_handle NativeHandle) {
const auto &ContextImpl = getSyclObjImpl(Context);
return detail::make_queue(NativeHandle, 0, Context, nullptr, false, {},
ContextImpl->get_async_handler(), backend::opencl);
}

//----------------------------------------------------------------------------
// Free functions to query OpenCL backend extensions
__SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,
Expand Down
11 changes: 7 additions & 4 deletions sycl/test-e2e/Plugin/interop-level-zero-keep-ownership.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ int main() {
{ // Scope in which SYCL interop context object is live
std::vector<device> Devices{};
Devices.push_back(Device);
auto Context = level_zero::make<context>(Devices, ZeContext,
level_zero::ownership::keep);
auto Context = make_context<backend::ext_oneapi_level_zero>(
backend_input_t<backend::ext_oneapi_level_zero, context>{
ZeContext, Devices, ext::oneapi::level_zero::ownership::keep});

// Create L0 event pool
ze_event_pool_handle_t ZeEventPool;
Expand All @@ -52,8 +53,10 @@ int main() {

{ // Scope in which SYCL interop event is alive
int i = 0;
event Event = level_zero::make<event>(Context, ZeEvent,
level_zero::ownership::keep);
event Event = make_event<backend::ext_oneapi_level_zero>(
backend_input_t<backend::ext_oneapi_level_zero, event>{
ZeEvent, ext::oneapi::level_zero::ownership::keep},
Context);

info::event_command_status status;
do {
Expand Down
9 changes: 5 additions & 4 deletions sycl/test-e2e/Plugin/interop-opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ int main() {
assert(ocl_buffers.size() == 1);

// Re-create SYCL objects from native OpenCL handles
auto PlatformInterop = opencl::make<platform>(ocl_platform);
auto DeviceInterop = opencl::make<device>(ocl_device);
auto ContextInterop = opencl::make<context>(ocl_context);
auto QueueInterop = opencl::make<queue>(ContextInterop, ocl_queue);
auto PlatformInterop = sycl::make_platform<backend::opencl>(ocl_platform);
auto DeviceInterop = sycl::make_device<backend::opencl>(ocl_device);
auto ContextInterop = sycl::make_context<backend::opencl>(ocl_context);
auto QueueInterop =
sycl::make_queue<backend::opencl>(ocl_queue, ContextInterop);
auto BufferInterop =
sycl::make_buffer<backend::opencl, int>(ocl_buffers[0], ContextInterop);

Expand Down
Loading
Loading