Skip to content

Commit a249316

Browse files
author
Alexander Batashev
authored
[SYCL] Deprecate old OpenCL interop APIs in SYCL 2020 mode (#3194)
These warnings can be suppressed by `SYCL2020_DISABLE_DEPRECATION_WARNINGS` macro or by setting `-sycl-std=2017` or `-sycl-std=1.2.1`. Also a new macro `SYCL_DISABLE_DEPRECATION_WARNINGS` is introduced, to disable all deprecation warnings completely (including SYCL 1.2.1 deprecation warnings).
1 parent 95bfba6 commit a249316

File tree

13 files changed

+93
-0
lines changed

13 files changed

+93
-0
lines changed

sycl/doc/PreprocessorMacros.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ This behavior is not following the SYCL spec since `constant_ptr` conversions to
1919
the underlying pointer types return pointers without any additional qualifiers
2020
so it's disabled by default.
2121

22+
### SYCL2020_DISABLE_DEPRECATION_WARNINGS
23+
24+
Disables warnings coming from usage of SYCL 1.2.1 APIs, that are deprecated in
25+
SYCL 2020.
26+
27+
### SYCL_DISABLE_DEPRECATION_WARNINGS
28+
29+
Disables all deprecation warnings in SYCL runtime headers, including SYCL 1.2.1 deprecations.
30+
2231
### Version macros
2332

2433
- `__LIBSYCL_MAJOR_VERSION` is set to SYCL runtime library major version.

sycl/include/CL/sycl/buffer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class buffer {
224224
}
225225

226226
template <int N = dimensions, typename = EnableIfOneDimension<N>>
227+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
227228
buffer(cl_mem MemObject, const context &SyclContext,
228229
event AvailableEvent = {})
229230
: Range{0} {

sycl/include/CL/sycl/context.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class __SYCL_EXPORT context {
148148
///
149149
/// \param ClContext is an instance of OpenCL cl_context.
150150
/// \param AsyncHandler is an instance of async_handler.
151+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
151152
context(cl_context ClContext, async_handler AsyncHandler = {});
152153

153154
/// Queries this SYCL context for information.
@@ -187,6 +188,7 @@ class __SYCL_EXPORT context {
187188
/// The OpenCL cl_context handle is retained on return.
188189
///
189190
/// \return a valid instance of OpenCL cl_context.
191+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
190192
cl_context get() const;
191193

192194
/// Checks if this context is a SYCL host context.

sycl/include/CL/sycl/detail/defines_elementary.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,26 @@
3939
#endif
4040

4141
#ifndef __SYCL_DEPRECATED
42+
#ifndef SYCL_DISABLE_DEPRECATION_WARNINGS
4243
#ifdef _WIN32
4344
#define __SYCL_DEPRECATED(message) __declspec(deprecated(message))
4445
#else
4546
#define __SYCL_DEPRECATED(message) __attribute__((deprecated(message)))
4647
#endif
48+
#else // SYCL_DISABLE_DEPRECATION_WARNINGS
49+
#define __SYCL_DEPRECATED(message)
50+
#endif // SYCL_DISABLE_DEPRECATION_WARNINGS
4751
#endif // __SYCL_DEPRECATED
4852

53+
#ifndef __SYCL2020_DEPRECATED
54+
#if SYCL_LANGUAGE_VERSION >= 202001 && \
55+
!defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS)
56+
#define __SYCL2020_DEPRECATED(message) __SYCL_DEPRECATED(message)
57+
#else
58+
#define __SYCL2020_DEPRECATED(message)
59+
#endif
60+
#endif // __SYCL2020_DEPRECATED
61+
4962
#ifndef __SYCL_INLINE_CONSTEXPR
5063
// inline constexpr is a C++17 feature
5164
#if __cplusplus >= 201703L

sycl/include/CL/sycl/device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ 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")
4344
explicit device(cl_device_id DeviceId);
4445

4546
/// Constructs a SYCL device instance using the device selected
@@ -64,6 +65,7 @@ class __SYCL_EXPORT device {
6465
///
6566
/// \return a valid cl_device_id instance in accordance with the requirements
6667
/// described in 4.3.1.
68+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
6769
cl_device_id get() const;
6870

6971
/// Check if device is a host device

sycl/include/CL/sycl/event.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ 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")
4445
event(cl_event ClEvent, const context &SyclContext);
4546

4647
event(const event &rhs) = default;
@@ -58,6 +59,7 @@ class __SYCL_EXPORT event {
5859
/// Returns a valid OpenCL event interoperability handle.
5960
///
6061
/// \return a valid instance of OpenCL cl_event.
62+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
6163
cl_event get() const;
6264

6365
/// Checks if this event is a SYCL host event.

sycl/include/CL/sycl/image.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class image {
220220
PropList);
221221
}
222222

223+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
223224
image(cl_mem ClMemObject, const context &SyclContext,
224225
event AvailableEvent = {}) {
225226
impl = std::make_shared<detail::image_impl<Dimensions>>(

sycl/include/CL/sycl/platform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class __SYCL_EXPORT platform {
3939
/// construction.
4040
///
4141
/// \param PlatformId is an OpenCL cl_platform_id instance.
42+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
4243
explicit platform(cl_platform_id PlatformId);
4344

4445
/// Constructs a SYCL platform instance using device selector.
@@ -65,6 +66,7 @@ class __SYCL_EXPORT platform {
6566
/// Returns an OpenCL interoperability platform.
6667
///
6768
/// \return an instance of OpenCL cl_platform_id.
69+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
6870
cl_platform_id get() const;
6971

7072
/// Checks if platform supports specified extension.

sycl/include/CL/sycl/queue.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class __SYCL_EXPORT queue {
142142
/// \param ClQueue is a valid instance of OpenCL queue.
143143
/// \param SyclContext is a valid SYCL context.
144144
/// \param AsyncHandler is a SYCL asynchronous exception handler.
145+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
145146
queue(cl_command_queue ClQueue, const context &SyclContext,
146147
const async_handler &AsyncHandler = {});
147148

@@ -159,6 +160,7 @@ class __SYCL_EXPORT queue {
159160

160161
/// \return a valid instance of OpenCL queue, which is retained before being
161162
/// returned.
163+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
162164
cl_command_queue get() const;
163165

164166
/// \return an associated SYCL context.

sycl/include/CL/sycl/sampler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class __SYCL_EXPORT sampler {
6868
addressing_mode addressingMode, filtering_mode filteringMode,
6969
const property_list &propList = {});
7070

71+
__SYCL2020_DEPRECATED("OpenCL interop APIs are deprecated")
7172
sampler(cl_sampler clSampler, const context &syclContext);
7273

7374
sampler(const sampler &rhs) = default;

sycl/source/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function(add_sycl_rt_library LIB_NAME)
6161
endif()
6262
endif()
6363

64+
target_compile_definitions(${LIB_OBJ_NAME} PRIVATE SYCL2020_DISABLE_DEPRECATION_WARNINGS)
65+
6466
target_include_directories(
6567
${LIB_OBJ_NAME}
6668
PRIVATE
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %clangxx -fsycl -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
2+
// RUN: %clangxx -fsycl -Xclang -verify -Xclang -verify-ignore-unexpected=note %s -o %t.out
3+
// RUN: %clangxx -fsycl -sycl-std=2017 -Werror %s -o %t.out
4+
// RUN: %clangxx -fsycl -sycl-std=1.2.1 -Werror %s -o %t.out
5+
6+
#include <CL/sycl.hpp>
7+
8+
int main() {
9+
cl_context ClCtx;
10+
// expected-warning@+1 {{'context' is deprecated: OpenCL interop APIs are deprecated}}
11+
sycl::context Ctx{ClCtx};
12+
// expected-warning@+1 {{'get' is deprecated: OpenCL interop APIs are deprecated}}
13+
(void)Ctx.get();
14+
15+
cl_mem Mem;
16+
// expected-warning@+1 {{'buffer' is deprecated: OpenCL interop APIs are deprecated}}
17+
sycl::buffer<int, 1> Buf{Mem, Ctx};
18+
(void)Buf;
19+
20+
cl_device_id DevId;
21+
// expected-warning@+1 {{'device' is deprecated: OpenCL interop APIs are deprecated}}
22+
sycl::device Device{DevId};
23+
// expected-warning@+1 {{'get' is deprecated: OpenCL interop APIs are deprecated}}
24+
(void)Device.get();
25+
26+
cl_event ClEvent;
27+
// expected-warning@+1 {{'event' is deprecated: OpenCL interop APIs are deprecated}}
28+
sycl::event Evt{ClEvent, Ctx};
29+
// expected-warning@+1 {{'get' is deprecated: OpenCL interop APIs are deprecated}}
30+
(void)Evt.get();
31+
32+
// expected-warning@+1 {{'image' is deprecated: OpenCL interop APIs are deprecated}}
33+
sycl::image<1> Img{Mem, Ctx};
34+
(void)Img;
35+
36+
cl_platform_id ClPlatform;
37+
// expected-warning@+1 {{'platform' is deprecated: OpenCL interop APIs are deprecated}}
38+
sycl::platform Platform{ClPlatform};
39+
// expected-warning@+1 {{'get' is deprecated: OpenCL interop APIs are deprecated}}
40+
(void)Platform.get();
41+
42+
cl_command_queue ClQueue;
43+
// expected-warning@+1 {{'queue' is deprecated: OpenCL interop APIs are deprecated}}
44+
sycl::queue Queue{ClQueue, Ctx};
45+
// expected-warning@+1 {{'get' is deprecated: OpenCL interop APIs are deprecated}}
46+
(void)Queue.get();
47+
48+
cl_sampler ClSampler;
49+
// expected-warning@+1 {{'sampler' is deprecated: OpenCL interop APIs are deprecated}}
50+
sycl::sampler Sampler{ClSampler, Ctx};
51+
(void)Sampler;
52+
53+
return 0;
54+
}

sycl/unittests/kernel-and-program/Cache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS
10+
911
#include "CL/sycl/detail/pi.h"
1012
#include "detail/context_impl.hpp"
1113
#include "detail/kernel_program_cache.hpp"

0 commit comments

Comments
 (0)