Skip to content

Commit bbafe08

Browse files
author
Alexander Batashev
authored
[SYCL] Remove SYCL 1.2.1-style OpenCL interop APIs (#4480)
1 parent a7e8bfa commit bbafe08

19 files changed

+117
-51
lines changed

sycl/include/CL/sycl/backend.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
207207
make_buffer(const typename backend_traits<Backend>::template input_type<
208208
buffer<T, Dimensions, AllocatorT>> &BackendObject,
209209
const context &TargetContext, event AvailableEvent = {}) {
210-
return buffer<T, Dimensions, AllocatorT>(
211-
reinterpret_cast<cl_mem>(BackendObject), TargetContext, AvailableEvent);
210+
return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
211+
detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
212+
AvailableEvent);
212213
}
213214

214215
template <backend Backend>

sycl/include/CL/sycl/buffer.hpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class handler;
2323
class queue;
2424
template <int dimensions> class range;
2525

26+
namespace detail {
27+
template <typename T, int Dimensions, typename AllocatorT>
28+
buffer<T, Dimensions, AllocatorT, void>
29+
make_buffer_helper(pi_native_handle Handle, const context &Ctx, event Evt) {
30+
return buffer<T, Dimensions, AllocatorT, void>(Handle, Ctx, Evt);
31+
}
32+
} // namespace detail
33+
2634
/// Defines a shared array that can be used by kernels in queues.
2735
///
2836
/// Buffers can be 1-, 2-, and 3-dimensional. They have to be accessed using
@@ -33,8 +41,8 @@ template <int dimensions> class range;
3341
/// \ingroup sycl_api
3442
template <typename T, int dimensions = 1,
3543
typename AllocatorT = cl::sycl::buffer_allocator,
36-
typename = typename detail::enable_if_t<(dimensions > 0) &&
37-
(dimensions <= 3)>>
44+
typename __Enabled = typename detail::enable_if_t<(dimensions > 0) &&
45+
(dimensions <= 3)>>
3846
class buffer {
3947
public:
4048
using value_type = T;
@@ -223,8 +231,8 @@ class buffer {
223231
"Requested sub-buffer region is not contiguous", PI_INVALID_VALUE);
224232
}
225233

