Skip to content

Commit 5d1c8a6

Browse files
author
Alexander Batashev
authored
[SYCL] Use forward declarations in ordered_queue (#1098)
This patch is a part of effort to decouple SYCL Runtime library interface from its actual implementation. The goal is to improve SYCL ABI/API compatibility between different versions of library. ordered_queue class was refactored to use queue_impl class as forward declaration in headers. All calls to impl were moved to the library. Also, std::shared_ptr was replaced with shared_ptr_class. Signed-off-by: Alexander Batashev <[email protected]>
1 parent 42cf5bf commit 5d1c8a6

File tree

2 files changed

+88
-32
lines changed

2 files changed

+88
-32
lines changed

sycl/include/CL/sycl/ordered_queue.hpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/common.hpp>
12-
#include <CL/sycl/detail/queue_impl.hpp>
1312
#include <CL/sycl/device_selector.hpp>
1413
#include <CL/sycl/exception_list.hpp>
1514
#include <CL/sycl/info/info_desc.hpp>
@@ -33,8 +32,12 @@ namespace sycl {
3332
// Forward declaration
3433
class context;
3534
class device;
35+
namespace detail {
36+
class queue_impl;
37+
}
3638

3739
class __SYCL_DEPRECATED__ ordered_queue {
40+
3841
public:
3942
explicit ordered_queue(const property_list &propList = {})
4043
: ordered_queue(default_selector(), async_handler{}, propList) {}
@@ -60,10 +63,7 @@ class __SYCL_DEPRECATED__ ordered_queue {
6063

6164
ordered_queue(const context &syclContext,
6265
const device_selector &deviceSelector,
63-
const property_list &propList = {})
64-
: ordered_queue(syclContext, deviceSelector,
65-
detail::getSyclObjImpl(syclContext)->get_async_handler(),
66-
propList) {}
66+
const property_list &propList = {});
6767

6868
ordered_queue(const context &syclContext,
6969
const device_selector &deviceSelector,
@@ -85,47 +85,36 @@ class __SYCL_DEPRECATED__ ordered_queue {
8585

8686
bool operator!=(const ordered_queue &rhs) const { return !(*this == rhs); }
8787

88-
cl_command_queue get() const { return impl->get(); }
88+
cl_command_queue get() const;
8989

90-
context get_context() const { return impl->get_context(); }
90+
context get_context() const;
9191

92-
device get_device() const { return impl->get_device(); }
92+
device get_device() const;
9393

94-
bool is_host() const { return impl->is_host(); }
94+
bool is_host() const;
9595

96-
template <info::ordered_queue param>
97-
typename info::param_traits<info::ordered_queue, param>::return_type
98-
get_info() const {
99-
return impl->get_info<param>();
100-
}
96+
template <info::queue param>
97+
typename info::param_traits<info::queue, param>::return_type get_info() const;
10198

102-
template <typename T> event submit(T cgf) { return impl->submit(cgf, impl); }
99+
template <typename T> event submit(T cgf) { return submit_impl(cgf); }
103100

104101
template <typename T> event submit(T cgf, ordered_queue &secondaryQueue) {
105-
return impl->submit(cgf, impl, secondaryQueue.impl);
102+
return submit_impl(cgf, secondaryQueue);
106103
}
107104

108-
void wait() { impl->wait(); }
105+
void wait();
109106

110-
void wait_and_throw() { impl->wait_and_throw(); }
107+
void wait_and_throw();
111108

112-
void throw_asynchronous() { impl->throw_asynchronous(); }
109+
void throw_asynchronous();
113110

114-
template <typename propertyT> bool has_property() const {
115-
return impl->has_property<propertyT>();
116-
}
111+
template <typename propertyT> bool has_property() const;
117112

118-
template <typename propertyT> propertyT get_property() const {
119-
return impl->get_property<propertyT>();
120-
}
113+
template <typename propertyT> propertyT get_property() const;
121114

122-
event memset(void *ptr, int value, size_t count) {
123-
return impl->memset(impl, ptr, value, count);
124-
}
115+
event memset(void *ptr, int value, size_t count);
125116

126-
event memcpy(void *dest, const void *src, size_t count) {
127-
return impl->memcpy(impl, dest, src, count);
128-
}
117+
event memcpy(void *dest, const void *src, size_t count);
129118

130119
event prefetch(const void *Ptr, size_t Count) {
131120
return submit([=](handler &cgh) { cgh.prefetch(Ptr, Count); });
@@ -175,9 +164,13 @@ class __SYCL_DEPRECATED__ ordered_queue {
175164
}
176165

177166
private:
178-
std::shared_ptr<detail::queue_impl> impl;
167+
shared_ptr_class<detail::queue_impl> impl;
179168
template <class Obj>
180169
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
170+
171+
event submit_impl(function_class<void(handler &)> CGH);
172+
event submit_impl(function_class<void(handler &)> CGH,
173+
ordered_queue &secondQueue);
181174
};
182175

183176
#undef __SYCL_DEPRECATED__

sycl/source/ordered_queue.cpp

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

9+
#include <CL/sycl/detail/queue_impl.hpp>
910
#include <CL/sycl/exception_list.hpp>
1011
#include <CL/sycl/ordered_queue.hpp>
1112

1213
#include <algorithm>
1314

1415
__SYCL_INLINE namespace cl {
1516
namespace sycl {
17+
ordered_queue::ordered_queue(const context &syclContext,
18+
const device_selector &deviceSelector,
19+
const property_list &propList)
20+
: ordered_queue(syclContext, deviceSelector,
21+
detail::getSyclObjImpl(syclContext)->get_async_handler(),
22+
propList) {}
1623
ordered_queue::ordered_queue(const context &syclContext,
1724
const device_selector &deviceSelector,
1825
const async_handler &asyncHandler,
@@ -54,5 +61,61 @@ ordered_queue::ordered_queue(cl_command_queue clQueue,
5461
m_CommandQueue, detail::getSyclObjImpl(syclContext), asyncHandler);
5562
}
5663

64+
cl_command_queue ordered_queue::get() const { return impl->get(); }
65+
66+
context ordered_queue::get_context() const { return impl->get_context(); }
67+
68+
device ordered_queue::get_device() const { return impl->get_device(); }
69+
70+
bool ordered_queue::is_host() const { return impl->is_host(); }
71+
72+
void ordered_queue::wait() { impl->wait(); }
73+
74+
void ordered_queue::wait_and_throw() { impl->wait_and_throw(); }
75+
76+
void ordered_queue::throw_asynchronous() { impl->throw_asynchronous(); }
77+
78+
event ordered_queue::memset(void *ptr, int value, size_t count) {
79+
return impl->memset(impl, ptr, value, count);
80+
}
81+
82+
event ordered_queue::memcpy(void *dest, const void *src, size_t count) {
83+
return impl->memcpy(impl, dest, src, count);
84+
}
85+
86+
event ordered_queue::submit_impl(function_class<void(handler &)> CGH) {
87+
return impl->submit(CGH, impl);
88+
}
89+
90+
event ordered_queue::submit_impl(function_class<void(handler &)> CGH,
91+
ordered_queue &secondQueue) {
92+
return impl->submit(CGH, impl, secondQueue.impl);
93+
}
94+
95+
template <info::queue param>
96+
typename info::param_traits<info::queue, param>::return_type
97+
ordered_queue::get_info() const {
98+
return impl->get_info<param>();
99+
}
100+
101+
#define PARAM_TRAITS_SPEC(param_type, param, ret_type) \
102+
template ret_type ordered_queue::get_info<info::param_type::param>() const;
103+
104+
#include <CL/sycl/info/queue_traits.def>
105+
106+
#undef PARAM_TRAITS_SPEC
107+
108+
template <typename propertyT> bool ordered_queue::has_property() const {
109+
return impl->has_property<propertyT>();
110+
}
111+
112+
template <typename propertyT> propertyT ordered_queue::get_property() const {
113+
return impl->get_property<propertyT>();
114+
}
115+
116+
template bool
117+
ordered_queue::has_property<property::queue::enable_profiling>() const;
118+
template property::queue::enable_profiling
119+
ordered_queue::get_property<property::queue::enable_profiling>() const;
57120
} // namespace sycl
58121
} // namespace cl

0 commit comments

Comments
 (0)