|
| 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> |
| 11 | +#include <detail/scheduler/scheduler.hpp> |
| 12 | +#include <detail/scheduler/scheduler_helpers.hpp> |
| 13 | +#include <detail/stream_impl.hpp> |
| 14 | + |
| 15 | +__SYCL_INLINE_NAMESPACE(cl) { |
| 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)->get_count(); |
| 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>(FlushBufSize), id<1>(0)); |
| 46 | + cgh.codeplay_host_task([=] { |
| 47 | + char *FlushBufPtr = FlushBufAcc.get_pointer(); |
| 48 | + std::memset(FlushBufPtr, 0, FlushBufAcc.get_size()); |
| 49 | + }); |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | +} // namespace detail |
| 54 | +} // namespace sycl |
| 55 | +} // __SYCL_INLINE_NAMESPACE(cl) |
0 commit comments