Skip to content

[SYCL][Ordered Queue] Begin moving ordered_queue to be a property on the queue. #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions sycl/include/CL/sycl/ordered_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
#include <memory>
#include <utility>

#ifdef __has_cpp_attribute
#if __has_cpp_attribute(deprecated)
#define __SYCL_DEPRECATED__ [[deprecated("Replaced by in_order queue property")]]
#endif
#endif
#ifndef __SYCL_DEPRECATED__
#define __SYCL_DEPRECATED__
#endif

__SYCL_INLINE namespace cl {
namespace sycl {

// Forward declaration
class context;
class device;
class ordered_queue {

class __SYCL_DEPRECATED__ ordered_queue {
public:
explicit ordered_queue(const property_list &propList = {})
: ordered_queue(default_selector(), async_handler{}, propList) {}
Expand All @@ -37,7 +47,6 @@ class ordered_queue {
const property_list &propList = {})
: ordered_queue(deviceSelector.select_device(), async_handler{},
propList) {}

ordered_queue(const device_selector &deviceSelector,
const async_handler &asyncHandler,
const property_list &propList = {})
Expand Down Expand Up @@ -171,6 +180,8 @@ class ordered_queue {
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
};

#undef __SYCL_DEPRECATED__

} // namespace sycl
} // namespace cl

Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class context_bound;

namespace queue {
class enable_profiling;
class in_order;
} // namespace queue

namespace detail {
Expand All @@ -57,6 +58,7 @@ enum PropKind {

// Queue properties
QueueEnableProfiling,
InOrder,

PropKindSize
};
Expand Down Expand Up @@ -110,6 +112,7 @@ RegisterProp(PropKind::BufferContextBound, buffer::context_bound);

// Queue
RegisterProp(PropKind::QueueEnableProfiling, queue::enable_profiling);
RegisterProp(PropKind::InOrder, queue::in_order);

// Sentinel, needed for automatic build of tuple in property_list.
RegisterProp(PropKind::PropKindSize, PropBase);
Expand Down Expand Up @@ -172,6 +175,8 @@ class context_bound
namespace queue {
class enable_profiling
: public detail::Prop<detail::PropKind::QueueEnableProfiling> {};

class in_order : public detail::Prop<detail::PropKind::InOrder> {};
} // namespace queue

} // namespace property
Expand Down
7 changes: 7 additions & 0 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ class queue {
});
}

/// Returns whether the queue is in order or OoO
///
/// Equivalent to has_property<property::queue::in_order>()
bool is_in_order() const {
return impl->has_property<property::queue::in_order>();
}

private:
std::shared_ptr<detail::queue_impl> impl;
template <class Obj>
Expand Down
17 changes: 15 additions & 2 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@

__SYCL_INLINE namespace cl {
namespace sycl {

namespace detail {

QueueOrder getQueueOrder(const property_list &propList) {
if (propList.has_property<property::queue::in_order>()) {
return QueueOrder::Ordered;
}
return QueueOrder::OOO;
}

} // namespace detail

queue::queue(const context &syclContext, const device_selector &deviceSelector,
const async_handler &asyncHandler, const property_list &propList) {

Expand All @@ -23,16 +35,17 @@ queue::queue(const context &syclContext, const device_selector &deviceSelector,
};

const device &syclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);

impl = std::make_shared<detail::queue_impl>(
detail::getSyclObjImpl(syclDevice), detail::getSyclObjImpl(syclContext),
asyncHandler, cl::sycl::detail::QueueOrder::OOO, propList);
asyncHandler, detail::getQueueOrder(propList), propList);
}

queue::queue(const device &syclDevice, const async_handler &asyncHandler,
const property_list &propList) {
impl = std::make_shared<detail::queue_impl>(
detail::getSyclObjImpl(syclDevice), asyncHandler,
cl::sycl::detail::QueueOrder::OOO, propList);
detail::getQueueOrder(propList), propList);
}

queue::queue(cl_command_queue clQueue, const context &syclContext,
Expand Down
44 changes: 44 additions & 0 deletions sycl/test/ordered_queue/prop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %clangxx -fsycl %s -o %t1.out -lOpenCL
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
// RUN: %GPU_RUN_PLACEHOLDER %t1.out

//==----------- ordered_dmemll.cpp - Device Memory Linked List test --------==//
// It uses an ordered queue where explicit waiting is not necessary between
// kernels
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>

using namespace cl::sycl;

constexpr int numNodes = 4;

bool getQueueOrder(cl_command_queue cq) {
cl_command_queue_properties reportedProps;
cl_int iRet = clGetCommandQueueInfo(
cq, CL_QUEUE_PROPERTIES, sizeof(reportedProps), &reportedProps, nullptr);
assert(CL_SUCCESS == iRet && "Failed to obtain queue info from ocl device");
return (reportedProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) ? false
: true;
}

int main() {
queue q{property::queue::in_order()};
auto dev = q.get_device();

cl_command_queue cq = q.get();
bool expected_result = dev.is_host() ? true : getQueueOrder(cq);
if (!expected_result)
return -1;

expected_result = dev.is_host() ? true : q.is_in_order();
if (!expected_result)
return -2;

return 0;
}