|
| 1 | +//==----------------- ordered queue.hpp - SYCL queue -----------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include <CL/sycl/detail/common.hpp> |
| 12 | +#include <CL/sycl/detail/queue_impl.hpp> |
| 13 | +#include <CL/sycl/device_selector.hpp> |
| 14 | +#include <CL/sycl/exception_list.hpp> |
| 15 | +#include <CL/sycl/info/info_desc.hpp> |
| 16 | +#include <CL/sycl/property_list.hpp> |
| 17 | + |
| 18 | +#include <memory> |
| 19 | +#include <utility> |
| 20 | + |
| 21 | +namespace cl { |
| 22 | +namespace sycl { |
| 23 | + |
| 24 | +// Forward declaration |
| 25 | +class context; |
| 26 | +class device; |
| 27 | +class ordered_queue { |
| 28 | +public: |
| 29 | + explicit ordered_queue(const property_list &propList = {}) |
| 30 | + : ordered_queue(default_selector(), async_handler{}, propList) {} |
| 31 | + |
| 32 | + ordered_queue(const async_handler &asyncHandler, const property_list &propList = {}) |
| 33 | + : ordered_queue(default_selector(), asyncHandler, propList) {} |
| 34 | + |
| 35 | + ordered_queue(const device_selector &deviceSelector, |
| 36 | + const property_list &propList = {}) |
| 37 | + : ordered_queue(deviceSelector.select_device(), async_handler{}, propList) {} |
| 38 | + |
| 39 | + ordered_queue(const device_selector &deviceSelector, |
| 40 | + const async_handler &asyncHandler, const property_list &propList = {}) |
| 41 | + : ordered_queue(deviceSelector.select_device(), asyncHandler, propList) {} |
| 42 | + |
| 43 | + ordered_queue(const device &syclDevice, const property_list &propList = {}) |
| 44 | + : ordered_queue(syclDevice, async_handler{}, propList) {} |
| 45 | + |
| 46 | + ordered_queue(const device &syclDevice, const async_handler &asyncHandler, |
| 47 | + const property_list &propList = {}); |
| 48 | + |
| 49 | + ordered_queue(const context &syclContext, const device_selector &deviceSelector, |
| 50 | + const property_list &propList = {}) |
| 51 | + : ordered_queue(syclContext, deviceSelector, |
| 52 | + detail::getSyclObjImpl(syclContext)->get_async_handler(), |
| 53 | + propList) {} |
| 54 | + |
| 55 | + ordered_queue(const context &syclContext, const device_selector &deviceSelector, |
| 56 | + const async_handler &asyncHandler, const property_list &propList = {}); |
| 57 | + |
| 58 | + ordered_queue(cl_command_queue cl_Queue, const context &syclContext, |
| 59 | + const async_handler &asyncHandler = {}); |
| 60 | + |
| 61 | + ordered_queue(const ordered_queue &rhs) = default; |
| 62 | + |
| 63 | + ordered_queue(ordered_queue &&rhs) = default; |
| 64 | + |
| 65 | + ordered_queue &operator=(const ordered_queue &rhs) = default; |
| 66 | + |
| 67 | + ordered_queue &operator=(ordered_queue &&rhs) = default; |
| 68 | + |
| 69 | + bool operator==(const ordered_queue &rhs) const { return impl == rhs.impl; } |
| 70 | + |
| 71 | + bool operator!=(const ordered_queue &rhs) const { return !(*this == rhs); } |
| 72 | + |
| 73 | + cl_command_queue get() const { return impl->get(); } |
| 74 | + |
| 75 | + context get_context() const { return impl->get_context(); } |
| 76 | + |
| 77 | + device get_device() const { return impl->get_device(); } |
| 78 | + |
| 79 | + bool is_host() const { return impl->is_host(); } |
| 80 | + |
| 81 | + template <info::ordered_queue param> |
| 82 | + typename info::param_traits<info::ordered_queue, param>::return_type |
| 83 | + get_info() const { |
| 84 | + return impl->get_info<param>(); |
| 85 | + } |
| 86 | + |
| 87 | + template <typename T> event submit(T cgf) { return impl->submit(cgf, impl); } |
| 88 | + |
| 89 | + template <typename T> event submit(T cgf, ordered_queue &secondaryQueue) { |
| 90 | + return impl->submit(cgf, impl, secondaryQueue.impl); |
| 91 | + } |
| 92 | + |
| 93 | + void wait() { impl->wait(); } |
| 94 | + |
| 95 | + void wait_and_throw() { impl->wait_and_throw(); } |
| 96 | + |
| 97 | + void throw_asynchronous() { impl->throw_asynchronous(); } |
| 98 | + |
| 99 | + template <typename propertyT> bool has_property() const { |
| 100 | + return impl->has_property<propertyT>(); |
| 101 | + } |
| 102 | + |
| 103 | + template <typename propertyT> propertyT get_property() const { |
| 104 | + return impl->get_property<propertyT>(); |
| 105 | + } |
| 106 | + |
| 107 | + event memset(void* ptr, int value, size_t count) { |
| 108 | + return impl->memset(ptr, value, count); |
| 109 | + } |
| 110 | + |
| 111 | + event memcpy(void* dest, const void* src, size_t count) { |
| 112 | + return impl->memcpy(dest, src, count); |
| 113 | + } |
| 114 | + |
| 115 | +private: |
| 116 | + std::shared_ptr<detail::queue_impl> impl; |
| 117 | + template <class Obj> |
| 118 | + friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject); |
| 119 | +}; |
| 120 | + |
| 121 | +} // namespace sycl |
| 122 | +} // namespace cl |
| 123 | + |
| 124 | +namespace std { |
| 125 | +template <> struct hash<cl::sycl::ordered_queue> { |
| 126 | + size_t operator()(const cl::sycl::ordered_queue &q) const { |
| 127 | + return std::hash<std::shared_ptr<cl::sycl::detail::queue_impl>>()( |
| 128 | + cl::sycl::detail::getSyclObjImpl(q)); |
| 129 | + } |
| 130 | +}; |
| 131 | +} // namespace std |
0 commit comments