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 
10 #include <CL/sycl/stream.hpp>
11 #include <detail/queue_impl.hpp>
12 #include <detail/stream_impl.hpp>
13 
15 namespace sycl {
16 
17 // Maximum possible size of a flush buffer statement in bytes
18 static constexpr size_t MAX_STATEMENT_SIZE =
19  (1 << (CHAR_BIT * detail::FLUSH_BUF_OFFSET_SIZE)) - 1;
20 
21 // Checks the MaxStatementSize argument of the sycl::stream class. This is
22 // called on MaxStatementSize as it is passed to the constructor of the
23 // underlying stream_impl to make it throw before the stream buffers are
24 // allocated, avoiding memory leaks.
25 static size_t CheckMaxStatementSize(const size_t &MaxStatementSize) {
26  if (MaxStatementSize > MAX_STATEMENT_SIZE) {
27  throw sycl::invalid_parameter_error(
28  "Maximum statement size exceeds limit of " +
29  std::to_string(MAX_STATEMENT_SIZE) + " bytes.",
31  }
32  return MaxStatementSize;
33 }
34 
35 stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH)
36  : stream(BufferSize, MaxStatementSize, CGH, {}) {}
37 
38 stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH,
39  const property_list &PropList)
40  : impl(std::make_shared<detail::stream_impl>(
41  BufferSize, CheckMaxStatementSize(MaxStatementSize), PropList)),
42  GlobalBuf(impl->accessGlobalBuf(CGH)),
43  GlobalOffset(impl->accessGlobalOffset(CGH)),
44  // Allocate the flush buffer, which contains space for each work item
45  GlobalFlushBuf(impl->accessGlobalFlushBuf(CGH)),
46  FlushBufferSize(MaxStatementSize + detail::FLUSH_BUF_OFFSET_SIZE) {
47  // Save stream implementation in the handler so that stream will be alive
48  // during kernel execution
49  CGH.addStream(impl);
50 
51  // Set flag identifying that created accessor has perWI size. Accessor
52  // will be resized in SYCL RT when number of work items will be
53  // available.
54  detail::getSyclObjImpl(GlobalFlushBuf)->PerWI = true;
55 }
56 
57 size_t stream::get_size() const { return impl->get_size(); }
58 
60  return impl->get_max_statement_size();
61 }
62 
63 bool stream::operator==(const stream &RHS) const { return (impl == RHS.impl); }
64 
65 bool stream::operator!=(const stream &RHS) const { return !(impl == RHS.impl); }
66 
67 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
68  template <> \
69  __SYCL_EXPORT bool stream::has_property<param_type>() const noexcept { \
70  return impl->has_property<param_type>(); \
71  }
72 #include <CL/sycl/detail/properties_traits.def>
73 
74 #undef __SYCL_PARAM_TRAITS_SPEC
75 
76 #define __SYCL_PARAM_TRAITS_SPEC(param_type) \
77  template <> \
78  __SYCL_EXPORT param_type stream::get_property<param_type>() const { \
79  return impl->get_property<param_type>(); \
80  }
81 #include <CL/sycl/detail/properties_traits.def>
82 
83 #undef __SYCL_PARAM_TRAITS_SPEC
84 
85 } // namespace sycl
86 } // __SYCL_INLINE_NAMESPACE(cl)
87 
cl::sycl::detail::stream_impl
Definition: stream_impl.hpp:25
cl::sycl::detail::FLUSH_BUF_OFFSET_SIZE
constexpr unsigned FLUSH_BUF_OFFSET_SIZE
Definition: stream.hpp:58
cl::sycl::MAX_STATEMENT_SIZE
static constexpr size_t MAX_STATEMENT_SIZE
Definition: stream.cpp:18
cl::sycl::stream::get_size
size_t get_size() const
Definition: stream.cpp:57
cl::sycl::stream::get_max_statement_size
size_t get_max_statement_size() const
Definition: stream.cpp:59
sycl
Definition: invoke_simd.hpp:68
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::stream::operator!=
bool operator!=(const stream &LHS) const
Definition: stream.cpp:65
cl::sycl::stream::stream
stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH)
Definition: stream.cpp:35
queue_impl.hpp
cl::sycl::stream::operator==
bool operator==(const stream &RHS) const
Definition: stream.cpp:63
cl::sycl::CheckMaxStatementSize
static size_t CheckMaxStatementSize(const size_t &MaxStatementSize)
Definition: stream.cpp:25
all_properties.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::handler
Command group handler class.
Definition: handler.hpp:361
PI_INVALID_VALUE
@ PI_INVALID_VALUE
Definition: pi.h:91
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
std
Definition: accessor.hpp:2616
stream.hpp
cl::sycl::stream
A buffered output stream that allows outputting the values of built-in, vector and SYCL types to the ...
Definition: stream.hpp:743
stream_impl.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12