Skip to content

[SYCL] [L0] Remove unneeded backwards compatibility of 2023.2 make_queue and get_native. #8871

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 16 commits into from
May 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,4 @@ The behavior of the SYCL buffer destructor depends on the Ownership flag. As wit
|9|2022-05-12|Steffen Larsen|Added device member to queue input type
|10|2022-08-18|Sergey Maslov|Moved free_memory device info query to be sycl_ext_intel_device_info extension
|11|2023-03-14|Rajiv Deodhar|Added support for Level Zero immediate command lists
|12|2023-04-06|Chris Perkins|Introduced make_image() API
|12|2023-04-06|Chris Perkins|Introduced make_image() API
53 changes: 26 additions & 27 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ auto get_native(const SyclObjectT &Obj)
Obj.getNative());
}

template <backend BackendName>
auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
}
int32_t IsImmCmdList;
pi_native_handle Handle = Obj.getNative(IsImmCmdList);
backend_return_t<BackendName, queue> RetVal;
if constexpr (BackendName == backend::ext_oneapi_level_zero)
RetVal = IsImmCmdList
? backend_return_t<BackendName, queue>{reinterpret_cast<
ze_command_list_handle_t>(Handle)}
: backend_return_t<BackendName, queue>{
reinterpret_cast<ze_command_queue_handle_t>(Handle)};
else
RetVal = reinterpret_cast<backend_return_t<BackendName, queue>>(Handle);

return RetVal;
}

template <backend BackendName, bundle_state State>
auto get_native(const kernel_bundle<State> &Obj)
-> backend_return_t<BackendName, kernel_bundle<State>> {
Expand Down Expand Up @@ -211,21 +233,11 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle,
const async_handler &Handler,
backend Backend);
__SYCL_EXPORT 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);

// The make_queue2 and getNative2 functions are added as a temporary measure so
// that the existing make_queue and getNative functions can co-exist with them.
// At the next ABI redefinition the current make_queue and getNative definitions
// will be removed. "make_queue2" will be renamed "make_queue" and "getNative2"
// will be renamed "getNative".
__SYCL_EXPORT queue make_queue2(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);
__SYCL_EXPORT event make_event(pi_native_handle NativeHandle,
const context &TargetContext, backend Backend);
__SYCL_EXPORT event make_event(pi_native_handle NativeHandle,
Expand Down Expand Up @@ -283,22 +295,9 @@ std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeQueue == true,
make_queue(const typename backend_traits<Backend>::template input_type<queue>
&BackendObject,
const context &TargetContext, const async_handler Handler = {}) {
if constexpr (Backend == backend::ext_oneapi_level_zero) {
bool IsImmCmdList = std::holds_alternative<ze_command_list_handle_t>(
BackendObject.NativeHandle);
pi_native_handle Handle =
IsImmCmdList ? reinterpret_cast<pi_native_handle>(
*(std::get_if<ze_command_list_handle_t>(
&BackendObject.NativeHandle)))
: reinterpret_cast<pi_native_handle>(
*(std::get_if<ze_command_queue_handle_t>(
&BackendObject.NativeHandle)));
return sycl::detail::make_queue2(Handle, IsImmCmdList, TargetContext,
nullptr, false, BackendObject.Properties,
Handler, Backend);
}
return detail::make_queue(detail::pi::cast<pi_native_handle>(BackendObject),
TargetContext, nullptr, false, Handler, Backend);
false, TargetContext, nullptr, false, {}, Handler,
Backend);
}

template <backend Backend>
Expand Down
5 changes: 0 additions & 5 deletions sycl/include/sycl/detail/pi.def
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,4 @@ _PI_API(piextEnqueueDeviceGlobalVariableRead)

_PI_API(piPluginGetBackendOption)

// Queue create and get APIs for immediate commandlists
_PI_API(piextQueueCreate2)
_PI_API(piextQueueGetNativeHandle2)
_PI_API(piextQueueCreateWithNativeHandle2)

