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 <CL/sycl/event.hpp>
12 #include <detail/context_impl.hpp>
13 #include <detail/event_impl.hpp>
14 
15 #include <memory>
16 
18 namespace sycl {
19 using ContextImplPtr = std::shared_ptr<cl::sycl::detail::context_impl>;
20 namespace detail {
21 std::vector<RT::PiEvent> getOrWaitEvents(std::vector<cl::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 default constructor will not have a context
27  // (which is set lazily) calling is_host(), getContextImpl() would set that
28  // context, which we wish to avoid as it is expensive.
29  if (SyclEventImplPtr->MIsContextInitialized == false) {
30  continue;
31  }
32  if (SyclEventImplPtr->is_host() ||
33  SyclEventImplPtr->getContextImpl() != Context) {
34  SyclEventImplPtr->waitInternal();
35  } else {
36  Events.push_back(SyclEventImplPtr->getHandleRef());
37  }
38  }
39  return Events;
40 }
41 
42 void waitEvents(std::vector<cl::sycl::event> DepEvents) {
43  for (auto SyclEvent : DepEvents) {
44  detail::getSyclObjImpl(SyclEvent)->waitInternal();
45  }
46 }
47 
48 } // namespace detail
49 } // namespace sycl
50 } // __SYCL_INLINE_NAMESPACE(cl)
event_impl.hpp
cl::sycl::detail::ContextImplPtr
std::shared_ptr< detail::context_impl > ContextImplPtr
Definition: memory_manager.hpp:31
context_impl.hpp
cl::sycl::detail::waitEvents
void waitEvents(std::vector< cl::sycl::event > DepEvents)
Definition: helpers.cpp:42
event.hpp
helpers.hpp
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::getOrWaitEvents
std::vector< RT::PiEvent > getOrWaitEvents(std::vector< cl::sycl::event > DepEvents, ContextImplPtr Context)
Definition: helpers.cpp:21
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12