DPC++ Runtime
Runtime libraries for oneAPI DPC++
stream_impl.hpp
Go to the documentation of this file.
1 //==----------------- stream_impl.hpp - 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 #pragma once
10 
11 #include <sycl/accessor.hpp>
12 #include <sycl/buffer.hpp>
13 #include <sycl/detail/export.hpp>
14 #include <sycl/handler.hpp>
15 #include <sycl/property_list.hpp>
16 #include <sycl/range.hpp>
17 #include <sycl/stream.hpp>
18 
19 #include <vector>
20 
21 namespace sycl {
22 inline namespace _V1 {
23 namespace detail {
24 
25 class __SYCL_EXPORT stream_impl {
26 public:
27  // TODO: This constructor is unused.
28  // To be removed when API/ABI changes are allowed.
29  stream_impl(size_t BufferSize, size_t MaxStatementSize, handler &CGH);
30 
31  stream_impl(size_t BufferSize, size_t MaxStatementSize,
32  const property_list &PropList);
33 
34  // Method to provide an access to the global stream buffer
35  GlobalBufAccessorT accessGlobalBuf(handler &CGH);
36 
37  // Method to provide an accessor to the global flush buffer
38  GlobalBufAccessorT accessGlobalFlushBuf(handler &CGH);
39 
40  // Method to provide an atomic access to the offset in the global stream
41  // buffer and offset in the flush buffer
42  GlobalOffsetAccessorT accessGlobalOffset(handler &CGH);
43 
44  // Initialize flush buffers on host.
45  void initStreamHost(QueueImplPtr Queue);
46 
47  // Enqueue task to copy stream buffer to the host and print the contents
48  // The host task event is then registered for post processing in the
49  // LeadEvent as well as in queue LeadEvent associated with.
50  void flush(const EventImplPtr &LeadEvent);
51 
52  // Enqueue task to copy stream buffer to the host and print the contents
53  // Remove during next ABI breaking window
54  void flush();
55 
56  size_t size() const noexcept;
57 
58  size_t get_work_item_buffer_size() const;
59 
60  // TODO: Unusued. Remove when ABI-break is allowed.
61  size_t get_size() const;
62 
63  // TODO: Unusued. Remove when ABI-break is allowed.
64  size_t get_max_statement_size() const;
65 
66  template <typename propertyT> bool has_property() const noexcept {
67  return PropList_.has_property<propertyT>();
68  }
69 
70  template <typename propertyT> propertyT get_property() const {
71  return PropList_.get_property<propertyT>();
72  }
73 
74 private:
75  // Size of the stream buffer
76  size_t BufferSize_;
77 
78  // Maximum number of symbols which could be streamed from the beginning of a
79  // statement till the semicolon
80  unsigned MaxStatementSize_;
81 
82  // Property list
83  property_list PropList_;
84 
85  // It's fine to store the buffers in the stream_impl itself since the
86  // underlying buffer_impls are relased in a deferred manner by scheduler.
87  // Stream buffer
88  buffer<char, 1> Buf_;
89 
90  // Global flush buffer
91  buffer<char, 1> FlushBuf_;
92 
93  // Additinonal memory is allocated in the beginning of the stream buffer for
94  // 2 variables: offset in the stream buffer and offset in the flush buffer.
95  static const size_t OffsetSize = 2 * sizeof(unsigned);
96 };
97 
98 } // namespace detail
99 } // namespace _V1
100 } // namespace sycl
The file contains implementations of accessor class.
propertyT get_property() const
Definition: stream_impl.hpp:70
bool has_property() const noexcept
Definition: stream_impl.hpp:66
Command group handler class.
Definition: handler.hpp:458
Objects of the property_list class are containers for the SYCL properties.
std::shared_ptr< event_impl > EventImplPtr
Definition: cg.hpp:43
std::shared_ptr< sycl::detail::queue_impl > QueueImplPtr
Definition: event_impl.hpp:34
constexpr stream_manipulator flush
Definition: stream.hpp:800
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324