Skip to content

Commit e1619fa

Browse files
authored
[SYCL][FPGA] Expose value_type and min_capacity from SYCL pipes extension class (#5471)
This is a convenience for users who may template their functions/classes on SYCL pipe types. This allows them to do something like: ```c++ template<typename MyPipe> void foo(/* ... */) { using PipeT = MyPipe::value_type; // ... } ``` Test update: [intel/llvm-test-suite#800](intel/llvm-test-suite#800)
1 parent d47dda3 commit e1619fa

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

sycl/doc/extensions/supported/sycl_ext_intel_dataflow_pipes.asciidoc

+6-2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ class pipe {
183183
// Non-blocking
184184
static dataT read( bool &success_code );
185185
static void write( const dataT &data, bool &success_code );
186+
187+
// Static members
188+
using value_type = dataT;
189+
size_t min_capacity = min_capacity;
186190
}
187191
----
188192

@@ -191,8 +195,8 @@ The read and write member functions may be invoked within device code, or within
191195
The template parameters of the device type are defined as:
192196

193197
* `name`: Type that is the basis of pipe identification. Typically a user-defined class, in a user namespace. Forward declaration of the type is sufficient, and the type does not need to be defined.
194-
* `dataT`: The type of data word/packet contained within a pipe. This is the data type that is read during a successful `pipe::read` operation, or written during a successful `pipe::write` operation. The type must be standard layout and trivially copyable.
195-
* `min_capacity`: User defined minimum number of words in units of `dataT` that the pipe must be able to store without any being read out. A minimum capacity is required in some algorithms to avoid deadlock, or for performance tuning. An implementation can include more capacity than this parameter, but not less.
198+
* `dataT`: The type of data word/packet contained within a pipe. This is the data type that is read during a successful `pipe::read` operation, or written during a successful `pipe::write` operation. The type must be standard layout and trivially copyable. This template parameter can be queried by using the `value_type` type alias.
199+
* `min_capacity`: User defined minimum number of words in units of `dataT` that the pipe must be able to store without any being read out. A minimum capacity is required in some algorithms to avoid deadlock, or for performance tuning. An implementation can include more capacity than this parameter, but not less. This template parameter can be queried by using the `min_capacity` static member.
196200

197201
== Pipe types and {cpp} scope
198202

sycl/include/sycl/ext/intel/pipes.hpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace intel {
1919

2020
template <class _name, class _dataT, int32_t _min_capacity = 0> class pipe {
2121
public:
22+
using value_type = _dataT;
23+
static constexpr int32_t min_capacity = _min_capacity;
2224
// Non-blocking pipes
2325
// Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
2426
// friendly LLVM IR.
@@ -82,10 +84,9 @@ template <class _name, class _dataT, int32_t _min_capacity = 0> class pipe {
8284
private:
8385
static constexpr int32_t m_Size = sizeof(_dataT);
8486
static constexpr int32_t m_Alignment = alignof(_dataT);
85-
static constexpr int32_t m_Capacity = _min_capacity;
8687
#ifdef __SYCL_DEVICE_ONLY__
8788
static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment,
88-
m_Capacity};
89+
min_capacity};
8990
#endif // __SYCL_DEVICE_ONLY__
9091
};
9192

@@ -112,6 +113,8 @@ using ethernet_write_pipe =
112113
template <class _name, class _dataT, size_t _min_capacity = 0>
113114
class kernel_readable_io_pipe {
114115
public:
116+
using value_type = _dataT;
117+
static constexpr int32_t min_capacity = _min_capacity;
115118
// Non-blocking pipes
116119
// Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V
117120
// friendly LLVM IR.
@@ -147,17 +150,18 @@ class kernel_readable_io_pipe {
147150
private:
148151
static constexpr int32_t m_Size = sizeof(_dataT);
149152
static constexpr int32_t m_Alignment = alignof(_dataT);
150-
static constexpr int32_t m_Capacity = _min_capacity;
151153
static constexpr int32_t ID = _name::id;
152154
#ifdef __SYCL_DEVICE_ONLY__
153155
static constexpr struct ConstantPipeStorage m_Storage
154-
__attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, m_Capacity};
156+
__attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, min_capacity};
155157
#endif // __SYCL_DEVICE_ONLY__
156158
};
157159

158160
template <class _name, class _dataT, size_t _min_capacity = 0>
159161
class kernel_writeable_io_pipe {
160162
public:
163+
using value_type = _dataT;
164+
static constexpr int32_t min_capacity = _min_capacity;
161165
// Non-blocking pipes
162166
// Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V
163167
// friendly LLVM IR.
@@ -191,11 +195,10 @@ class kernel_writeable_io_pipe {
191195
private:
192196
static constexpr int32_t m_Size = sizeof(_dataT);
193197
static constexpr int32_t m_Alignment = alignof(_dataT);
194-
static constexpr int32_t m_Capacity = _min_capacity;
195198
static constexpr int32_t ID = _name::id;
196199
#ifdef __SYCL_DEVICE_ONLY__
197200
static constexpr struct ConstantPipeStorage m_Storage
198-
__attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, m_Capacity};
201+
__attribute__((io_pipe_id(ID))) = {m_Size, m_Alignment, min_capacity};
199202
#endif // __SYCL_DEVICE_ONLY__
200203
};
201204

sycl/test/extensions/fpga.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include <CL/sycl.hpp>
44
#include <sycl/ext/intel/fpga_extensions.hpp>
5+
6+
#include <type_traits>
7+
58
namespace intelfpga {
69
template <unsigned ID> struct ethernet_pipe_id {
710
static constexpr unsigned id = ID;
@@ -36,6 +39,11 @@ using ethernet_read_pipe =
3639
sycl::ext::intel::kernel_readable_io_pipe<ethernet_pipe_id<0>, int, 0>;
3740
using ethernet_write_pipe =
3841
sycl::ext::intel::kernel_writeable_io_pipe<ethernet_pipe_id<1>, int, 0>;
42+
43+
static_assert(std::is_same_v<ethernet_read_pipe::value_type, int>);
44+
static_assert(std::is_same_v<ethernet_write_pipe::value_type, int>);
45+
static_assert(ethernet_read_pipe::min_capacity == 0);
46+
static_assert(ethernet_write_pipe::min_capacity == 0);
3947
} // namespace intelfpga
4048

4149
int main() {

0 commit comments

Comments
 (0)