#undef _PI_API
44 changes: 9 additions & 35 deletions sycl/include/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@
// 12.25 Added PI_EXT_DEVICE_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES and
// PI_EXT_DEVICE_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES for piDeviceGetInfo.
// 12.26 Added piextEnqueueReadHostPipe and piextEnqueueWriteHostPipe functions.
// 12.27 Added new queue create and get APIs for immediate commandlists
// piextQueueCreate2, piextQueueCreateWithNativeHandle2,
// piextQueueGetNativeHandle2
// 12.27 Added properties parameter to piextQueueCreateWithNativeHandle and
// changed native handle type of piextQueueCreateWithNativeHandle and
// piextQueueGetNativeHandle
// 12.28 Added piextMemImageCreateWithNativeHandle for creating images from
// native handles.
// 12.29 Support PI_EXT_PLATFORM_INFO_BACKEND query in piPlatformGetInfo
// 12.30 Added PI_EXT_INTEL_DEVICE_INFO_MEM_CHANNEL_SUPPORT device info query.
// 12.31 Added PI_EXT_CODEPLAY_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP device
// info query.
// 12.32 Removed backwards compatibility of piextQueueCreateWithNativeHandle and
// piextQueueGetNativeHandle

#define _PI_H_VERSION_MAJOR 12
#define _PI_H_VERSION_MINOR 31
#define _PI_H_VERSION_MAJOR 13
#define _PI_H_VERSION_MINOR 32

