DPC++ Runtime
Runtime libraries for oneAPI DPC++
queue.cpp
Go to the documentation of this file.
1 //==-------------- queue.cpp -----------------------------------------------==//
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 
10 #include <detail/event_impl.hpp>
11 #include <detail/queue_impl.hpp>
12 #include <sycl/detail/common.hpp>
13 #include <sycl/event.hpp>
14 #include <sycl/exception_list.hpp>
16 #include <sycl/handler.hpp>
17 #include <sycl/queue.hpp>
18 #include <sycl/stl.hpp>
19 
20 #include <algorithm>
21 
22 namespace sycl {
24 
25 queue::queue(const context &SyclContext, const device_selector &DeviceSelector,
26  const async_handler &AsyncHandler, const property_list &PropList) {
27 
28  const std::vector<device> Devs = SyclContext.get_devices();
29 
30  auto Comp = [&DeviceSelector](const device &d1, const device &d2) {
31  return DeviceSelector(d1) < DeviceSelector(d2);
32  };
33 
34  const device &SyclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);
35 
36  impl = std::make_shared<detail::queue_impl>(
37  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
38  AsyncHandler, PropList);
39 }
40 
41 queue::queue(const context &SyclContext, const device &SyclDevice,
42  const async_handler &AsyncHandler, const property_list &PropList) {
43  impl = std::make_shared<detail::queue_impl>(
44  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
45  AsyncHandler, PropList);
46 }
47 
48 queue::queue(const device &SyclDevice, const async_handler &AsyncHandler,
49  const property_list &PropList) {
50  impl = std::make_shared<detail::queue_impl>(
51  detail::getSyclObjImpl(SyclDevice), AsyncHandler, PropList);
52 }
53 
54 queue::queue(cl_command_queue clQueue, const context &SyclContext,
55  const async_handler &AsyncHandler) {
56  impl = std::make_shared<detail::queue_impl>(
57  reinterpret_cast<RT::PiQueue>(clQueue),
58  detail::getSyclObjImpl(SyclContext), AsyncHandler);
59 }
60 
61 queue::queue(const context &SyclContext, const device_selector &deviceSelector,
62  const property_list &PropList)
63  : queue(SyclContext, deviceSelector,
64  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
65  PropList) {}
66 
67 queue::queue(const context &SyclContext, const device &SyclDevice,
68  const property_list &PropList)
69  : queue(SyclContext, SyclDevice,
70  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
71  PropList) {}
72 
73 cl_command_queue queue::get() const { return impl->get(); }
74 
75 context queue::get_context() const { return impl->get_context(); }
76 
77 device queue::get_device() const { return impl->get_device(); }
78 
79 bool queue::is_host() const {
80  bool IsHost = impl->is_host();
81  assert(!IsHost && "queue::is_host should not be called in implementation.");
82  return IsHost;
83 }
84 
85 void queue::throw_asynchronous() { impl->throw_asynchronous(); }
86 
87 event queue::memset(void *Ptr, int Value, size_t Count) {
88  return impl->memset(impl, Ptr, Value, Count, {});
89 }
90 
91 event queue::memset(void *Ptr, int Value, size_t Count, event DepEvent) {
92  return impl->memset(impl, Ptr, Value, Count, {DepEvent});
93 }
94 
95 event queue::memset(void *Ptr, int Value, size_t Count,
96  const std::vector<event> &DepEvents) {
97  return impl->memset(impl, Ptr, Value, Count, DepEvents);
98 }
99 
100 event queue::memcpy(void *Dest, const void *Src, size_t Count) {
101  return impl->memcpy(impl, Dest, Src, Count, {});
102 }
103 
104 event queue::memcpy(void *Dest, const void *Src, size_t Count, event DepEvent) {
105  return impl->memcpy(impl, Dest, Src, Count, {DepEvent});
106 }
107 
108 event queue::memcpy(void *Dest, const void *Src, size_t Count,
109  const std::vector<event> &DepEvents) {
110  return impl->memcpy(impl, Dest, Src, Count, DepEvents);
111 }
112 
113 event queue::mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice) {
114  return mem_advise(Ptr, Length, int(Advice));
115 }
116 
117 event queue::mem_advise(const void *Ptr, size_t Length, int Advice) {
118  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {});
119 }
120 
121 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
122  event DepEvent) {
123  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {DepEvent});
124 }
125 
126 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
127  const std::vector<event> &DepEvents) {
128  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), DepEvents);
129 }
130 
131 event queue::discard_or_return(const event &Event) {
132  if (!(impl->MDiscardEvents))
133  return Event;
134  using detail::event_impl;
135  auto Impl = std::make_shared<event_impl>(event_impl::HES_Discarded);
136  return detail::createSyclObjFromImpl<event>(Impl);
137 }
138 
139 event queue::submit_impl(std::function<void(handler &)> CGH,
140  const detail::code_location &CodeLoc) {
141  return impl->submit(CGH, impl, CodeLoc);
142 }
143 
144 event queue::submit_impl(std::function<void(handler &)> CGH, queue SecondQueue,
145  const detail::code_location &CodeLoc) {
146  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc);
147 }
148 
149 event queue::submit_impl_and_postprocess(
150  std::function<void(handler &)> CGH, const detail::code_location &CodeLoc,
151  const SubmitPostProcessF &PostProcess) {
152  return impl->submit(CGH, impl, CodeLoc, &PostProcess);
153 }
154 
155 event queue::submit_impl_and_postprocess(
156  std::function<void(handler &)> CGH, queue SecondQueue,
157  const detail::code_location &CodeLoc,
158  const SubmitPostProcessF &PostProcess) {
159  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc, &PostProcess);
160 }
161 
163  impl->wait(CodeLoc);
164 }
165 
167  impl->wait_and_throw(CodeLoc);
168 }
169 
170 template <typename Param>
173  return impl->get_info<Param>();
174 }
175 
176 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \
177  template __SYCL_EXPORT ReturnT queue::get_info<info::queue::Desc>() const;
178 
179 #include <sycl/info/queue_traits.def>
180 
181 #undef __SYCL_PARAM_TRAITS_SPEC
182 
183 template <typename PropertyT> bool queue::has_property() const noexcept {
184  return impl->has_property<PropertyT>();
185 }
186 
187 template <typename PropertyT> PropertyT queue::get_property() const {
188  return impl->get_property<PropertyT>();
189 }
190 
191 #define __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME) \
192  template __SYCL_EXPORT bool queue::has_property<NS_QUALIFIER::PROP_NAME>() \
193  const noexcept; \
194  template __SYCL_EXPORT NS_QUALIFIER::PROP_NAME \
195  queue::get_property<NS_QUALIFIER::PROP_NAME>() const;
196 
197 #define __SYCL_DATA_LESS_PROP(NS_QUALIFIER, PROP_NAME, ENUM_VAL) \
198  __SYCL_MANUALLY_DEFINED_PROP(NS_QUALIFIER, PROP_NAME)
199 
200 #include <sycl/properties/queue_properties.def>
201 
202 bool queue::is_in_order() const {
203  return impl->has_property<property::queue::in_order>();
204 }
205 
206 backend queue::get_backend() const noexcept { return getImplBackend(impl); }
207 
208 bool queue::ext_oneapi_empty() const { return impl->ext_oneapi_empty(); }
209 
210 pi_native_handle queue::getNative() const { return impl->getNative(); }
211 
212 buffer<detail::AssertHappened, 1> &queue::getAssertHappenedBuffer() {
213  return impl->getAssertHappenedBuffer();
214 }
215 
216 event queue::memcpyToDeviceGlobal(void *DeviceGlobalPtr, const void *Src,
217  bool IsDeviceImageScope, size_t NumBytes,
218  size_t Offset,
219  const std::vector<event> &DepEvents) {
220  return impl->memcpyToDeviceGlobal(impl, DeviceGlobalPtr, Src,
221  IsDeviceImageScope, NumBytes, Offset,
222  DepEvents);
223 }
224 
225 event queue::memcpyFromDeviceGlobal(void *Dest, const void *DeviceGlobalPtr,
226  bool IsDeviceImageScope, size_t NumBytes,
227  size_t Offset,
228  const std::vector<event> &DepEvents) {
229  return impl->memcpyFromDeviceGlobal(impl, Dest, DeviceGlobalPtr,
230  IsDeviceImageScope, NumBytes, Offset,
231  DepEvents);
232 }
233 
234 bool queue::device_has(aspect Aspect) const {
235  // avoid creating sycl object from impl
236  return impl->getDeviceImplPtr()->has(Aspect);
237 }
238 
240  return impl->has_property<
242 }
243 
244 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
245 } // namespace sycl
sycl::_V1::queue::is_in_order
bool is_in_order() const
Returns whether the queue is in order or OoO.
Definition: queue.cpp:202
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:24
event_impl.hpp
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
stl.hpp
sycl::_V1::queue::queue
queue(const property_list &PropList={})
Constructs a SYCL queue instance using the device returned by an instance of default_selector.
Definition: queue.hpp:95
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
_pi_mem_advice
_pi_mem_advice
Definition: pi.h:465
sycl::_V1::queue::has_property
bool has_property() const noexcept
Definition: queue.cpp:183
sycl::_V1::ext::codeplay::experimental::property::queue::enable_fusion
Definition: fusion_properties.hpp:30
event.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:40
queue_impl.hpp
sycl::_V1::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:17
sycl::_V1::queue::ext_oneapi_empty
bool ext_oneapi_empty() const
Allows to check status of the queue (completed vs noncompleted).
Definition: queue.cpp:208
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
sycl::_V1::queue::wait_proxy
void wait_proxy(const detail::code_location &CodeLoc)
Proxy method for wait to forward the code location information to the implementation.
Definition: queue.cpp:162
sycl::_V1::detail::event_impl
Definition: event_impl.hpp:36
sycl::_V1::queue::get_backend
backend get_backend() const noexcept
Returns the backend associated with this queue.
Definition: queue.cpp:206
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:89
device_selector
sycl::_V1::queue::mem_advise
event mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice)
Provides additional information to the underlying runtime about how different allocations are used.
Definition: queue.cpp:113
sycl::_V1::queue::get_property
PropertyT get_property() const
Definition: queue.cpp:187
common.hpp
sycl::_V1::detail::pi::PiQueue
::pi_queue PiQueue
Definition: pi.hpp:132
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
queue.hpp
sycl::_V1::access::target::device
@ device
pi_mem_advice
_pi_mem_advice pi_mem_advice
Definition: pi.h:658
fusion_properties.hpp
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
sycl::_V1::queue::get_info
detail::is_queue_info_desc< Param >::return_type get_info() const
Queries SYCL queue for information.
Definition: queue.cpp:172
sycl::_V1::queue::get_context
context get_context() const
Definition: queue.cpp:75
sycl::_V1::detail::code_location
Definition: common.hpp:66
handler.hpp
sycl::_V1::queue::memset
event memset(void *Ptr, int Value, size_t Count)
Fills the memory pointed by a USM pointer with the value specified.
Definition: queue.cpp:87
sycl::_V1::async_handler
std::function< void(sycl::exception_list)> async_handler
Definition: exception_list.hpp:54
sycl::_V1::queue::wait_and_throw_proxy
void wait_and_throw_proxy(const detail::code_location &CodeLoc)
Proxy method for wait_and_throw to forward the code location information to the implementation.
Definition: queue.cpp:166
sycl::_V1::queue::ext_codeplay_supports_fusion
bool ext_codeplay_supports_fusion() const
Returns true if the queue was created with the ext::codeplay::experimental::property::queue::enable_f...
Definition: queue.cpp:239
backend_impl.hpp
exception_list.hpp
sycl::_V1::queue::memcpy
event memcpy(void *Dest, const void *Src, size_t Count)
Copies data from one memory region to another, each is either a host pointer or a pointer within USM ...
Definition: queue.cpp:100
sycl::_V1::queue::throw_asynchronous
void throw_asynchronous()
Checks if any asynchronous errors have been produced by the queue and if so reports them to the async...
Definition: queue.cpp:85
sycl::_V1::queue::get_device
device get_device() const
Definition: queue.cpp:77
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41
sycl::_V1::detail::is_queue_info_desc
Definition: info_desc_helpers.hpp:22