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 <CL/sycl/queue.hpp>
10 #include <detail/queue_impl.hpp>
13 #include <detail/stream_impl.hpp>
14 
16 namespace sycl {
17 namespace detail {
18 
19 void initStream(StreamImplPtr Stream, QueueImplPtr Queue) {
20  Scheduler::StreamBuffers *StrBufs{};
21 
22  {
23  std::lock_guard<std::recursive_mutex> lock(
24  Scheduler::getInstance().StreamBuffersPoolMutex);
25 
26  auto StreamBuf =
27  Scheduler::getInstance().StreamBuffersPool.find(Stream.get());
28  assert((StreamBuf != Scheduler::getInstance().StreamBuffersPool.end()) &&
29  "Stream is unexpectedly not found in pool.");
30 
31  StrBufs = StreamBuf->second;
32  }
33 
34  assert(StrBufs && "No buffers for a stream.");
35 
36  // Real size of full flush buffer is saved only in buffer_impl field of
37  // FlushBuf object.
38  size_t FlushBufSize = getSyclObjImpl(StrBufs->FlushBuf)->size();
39 
40  auto Q = createSyclObjFromImpl<queue>(Queue);
41  Q.submit([&](handler &cgh) {
42  auto FlushBufAcc =
43  StrBufs->FlushBuf.get_access<access::mode::discard_write,
44  access::target::host_buffer>(
45  cgh, range<1>(1), id<1>(0));
46  cgh.host_task([=] {
47  char *FlushBufPtr = FlushBufAcc.get_pointer();
48  std::memset(FlushBufPtr, 0, FlushBufSize);
49  });
50  });
51 }
52 
53 } // namespace detail
54 } // namespace sycl
55 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::Scheduler::StreamBuffers
Stream buffers structure.
Definition: scheduler.hpp:783
cl::sycl::id< 1 >
scheduler_helpers.hpp
sycl
Definition: invoke_simd.hpp:68
queue_impl.hpp
scheduler.hpp
cl::sycl::range< 1 >
cl::sycl::detail::StreamImplPtr
std::shared_ptr< detail::stream_impl > StreamImplPtr
Definition: commands.hpp:38
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
queue.hpp
cl::sycl::handler
Command group handler class.
Definition: handler.hpp:361
cl::sycl::detail::QueueImplPtr
std::shared_ptr< detail::queue_impl > QueueImplPtr
Definition: memory_manager.hpp:30
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
cl::sycl::detail::initStream
void initStream(StreamImplPtr Stream, QueueImplPtr Queue)
Definition: scheduler_helpers.cpp:19
stream_impl.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12