DPC++ Runtime
Runtime libraries for oneAPI DPC++
event_impl.hpp
Go to the documentation of this file.
1 //==---------------- event_impl.hpp - SYCL event ---------------------------==//
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 
13 #include <CL/sycl/detail/pi.hpp>
15 #include <CL/sycl/stl.hpp>
16 #include <detail/plugin.hpp>
17 
18 #include <atomic>
19 #include <cassert>
20 
22 namespace sycl {
23 class context;
24 namespace detail {
25 class plugin;
26 class context_impl;
27 using ContextImplPtr = std::shared_ptr<cl::sycl::detail::context_impl>;
28 class queue_impl;
29 using QueueImplPtr = std::shared_ptr<cl::sycl::detail::queue_impl>;
30 class event_impl;
31 using EventImplPtr = std::shared_ptr<cl::sycl::detail::event_impl>;
32 
33 class event_impl {
34 public:
35  enum HostEventState : int {
36  HES_NotComplete = 0,
38  HES_Discarded
39  };
40 
44  event_impl(HostEventState State = HES_Complete);
52  event_impl(RT::PiEvent Event, const context &SyclContext);
53  event_impl(const QueueImplPtr &Queue);
54 
59  //
61  bool is_host() const;
62 
66  cl_event get() const;
67 
73  void wait(std::shared_ptr<cl::sycl::detail::event_impl> Self) const;
74 
83  void wait_and_throw(std::shared_ptr<cl::sycl::detail::event_impl> Self);
84 
89  void cleanupCommand(std::shared_ptr<cl::sycl::detail::event_impl> Self) const;
90 
102  template <info::event_profiling param>
104  get_profiling_info() const;
105 
109  template <info::event param>
110  typename info::param_traits<info::event, param>::return_type get_info() const;
111 
112  ~event_impl();
113 
115  void waitInternal() const;
116 
118  void setComplete();
119 
124  RT::PiEvent &getHandleRef();
129  const RT::PiEvent &getHandleRef() const;
130 
134  const ContextImplPtr &getContextImpl();
135 
138  const plugin &getPlugin() const;
139 
146  void setContextImpl(const ContextImplPtr &Context);
147 
153  void *getCommand() { return MCommand; }
154 
160  void setCommand(void *Command) { MCommand = Command; }
161 
165  HostProfilingInfo *getHostProfilingInfo() { return MHostProfilingInfo.get(); }
166 
170  pi_native_handle getNative() const;
171 
175  std::vector<std::shared_ptr<event_impl>> &getPreparedDepsEvents() {
176  return MPreparedDepsEvents;
177  }
178 
182  std::vector<std::shared_ptr<event_impl>> &getPreparedHostDepsEvents() {
183  return MPreparedHostDepsEvents;
184  }
185 
189  std::vector<EventImplPtr> getWaitList();
190 
194  void flushIfNeeded(const QueueImplPtr &UserQueue);
195 
197  void cleanupDependencyEvents();
198 
200  void cleanDepEventsThroughOneLevel();
201 
205  bool isDiscarded() const { return MState == HES_Discarded; }
206 
207  void setNeedsCleanupAfterWait(bool NeedsCleanupAfterWait) {
208  MNeedsCleanupAfterWait = NeedsCleanupAfterWait;
209  }
210  bool needsCleanupAfterWait() { return MNeedsCleanupAfterWait; }
211 
212 private:
213  // When instrumentation is enabled emits trace event for event wait begin and
214  // returns the telemetry event generated for the wait
215  void *instrumentationProlog(std::string &Name, int32_t StreamID,
216  uint64_t &instance_id) const;
217  // Uses events generated by the Prolog and emits event wait done event
218  void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
219  int32_t StreamID, uint64_t IId) const;
220  void checkProfilingPreconditions() const;
221  mutable bool MIsInitialized = true;
222  mutable RT::PiEvent MEvent = nullptr;
223  mutable ContextImplPtr MContext;
224  mutable bool MOpenCLInterop = false;
225  mutable bool MHostEvent = true;
226  std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
227  void *MCommand = nullptr;
228  std::weak_ptr<queue_impl> MQueue;
229  const bool MIsProfilingEnabled = false;
230 
232  std::vector<EventImplPtr> MPreparedDepsEvents;
233  std::vector<EventImplPtr> MPreparedHostDepsEvents;
234 
237  std::atomic<bool> MIsFlushed = false;
238 
239  // State of host event. Employed only for host events and event with no
240  // backend's representation (e.g. alloca). Used values are listed in
241  // HostEventState enum.
242  std::atomic<int> MState;
243 
244  // A temporary workaround for the current limitations of post enqueue graph
245  // cleanup. Indicates that the command associated with this event isn't
246  // handled by post enqueue cleanup yet and has to be deleted by cleanup after
247  // wait.
248  bool MNeedsCleanupAfterWait = false;
249 
250  std::mutex MMutex;
251 };
252 
253 } // namespace detail
254 } // namespace sycl
255 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::pi::getPlugin
const plugin & getPlugin()
Definition: pi.cpp:511
cl::sycl::detail::ContextImplPtr
std::shared_ptr< detail::context_impl > ContextImplPtr
Definition: memory_manager.hpp:32
cl::sycl::detail::event_impl::needsCleanupAfterWait
bool needsCleanupAfterWait()
Definition: event_impl.hpp:210
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::detail::HostProfilingInfo
Profiling info for the host execution.
Definition: host_profiling_info.hpp:19
stl.hpp
cl::sycl::detail::event_impl::HostEventState
HostEventState
Definition: event_impl.hpp:35
cl::sycl::detail::event_impl::setNeedsCleanupAfterWait
void setNeedsCleanupAfterWait(bool NeedsCleanupAfterWait)
Definition: event_impl.hpp:207
sycl
Definition: invoke_simd.hpp:68
host_profiling_info.hpp
plugin.hpp
cl::sycl::detail::event_impl::HES_Complete
@ HES_Complete
Definition: event_impl.hpp:37
pi.hpp
cl::sycl::detail::event_impl::isDiscarded
bool isDiscarded() const
Checks if this event is discarded by SYCL implementation.
Definition: event_impl.hpp:205
cl::sycl::detail::EventImplPtr
std::shared_ptr< detail::event_impl > EventImplPtr
Definition: memory_manager.hpp:31
cl::sycl::detail::event_impl::setCommand
void setCommand(void *Command)
Associates this event with the command.
Definition: event_impl.hpp:160
cl::sycl::detail::Command
The Command class represents some action that needs to be performed on one or more memory objects.
Definition: commands.hpp:95
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::event_impl::getPreparedDepsEvents
std::vector< std::shared_ptr< event_impl > > & getPreparedDepsEvents()
Returns vector of event dependencies.
Definition: event_impl.hpp:175
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
cl::sycl::detail::event_impl::getPreparedHostDepsEvents
std::vector< std::shared_ptr< event_impl > > & getPreparedHostDepsEvents()
Returns vector of host event dependencies.
Definition: event_impl.hpp:182
cl::sycl::detail::QueueImplPtr
std::shared_ptr< detail::queue_impl > QueueImplPtr
Definition: memory_manager.hpp:30
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
_pi_event
PI Event mapping to CUevent.
Definition: pi_cuda.hpp:458
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
info_desc.hpp
common.hpp
cl::sycl::detail::event_impl
Definition: event_impl.hpp:33
cl::sycl::info::context
context
Definition: info_desc.hpp:42
cl::sycl::detail::event_impl::getCommand
void * getCommand()
Returns command that is associated with the event.
Definition: event_impl.hpp:153
cl::sycl::detail::event_impl::getHostProfilingInfo
HostProfilingInfo * getHostProfilingInfo()
Returns host profiling information.
Definition: event_impl.hpp:165
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12