DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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/queue_impl.hpp>
16 
17 #include <algorithm>
18 
20 namespace sycl {
21 
22 queue::queue(const context &SyclContext, const device_selector &DeviceSelector,
23  const async_handler &AsyncHandler, const property_list &PropList) {
24 
25  const std::vector<device> Devs = SyclContext.get_devices();
26 
27  auto Comp = [&DeviceSelector](const device &d1, const device &d2) {
28  return DeviceSelector(d1) < DeviceSelector(d2);
29  };
30 
31  const device &SyclDevice = *std::max_element(Devs.begin(), Devs.end(), Comp);
32 
33  impl = std::make_shared<detail::queue_impl>(
34  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
35  AsyncHandler, PropList);
36 }
37 
38 queue::queue(const context &SyclContext, const device &SyclDevice,
39  const async_handler &AsyncHandler, const property_list &PropList) {
40  impl = std::make_shared<detail::queue_impl>(
41  detail::getSyclObjImpl(SyclDevice), detail::getSyclObjImpl(SyclContext),
42  AsyncHandler, PropList);
43 }
44 
45 queue::queue(const device &SyclDevice, const async_handler &AsyncHandler,
46  const property_list &PropList) {
47  impl = std::make_shared<detail::queue_impl>(
48  detail::getSyclObjImpl(SyclDevice), AsyncHandler, PropList);
49 }
50 
51 queue::queue(cl_command_queue clQueue, const context &SyclContext,
52  const async_handler &AsyncHandler) {
53  impl = std::make_shared<detail::queue_impl>(
54  reinterpret_cast<RT::PiQueue>(clQueue),
55  detail::getSyclObjImpl(SyclContext), AsyncHandler);
56 }
57 
58 queue::queue(const context &SyclContext, const device_selector &deviceSelector,
59  const property_list &PropList)
60  : queue(SyclContext, deviceSelector,
61  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
62  PropList) {}
63 
64 queue::queue(const context &SyclContext, const device &SyclDevice,
65  const property_list &PropList)
66  : queue(SyclContext, SyclDevice,
67  detail::getSyclObjImpl(SyclContext)->get_async_handler(),
68  PropList) {}
69 
70 cl_command_queue queue::get() const { return impl->get(); }
71 
72 context queue::get_context() const { return impl->get_context(); }
73 
74 device queue::get_device() const { return impl->get_device(); }
75 
76 bool queue::is_host() const { return impl->is_host(); }
77 
78 
79 void queue::throw_asynchronous() { impl->throw_asynchronous(); }
80 
81 event queue::memset(void *Ptr, int Value, size_t Count) {
82  return impl->memset(impl, Ptr, Value, Count, {});
83 }
84 
85 event queue::memset(void *Ptr, int Value, size_t Count, event DepEvent) {
86  return impl->memset(impl, Ptr, Value, Count, {DepEvent});
87 }
88 
89 event queue::memset(void *Ptr, int Value, size_t Count,
90  const std::vector<event> &DepEvents) {
91  return impl->memset(impl, Ptr, Value, Count, DepEvents);
92 }
93 
94 event queue::memcpy(void *Dest, const void *Src, size_t Count) {
95  return impl->memcpy(impl, Dest, Src, Count, {});
96 }
97 
98 event queue::memcpy(void *Dest, const void *Src, size_t Count, event DepEvent) {
99  return impl->memcpy(impl, Dest, Src, Count, {DepEvent});
100 }
101 
102 event queue::memcpy(void *Dest, const void *Src, size_t Count,
103  const std::vector<event> &DepEvents) {
104  return impl->memcpy(impl, Dest, Src, Count, DepEvents);
105 }
106 
107 event queue::mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice) {
108  return mem_advise(Ptr, Length, int(Advice));
109 }
110 
111 event queue::mem_advise(const void *Ptr, size_t Length, int Advice) {
112  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {});
113 }
114 
115 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
116  event DepEvent) {
117  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), {DepEvent});
118 }
119 
120 event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
121  const std::vector<event> &DepEvents) {
122  return impl->mem_advise(impl, Ptr, Length, pi_mem_advice(Advice), DepEvents);
123 }
124 
125 event queue::submit_impl(std::function<void(handler &)> CGH,
126  const detail::code_location &CodeLoc) {
127  return impl->submit(CGH, impl, CodeLoc);
128 }
129 
130 event queue::submit_impl(std::function<void(handler &)> CGH, queue SecondQueue,
131  const detail::code_location &CodeLoc) {
132  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc);
133 }
134 
135 event queue::submit_impl_and_postprocess(
136  std::function<void(handler &)> CGH, const detail::code_location &CodeLoc,
137  const SubmitPostProcessF &PostProcess) {
138  return impl->submit(CGH, impl, CodeLoc, &PostProcess);
139 }
140 
141 event queue::submit_impl_and_postprocess(
142  std::function<void(handler &)> CGH, queue SecondQueue,
143  const detail::code_location &CodeLoc,
144  const SubmitPostProcessF &PostProcess) {
145  return impl->submit(CGH, impl, SecondQueue.impl, CodeLoc, &PostProcess);
146 }
147 
149  impl->wait(CodeLoc);
150 }
151 
153  impl->wait_and_throw(CodeLoc);
154 }
155 
156 template <info::queue Param>
159  return impl->get_info<Param>();
160 }
161 
162 #define __SYCL_PARAM_TRAITS_SPEC(ParamType, Param, RetType) \
163  template __SYCL_EXPORT RetType queue::get_info<info::ParamType::Param>() \
164  const;
165 
166 #include <CL/sycl/info/queue_traits.def>
167 
168 #undef __SYCL_PARAM_TRAITS_SPEC
169 
170 template <typename PropertyT> bool queue::has_property() const {
171  return impl->has_property<PropertyT>();
172 }
173 
174 template <typename PropertyT> PropertyT queue::get_property() const {
175  return impl->get_property<PropertyT>();
176 }
177 
178 template __SYCL_EXPORT bool
179 queue::has_property<property::queue::enable_profiling>() const;
180 template __SYCL_EXPORT property::queue::enable_profiling
181 queue::get_property<property::queue::enable_profiling>() const;
182 
183 bool queue::is_in_order() const {
184  return impl->has_property<property::queue::in_order>();
185 }
186 
187 backend queue::get_backend() const noexcept { return getImplBackend(impl); }
188 
189 pi_native_handle queue::getNative() const { return impl->getNative(); }
190 
191 buffer<detail::AssertHappened, 1> &queue::getAssertHappenedBuffer() {
192  return impl->getAssertHappenedBuffer();
193 }
194 
195 bool queue::device_has(aspect Aspect) const {
196  // avoid creating sycl object from impl
197  return impl->getDeviceImplPtr()->has(Aspect);
198 }
199 } // namespace sycl
200 } // __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:107
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
cl::sycl::queue::get_property
PropertyT get_property() const
Definition: queue.cpp:174
cl::sycl::queue::has_property
bool has_property() const
Definition: queue.cpp:170
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:297
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:81
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:441
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:94
event.hpp
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:25
cl::sycl::property::queue::in_order
Definition: queue_properties.hpp:17
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:152
queue_impl.hpp
cl::sycl::queue::get_backend
backend get_backend() const noexcept
Returns the backend associated with this queue.
Definition: queue.cpp:187
cl::sycl::detail::code_location
Definition: common.hpp:29
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:219
cl::sycl::queue::is_in_order
bool is_in_order() const
Returns whether the queue is in order or OoO.
Definition: queue.cpp:183
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:379
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:34
cl::sycl::queue::device_has
bool device_has(aspect Aspect) const
Definition: queue.cpp:195
cl::sycl::property::queue::enable_profiling
Definition: queue_properties.hpp:18
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:79
queue.hpp
cl::sycl::aspect
aspect
Definition: aspects.hpp:15
pi_mem_advice
_pi_mem_advice pi_mem_advice
Definition: pi.h:596
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:72
cl::sycl::context::get_devices
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
Definition: context.cpp:127
cl::sycl::handler
Command group handler class.
Definition: handler.hpp:361
cl::sycl::queue::get_device
device get_device() const
Definition: queue.cpp:74
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:148
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:72
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:182
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:76
backend_impl.hpp
exception_list.hpp
cl::sycl::queue::get_info
info::param_traits< info::queue, param >::return_type get_info() const
Queries SYCL queue for information.
Definition: queue.cpp:158
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