DPC++ Runtime
Runtime libraries for oneAPI DPC++
stream.cpp
Go to the documentation of this file.
1 //==------------------- stream.cpp - SYCL standard header file ------------==//
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/queue_impl.hpp>
10 #include <detail/stream_impl.hpp>
12 #include <sycl/stream.hpp>
13 
14 #include <climits>
15 
16 namespace sycl {
17 inline namespace _V1 {
18 
19 // Maximum possible size of a flush buffer statement in bytes
20 static constexpr size_t MAX_STATEMENT_SIZE =
21  (1 << (CHAR_BIT * detail::FLUSH_BUF_OFFSET_SIZE)) - 1;
22 
23 // Checks the MaxStatementSize argument of the sycl::stream class. This is
24 // called on MaxStatementSize as it is passed to the constructor of the
25 // underlying stream_impl to make it throw before the stream buffers are
26 // allocated, avoiding memory leaks.
27 static size_t CheckMaxStatementSize(const size_t &MaxStatementSize) {
28  if (MaxStatementSize > MAX_STATEMENT_SIZE) {
29  throw sycl::invalid_parameter_error(
30  "Maximum statement size exceeds limit of " +
31  std::to_string(MAX_STATEMENT_SIZE) + " bytes.",
32  PI_ERROR_INVALID_VALUE);
33  }
34  return MaxStatementSize;
35 }
36 
37 stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH)
38  : stream(BufferSize, MaxStatementSize, CGH, {}) {}
39 
40 stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH,
41  const property_list &PropList)
42  : impl(std::make_shared<detail::stream_impl>(
43  BufferSize, CheckMaxStatementSize(MaxStatementSize), PropList)),
44  GlobalBuf(impl->accessGlobalBuf(CGH)),
45  GlobalOffset(impl->accessGlobalOffset(CGH)),
46  // Allocate the flush buffer, which contains space for each work item
47  GlobalFlushBuf(impl->accessGlobalFlushBuf(CGH)),
48  FlushBufferSize(MaxStatementSize + detail::FLUSH_BUF_OFFSET_SIZE) {
49  // Save stream implementation in the handler so that stream will be alive
50  // during kernel execution
51  CGH.addStream(impl);
52 
53  // Set flag identifying that created accessor has perWI size. Accessor
54  // will be resized in SYCL RT when number of work items will be
55  // available.
56  detail::getSyclObjImpl(GlobalFlushBuf)->PerWI = true;
57 }
58 
59 size_t stream::size() const noexcept { return impl->get_size(); }
60 
61 size_t stream::get_work_item_buffer_size() const {
62  return impl->get_work_item_buffer_size();
63 }
64 
65 size_t stream::get_size() const { return size(); }
66 
67 size_t stream::get_max_statement_size() const {
68  return get_work_item_buffer_size();
69 }
70 
71 bool stream::operator==(const stream &RHS) const { return (impl == RHS.impl); }
72 
73 bool stream::operator!=(const stream &RHS) const { return !(impl == RHS.impl); }
74 
75 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
76  template <> \
77  __SYCL_EXPORT bool stream::has_property<param_type>() const noexcept { \
78  return impl->has_property<param_type>(); \
79  }
80 #include <sycl/detail/properties_traits.def>
81 
82 #undef __SYCL_PARAM_TRAITS_SPEC
83 
84 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
85  template <> \
86  __SYCL_EXPORT param_type stream::get_property<param_type>() const { \
87  return impl->get_property<param_type>(); \
88  }
89 #include <sycl/detail/properties_traits.def>
90 
91 #undef __SYCL_PARAM_TRAITS_SPEC
92 
93 } // namespace _V1
94 } // namespace sycl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
constexpr unsigned FLUSH_BUF_OFFSET_SIZE
Definition: stream.hpp:84
bool operator==(const cache_config &lhs, const cache_config &rhs)
bool operator!=(const cache_config &lhs, const cache_config &rhs)
static constexpr size_t MAX_STATEMENT_SIZE
Definition: stream.cpp:20
static size_t CheckMaxStatementSize(const size_t &MaxStatementSize)
Definition: stream.cpp:27
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324