DPC++ Runtime
Runtime libraries for oneAPI DPC++
helpers.cpp
Go to the documentation of this file.
1 //==---------------- helpers.cpp - SYCL helpers ---------------------------==//
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 
11 #include <detail/context_impl.hpp>
12 #include <detail/event_impl.hpp>
13 #include <sycl/event.hpp>
14 
15 #include <memory>
16 
17 namespace sycl {
19 using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
20 namespace detail {
21 std::vector<RT::PiEvent> getOrWaitEvents(std::vector<sycl::event> DepEvents,
22  ContextImplPtr Context) {
23  std::vector<RT::PiEvent> Events;
24  for (auto SyclEvent : DepEvents) {
25  auto SyclEventImplPtr = detail::getSyclObjImpl(SyclEvent);
26  // throwaway events created with empty constructor will not have a context
27  // (which is set lazily) calling getContextImpl() would set that
28  // context, which we wish to avoid as it is expensive.
29  if (SyclEventImplPtr->MIsContextInitialized == false &&
30  !SyclEventImplPtr->is_host()) {
31  continue;
32  }
33  if (SyclEventImplPtr->is_host() ||
34  SyclEventImplPtr->getContextImpl() != Context) {
35  SyclEventImplPtr->waitInternal();
36  } else {
37  Events.push_back(SyclEventImplPtr->getHandleRef());
38  }
39  }
40  return Events;
41 }
42 
43 void waitEvents(std::vector<sycl::event> DepEvents) {
44  for (auto SyclEvent : DepEvents) {
45  detail::getSyclObjImpl(SyclEvent)->waitInternal();
46  }
47 }
48 
49 } // namespace detail
50 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
51 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: event_impl.hpp:30
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
std::vector< RT::PiEvent > getOrWaitEvents(std::vector< sycl::event > DepEvents, ContextImplPtr Context)
Definition: helpers.cpp:21
void waitEvents(std::vector< sycl::event > DepEvents)
Definition: helpers.cpp:43
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: helpers.cpp:19
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14