DPC++ Runtime
Runtime libraries for oneAPI DPC++
pipes.hpp
Go to the documentation of this file.
1 //==---------------- pipes.hpp - SYCL pipes ------------*- 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 #pragma once
10 
11 #include <CL/__spirv/spirv_types.hpp> // for ConstantPipeStorage
12 #include <sycl/exception.hpp> // for make_error_code, errc, exception
13 
14 #include <stddef.h> // for size_t
15 #include <stdint.h> // for int32_t
16 
17 namespace sycl {
18 inline namespace _V1 {
19 namespace ext::intel {
20 
21 template <class _name, class _dataT, int32_t _min_capacity = 0> class pipe {
22 public:
23  using value_type = _dataT;
24  static constexpr int32_t min_capacity = _min_capacity;
25  // Non-blocking pipes
26  // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
27  // friendly LLVM IR.
28  static _dataT read(bool &_Success) {
29 #ifdef __SYCL_DEVICE_ONLY__
30  __ocl_RPipeTy<_dataT> _RPipe =
31  __spirv_CreatePipeFromPipeStorage_read<_dataT>(&m_Storage);
32  _dataT TempData;
33  _Success = !static_cast<bool>(
34  __spirv_ReadPipe(_RPipe, &TempData, m_Size, m_Alignment));
35  return TempData;
36 #else
37  (void)_Success;
38  throw sycl::exception(
39  sycl::make_error_code(sycl::errc::feature_not_supported),
40  "Device-side API are not supported on a host device. Please use "
41  "host-side API instead.");
42 #endif // __SYCL_DEVICE_ONLY__
43  }
44 
45  // Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V
46  // friendly LLVM IR.
47  static void write(const _dataT &_Data, bool &_Success) {
48 #ifdef __SYCL_DEVICE_ONLY__
49  __ocl_WPipeTy<_dataT> _WPipe =
50  __spirv_CreatePipeFromPipeStorage_write<_dataT>(&m_Storage);
51  _Success = !static_cast<bool>(
52  __spirv_WritePipe(_WPipe, &_Data, m_Size, m_Alignment));
53 #else
54  (void)_Success;
55  (void)_Data;
56  throw sycl::exception(
57  sycl::make_error_code(sycl::errc::feature_not_supported),
58  "Device-side API are not supported on a host device. Please use "
59  "host-side API instead.");
60 #endif // __SYCL_DEVICE_ONLY__
61  }
62 
63  // Blocking pipes
64  // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
65  // friendly LLVM IR.
66  static _dataT read() {
67 #ifdef __SYCL_DEVICE_ONLY__
68  __ocl_RPipeTy<_dataT> _RPipe =
69  __spirv_CreatePipeFromPipeStorage_read<_dataT>(&m_Storage);
70  _dataT TempData;
71  __spirv_ReadPipeBlockingINTEL(_RPipe, &TempData, m_Size, m_Alignment);
72  return TempData;
73 #else
74  throw sycl::exception(
75  sycl::make_error_code(sycl::errc::feature_not_supported),
76  "Device-side API are not supported on a host device. Please use "
77  "host-side API instead..");
78 #endif // __SYCL_DEVICE_ONLY__
79  }
80 
81  // Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V
82  // friendly LLVM IR.
83  static void write(const _dataT &_Data) {
84 #ifdef __SYCL_DEVICE_ONLY__
85  __ocl_WPipeTy<_dataT> _WPipe =
86  __spirv_CreatePipeFromPipeStorage_write<_dataT>(&m_Storage);
87  __spirv_WritePipeBlockingINTEL(_WPipe, &_Data, m_Size, m_Alignment);
88 #else
89  (void)_Data;
90  throw sycl::exception(
91  sycl::make_error_code(sycl::errc::feature_not_supported),
92  "Device-side API are not supported on a host device. Please use "
93  "host-side API instead.");
94 #endif // __SYCL_DEVICE_ONLY__
95  }
96 
97 private:
98  static constexpr int32_t m_Size = sizeof(_dataT);
99  static constexpr int32_t m_Alignment = alignof(_dataT);
100 #ifdef __SYCL_DEVICE_ONLY__
101  static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment,
102  min_capacity};
103 #endif // __SYCL_DEVICE_ONLY__
104 };
105 
106 // IO pipes that provide interface to connect with hardware peripheral.
107 // Their name aliases are defined in vendor-provided header, below you can see
108 // an example of this header. There are defined aliases to ethernet_read_pipe
109 // and ethernet_write_pipe that users can use in their code to connect with
110 // HW peripheral.
111 /* namespace intelfpga {
112 template <int32_t ID>
113 struct ethernet_pipe_id {
114  static constexpr int32_t id = ID;
115 };
116 
117 template <class _dataT, size_t _min_capacity>
118 using ethernet_read_pipe =
119  kernel_readable_io_pipe<ethernet_pipe_id<0>, _dataT, _min_capacity>;
120 
121 template <class _dataT, size_t _min_capacity>
122 using ethernet_write_pipe =
123  kernel_writeable_io_pipe<ethernet_pipe_id<1>, _dataT, _min_capacity>;
124 } // namespace intelfpga */
125 
126 template <class _name, class _dataT, size_t _min_capacity = 0>
128 public:
129  using value_type = _dataT;
130  static constexpr int32_t min_capacity = _min_capacity;
131  // Non-blocking pipes
132  // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
133  // friendly LLVM IR.
134  static _dataT read(bool &_Success) {
135 #ifdef __SYCL_DEVICE_ONLY__
136  __ocl_RPipeTy<_dataT> _RPipe =
137  __spirv_CreatePipeFromPipeStorage_read<_dataT>(&m_Storage);
138  _dataT TempData;
139  _Success = !static_cast<bool>(
140  __spirv_ReadPipe(_RPipe, &TempData, m_Size, m_Alignment));
141  return TempData;
142 #else
143  (void)_Success;
144  throw sycl::exception(
145  sycl::make_error_code(sycl::errc::feature_not_supported),
146  "Device-side API are not supported on a host device. Please use "
147  "host-side API instead.");
148 #endif // __SYCL_DEVICE_ONLY__
149  }
150 
151  // Blocking pipes
152  // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
153  // friendly LLVM IR.
154  static _dataT read() {
155 #ifdef __SYCL_DEVICE_ONLY__
156  __ocl_RPipeTy<_dataT> _RPipe =
157  __spirv_CreatePipeFromPipeStorage_read<_dataT>(&m_Storage);
158  _dataT TempData;
159  __spirv_ReadPipeBlockingINTEL(_RPipe, &TempData, m_Size, m_Alignment);
160  return TempData;
161 #else
162  throw sycl::exception(
163  sycl::make_error_code(sycl::errc::feature_not_supported),
164  "Device-side API are not supported on a host device. Please use "
165  "host-side API instead.");
166 #endif // __SYCL_DEVICE_ONLY__
167  }
168 
169 private:
170  static constexpr int32_t m_Size = sizeof(_dataT);
171  static constexpr int32_t m_Alignment = alignof(_dataT);
172  static constexpr int32_t ID = _name::id;
173 #ifdef __SYCL_DEVICE_ONLY__
174  static constexpr ConstantPipeStorage m_Storage
175  __attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, min_capacity};
176 #endif // __SYCL_DEVICE_ONLY__
177 };
178 
179 template <class _name, class _dataT, size_t _min_capacity = 0>
181 public:
182  using value_type = _dataT;
183  static constexpr int32_t min_capacity = _min_capacity;
184  // Non-blocking pipes
185  // Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V
186  // friendly LLVM IR.
187  static void write(const _dataT &_Data, bool &_Success) {
188 #ifdef __SYCL_DEVICE_ONLY__
189  __ocl_WPipeTy<_dataT> _WPipe =
190  __spirv_CreatePipeFromPipeStorage_write<_dataT>(&m_Storage);
191  _Success = !static_cast<bool>(
192  __spirv_WritePipe(_WPipe, &_Data, m_Size, m_Alignment));
193 #else
194  (void)_Data;
195  (void)_Success;
196  throw sycl::exception(
197  sycl::make_error_code(sycl::errc::feature_not_supported),
198  "Device-side API are not supported on a host device. Please use "
199  "host-side API instead.");
200 #endif // __SYCL_DEVICE_ONLY__
201  }
202 
203  // Blocking pipes
204  // Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V
205  // friendly LLVM IR.
206  static void write(const _dataT &_Data) {
207 #ifdef __SYCL_DEVICE_ONLY__
208  __ocl_WPipeTy<_dataT> _WPipe =
209  __spirv_CreatePipeFromPipeStorage_write<_dataT>(&m_Storage);
210  __spirv_WritePipeBlockingINTEL(_WPipe, &_Data, m_Size, m_Alignment);
211 #else
212  (void)_Data;
213  throw sycl::exception(
214  sycl::make_error_code(sycl::errc::feature_not_supported),
215  "Device-side API are not supported on a host device. Please use "
216  "host-side API instead.");
217 #endif // __SYCL_DEVICE_ONLY__
218  }
219 
220 private:
221  static constexpr int32_t m_Size = sizeof(_dataT);
222  static constexpr int32_t m_Alignment = alignof(_dataT);
223  static constexpr int32_t ID = _name::id;
224 #ifdef __SYCL_DEVICE_ONLY__
225  static constexpr ConstantPipeStorage m_Storage
226  __attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, min_capacity};
227 #endif // __SYCL_DEVICE_ONLY__
228 };
229 
230 } // namespace ext::intel
231 
232 } // namespace _V1
233 } // namespace sycl
static constexpr int32_t min_capacity
Definition: pipes.hpp:130
static _dataT read(bool &_Success)
Definition: pipes.hpp:134
static void write(const _dataT &_Data)
Definition: pipes.hpp:206
static void write(const _dataT &_Data, bool &_Success)
Definition: pipes.hpp:187
static void write(const _dataT &_Data)
Definition: pipes.hpp:83
static _dataT read(bool &_Success)
Definition: pipes.hpp:28
static _dataT read()
Definition: pipes.hpp:66
static void write(const _dataT &_Data, bool &_Success)
Definition: pipes.hpp:47
static constexpr int32_t min_capacity
Definition: pipes.hpp:24
__attribute__((always_inline)) auto invoke_simd(sycl
The invoke_simd free function invokes a SIMD function using all work-items in a sub_group.
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:65
Definition: access.hpp:18