Skip to content

Commit 97f916e

Browse files
author
Pavel Samolysov
authored
[SYCL] Rename cuda, hip and fix renaming for level_zero backends (#4785)
According to SYCL spec, backend::cuda was renamed to backend::ext_oneapi_cuda, and backend::hip was renamed to backend::ext_oneapi_hip. Old names were marked as deprecated. The renaming is also applied in the sources, tests and unit-tests. Renaming for the Level Zero backend was also applied for the sources, tests and unit-tests. The following properties were moved into namespaces reserved for extensions: * ext::oneapi::cuda::property::context::use_primary_context, * ext::oneapi::cuda::property::queue::use_default_stream. The interop class template was re-defined in the sycl::detail namespace since it is not an extension of the SYCL API but just an implementation detail. The parts of CL/sycl/backend/opencl.hpp that contain specializations for the sycl::detail::interop class template were moved into the new created CL/sycl/detail/backend_traits_opencl.hpp header, as well as the same parts of the sycl/ext/oneapi/backend/level_zero.hpp header. The whole CL/sycl/backend/cuda.hpp header file was also renamed into the CL/sycl/detail/backend_traits_cuda.hpp one since the file contains a number of sycl::detail::interop class template specializations only. A warning was added into the old file.
1 parent 1cff0c6 commit 97f916e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1054
-562
lines changed

sycl/include/CL/sycl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <CL/sycl/atomic.hpp>
1414
#include <CL/sycl/atomic_fence.hpp>
1515
#include <CL/sycl/backend.hpp>
16+
#if SYCL_BACKEND_OPENCL
17+
#include <CL/sycl/backend/opencl.hpp>
18+
#endif
1619
#include <CL/sycl/buffer.hpp>
1720
#include <CL/sycl/builtins.hpp>
1821
#include <CL/sycl/context.hpp>
@@ -53,6 +56,9 @@
5356
#include <CL/sycl/usm.hpp>
5457
#include <CL/sycl/version.hpp>
5558
#include <sycl/ext/oneapi/atomic.hpp>
59+
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
60+
#include <sycl/ext/oneapi/backend/level_zero.hpp>
61+
#endif
5662
#include <sycl/ext/oneapi/experimental/builtins.hpp>
5763
#include <sycl/ext/oneapi/filter_selector.hpp>
5864
#include <sycl/ext/oneapi/group_algorithm.hpp>

sycl/include/CL/sycl/backend.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@
99
#pragma once
1010

1111
#include <CL/sycl/accessor.hpp>
12-
#include <CL/sycl/backend.hpp>
1312
#include <CL/sycl/backend_types.hpp>
1413
#include <CL/sycl/buffer.hpp>
1514
#include <CL/sycl/context.hpp>
1615
#include <CL/sycl/detail/backend_traits.hpp>
16+
#include <CL/sycl/feature_test.hpp>
17+
#if SYCL_BACKEND_OPENCL
18+
#include <CL/sycl/detail/backend_traits_opencl.hpp>
19+
#endif
20+
#if SYCL_EXT_ONEAPI_BACKEND_CUDA
21+
#include <CL/sycl/detail/backend_traits_cuda.hpp>
22+
#endif
23+
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
24+
#include <CL/sycl/detail/backend_traits_level_zero.hpp>
25+
#endif
1726
#include <CL/sycl/detail/common.hpp>
1827
#include <CL/sycl/detail/export.hpp>
1928
#include <CL/sycl/detail/pi.h>
@@ -31,16 +40,6 @@ __SYCL_INLINE_NAMESPACE(cl) {
3140
namespace sycl {
3241

3342
namespace detail {
34-
template <backend Backend, typename T> struct BackendInput {
35-
// TODO replace usage of interop with specializations.
36-
using type = typename interop<Backend, T>::type;
37-
};
38-
39-
template <backend Backend, typename T> struct BackendReturn {
40-
// TODO replace usage of interop with specializations.
41-
using type = typename interop<Backend, T>::type;
42-
};
43-
4443
// TODO each backend can have its own custom errc enumeration
4544
// but the details for this are not fully specified yet
4645
enum class backend_errc : unsigned int {};
@@ -69,8 +68,10 @@ template <backend BackendName, class SyclObjectT>
6968
auto get_native(const SyclObjectT &Obj)
7069
-> backend_return_t<BackendName, SyclObjectT> {
7170
// TODO use SYCL 2020 exception when implemented
72-
if (Obj.get_backend() != BackendName)
71+
if (Obj.get_backend() != BackendName) {
7372
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
73+
}
74+
7475
return Obj.template get_native<BackendName>();
7576
}
7677

@@ -80,9 +81,9 @@ template <backend BackendName, typename DataT, int Dimensions,
8081
access::placeholder IsPlaceholder>
8182
auto get_native(const accessor<DataT, Dimensions, AccessMode, AccessTarget,
8283
IsPlaceholder> &Obj) ->
83-
typename interop<BackendName, accessor<DataT, Dimensions, AccessMode,
84-
AccessTarget, IsPlaceholder>>::type =
85-
delete;
84+
typename detail::interop<
85+
BackendName, accessor<DataT, Dimensions, AccessMode, AccessTarget,
86+
IsPlaceholder>>::type = delete;
8687

8788
namespace detail {
8889
// Forward declaration

sycl/include/CL/sycl/backend/cuda.hpp

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,6 @@
99

1010
#pragma once
1111

12-
#include <CL/sycl/accessor.hpp>
13-
#include <CL/sycl/backend_types.hpp>
14-
#include <CL/sycl/context.hpp>
15-
#include <CL/sycl/detail/defines.hpp>
16-
#include <CL/sycl/device.hpp>
17-
#include <CL/sycl/event.hpp>
18-
#include <CL/sycl/queue.hpp>
12+
#include <CL/sycl/detail/defines_elementary.hpp>
1913

20-
typedef int CUdevice;
21-
typedef struct CUctx_st *CUcontext;
22-
typedef struct CUstream_st *CUstream;
23-
typedef struct CUevent_st *CUevent;
24-
typedef struct CUmod_st *CUmodule;
25-
26-
// As defined in the CUDA 10.1 header file. This requires CUDA version > 3.2
27-
#if defined(_WIN64) || defined(__LP64__)
28-
typedef unsigned long long CUdeviceptr;
29-
#else
30-
typedef unsigned int CUdeviceptr;
31-
#endif
32-
33-
__SYCL_INLINE_NAMESPACE(cl) {
34-
namespace sycl {
35-
36-
template <> struct interop<backend::cuda, device> { using type = CUdevice; };
37-
38-
template <> struct interop<backend::cuda, context> { using type = CUcontext; };
39-
40-
template <> struct interop<backend::cuda, queue> { using type = CUstream; };
41-
42-
template <> struct interop<backend::cuda, event> { using type = CUevent; };
43-
44-
#ifdef __SYCL_INTERNAL_API
45-
template <> struct interop<backend::cuda, program> { using type = CUmodule; };
46-
#endif
47-
48-
template <typename DataT, int Dimensions, access::mode AccessMode>
49-
struct interop<backend::cuda,
50-
accessor<DataT, Dimensions, AccessMode, access::target::device,
51-
access::placeholder::false_t>> {
52-
using type = CUdeviceptr;
53-
};
54-
55-
template <typename DataT, int Dimensions, access::mode AccessMode>
56-
struct interop<backend::cuda, accessor<DataT, Dimensions, AccessMode,
57-
access::target::constant_buffer,
58-
access::placeholder::false_t>> {
59-
using type = CUdeviceptr;
60-
};
61-
62-
template <typename DataT, int Dimensions, typename AllocatorT>
63-
struct interop<backend::cuda, buffer<DataT, Dimensions, AllocatorT>> {
64-
using type = CUdeviceptr;
65-
};
66-
67-
} // namespace sycl
68-
} // namespace cl
14+
__SYCL_WARNING("CL/sycl/backend/cuda.hpp is deprecated and no required anymore")

sycl/include/CL/sycl/backend/opencl.hpp

Lines changed: 11 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,103 +9,13 @@
99

1010
#pragma once
1111

12-
#include <CL/sycl/accessor.hpp>
1312
#include <CL/sycl/backend.hpp>
14-
#include <CL/sycl/backend_types.hpp>
15-
#include <CL/sycl/detail/backend_traits.hpp>
16-
#include <CL/sycl/detail/cl.h>
17-
#include <CL/sycl/kernel_bundle.hpp>
18-
19-
#include <vector>
2013

2114
__SYCL_INLINE_NAMESPACE(cl) {
2215
namespace sycl {
23-
24-
template <> struct interop<backend::opencl, platform> {
25-
using type = cl_platform_id;
26-
};
27-
28-
template <> struct interop<backend::opencl, device> {
29-
using type = cl_device_id;
30-
};
31-
32-
template <> struct interop<backend::opencl, context> {
33-
using type = cl_context;
34-
};
35-
36-
template <> struct interop<backend::opencl, queue> {
37-
using type = cl_command_queue;
38-
};
39-
40-
#ifdef __SYCL_INTERNAL_API
41-
template <> struct interop<backend::opencl, program> {
42-
using type = cl_program;
43-
};
44-
#endif
45-
46-
template <> struct interop<backend::opencl, event> { using type = cl_event; };
47-
48-
template <typename DataT, int Dimensions, access::mode AccessMode>
49-
struct interop<backend::opencl,
50-
accessor<DataT, Dimensions, AccessMode, access::target::device,
51-
access::placeholder::false_t>> {
52-
using type = cl_mem;
53-
};
54-
55-
template <typename DataT, int Dimensions, access::mode AccessMode>
56-
struct interop<backend::opencl, accessor<DataT, Dimensions, AccessMode,
57-
access::target::constant_buffer,
58-
access::placeholder::false_t>> {
59-
using type = cl_mem;
60-
};
61-
62-
template <typename DataT, int Dimensions, access::mode AccessMode>
63-
struct interop<backend::opencl,
64-
accessor<DataT, Dimensions, AccessMode, access::target::image,
65-
access::placeholder::false_t>> {
66-
using type = cl_mem;
67-
};
68-
69-
template <typename DataT, int Dimensions, typename AllocatorT>
70-
struct interop<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
71-
using type = cl_mem;
72-
};
73-
74-
namespace detail {
75-
template <bundle_state State>
76-
struct BackendInput<backend::opencl, kernel_bundle<State>> {
77-
using type = cl_program;
78-
};
79-
80-
template <bundle_state State>
81-
struct BackendReturn<backend::opencl, kernel_bundle<State>> {
82-
using type = std::vector<cl_program>;
83-
};
84-
85-
template <> struct BackendInput<backend::opencl, kernel> {
86-
using type = cl_kernel;
87-
};
88-
89-
template <> struct BackendReturn<backend::opencl, kernel> {
90-
using type = cl_kernel;
91-
};
92-
93-
template <> struct InteropFeatureSupportMap<backend::opencl> {
94-
static constexpr bool MakePlatform = true;
95-
static constexpr bool MakeDevice = true;
96-
static constexpr bool MakeContext = true;
97-
static constexpr bool MakeQueue = true;
98-
static constexpr bool MakeEvent = true;
99-
static constexpr bool MakeBuffer = true;
100-
static constexpr bool MakeKernel = true;
101-
static constexpr bool MakeKernelBundle = true;
102-
};
103-
} // namespace detail
104-
10516
namespace opencl {
106-
10717
// Implementation of various "make" functions resides in SYCL RT because
108-
// creating SYCL objects requires knowing details not acessible here.
18+
// creating SYCL objects requires knowing details not accessible here.
10919
// Note that they take opaque pi_native_handle that real OpenCL handles
11020
// are casted to.
11121
//
@@ -122,42 +32,46 @@ __SYCL_EXPORT queue make_queue(const context &Context,
12232
// Construction of SYCL platform.
12333
template <typename T, typename detail::enable_if_t<
12434
std::is_same<T, platform>::value> * = nullptr>
125-
T make(typename interop<backend::opencl, T>::type Interop) {
35+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
36+
T make(typename detail::interop<backend::opencl, T>::type Interop) {
12637
return make_platform(detail::pi::cast<pi_native_handle>(Interop));
12738
}
12839

12940
// Construction of SYCL device.
13041
template <typename T, typename detail::enable_if_t<
13142
std::is_same<T, device>::value> * = nullptr>
132-
T make(typename interop<backend::opencl, T>::type Interop) {
43+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
44+
T make(typename detail::interop<backend::opencl, T>::type Interop) {
13345
return make_device(detail::pi::cast<pi_native_handle>(Interop));
13446
}
13547

13648
// Construction of SYCL context.
13749
template <typename T, typename detail::enable_if_t<
13850
std::is_same<T, context>::value> * = nullptr>
139-
T make(typename interop<backend::opencl, T>::type Interop) {
51+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
52+
T make(typename detail::interop<backend::opencl, T>::type Interop) {
14053
return make_context(detail::pi::cast<pi_native_handle>(Interop));
14154
}
14255

14356
// Construction of SYCL program.
14457
#ifdef __SYCL_INTERNAL_API
14558
template <typename T, typename detail::enable_if_t<
14659
std::is_same<T, program>::value> * = nullptr>
60+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_program free function")
14761
T make(const context &Context,
148-
typename interop<backend::opencl, T>::type Interop) {
62+
typename detail::interop<backend::opencl, T>::type Interop) {
14963
return make_program(Context, detail::pi::cast<pi_native_handle>(Interop));
15064
}
15165
#endif
15266

15367
// Construction of SYCL queue.
15468
template <typename T, typename detail::enable_if_t<
15569
std::is_same<T, queue>::value> * = nullptr>
70+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function")
15671
T make(const context &Context,
157-
typename interop<backend::opencl, T>::type Interop) {
72+
typename detail::interop<backend::opencl, T>::type Interop) {
15873
return make_queue(Context, detail::pi::cast<pi_native_handle>(Interop));
15974
}
160-
16175
} // namespace opencl
16276
} // namespace sycl
16377
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/backend_types.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ enum class backend : char {
2424
ext_oneapi_level_zero = 2,
2525
level_zero __SYCL2020_DEPRECATED("use 'ext_oneapi_level_zero' instead") =
2626
ext_oneapi_level_zero,
27-
cuda = 3,
27+
ext_oneapi_cuda = 3,
28+
cuda __SYCL2020_DEPRECATED("use 'ext_oneapi_cuda' instead") = ext_oneapi_cuda,
2829
all = 4,
2930
ext_intel_esimd_emulator = 5,
3031
esimd_cpu __SYCL2020_DEPRECATED("use 'ext_oneapi_esimd_emulator' instead") =
3132
ext_intel_esimd_emulator,
32-
hip = 6,
33+
ext_oneapi_hip = 6,
34+
hip __SYCL2020_DEPRECATED("use 'ext_oneapi_hip' instead") = ext_oneapi_hip,
3335
};
3436

35-
template <backend Backend, typename SYCLObjectT> struct interop;
36-
3737
template <backend Backend> class backend_traits;
3838

3939
template <backend Backend, typename SYCLObjectT>
@@ -51,17 +51,17 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) {
5151
case backend::opencl:
5252
Out << "opencl";
5353
break;
54-
case backend::level_zero:
55-
Out << "level_zero";
54+
case backend::ext_oneapi_level_zero:
55+
Out << "ext_oneapi_level_zero";
5656
break;
57-
case backend::cuda:
58-
Out << "cuda";
57+
case backend::ext_oneapi_cuda:
58+
Out << "ext_oneapi_cuda";
5959
break;
6060
case backend::ext_intel_esimd_emulator:
6161
Out << "ext_intel_esimd_emulator";
6262
break;
63-
case backend::hip:
64-
Out << "hip";
63+
case backend::ext_oneapi_hip:
64+
Out << "ext_oneapi_hip";
6565
break;
6666
case backend::all:
6767
Out << "all";

sycl/include/CL/sycl/context.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#include <CL/sycl/backend_types.hpp>
11+
#include <CL/sycl/detail/backend_traits.hpp>
1212
#include <CL/sycl/detail/common.hpp>
1313
#include <CL/sycl/detail/export.hpp>
1414
#include <CL/sycl/detail/stl_type_traits.hpp>
@@ -219,9 +219,10 @@ class __SYCL_EXPORT context {
219219
/// \return a native handle, the type of which defined by the backend.
220220
template <backend BackendName>
221221
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
222-
auto get_native() const -> typename interop<BackendName, context>::type {
223-
return reinterpret_cast<typename interop<BackendName, context>::type>(
224-
getNative());
222+
auto get_native() const ->
223+
typename detail::interop<BackendName, context>::type {
224+
return reinterpret_cast<
225+
typename detail::interop<BackendName, context>::type>(getNative());
225226
}
226227

227228
private:

sycl/include/CL/sycl/detail/assert_happened.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <CL/sycl/detail/defines_elementary.hpp>
1212

13+
#include <cstdint>
14+
1315
#ifdef __SYCL_DEVICE_ONLY__
1416
// Reads Flag of AssertHappened on device
1517
SYCL_EXTERNAL __attribute__((weak)) extern "C" void

sycl/include/CL/sycl/detail/backend_traits.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
__SYCL_INLINE_NAMESPACE(cl) {
1515
namespace sycl {
1616
namespace detail {
17+
18+
template <backend Backend, typename SYCLObjectT> struct interop;
19+
20+
template <backend Backend, typename T> struct BackendInput;
21+
22+
template <backend Backend, typename T> struct BackendReturn;
23+
1724
template <backend Backend> struct InteropFeatureSupportMap {
1825
static constexpr bool MakePlatform = false;
1926
static constexpr bool MakeDevice = false;

0 commit comments

Comments
 (0)