DPC++ Runtime
Runtime libraries for oneAPI DPC++
scheduler_helpers.cpp
Go to the documentation of this file.
1 //==-- scheduler_helpers.cpp - SYCL Scheduler helper functions --*- C++ -*-===//
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 <detail/buffer_impl.hpp>
10 #include <detail/queue_impl.hpp>
13 #include <detail/stream_impl.hpp>
14 #include <sycl/queue.hpp>
15 
16 namespace sycl {
18 namespace detail {
19 
20 void initStream(StreamImplPtr Stream, QueueImplPtr Queue) {
21  Scheduler::StreamBuffers *StrBufs{};
22 
23  {
24  std::lock_guard<std::recursive_mutex> lock(
25  Scheduler::getInstance().StreamBuffersPoolMutex);
26 
27  auto StreamBuf =
28  Scheduler::getInstance().StreamBuffersPool.find(Stream.get());
29  assert((StreamBuf != Scheduler::getInstance().StreamBuffersPool.end()) &&
30  "Stream is unexpectedly not found in pool.");
31 
32  StrBufs = StreamBuf->second;
33  }
34 
35  assert(StrBufs && "No buffers for a stream.");
36 
37  // Real size of full flush buffer is saved only in buffer_impl field of
38  // FlushBuf object.
39  size_t FlushBufSize = getSyclObjImpl(StrBufs->FlushBuf)->size();
40 
41  auto Q = createSyclObjFromImpl<queue>(Queue);
42  Q.submit([&](handler &cgh) {
43  auto FlushBufAcc =
44  StrBufs->FlushBuf.get_access<access::mode::discard_write,
45  access::target::host_buffer>(
46  cgh, range<1>(1), id<1>(0));
47  cgh.host_task([=] {
48  char *FlushBufPtr = FlushBufAcc.get_pointer();
49  std::memset(FlushBufPtr, 0, FlushBufSize);
50  });
51  });
52 }
53 
54 } // namespace detail
55 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
56 } // namespace sycl
Command group handler class.
Definition: handler.hpp:310
#define __SYCL_INLINE_VER_NAMESPACE(X)
void initStream(StreamImplPtr Stream, QueueImplPtr Queue)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
std::shared_ptr< detail::stream_impl > StreamImplPtr
Definition: commands.hpp:38
std::shared_ptr< sycl::detail::queue_impl > QueueImplPtr
Definition: event_impl.hpp:32
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14