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 
9 #include <CL/sycl/event.hpp>
11 #include <CL/sycl/handler.hpp>
12 #include <CL/sycl/queue.hpp>
13 #include <CL/sycl/stl.hpp>
14 #include <detail/backend_impl.hpp>
15 #include <detail/event_impl.hpp>
16 #include <detail/queue_impl.hpp>
17 
18 #include <algorithm>
19 
21 namespace sycl {
22 
23 queue::queue(const context &SyclContext, const device_selector &DeviceSelector,
24  const async_handler &AsyncHandler, const property_list &PropList) {
25 
26  const std::vector<device> Devs = SyclContext.get_devices();
27 
28  auto Comp = [&DeviceSelector](const device &d1, const device &d2) {
29  return DeviceSelector(d1) < DeviceSelector(d2);
30  };
31 
32  const device &SyclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);
33 
34  impl = std::make_shared<detail::queue_impl>(
35  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
36  AsyncHandler, PropList);
37 }
38 
39 queue::queue(const context &SyclContext, const device &SyclDevice,
40  const async_handler &AsyncHandler, const property_list &PropList) {
41  impl = std::make_shared<detail::queue_impl>(
42  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
43  AsyncHandler, PropList);
44 }
45 
46 queue::queue(const device &SyclDevice, const async_handler &AsyncHandler,
47  const property_list &PropList) {
48  impl = std::make_shared<detail::queue_impl>(
49  detail::getSyclObjImpl(SyclDevice), AsyncHandler, PropList);
50 }
51 
52 queue::queue(cl_command_queue clQueue, const context &SyclContext,
53  const async_handler &AsyncHandler) {
54  impl = std::make_shared<detail::queue_impl>(
55  reinterpret_cast<RT::PiQueue>(clQueue),
56  detail::getSyclObjImpl(SyclContext), AsyncHandler);
57 }
58 
59 queue::queue(const context &SyclContext, const device_selector &deviceSelector,
60  const property_list &PropList)
61  : queue(SyclContext, deviceSelector,
62  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
63  PropList) {}
64 
65 queue::queue(const context &SyclContext, const device &SyclDevice,
66  const property_list &PropList)
67  : queue(SyclContext, SyclDevice,
68  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
69  PropList) {}
70 
71 cl_command_queue queue::get() const { return impl->get(); }
72 
73 context queue::get_context() const { return impl->get_context(); }
74 
75 device queue::get_device() const { return impl->get_device(); }
76 
77 bool queue::is_host() const { return impl->is_host(); }
78 
79 
80 void queue::throw_asynchronous() { impl->throw_asynchronous(); }
81 
82 event queue::memset(void *Ptr, int Value, size_t Count) {
83  return impl->memset(impl, Ptr, Value, Count, {});
84 }
85 
86 event queue::memset(void *Ptr, int Value, size_t Count, event DepEvent) {
87  return impl->memset(impl, Ptr, Value, Count, {DepEvent});
88 }
89 
90 event queue::memset(void *Ptr, int Value, size_t Count,
91  const std::vector<event> &DepEvents) {
92  return impl->memset(impl, Ptr, Value, Count, DepEvents);
93 }
94 
95 event queue::memcpy(void *Dest, const void *Src, size_t Count) {
96  return impl->memcpy(impl, Dest, Src, Count, {});
97 }
98 
99 event queue::memcpy(void *Dest, const void *Src, size_t Count, event DepEvent) {
100  return impl->memcpy(impl, Dest, Src, Count, {DepEvent});
101 }
102 
103 event queue::memcpy(void *Dest, const void *Src, size_t Count,
104  const std::vector<event> &DepEvents) {
105  return impl->memcpy(impl, Dest, Src, Count, DepEvents);
106 }
107 
108 event queue::mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice) {
109  return mem_advise(Ptr, Length, int(Advice));
110 }
111 
112 event queue::mem_advise(const void *Ptr, size_t Length, int Advice) {
113  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {});
114 }
115 
116 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
117  event DepEvent) {
118  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {DepEvent});
119 }
120 
121 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
122  const std::vector<event> &DepEvents) {
123  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), DepEvents);
124 }
125 
126 event queue::discard_or_return(const event &Event) {
127  if (impl->MDiscardEvents) {
128  using detail::event_impl;
129  auto Impl = std::make_shared<event_impl>(event_impl::HES_Discarded);
130  return detail::createSyclObjFromImpl<event>(Impl);
131  }
132  return Event;
133 }
134 
135 event queue::submit_impl(std::function<void(handler &)> CGH,
136  const detail::code_location &CodeLoc) {
137  return impl->submit(CGH, impl, CodeLoc);
138 }
139 
140 event queue::submit_impl(std::function<void(handler &)> CGH, queue SecondQueue,
141  const detail::code_location &CodeLoc) {
142  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc);
143 }
144 
145 event queue::submit_impl_and_postprocess(
146  std::function<void(handler &)> CGH, const detail::code_location &CodeLoc,
147  const SubmitPostProcessF &PostProcess) {
148  return impl->submit(CGH, impl, CodeLoc, &PostProcess);
149 }
150 
151 event queue::submit_impl_and_postprocess(
152  std::function<void(handler &)> CGH, queue SecondQueue,
153  const detail::code_location &CodeLoc,
154  const SubmitPostProcessF &PostProcess) {
155  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc, &PostProcess);
156 }
157 
159  impl->wait(CodeLoc);
160 }
161 
163  impl->wait_and_throw(CodeLoc);
164 }
165 
166 template <info::queue Param>
169  return impl->get_info<Param>();
170 }
171 
172 #define __SYCL_PARAM_TRAITS_SPEC(ParamType, Param, RetType) \
173  template __SYCL_EXPORT RetType queue::get_info<info::ParamType::Param>() \
174  const;
175 
176 #include <CL/sycl/info/queue_traits.def>
177 
178 #undef __SYCL_PARAM_TRAITS_SPEC
179 
180 template <typename PropertyT> bool queue::has_property() const {
181  return impl->has_property<PropertyT>();
182 }
183 
184 template <typename PropertyT> PropertyT queue::get_property() const {
185  return impl->get_property<PropertyT>();
186 }
187 
188 template __SYCL_EXPORT bool
189 queue::has_property<property::queue::enable_profiling>() const;
190 template __SYCL_EXPORT property::queue::enable_profiling
191 queue::get_property<property::queue::enable_profiling>() const;
192 
193 template __SYCL_EXPORT bool
194 queue::has_property<property::queue::in_order>() const;
195 template __SYCL_EXPORT property::queue::in_order
196 queue::get_property<property::queue::in_order>() const;
197 
198 bool queue::is_in_order() const {
199  return impl->has_property<property::queue::in_order>();
200 }
201 
202 backend queue::get_backend() const noexcept { return getImplBackend(impl); }
203 
204 pi_native_handle queue::getNative() const { return impl->getNative(); }
205 
206 buffer<detail::AssertHappened, 1> &queue::getAssertHappenedBuffer() {
207  return impl->getAssertHappenedBuffer();
208 }
209 
210 bool queue::device_has(aspect Aspect) const {
211  // avoid creating sycl object from impl
212  return impl->getDeviceImplPtr()->has(Aspect);
213 }
214 } // namespace sycl
215 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::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:108
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::device_selector
The device_selector class provides ability to choose the best SYCL device based on heuristics specifi...
Definition: device_selector.hpp:28
event_impl.hpp
cl::sycl::queue::get_property
PropertyT get_property() const
Definition: queue.cpp:184
cl::sycl::queue::has_property
bool has_property() const
Definition: queue.cpp:180
cl::sycl::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:31
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::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:82
stl.hpp
cl::sycl::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:109
_pi_mem_advice
_pi_mem_advice
Definition: pi.h:459
cl::sycl::queue::memcpy
event memcpy(void *Dest, const void *Src, size_t Count)
Copies data from one memory region to another, both pointed by USM pointers.
Definition: queue.cpp:95
event.hpp
cl::sycl::detail::event_impl::HES_Discarded
@ HES_Discarded
Definition: event_impl.hpp:38
sycl
Definition: invoke_simd.hpp:68
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::property::queue::in_order
Definition: queue_properties.hpp:18
cl::sycl::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:162
queue_impl.hpp
cl::sycl::queue::get_backend
backend get_backend() const noexcept
Returns the backend associated with this queue.
Definition: queue.cpp:202
cl::sycl::detail::code_location
Definition: common.hpp:54
cl::sycl::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:103
cl::sycl::info::queue
queue
Definition: info_desc.hpp:229
cl::sycl::queue::is_in_order
bool is_in_order() const
Returns whether the queue is in order or OoO.
Definition: queue.cpp:198
cl::sycl::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:16
_pi_queue
PI queue mapping on to CUstream objects.
Definition: pi_cuda.hpp:378
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
cl::sycl::property::queue::enable_profiling
Definition: queue_properties.hpp:19
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::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:80
queue.hpp
cl::sycl::aspect
aspect
Definition: aspects.hpp:15
pi_mem_advice
_pi_mem_advice pi_mem_advice
Definition: pi.h:649
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
cl::sycl::context::get_devices
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
Definition: context.cpp:127
cl::sycl::queue::get_device
device get_device() const
Definition: queue.cpp:75
cl::sycl::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:158
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::queue::get_context
context get_context() const
Definition: queue.cpp:73
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
handler.hpp
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::queue::is_host
bool is_host() const
Definition: queue.cpp:77
backend_impl.hpp
exception_list.hpp
cl::sycl::detail::event_impl
Definition: event_impl.hpp:33
cl::sycl::queue::get_info
info::param_traits< info::queue, param >::return_type get_info() const
Queries SYCL queue for information.
Definition: queue.cpp:168
cl::sycl::async_handler
std::function< void(cl::sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12