Skip to content

Commit a3bede2

Browse files
authored
FPGA: Remove DataBundle from convolution2d code sample, update gasket IP (#2310)
Simplify convolution2d code sample by removing the proprietary DataBundle header and replace it with std::array for simplicity and portability.
1 parent 2305b89 commit a3bede2

25 files changed

+1119
-703
lines changed

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/convolution2d/README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct Convolution2d {
118118
myLineBuffer(rows, cols);
119119

120120
bool keep_going = true;
121-
bool bypass = true;
121+
bool bypass = false;
122122

123123
[[intel::initiation_interval(1)]] // NO-FORMAT: Attribute
124124
while (keep_going) {
@@ -196,9 +196,9 @@ conv2d::PixelType ConvolutionFunction(
196196
// handle the case where the center of the window is at the image edge.
197197
// In this design, simply 'reflect' pixels that are already in the
198198
// window.
199-
SaturateWindowCoordinates(w_row, w_col, //
200-
row, col, //
201-
rows, cols, //
199+
SaturateWindowCoordinates(w_row, w_col, // NO-FORMAT: Alignment
200+
row, col, // NO-FORMAT: Alignment
201+
rows, cols, // NO-FORMAT: Alignment
202202
r_select, c_select);
203203
conv2d::PixelType pixel =
204204
buffer[c_select + r_select * conv2d::kWindowSize];
@@ -245,7 +245,7 @@ For convenience, you may use the header file included in `quartus_project_files/
245245

246246
### Test bench utilities
247247

248-
In this design, pipes are used to transfer data between kernels, and between the design and the testbench (host code). An aggregate type (`fpga_tools::DataBundle`) is used to allow multiple pixels to transfer in one clock cycle. To help with this, this reference design uses the `WriteFrameToPipe()` and `ReadFrameFromPipe()` functions, which are defined in `include/vvp_stream_adapters.hpp`.
248+
In this design, pipes are used to transfer data between kernels, and between the design and the testbench (host code). An aggregate type (`std::array`) is used to allow multiple pixels to transfer in one clock cycle. To help with this, this reference design uses the `WriteFrameToPipe()` and `ReadFrameFromPipe()` functions, which are defined in `include/vvp_stream_adapters.hpp`.
249249

250250
`WriteFrameToPipe()` writes the contents of an array of pixels *into* a SYCL pipe that can be consumed by a oneAPI kernel. It detects the parameterization of the aggregate type used by the pipe, and groups pixels together accordingly. It also generates start-of-packet and end-of-packet sideband signals like a VVP FPGA IP would, so you can test that your IP can interface with other IPs that use the VVP standard.
251251

@@ -260,7 +260,11 @@ The following diagram illustrates how these functions adapt image data to pipes,
260260
The following code snippet demonstrates how you can use these functions to populate a pipe with image data before invoking a kernel, and how you can parse the output.
261261

262262
```c++
263-
bool TestTinyFrameOnStencil(sycl::queue q) {
263+
bool TestTinyFrameOnStencil(sycl::queue q, bool print_debug_info) {
264+
std::cout << "\n**********************************\n"
265+
<< "Check Tiny frame... "
266+
<< "\n**********************************\n"
267+
<< std::endl;
264268
constexpr int rows_small = 3;
265269
constexpr int cols_small = 8;
266270

@@ -274,28 +278,22 @@ bool TestTinyFrameOnStencil(sycl::queue q) {
274278
vvp_stream_adapters::WriteFrameToPipe<InputImageStreamGrey>(
275279
q, rows_small, cols_small, grey_pixels_in);
276280

277-
// extra pixels to flush out the FIFO
281+
// add extra pixels to flush out the FIFO after all image frames
282+
// have been added
278283
int dummy_pixels = cols_small * conv2d::kWindowSize;
279284
vvp_stream_adapters::WriteDummyPixelsToPipe<InputImageStreamGrey>(
280285
q, dummy_pixels, (uint16_t)15);
281286

282-
// disable bypass, since it's on by default
283-
BypassCSR::write(q, false);
284-
285-
// Make sure that there is no 'true' still sitting in the 'stop' register from
286-
// the last time the kernel was stopped
287-
StopCSR::write(q, false);
288-
289287
sycl::event e = q.single_task<ID_Convolution2d>(
290288
Convolution2d<InputImageStreamGrey, OutputImageStreamGrey>{
291289
(int)rows_small, (int)cols_small, identity_coeffs});
292290

293291
conv2d::PixelType grey_pixels_out[pixels_count];
294292
bool sidebands_ok;
295-
int defective_frames;
293+
int parsed_frames;
296294
vvp_stream_adapters::ReadFrameFromPipe<OutputImageStreamGrey>(
297-
q, rows_small, cols_small, grey_pixels_out, sidebands_ok,
298-
defective_frames);
295+
q, rows_small, cols_small, grey_pixels_out, sidebands_ok, parsed_frames,
296+
print_debug_info);
299297

300298
bool pixels_match = true;
301299
for (int i = 0; i < pixels_count; i++) {

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/convolution2d/assets/testbench_architecture.svg

Lines changed: 4 additions & 4 deletions
Loading

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/convolution2d/include/data_bundle.hpp

Lines changed: 0 additions & 184 deletions
This file was deleted.

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/convolution2d/include/linebuffer2d.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
#pragma once
77

8+
#include <array>
9+
810
#include "comparisons.hpp"
9-
#include "data_bundle.hpp"
1011
#include "shift_reg.hpp"
1112

1213
namespace line_buffer_2d {
@@ -29,10 +30,8 @@ template <typename PixelTypeIn, typename PixelTypeOut, short kStencilSize,
2930
class LineBuffer2d {
3031
public:
3132
// types used by LineBuffer2d
32-
using LineBufferDataBundleIn =
33-
fpga_tools::DataBundle<PixelTypeIn, kParallelPixels>;
34-
using LineBufferDataBundleOut =
35-
fpga_tools::DataBundle<PixelTypeOut, kParallelPixels>;
33+
using LineBufferDataBundleIn = std::array<PixelTypeIn, kParallelPixels>;
34+
using LineBufferDataBundleOut = std::array<PixelTypeOut, kParallelPixels>;
3635

3736
// public members
3837
[[intel::fpga_register]] // NO-FORMAT: Attribute
@@ -44,8 +43,7 @@ class LineBuffer2d {
4443
private:
4544
// types used internally
4645
using PixelWithSignals = PixelWithSignals_<PixelTypeIn>;
47-
using BundledPixels =
48-
fpga_tools::DataBundle<PixelWithSignals, kParallelPixels>;
46+
using BundledPixels = std::array<PixelWithSignals, kParallelPixels>;
4947
constexpr static short kRowWriteInit = (short)(0 - kStencilSize);
5048
constexpr static short kColWriteInit = (short)(0 - kStencilSize);
5149

@@ -80,7 +78,7 @@ class LineBuffer2d {
8078
constexpr static short kPreBufferSize = kParallelPixels + kBufferOffset;
8179

8280
[[intel::fpga_register]] // NO-FORMAT: Attribute
83-
fpga_tools::DataBundle<PixelWithSignals, kPreBufferSize>
81+
fpga_tools::ShiftReg<PixelWithSignals, kPreBufferSize>
8482
pre_buffer;
8583

8684
// separate the loop bound calculation so loop iterations are easier to
@@ -171,8 +169,10 @@ class LineBuffer2d {
171169
// grab the first `kParallelPixels` samples to push into the stencil
172170
[[intel::fpga_register]] // NO-FORMAT: Attribute
173171
BundledPixels input_val;
174-
input_val.template ShiftMultiVals<kParallelPixels, kPreBufferSize>(
175-
pre_buffer);
172+
#pragma unroll
173+
for (int i = 0; i < kParallelPixels; i++) {
174+
input_val[i] = pre_buffer[i];
175+
}
176176

177177
[[intel::fpga_register]] // NO-FORMAT: Attribute
178178
BundledPixels pixel_column[kStencilSize];

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/convolution2d/include/shift_reg.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef __SHIFT_REG_HPP__
77
#define __SHIFT_REG_HPP__
88

9-
#include "data_bundle.hpp"
9+
#include <array>
10+
1011
#include "unrolled_loop.hpp"
1112

1213
namespace fpga_tools {
@@ -57,7 +58,7 @@ class ShiftReg {
5758
}
5859

5960
template <size_t kShiftAmt>
60-
void ShiftMultiVals(DataBundle<T, kShiftAmt> in) {
61+
void ShiftMultiVals(std::array<T, kShiftAmt> in) {
6162
fpga_tools::UnrolledLoop<0, (kRegDepth - kShiftAmt)>(
6263
[&](int i) { registers[i] = registers[i + kShiftAmt]; });
6364

@@ -129,7 +130,7 @@ class ShiftReg2d {
129130
}
130131

131132
template <size_t kShiftAmt>
132-
void ShiftCols(DataBundle<T, kShiftAmt> in[kRegRows]) {
133+
void ShiftCols(std::array<T, kShiftAmt> in[kRegRows]) {
133134
fpga_tools::UnrolledLoop<0, kRegRows>(
134135
[&](int i) { registers[i].template ShiftMultiVals<kShiftAmt>(in[i]); });
135136
}

0 commit comments

Comments
 (0)