Skip to content

Commit ae8bb7f

Browse files
committed
[SYCL] Support make_buffer for the Level Zero backend
1 parent 9eb7a30 commit ae8bb7f

18 files changed

+221
-74
lines changed

sycl/include/CL/sycl/backend.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext,
121121
__SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
122122
make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext,
123123
bool KeepOwnership, bundle_state State, backend Backend);
124+
__SYCL_EXPORT detail::pi::PiMem make_pi_mem(pi_native_handle NativeHandle,
125+
size_t Size, context Context,
126+
bool KeepOwnership,
127+
backend Backend);
124128
} // namespace detail
125129

126130
template <backend Backend>
@@ -203,7 +207,8 @@ typename std::enable_if<
203207
template <backend Backend, typename T, int Dimensions = 1,
204208
typename AllocatorT = buffer_allocator>
205209
typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
206-
true,
210+
true &&
211+
Backend != backend::ext_oneapi_level_zero,
207212
buffer<T, Dimensions, AllocatorT>>::type
208213
make_buffer(const typename backend_traits<Backend>::template input_type<
209214
buffer<T, Dimensions, AllocatorT>> &BackendObject,
@@ -213,6 +218,25 @@ make_buffer(const typename backend_traits<Backend>::template input_type<
213218
AvailableEvent);
214219
}
215220

221+
template <backend Backend, typename T, int Dimensions = 1,
222+
typename AllocatorT = buffer_allocator>
223+
typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
224+
true &&
225+
Backend == backend::ext_oneapi_level_zero,
226+
buffer<T, Dimensions, AllocatorT>>::type
227+
make_buffer(const typename backend_traits<Backend>::template input_type<
228+
buffer<T, Dimensions, AllocatorT>> &BackendObject,
229+
const context &TargetContext, event AvailableEvent = {}) {
230+
detail::pi::PiMem PiBuffer = detail::make_pi_mem(
231+
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
232+
BackendObject.Size, TargetContext,
233+
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
234+
Backend);
235+
return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
236+
detail::pi::cast<pi_native_handle>(PiBuffer), TargetContext,
237+
AvailableEvent);
238+
}
239+
216240
template <backend Backend>
217241
kernel
218242
make_kernel(const typename backend_traits<Backend>::template input_type<kernel>

sycl/include/CL/sycl/detail/backend_traits_level_zero.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ template <> struct BackendInput<backend::ext_oneapi_level_zero, queue> {
138138
};
139139
};
140140

141+
template <typename DataT, int Dimensions, typename AllocatorT>
142+
struct BackendInput<backend::ext_oneapi_level_zero,
143+
buffer<DataT, Dimensions, AllocatorT>> {
144+
struct type {
145+
void *NativeHandle;
146+
size_t Size;
147+
ext::oneapi::level_zero::ownership Ownership{
148+
ext::oneapi::level_zero::ownership::transfer};
149+
};
150+
};
151+
152+
template <typename DataT, int Dimensions, typename AllocatorT>
153+
struct BackendReturn<backend::ext_oneapi_level_zero,
154+
buffer<DataT, Dimensions, AllocatorT>> {
155+
using type = void *;
156+
};
157+
141158
template <> struct BackendReturn<backend::ext_oneapi_level_zero, queue> {
142159
using type = ze_command_queue_handle_t;
143160
};
@@ -195,7 +212,7 @@ template <> struct InteropFeatureSupportMap<backend::ext_oneapi_level_zero> {
195212
static constexpr bool MakeEvent = true;
196213
static constexpr bool MakeKernelBundle = true;
197214
static constexpr bool MakeKernel = true;
198-
static constexpr bool MakeBuffer = false;
215+
static constexpr bool MakeBuffer = true;
199216
};
200217

201218
} // namespace detail

sycl/include/CL/sycl/detail/pi.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,10 @@ __SYCL_EXPORT pi_result piextMemGetNativeHandle(pi_mem mem,
11501150
/// \param nativeHandle is the native handle to create PI mem from.
11511151
/// \param mem is the PI mem created from the native handle.
11521152
__SYCL_EXPORT pi_result
1153-
piextMemCreateWithNativeHandle(pi_native_handle nativeHandle, pi_mem *mem);
1153+
// piextMemCreateWithNativeHandle(pi_native_handle nativeHandle, pi_mem *mem);
1154+
piextMemCreateWithNativeHandle(pi_native_handle NativeHandle, size_t Size,
1155+
pi_context Context, bool ownNativeHandle,
1156+
pi_mem *Mem);
11541157

11551158
//
11561159
// Program

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,9 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
327327
EventImplPtr MInteropEvent;
328328
// Context passed by user to interoperability constructor.
329329
ContextImplPtr MInteropContext;
330-
// OpenCL's memory object handle passed by user to interoperability
330+
// Native backend memory object handle passed by user to interoperability
331331
// constructor.
332-
// TODO update this member to support other backends.
333-
cl_mem MInteropMemObject;
332+
RT::PiMem MInteropMemObject;
334333
// Indicates whether memory object is created using interoperability
335334
// constructor or not.
336335
bool MOpenCLInterop;

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,11 @@ pi_result cuda_piextMemGetNativeHandle(pi_mem mem,
21162116
/// \param[out] mem Set to the PI mem object created from native handle.
21172117
///
21182118
/// \return TBD
2119-
pi_result cuda_piextMemCreateWithNativeHandle(pi_native_handle, pi_mem *) {
2119+
// pi_result cuda_piextMemCreateWithNativeHandle(pi_native_handle, pi_mem *) {
2120+
pi_result cuda_piextMemCreateWithNativeHandle(pi_native_handle NativeHandle,
2121+
size_t Size, pi_context Context,
2122+
bool ownNativeHandle,
2123+
pi_mem *Mem) {
21202124
cl::sycl::detail::pi::die(
21212125
"Creation of PI mem from native handle not implemented");
21222126
return {};

sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,9 @@ pi_result piextMemGetNativeHandle(pi_mem, pi_native_handle *) {
965965
DIE_NO_IMPLEMENTATION;
966966
}
967967

968-
pi_result piextMemCreateWithNativeHandle(pi_native_handle, pi_mem *) {
968+
pi_result piextMemCreateWithNativeHandle(pi_native_handle NativeHandle,
969+
size_t Size, pi_context Context,
970+
bool ownNativeHandle, pi_mem *Mem) {
969971
DIE_NO_IMPLEMENTATION;
970972
}
971973

sycl/plugins/hip/pi_hip.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,9 +2068,17 @@ pi_result hip_piMemGetInfo(pi_mem memObj, cl_mem_info queriedInfo,
20682068
/// \param[out] mem Set to the PI mem object created from native handle.
20692069
///
20702070
/// \return TBD
2071+
// pi_result hip_piextMemCreateWithNativeHandle(pi_native_handle nativeHandle,
2072+
// pi_mem *mem) {
2073+
20712074
pi_result hip_piextMemCreateWithNativeHandle(pi_native_handle nativeHandle,
2075+
size_t size, pi_context context,
2076+
bool ownNativeHandle,
20722077
pi_mem *mem) {
20732078
(void)nativeHandle;
2079+
(void)size;
2080+
(void)context;
2081+
(void)ownNativeHandle;
20742082
(void)mem;
20752083

20762084
cl::sycl::detail::pi::die(

0 commit comments

Comments
 (0)