234+
#ifdef __SYCL_INTERNAL_API
226235
template <int N = dimensions, typename = EnableIfOneDimension<N>>
227-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
228236
buffer(cl_mem MemObject, const context &SyclContext,
229237
event AvailableEvent = {})
230238
: Range{0} {
@@ -234,10 +242,11 @@ class buffer {
234242

235243
Range[0] = BufSize / sizeof(T);
236244
impl = std::make_shared<detail::buffer_impl>(
237-
MemObject, SyclContext, BufSize,
245+
detail::pi::cast<pi_native_handle>(MemObject), SyclContext, BufSize,
238246
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
239247
AvailableEvent);
240248
}
249+
#endif
241250

242251
buffer(const buffer &rhs) = default;
243252

@@ -398,12 +407,31 @@ class buffer {
398407
template <typename DataT, int dims, access::mode mode, access::target target,
399408
access::placeholder isPlaceholder, typename PropertyListT>
400409
friend class accessor;
410+
template <typename HT, int HDims, typename HAllocT>
411+
friend buffer<HT, HDims, HAllocT, void>
412+
detail::make_buffer_helper(pi_native_handle, const context &, event);
401413
range<dimensions> Range;
402414
// Offset field specifies the origin of the sub buffer inside the parent
403415
// buffer
404416
size_t OffsetInBytes = 0;
405417
bool IsSubBuffer = false;
406418

419+
// Interop constructor
420+
template <int N = dimensions, typename = EnableIfOneDimension<N>>
421+
buffer(pi_native_handle MemObject, const context &SyclContext,
422+
event AvailableEvent = {})
423+
: Range{0} {
424+
425+
size_t BufSize = detail::SYCLMemObjT::getBufSizeForContext(
426+
detail::getSyclObjImpl(SyclContext), MemObject);
427+
428+
Range[0] = BufSize / sizeof(T);
429+
impl = std::make_shared<detail::buffer_impl>(
430+
MemObject, SyclContext, BufSize,
431+
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
432+
AvailableEvent);
433+
}
434+
407435
// Reinterpret contructor
408436
buffer(std::shared_ptr<detail::buffer_impl> Impl,
409437
range<dimensions> reinterpretRange, size_t reinterpretOffset,

sycl/include/CL/sycl/context.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ class __SYCL_EXPORT context {
149149
///
150150
/// \param ClContext is an instance of OpenCL cl_context.
151151
/// \param AsyncHandler is an instance of async_handler.
152-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
152+
#ifdef __SYCL_INTERNAL_API
153153
context(cl_context ClContext, async_handler AsyncHandler = {});
154+
#endif
154155

155156
/// Queries this SYCL context for information.
156157
///
@@ -189,8 +190,9 @@ class __SYCL_EXPORT context {
189190
/// The OpenCL cl_context handle is retained on return.
190191
///
191192
/// \return a valid instance of OpenCL cl_context.
192-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
193+
#ifdef __SYCL_INTERNAL_API
193194
cl_context get() const;
195+
#endif
194196

195197
/// Checks if this context is a SYCL host context.
196198
///

sycl/include/CL/sycl/detail/buffer_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include "CL/sycl/detail/pi.h"
1112
#include <CL/sycl/access/access.hpp>
1213
#include <CL/sycl/context.hpp>
1314
#include <CL/sycl/detail/common.hpp>
@@ -141,6 +142,14 @@ class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {
141142
const size_t SizeInBytes,
142143
std::unique_ptr<SYCLMemObjAllocator> Allocator,
143144
event AvailableEvent)
145+
: buffer_impl(pi::cast<pi_native_handle>(MemObject), SyclContext,
146+
SizeInBytes, std::move(Allocator),
147+
std::move(AvailableEvent)) {}
148+
149+
buffer_impl(pi_native_handle MemObject, const context &SyclContext,
150+
const size_t SizeInBytes,
151+
std::unique_ptr<SYCLMemObjAllocator> Allocator,
152+
event AvailableEvent)
144153
: BaseT(MemObject, SyclContext, SizeInBytes, std::move(AvailableEvent),
145154
std::move(Allocator)) {}
146155

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
7575
std::unique_ptr<SYCLMemObjAllocator> Allocator)
7676
: SYCLMemObjT(/*SizeInBytes*/ 0, Props, std::move(Allocator)) {}
7777

78+
// For ABI compatibility
7879
SYCLMemObjT(cl_mem MemObject, const context &SyclContext,
7980
const size_t SizeInBytes, event AvailableEvent,
8081
std::unique_ptr<SYCLMemObjAllocator> Allocator);
8182

83+
SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext,
84+
const size_t SizeInBytes, event AvailableEvent,
85+
std::unique_ptr<SYCLMemObjAllocator> Allocator);
86+
8287
SYCLMemObjT(cl_mem MemObject, const context &SyclContext,
8388
event AvailableEvent,
8489
std::unique_ptr<SYCLMemObjAllocator> Allocator)
@@ -281,9 +286,13 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
281286
MAllocator->setAlignment(RequiredAlign);
282287
}
283288

289+
// For ABI compatibility
284290
static size_t getBufSizeForContext(const ContextImplPtr &Context,
285291
cl_mem MemObject);
286292

293+
static size_t getBufSizeForContext(const ContextImplPtr &Context,
294+
pi_native_handle MemObject);
295+
287296
__SYCL_DLL_LOCAL void *allocateMem(ContextImplPtr Context,
288297
bool InitFromUserData, void *HostPtr,
289298
RT::PiEvent &InteropEvent) override {
@@ -320,6 +329,7 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
320329
ContextImplPtr MInteropContext;
321330
// OpenCL's memory object handle passed by user to interoperability
322331
// constructor.
332+
// TODO update this member to support other backends.
323333
cl_mem MInteropMemObject;
324334
// Indicates whether memory object is created using interoperability
325335
// constructor or not.

sycl/include/CL/sycl/device.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class __SYCL_EXPORT device {
4040
/// in accordance with the requirements described in 4.3.1.
4141
///
4242
/// \param DeviceId is OpenCL device represented with cl_device_id
43-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
43+
#ifdef __SYCL_INTERNAL_API
4444
explicit device(cl_device_id DeviceId);
45+
#endif
4546

4647
/// Constructs a SYCL device instance using the device selected
4748
/// by the DeviceSelector provided.
@@ -65,8 +66,9 @@ class __SYCL_EXPORT device {
6566
///
6667
/// \return a valid cl_device_id instance in accordance with the requirements
6768
/// described in 4.3.1.
68-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
69+
#ifdef __SYCL_INTERNAL_API
6970
cl_device_id get() const;
71+
#endif
7072

7173
/// Check if device is a host device
7274
///

sycl/include/CL/sycl/event.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class __SYCL_EXPORT event {
4141
///
4242
/// \param ClEvent is a valid instance of OpenCL cl_event.
4343
/// \param SyclContext is an instance of SYCL context.
44-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
44+
#ifdef __SYCL_INTERNAL_API
4545
event(cl_event ClEvent, const context &SyclContext);
46+
#endif
4647

4748
event(const event &rhs) = default;
4849

@@ -59,8 +60,9 @@ class __SYCL_EXPORT event {
5960
/// Returns a valid OpenCL event interoperability handle.
6061
///
6162
/// \return a valid instance of OpenCL cl_event.
62-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
63+
#ifdef __SYCL_INTERNAL_API
6364
cl_event get() const;
65+
#endif
6466

6567
/// Checks if this event is a SYCL host event.
6668
///

sycl/include/CL/sycl/image.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,14 @@ class image {
224224
PropList);
225225
}
226226

227-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
227+
#ifdef __SYCL_INTERNAL_API
228228
image(cl_mem ClMemObject, const context &SyclContext,
229229
event AvailableEvent = {}) {
230230
impl = std::make_shared<detail::image_impl<Dimensions>>(
231231
ClMemObject, SyclContext, AvailableEvent,
232232
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
233233
}
234+
#endif
234235

235236
/* -- common interface members -- */
236237

sycl/include/CL/sycl/kernel.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class __SYCL_EXPORT kernel {
7171
///
7272
/// \param ClKernel is a valid OpenCL cl_kernel instance
7373
/// \param SyclContext is a valid SYCL context
74-
__SYCL2020_DEPRECATED(
75-
"OpenCL interop constructors are deprecated, use make_kernel() instead")
74+
#ifdef __SYCL_INTERNAL_API
7675
kernel(cl_kernel ClKernel, const context &SyclContext);
76+
#endif
7777

7878
kernel(const kernel &RHS) = default;
7979

@@ -94,9 +94,9 @@ class __SYCL_EXPORT kernel {
9494
/// an invalid_object_error exception will be thrown.
9595
///
9696
/// \return a valid cl_kernel instance
97-
__SYCL2020_DEPRECATED(
98-
"OpenCL interop get() functions are deprecated, use get_native() instead")
97+
#ifdef __SYCL_INTERNAL_API
9998
cl_kernel get() const;
99+
#endif
100100

101101
/// Check if the associated SYCL context is a SYCL host context.
102102
///

sycl/include/CL/sycl/platform.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class __SYCL_EXPORT platform {
4444
/// construction.
4545
///
4646
/// \param PlatformId is an OpenCL cl_platform_id instance.
47-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
47+
#ifdef __SYCL_INTERNAL_API
4848
explicit platform(cl_platform_id PlatformId);
49+
#endif
4950

5051
/// Constructs a SYCL platform instance using device selector.
5152
///
@@ -71,8 +72,9 @@ class __SYCL_EXPORT platform {
7172
/// Returns an OpenCL interoperability platform.
7273
///
7374
/// \return an instance of OpenCL cl_platform_id.
74-
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
75+
#ifdef __SYCL_INTERNAL_API
7576
cl_platform_id get() const;
77+
#endif
7678

7779
/// Checks if platform supports specified extension.
7880
///

0 commit comments

Comments
 (0)