#define _PI_STRING_HELPER(a) #a
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
Expand Down Expand Up @@ -1210,12 +1212,6 @@ __SYCL_EXPORT pi_result piQueueCreate(pi_context context, pi_device device,
__SYCL_EXPORT pi_result piextQueueCreate(pi_context context, pi_device device,
pi_queue_properties *properties,
pi_queue *queue);
/// \param properties points to a zero-terminated array of extra data describing
/// desired queue properties. Format is
/// {[PROPERTY[, property-specific elements of data]*,]* 0}
__SYCL_EXPORT pi_result piextQueueCreate2(pi_context context, pi_device device,
pi_queue_properties *properties,
pi_queue *queue);

__SYCL_EXPORT pi_result piQueueGetInfo(pi_queue command_queue,
pi_queue_info param_name,
Expand All @@ -1231,36 +1227,14 @@ __SYCL_EXPORT pi_result piQueueFinish(pi_queue command_queue);

__SYCL_EXPORT pi_result piQueueFlush(pi_queue command_queue);

/// Gets the native handle of a PI queue object.
///
/// \param queue is the PI queue to get the native handle of.
/// \param nativeHandle is the native handle of queue.
__SYCL_EXPORT pi_result
piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle);

/// Gets the native handle of a PI queue object.
///
/// \param queue is the PI queue to get the native handle of.
/// \param nativeHandle is the native handle of queue or commandlist.
/// \param nativeHandleDesc provides additional properties of the native handle.
__SYCL_EXPORT pi_result piextQueueGetNativeHandle2(
__SYCL_EXPORT pi_result piextQueueGetNativeHandle(
pi_queue queue, pi_native_handle *nativeHandle, int32_t *nativeHandleDesc);

/// Creates PI queue object from a native handle.
/// NOTE: The created PI object takes ownership of the native handle.
///
/// \param nativeHandle is the native handle to create PI queue from.
/// \param context is the PI context of the queue.
/// \param device is the PI device associated with the native device used when
/// creating the native queue. This parameter is optional but some backends
/// may fail to create the right PI queue if omitted.
/// \param pluginOwnsNativeHandle Indicates whether the created PI object
/// should take ownership of the native handle.
/// \param queue is the PI queue created from the native handle.
__SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle(
pi_native_handle nativeHandle, pi_context context, pi_device device,
bool pluginOwnsNativeHandle, pi_queue *queue);

/// Creates PI queue object from a native handle.
/// NOTE: The created PI object takes ownership of the native handle.
///
Expand All @@ -1274,7 +1248,7 @@ __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle(
/// should take ownership of the native handle.
/// \param Properties holds queue properties.
/// \param queue is the PI queue created from the native handle.
__SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle2(
__SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle(
pi_native_handle nativeHandle, int32_t nativeHandleDesc, pi_context context,
pi_device device, bool pluginOwnsNativeHandle,
pi_queue_properties *Properties, pi_queue *queue);
Expand Down
44 changes: 11 additions & 33 deletions sycl/include/sycl/ext/oneapi/backend/level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@ __SYCL_EXPORT device make_device(const platform &Platform,
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
pi_native_handle NativeHandle,
bool keep_ownership = false);
__SYCL_DEPRECATED("Use make_queue with device parameter")
__SYCL_EXPORT queue make_queue(const context &Context,
pi_native_handle InteropHandle,
bool keep_ownership = false);
__SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
pi_native_handle InteropHandle,
bool keep_ownership = false);
__SYCL_EXPORT queue make_queue2(const context &Context, const device &Device,
pi_native_handle InteropHandle,
bool IsImmCmdList, bool keep_ownership,
const property_list &Properties);
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);
Expand Down Expand Up @@ -78,19 +71,6 @@ T make(const std::vector<device> &DeviceList,
Ownership == ownership::keep);
}

// 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 sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
Interop,
ownership Ownership = ownership::transfer) {
return make_queue(Context, Context.get_devices()[0],
*(reinterpret_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>
Expand All @@ -102,6 +82,7 @@ T make(const context &Context,
return make_event(Context, reinterpret_cast<pi_native_handle>(Interop),
Ownership == ownership::keep);
}

} // namespace ext::oneapi::level_zero

// Specialization of sycl::make_context for Level-Zero backend.
Expand Down Expand Up @@ -133,7 +114,7 @@ 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_queue2(
return ext::oneapi::level_zero::make_queue(
TargetContext, Device, Handle, IsImmCmdList,
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
BackendObject.Properties);
Expand All @@ -144,16 +125,13 @@ template <>
inline auto get_native<backend::ext_oneapi_level_zero, queue>(const queue &Obj)
-> backend_return_t<backend::ext_oneapi_level_zero, queue> {
int32_t IsImmCmdList;
pi_native_handle Handle = Obj.getNative2(IsImmCmdList);
if (IsImmCmdList) {
return backend_return_t<backend::ext_oneapi_level_zero, queue>{
std::in_place_index<1>,
reinterpret_cast<ze_command_list_handle_t>(Handle)};
} else {
return backend_return_t<backend::ext_oneapi_level_zero, queue>{
std::in_place_index<0>,
reinterpret_cast<ze_command_queue_handle_t>(Handle)};
}
pi_native_handle Handle = Obj.getNative(IsImmCmdList);
return IsImmCmdList
? backend_return_t<
backend::ext_oneapi_level_zero,
queue>{reinterpret_cast<ze_command_list_handle_t>(Handle)}
: backend_return_t<backend::ext_oneapi_level_zero, queue>{
reinterpret_cast<ze_command_queue_handle_t>(Handle)};
}

// Specialization of sycl::make_event for Level-Zero backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ template <>
inline queue make_queue<backend::ext_oneapi_cuda>(
const backend_input_t<backend::ext_oneapi_cuda, queue> &BackendObject,
const context &TargetContext, const async_handler Handler) {
int32_t nativeHandleDesc = 0;
const property_list &PropList{};
return detail::make_queue(detail::pi::cast<pi_native_handle>(BackendObject),
TargetContext, nullptr, true, Handler,
nativeHandleDesc, TargetContext, nullptr, true,
PropList, Handler,
/*Backend*/ backend::ext_oneapi_cuda);
}

Expand Down
7 changes: 5 additions & 2 deletions sycl/include/sycl/interop_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class interop_handle {
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
return reinterpret_cast<backend_return_t<Backend, queue>>(getNativeQueue());
int32_t NativeHandleDesc;
return reinterpret_cast<backend_return_t<Backend, queue>>(
getNativeQueue(NativeHandleDesc));
#else
// we believe this won't be ever called on device side
return 0;
Expand Down Expand Up @@ -197,7 +199,8 @@ class interop_handle {

__SYCL_EXPORT pi_native_handle
getNativeMem(detail::AccessorImplHost *Req) const;
__SYCL_EXPORT pi_native_handle getNativeQueue() const;
__SYCL_EXPORT pi_native_handle
getNativeQueue(int32_t &NativeHandleDesc) const;
__SYCL_EXPORT pi_native_handle getNativeDevice() const;
__SYCL_EXPORT pi_native_handle getNativeContext() const;

Expand Down
6 changes: 4 additions & 2 deletions sycl/include/sycl/interop_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class __SYCL_DEPRECATED("interop_handler class is deprecated, use"

template <backend BackendName = backend::opencl>
auto get_queue() const -> typename detail::interop<BackendName, queue>::type {
int32_t NativeHandleDesc;
return reinterpret_cast<typename detail::interop<BackendName, queue>::type>(
GetNativeQueue());
GetNativeQueue(NativeHandleDesc));
}

template <backend BackendName = backend::opencl, typename DataT, int Dims,
Expand Down Expand Up @@ -70,7 +71,8 @@ class __SYCL_DEPRECATED("interop_handler class is deprecated, use"

__SYCL_EXPORT pi_native_handle
GetNativeMem(detail::AccessorImplHost *Req) const;
__SYCL_EXPORT pi_native_handle GetNativeQueue() const;
__SYCL_EXPORT pi_native_handle
GetNativeQueue(int32_t &NativeHandleDesc) const;
};

} // __SYCL_INLINE_VER_NAMESPACE(_V1)
Expand Down
Loading