Skip to content

Commit

Permalink
[SYCL] Remove SYCL 1.2.1-style OpenCL interop APIs (#4480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Batashev authored Oct 8, 2021
1 parent a7e8bfa commit bbafe08
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 51 deletions.
5 changes: 3 additions & 2 deletions sycl/include/CL/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
make_buffer(const typename backend_traits<Backend>::template input_type<
buffer<T, Dimensions, AllocatorT>> &BackendObject,
const context &TargetContext, event AvailableEvent = {}) {
return buffer<T, Dimensions, AllocatorT>(
reinterpret_cast<cl_mem>(BackendObject), TargetContext, AvailableEvent);
return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
AvailableEvent);
}

template <backend Backend>
Expand Down
36 changes: 32 additions & 4 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class handler;
class queue;
template <int dimensions> class range;

namespace detail {
template <typename T, int Dimensions, typename AllocatorT>
buffer<T, Dimensions, AllocatorT, void>
make_buffer_helper(pi_native_handle Handle, const context &Ctx, event Evt) {
return buffer<T, Dimensions, AllocatorT, void>(Handle, Ctx, Evt);
}
} // namespace detail

/// Defines a shared array that can be used by kernels in queues.
///
/// Buffers can be 1-, 2-, and 3-dimensional. They have to be accessed using
Expand All @@ -33,8 +41,8 @@ template <int dimensions> class range;
/// \ingroup sycl_api
template <typename T, int dimensions = 1,
typename AllocatorT = cl::sycl::buffer_allocator,
typename = typename detail::enable_if_t<(dimensions > 0) &&
(dimensions <= 3)>>
typename __Enabled = typename detail::enable_if_t<(dimensions > 0) &&
(dimensions <= 3)>>
class buffer {
public:
using value_type = T;
Expand Down Expand Up @@ -223,8 +231,8 @@ class buffer {
"Requested sub-buffer region is not contiguous", PI_INVALID_VALUE);
}

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

Range[0] = BufSize / sizeof(T);
impl = std::make_shared<detail::buffer_impl>(
MemObject, SyclContext, BufSize,
detail::pi::cast<pi_native_handle>(MemObject), SyclContext, BufSize,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
AvailableEvent);
}
#endif

buffer(const buffer &rhs) = default;

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

// Interop constructor
template <int N = dimensions, typename = EnableIfOneDimension<N>>
buffer(pi_native_handle MemObject, const context &SyclContext,
event AvailableEvent = {})
: Range{0} {

size_t BufSize = detail::SYCLMemObjT::getBufSizeForContext(
detail::getSyclObjImpl(SyclContext), MemObject);

Range[0] = BufSize / sizeof(T);
impl = std::make_shared<detail::buffer_impl>(
MemObject, SyclContext, BufSize,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
AvailableEvent);
}

// Reinterpret contructor
buffer(std::shared_ptr<detail::buffer_impl> Impl,
range<dimensions> reinterpretRange, size_t reinterpretOffset,
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ class __SYCL_EXPORT context {
///
/// \param ClContext is an instance of OpenCL cl_context.
/// \param AsyncHandler is an instance of async_handler.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
context(cl_context ClContext, async_handler AsyncHandler = {});
#endif

/// Queries this SYCL context for information.
///
Expand Down Expand Up @@ -189,8 +190,9 @@ class __SYCL_EXPORT context {
/// The OpenCL cl_context handle is retained on return.
///
/// \return a valid instance of OpenCL cl_context.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
cl_context get() const;
#endif

/// Checks if this context is a SYCL host context.
///
Expand Down
9 changes: 9 additions & 0 deletions sycl/include/CL/sycl/detail/buffer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "CL/sycl/detail/pi.h"
#include <CL/sycl/access/access.hpp>
#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/common.hpp>
Expand Down Expand Up @@ -141,6 +142,14 @@ class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {
const size_t SizeInBytes,
std::unique_ptr<SYCLMemObjAllocator> Allocator,
event AvailableEvent)
: buffer_impl(pi::cast<pi_native_handle>(MemObject), SyclContext,
SizeInBytes, std::move(Allocator),
std::move(AvailableEvent)) {}

buffer_impl(pi_native_handle MemObject, const context &SyclContext,
const size_t SizeInBytes,
std::unique_ptr<SYCLMemObjAllocator> Allocator,
event AvailableEvent)
: BaseT(MemObject, SyclContext, SizeInBytes, std::move(AvailableEvent),
std::move(Allocator)) {}

Expand Down
10 changes: 10 additions & 0 deletions sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
std::unique_ptr<SYCLMemObjAllocator> Allocator)
: SYCLMemObjT(/*SizeInBytes*/ 0, Props, std::move(Allocator)) {}

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

SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext,
const size_t SizeInBytes, event AvailableEvent,
std::unique_ptr<SYCLMemObjAllocator> Allocator);

SYCLMemObjT(cl_mem MemObject, const context &SyclContext,
event AvailableEvent,
std::unique_ptr<SYCLMemObjAllocator> Allocator)
Expand Down Expand Up @@ -281,9 +286,13 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
MAllocator->setAlignment(RequiredAlign);
}

