Skip to content

Commit c855520

Browse files
authored
[SYCL][Ordered Queue] Begin moving ordered_queue to be a property on the queue (#1035)
Old ordered_queue is marked as deprecated. Signed-off-by: James Brodman <[email protected]>
1 parent 835a05d commit c855520

File tree

5 files changed

+84
-4
lines changed

5 files changed

+84
-4
lines changed

sycl/include/CL/sycl/ordered_queue.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@
1818
#include <memory>
1919
#include <utility>
2020

21+
#ifdef __has_cpp_attribute
22+
#if __has_cpp_attribute(deprecated)
23+
#define __SYCL_DEPRECATED__ [[deprecated("Replaced by in_order queue property")]]
24+
#endif
25+
#endif
26+
#ifndef __SYCL_DEPRECATED__
27+
#define __SYCL_DEPRECATED__
28+
#endif
29+
2130
__SYCL_INLINE namespace cl {
2231
namespace sycl {
2332

2433
// Forward declaration
2534
class context;
2635
class device;
27-
class ordered_queue {
36+
37+
class __SYCL_DEPRECATED__ ordered_queue {
2838
public:
2939
explicit ordered_queue(const property_list &propList = {})
3040
: ordered_queue(default_selector(), async_handler{}, propList) {}
@@ -37,7 +47,6 @@ class ordered_queue {
3747
const property_list &propList = {})
3848
: ordered_queue(deviceSelector.select_device(), async_handler{},
3949
propList) {}
40-
4150
ordered_queue(const device_selector &deviceSelector,
4251
const async_handler &asyncHandler,
4352
const property_list &propList = {})
@@ -171,6 +180,8 @@ class ordered_queue {
171180
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
172181
};
173182

183+
#undef __SYCL_DEPRECATED__
184+
174185
} // namespace sycl
175186
} // namespace cl
176187

sycl/include/CL/sycl/property_list.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class context_bound;
3939

4040
namespace queue {
4141
class enable_profiling;
42+
class in_order;
4243
} // namespace queue
4344

4445
namespace detail {
@@ -57,6 +58,7 @@ enum PropKind {
5758

5859
// Queue properties
5960
QueueEnableProfiling,
61+
InOrder,
6062

6163
PropKindSize
6264
};
@@ -110,6 +112,7 @@ RegisterProp(PropKind::BufferContextBound, buffer::context_bound);
110112

111113
// Queue
112114
RegisterProp(PropKind::QueueEnableProfiling, queue::enable_profiling);
115+
RegisterProp(PropKind::InOrder, queue::in_order);
113116

114117
// Sentinel, needed for automatic build of tuple in property_list.
115118
RegisterProp(PropKind::PropKindSize, PropBase);
@@ -172,6 +175,8 @@ class context_bound
172175
namespace queue {
173176
class enable_profiling
174177
: public detail::Prop<detail::PropKind::QueueEnableProfiling> {};
178+
179+
class in_order : public detail::Prop<detail::PropKind::InOrder> {};
175180
} // namespace queue
176181

177182
} // namespace property

sycl/include/CL/sycl/queue.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ class queue {
421421
});
422422
}
423423

424+
/// Returns whether the queue is in order or OoO
425+
///
426+
/// Equivalent to has_property<property::queue::in_order>()
427+
bool is_in_order() const {
428+
return impl->has_property<property::queue::in_order>();
429+
}
430+
424431
private:
425432
shared_ptr_class<detail::queue_impl> impl;
426433
template <class Obj>

sycl/source/queue.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818
__SYCL_INLINE namespace cl {
1919
namespace sycl {
20+
21+
namespace detail {
22+
23+
QueueOrder getQueueOrder(const property_list &propList) {
24+
if (propList.has_property<property::queue::in_order>()) {
25+
return QueueOrder::Ordered;
26+
}
27+
return QueueOrder::OOO;
28+
}
29+
30+
} // namespace detail
31+
2032
queue::queue(const context &syclContext, const device_selector &deviceSelector,
2133
const async_handler &asyncHandler, const property_list &propList) {
2234

@@ -27,16 +39,17 @@ queue::queue(const context &syclContext, const device_selector &deviceSelector,
2739
};
2840

2941
const device &syclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);
42+
3043
impl = std::make_shared<detail::queue_impl>(
3144
detail::getSyclObjImpl(syclDevice), detail::getSyclObjImpl(syclContext),
32-
asyncHandler, cl::sycl::detail::QueueOrder::OOO, propList);
45+
asyncHandler, detail::getQueueOrder(propList), propList);
3346
}
3447

3548
queue::queue(const device &syclDevice, const async_handler &asyncHandler,
3649
const property_list &propList) {
3750
impl = std::make_shared<detail::queue_impl>(
3851
detail::getSyclObjImpl(syclDevice), asyncHandler,
39-
cl::sycl::detail::QueueOrder::OOO, propList);
52+
detail::getQueueOrder(propList), propList);
4053
}
4154

4255
queue::queue(cl_command_queue clQueue, const context &syclContext,

sycl/test/ordered_queue/prop.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clangxx -fsycl %s -o %t1.out -lOpenCL
2+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
4+
5+
//==----------- ordered_dmemll.cpp - Device Memory Linked List test --------==//
6+
// It uses an ordered queue where explicit waiting is not necessary between
7+
// kernels
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
17+
using namespace cl::sycl;
18+
19+
constexpr int numNodes = 4;
20+
21+
bool getQueueOrder(cl_command_queue cq) {
22+
cl_command_queue_properties reportedProps;
23+
cl_int iRet = clGetCommandQueueInfo(
24+
cq, CL_QUEUE_PROPERTIES, sizeof(reportedProps), &reportedProps, nullptr);
25+
assert(CL_SUCCESS == iRet && "Failed to obtain queue info from ocl device");
26+
return (reportedProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) ? false
27+
: true;
28+
}
29+
30+
int main() {
31+
queue q{property::queue::in_order()};
32+
auto dev = q.get_device();
33+
34+
cl_command_queue cq = q.get();
35+
bool expected_result = dev.is_host() ? true : getQueueOrder(cq);
36+
if (!expected_result)
37+
return -1;
38+
39+
expected_result = dev.is_host() ? true : q.is_in_order();
40+
if (!expected_result)
41+
return -2;
42+
43+
return 0;
44+
}

0 commit comments

Comments
 (0)