// For ABI compatibility
static size_t getBufSizeForContext(const ContextImplPtr &Context,
cl_mem MemObject);

static size_t getBufSizeForContext(const ContextImplPtr &Context,
pi_native_handle MemObject);

__SYCL_DLL_LOCAL void *allocateMem(ContextImplPtr Context,
bool InitFromUserData, void *HostPtr,
RT::PiEvent &InteropEvent) override {
Expand Down Expand Up @@ -320,6 +329,7 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
ContextImplPtr MInteropContext;
// OpenCL's memory object handle passed by user to interoperability
// constructor.
// TODO update this member to support other backends.
cl_mem MInteropMemObject;
// Indicates whether memory object is created using interoperability
// constructor or not.
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class __SYCL_EXPORT device {
/// in accordance with the requirements described in 4.3.1.
///
/// \param DeviceId is OpenCL device represented with cl_device_id
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
explicit device(cl_device_id DeviceId);
#endif

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

/// Check if device is a host device
///
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class __SYCL_EXPORT event {
///
/// \param ClEvent is a valid instance of OpenCL cl_event.
/// \param SyclContext is an instance of SYCL context.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
event(cl_event ClEvent, const context &SyclContext);
#endif

event(const event &rhs) = default;

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

/// Checks if this event is a SYCL host event.
///
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,14 @@ class image {
PropList);
}

__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
image(cl_mem ClMemObject, const context &SyclContext,
event AvailableEvent = {}) {
impl = std::make_shared<detail::image_impl<Dimensions>>(
ClMemObject, SyclContext, AvailableEvent,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
}
#endif

/* -- common interface members -- */

Expand Down
8 changes: 4 additions & 4 deletions sycl/include/CL/sycl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class __SYCL_EXPORT kernel {
///
/// \param ClKernel is a valid OpenCL cl_kernel instance
/// \param SyclContext is a valid SYCL context
__SYCL2020_DEPRECATED(
"OpenCL interop constructors are deprecated, use make_kernel() instead")
#ifdef __SYCL_INTERNAL_API
kernel(cl_kernel ClKernel, const context &SyclContext);
#endif

kernel(const kernel &RHS) = default;

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

/// Check if the associated SYCL context is a SYCL host context.
///
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class __SYCL_EXPORT platform {
/// construction.
///
/// \param PlatformId is an OpenCL cl_platform_id instance.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
explicit platform(cl_platform_id PlatformId);
#endif

/// Constructs a SYCL platform instance using device selector.
///
Expand All @@ -71,8 +72,9 @@ class __SYCL_EXPORT platform {
/// Returns an OpenCL interoperability platform.
///
/// \return an instance of OpenCL cl_platform_id.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
cl_platform_id get() const;
#endif

/// Checks if platform supports specified extension.
///
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ class __SYCL_EXPORT queue {
/// \param ClQueue is a valid instance of OpenCL queue.
/// \param SyclContext is a valid SYCL context.
/// \param AsyncHandler is a SYCL asynchronous exception handler.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
queue(cl_command_queue ClQueue, const context &SyclContext,
const async_handler &AsyncHandler = {});
#endif

queue(const queue &RHS) = default;

Expand All @@ -217,8 +218,9 @@ class __SYCL_EXPORT queue {

/// \return a valid instance of OpenCL queue, which is retained before being
/// returned.
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
cl_command_queue get() const;
#endif

/// \return an associated SYCL context.
context get_context() const;
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ class __SYCL_EXPORT sampler {
addressing_mode addressingMode, filtering_mode filteringMode,
const property_list &propList = {});

__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
#ifdef __SYCL_INTERNAL_API
sampler(cl_sampler clSampler, const context &syclContext);
#endif

sampler(const sampler &rhs) = default;

Expand Down
13 changes: 12 additions & 1 deletion sycl/source/detail/sycl_mem_obj_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ namespace detail {
SYCLMemObjT::SYCLMemObjT(cl_mem MemObject, const context &SyclContext,
const size_t SizeInBytes, event AvailableEvent,
std::unique_ptr<SYCLMemObjAllocator> Allocator)
: SYCLMemObjT(pi::cast<pi_native_handle>(MemObject), SyclContext,
SizeInBytes, AvailableEvent, std::move(Allocator)) {}

SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext,
const size_t SizeInBytes, event AvailableEvent,
std::unique_ptr<SYCLMemObjAllocator> Allocator)
: MAllocator(std::move(Allocator)), MProps(),
MInteropEvent(detail::getSyclObjImpl(std::move(AvailableEvent))),
MInteropContext(detail::getSyclObjImpl(SyclContext)),
MInteropMemObject(MemObject), MOpenCLInterop(true),
MInteropMemObject(pi::cast<cl_mem>(MemObject)), MOpenCLInterop(true),
MHostPtrReadOnly(false), MNeedWriteBack(true), MSizeInBytes(SizeInBytes),
MUserPtr(nullptr), MShadowCopy(nullptr), MUploadDataFunctor(nullptr),
MSharedPtrStorage(nullptr) {
Expand Down Expand Up @@ -92,8 +98,13 @@ const plugin &SYCLMemObjT::getPlugin() const {

size_t SYCLMemObjT::getBufSizeForContext(const ContextImplPtr &Context,
cl_mem MemObject) {
return getBufSizeForContext(Context, pi::cast<pi_native_handle>(MemObject));
}
size_t SYCLMemObjT::getBufSizeForContext(const ContextImplPtr &Context,
pi_native_handle MemObject) {
size_t BufSize = 0;
const detail::plugin &Plugin = Context->getPlugin();
// TODO is there something required to support non-OpenCL backends?
Plugin.call<detail::PiApiKind::piMemGetInfo>(
detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
sizeof(size_t), &BufSize, nullptr);
Expand Down
3 changes: 3 additions & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -3774,8 +3774,11 @@ _ZN2cl4sycl6detail11SYCLMemObjT16determineHostPtrERKSt10shared_ptrINS1_12context
_ZN2cl4sycl6detail11SYCLMemObjT16updateHostMemoryEPv
_ZN2cl4sycl6detail11SYCLMemObjT16updateHostMemoryEv
_ZN2cl4sycl6detail11SYCLMemObjT20getBufSizeForContextERKSt10shared_ptrINS1_12context_implEEP7_cl_mem
_ZN2cl4sycl6detail11SYCLMemObjT20getBufSizeForContextERKSt10shared_ptrINS1_12context_implEEm
_ZN2cl4sycl6detail11SYCLMemObjTC1EP7_cl_memRKNS0_7contextEmNS0_5eventESt10unique_ptrINS1_19SYCLMemObjAllocatorESt14default_deleteISA_EE
_ZN2cl4sycl6detail11SYCLMemObjTC1EmRKNS0_7contextEmNS0_5eventESt10unique_ptrINS1_19SYCLMemObjAllocatorESt14default_deleteIS8_EE
_ZN2cl4sycl6detail11SYCLMemObjTC2EP7_cl_memRKNS0_7contextEmNS0_5eventESt10unique_ptrINS1_19SYCLMemObjAllocatorESt14default_deleteISA_EE
_ZN2cl4sycl6detail11SYCLMemObjTC2EmRKNS0_7contextEmNS0_5eventESt10unique_ptrINS1_19SYCLMemObjAllocatorESt14default_deleteIS8_EE
_ZN2cl4sycl6detail11buffer_impl11allocateMemESt10shared_ptrINS1_12context_implEEbPvRP9_pi_event
_ZN2cl4sycl6detail11make_deviceEmNS0_7backendE
_ZN2cl4sycl6detail11make_kernelERKNS0_7contextERKNS0_13kernel_bundleILNS0_12bundle_stateE2EEEmbNS0_7backendE
Expand Down
3 changes: 3 additions & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
??0SYCLMemObjT@detail@sycl@cl@@QEAA@AEBVproperty_list@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0SYCLMemObjT@detail@sycl@cl@@QEAA@PEAU_cl_mem@@AEBVcontext@23@Vevent@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0SYCLMemObjT@detail@sycl@cl@@QEAA@PEAU_cl_mem@@AEBVcontext@23@_KVevent@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0SYCLMemObjT@detail@sycl@cl@@QEAA@_KAEBVcontext@23@_KVevent@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0SYCLMemObjT@detail@sycl@cl@@QEAA@_KAEBVproperty_list@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0accelerator_selector@sycl@cl@@QEAA@$$QEAV012@@Z
??0accelerator_selector@sycl@cl@@QEAA@AEBV012@@Z
Expand All @@ -266,6 +267,7 @@
??0buffer_impl@detail@sycl@cl@@QEAA@PEAX_K1AEBVproperty_list@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0buffer_impl@detail@sycl@cl@@QEAA@PEBX_K1AEBVproperty_list@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0buffer_impl@detail@sycl@cl@@QEAA@_K0AEBVproperty_list@23@V?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@@Z
??0buffer_impl@detail@sycl@cl@@QEAA@_KAEBVcontext@23@_KV?$unique_ptr@VSYCLMemObjAllocator@detail@sycl@cl@@U?$default_delete@VSYCLMemObjAllocator@detail@sycl@cl@@@std@@@std@@Vevent@23@@Z
??0context@sycl@cl@@AEAA@V?$shared_ptr@Vcontext_impl@detail@sycl@cl@@@std@@@Z
??0context@sycl@cl@@QEAA@$$QEAV012@@Z
??0context@sycl@cl@@QEAA@AEBV012@@Z
Expand Down Expand Up @@ -2036,6 +2038,7 @@
?getAssertHappenedBuffer@queue@sycl@cl@@AEAAAEAV?$buffer@UAssertHappened@detail@sycl@cl@@$00V?$aligned_allocator@D@234@X@23@XZ
?getBorderColor@detail@sycl@cl@@YA?AV?$vec@M$03@23@W4image_channel_order@23@@Z
?getBufSizeForContext@SYCLMemObjT@detail@sycl@cl@@SA_KAEBV?$shared_ptr@Vcontext_impl@detail@sycl@cl@@@std@@PEAU_cl_mem@@@Z
?getBufSizeForContext@SYCLMemObjT@detail@sycl@cl@@SA_KAEBV?$shared_ptr@Vcontext_impl@detail@sycl@cl@@@std@@_K@Z
?getChannelOrder@?$image_impl@$00@detail@sycl@cl@@QEBA?AW4image_channel_order@34@XZ
?getChannelOrder@?$image_impl@$01@detail@sycl@cl@@QEBA?AW4image_channel_order@34@XZ
?getChannelOrder@?$image_impl@$02@detail@sycl@cl@@QEBA?AW4image_channel_order@34@XZ
Expand Down
Loading

0 comments on commit bbafe08

Please sign in to comment.