Skip to content

Commit 9c8ca83

Browse files
authored
Merge pull request #46 from MicrochipTech/revert-44-dev
Revert "Merge dev to main for release 2023.2"
2 parents b361134 + b25719e commit 9c8ca83

File tree

79 files changed

+658
-1685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+658
-1685
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Example | Description
1414
[Training1](./Training1)|SmartHLS™ Training Session 1: Image Processing on the PolarFire® Video Kit
1515
[Training2](./Training2)|SmartHLS™ Training Session 2: Multi-threaded Digit Recognition on the PolarFire® Video Kit
1616
[Training3](./Training3)|SmartHLS™ Training Session 3: AXI Interfaces to DDR & Mi-V Soft Processor on the PolarFire® Video Kit
17-
[Training4](./Training4)|SmartHLS™ Training Session 4: SmartHLS™ Training for Microchip PolarFire® SoC Flow
1817

1918
## Examples of HLS Features
2019

Training1/Canny/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ NAME = Canny
44
LOCAL_CONFIG = -legup-config=config.tcl
55
SRCS = canny.cpp gaussian_filter.cpp gf_sw.cpp hf_sw.cpp hysteresis_filter.cpp nm_sw.cpp nonmaximum_suppression.cpp sf_sw.cpp sobel_filter.cpp util.cpp
66
GUI_BASE_DIR =
7-
LEVEL = $(SHLS_ROOT_DIR)/examples
7+
LEVEL = $(LEGUP_ROOT_DIR)/examples
88

99

10-
USER_CXX_FLAG += -O3 -pg -Wall -Wno-strict-aliasing -Wno-unused-label -Wno-unknown-pragmas -Wno-attributes -I$(SHLS_ROOT_DIR)/smarthls-library
10+
USER_CXX_FLAG += -O3 -pg -Wall -Wno-strict-aliasing -Wno-unused-label -Wno-unknown-pragmas -Wno-attributes -I$(LEGUP_ROOT_DIR)/smarthls-library
1111

1212
ifneq ("$(wildcard $(GUI_BASE_DIR)Makefile.user)","")
1313
include $(GUI_BASE_DIR)Makefile.user

Training1/Canny/canny.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ void canny(hls::FIFO<unsigned char> &input_fifo,
88
#pragma HLS function top
99
#pragma HLS function dataflow
1010

11-
12-
#ifndef __SYNTHESIS__
13-
// For software, the fifo depth has to be larger.
14-
hls::FIFO<unsigned char> output_fifo_gf(WIDTH * HEIGHT * 2);
15-
hls::FIFO<unsigned short> output_fifo_sf(WIDTH * HEIGHT * 2);
16-
hls::FIFO<unsigned char> output_fifo_nm(WIDTH * HEIGHT * 2);
17-
#else
1811
hls::FIFO<unsigned char> output_fifo_gf(/* depth = */ 2);
1912
hls::FIFO<unsigned short> output_fifo_sf(/* depth = */ 2);
2013
hls::FIFO<unsigned char> output_fifo_nm(/* depth = */ 2);
21-
#endif
14+
2215
gaussian_filter(input_fifo, output_fifo_gf);
2316
sobel_filter(output_fifo_gf, output_fifo_sf);
2417
nonmaximum_suppression(output_fifo_sf, output_fifo_nm);
@@ -82,17 +75,17 @@ int main() {
8275
unsigned char b = input_channel->b;
8376
unsigned grayscale = (r + g + b) / 3;
8477
input_fifo.write(grayscale);
78+
canny(input_fifo, output_fifo);
8579
input_channel++;
8680
}
8781
}
8882

8983
// Give more inputs to flush out all pixels.
9084
for (i = 0; i < GF_KERNEL_SIZE * WIDTH + GF_KERNEL_SIZE; i++) {
9185
input_fifo.write(0);
86+
canny(input_fifo, output_fifo);
9287
}
9388

94-
canny(input_fifo, output_fifo);
95-
9689
// output validation
9790
for (i = 0; i < HEIGHT; i++) {
9891
for (j = 0; j < WIDTH; j++) {

Training1/Canny/config.tcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
########## This file is automatically generated. Any changes to this file will be lost. ##########
22
########## If you have your own constraints tcl file, please add it to the project ##########
33
########## by using the "Set custom config file" constraint in the HLS Constraints dialog. ##########
4-
source $env(SHLS_ROOT_DIR)/examples/legup.tcl
4+
source $env(LEGUP_ROOT_DIR)/examples/legup.tcl
55
set_project PolarFire MPF300 MiV_SoC
66
set_parameter CLOCK_PERIOD 10

Training1/Canny/gaussian_filter.cpp

+39-37
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,51 @@ const unsigned int DIVISOR = 128;
1212

1313
void gaussian_filter(hls::FIFO<unsigned char> &input_fifo,
1414
hls::FIFO<unsigned char> &output_fifo) {
15+
#pragma HLS function pipeline
1516

16-
hls::LineBuffer<unsigned char, WIDTH, GF_KERNEL_SIZE> line_buffer;
17-
const unsigned center = GF_KERNEL_SIZE / 2;
18-
const unsigned LineBufferFillCount = center * WIDTH + center;
19-
// track the position we are at while processing each input frame
20-
unsigned int x = 0, y = 0;
21-
22-
#pragma HLS loop pipeline
23-
for (unsigned int i = 0; i < (HEIGHT * WIDTH + LineBufferFillCount); i++) {
24-
unsigned char input_pixel = 0;
25-
if (i < HEIGHT * WIDTH)
26-
input_pixel = input_fifo.read();
27-
line_buffer.ShiftInPixel(input_pixel);
28-
29-
// keep track of how many pixels we have shifted into the line_buffer to
30-
// tell when it is filled
31-
if (!is_filled(GF_KERNEL_SIZE, i)) {
32-
continue;
33-
}
17+
if (input_fifo.empty())
18+
return;
3419

35-
// calculate if the kernel is currently out of bounds, i.e. the kernel
36-
// overlaps with pixels outside of the current input frame
37-
bool out_of_bounds =
38-
is_out_of_bounds(GF_KERNEL_SIZE, y, x);
20+
unsigned char input_pixel = input_fifo.read();
3921

40-
// update x, y for next iteration
41-
update_image_position(y, x);
22+
static hls::LineBuffer<unsigned char, WIDTH, GF_KERNEL_SIZE> line_buffer;
4223

43-
if (out_of_bounds) {
44-
output_fifo.write(line_buffer.window[center][center]);
45-
continue;
46-
}
24+
line_buffer.ShiftInPixel(input_pixel);
4725

48-
unsigned int sum = 0;
49-
for (unsigned int m = 0; m < GF_KERNEL_SIZE; m++) {
50-
for (unsigned int n = 0; n < GF_KERNEL_SIZE; n++) {
51-
sum +=
52-
((unsigned int)line_buffer.window[m][n] * GAUSSIAN[m][n]);
53-
}
54-
}
26+
// keep track of how many pixels we have shifted into the line_buffer to
27+
// tell when it is filled
28+
static int count = 0;
29+
if (!is_filled(GF_KERNEL_SIZE, count)) {
30+
count++;
31+
return;
32+
}
33+
34+
// i, j to track the position we are at while processing each input frame
35+
static unsigned int i = 0, j = 0;
36+
37+
// calculate if the kernel is currently out of bounds, i.e. the kernel
38+
// overlaps with pixels outside of the current input frame
39+
bool outofbounds = is_out_of_bounds(GF_KERNEL_SIZE, i, j);
5540

56-
sum /= DIVISOR;
41+
// update i, j for next iteration
42+
update_image_position(i, j);
5743

58-
output_fifo.write((unsigned char)sum);
44+
if (outofbounds) {
45+
unsigned int center = GF_KERNEL_SIZE / 2;
46+
unsigned char current_pixel = line_buffer.window[center][center];
47+
output_fifo.write(current_pixel);
48+
return;
5949
}
50+
51+
unsigned int sum = 0;
52+
for (unsigned int m = 0; m < GF_KERNEL_SIZE; m++) {
53+
for (unsigned int n = 0; n < GF_KERNEL_SIZE; n++) {
54+
sum += ((unsigned int)line_buffer.window[m][n]) * GAUSSIAN[m][n];
55+
}
56+
}
57+
58+
int output = sum / DIVISOR;
59+
60+
output_fifo.write(output);
6061
}
62+

Training1/Canny/hysteresis_filter.cpp

+44-43
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,57 @@
33

44
void hysteresis_filter(hls::FIFO<unsigned char> &input_fifo,
55
hls::FIFO<unsigned char> &output_fifo) {
6+
#pragma HLS function pipeline
67

7-
hls::LineBuffer<unsigned char, WIDTH, HF_KERNEL_SIZE> line_buffer;
8-
const unsigned center = HF_KERNEL_SIZE / 2;
9-
const unsigned LineBufferFillCount = center * WIDTH + center;
10-
// track the position we are at while processing each input frame
11-
unsigned int x = 0, y = 0;
12-
13-
#pragma HLS loop pipeline
14-
for (unsigned int i = 0; i < (HEIGHT * WIDTH + LineBufferFillCount); i++) {
15-
unsigned char input_pixel = 0;
16-
if (i < HEIGHT * WIDTH)
17-
input_pixel = input_fifo.read();
18-
line_buffer.ShiftInPixel(input_pixel);
19-
20-
// keep track of how many pixels we have shifted into the line_buffer to
21-
// tell when it is filled
22-
if (!is_filled(HF_KERNEL_SIZE, i)) {
23-
continue;
24-
}
8+
if (input_fifo.empty())
9+
return;
2510

26-
// calculate if the kernel is currently out of bounds, i.e. the kernel
27-
// overlaps with pixels outside of the current input frame
28-
bool out_of_bounds =
29-
is_out_of_bounds(HF_KERNEL_SIZE, y, x);
11+
unsigned char input_pixel = input_fifo.read();
3012

31-
// update x, y for next iteration
32-
update_image_position(y, x);
13+
static hls::LineBuffer<unsigned char, WIDTH, HF_KERNEL_SIZE> line_buffer;
3314

34-
if (out_of_bounds) {
35-
output_fifo.write(0);
36-
continue;
37-
}
15+
line_buffer.ShiftInPixel(input_pixel);
3816

39-
// check stencil for strong edges where the two most
40-
// significant bits are set to one (& 0xC0)
41-
int threshold = 0;
42-
for (unsigned int m = 0; m < HF_KERNEL_SIZE; m++) {
43-
for (unsigned int n = 0; n < HF_KERNEL_SIZE; n++) {
44-
threshold = (line_buffer.window[m][n] & 0xC0) ? 1 : threshold;
45-
}
46-
}
17+
// keep track of how many pixels we have shifted into the line_buffer to
18+
// tell when it is filled
19+
static int count = 0;
20+
if (!is_filled(HF_KERNEL_SIZE, count)) {
21+
count++;
22+
return;
23+
}
24+
25+
// i, j to track the position we are at while processing each input frame
26+
static unsigned int i = 0, j = 0;
27+
28+
// calculate if the kernel is currently out of bounds, i.e. the kernel
29+
// overlaps with pixels outside of the current input frame
30+
bool outofbounds = is_out_of_bounds(HF_KERNEL_SIZE, i, j);
4731

48-
// strengthen edge by a factor of 2
49-
unsigned int center = HF_KERNEL_SIZE / 2;
50-
int output = line_buffer.window[center][center] * 2;
51-
output = (output > 255) ? 255 : output;
32+
// update i, j for next iteration
33+
update_image_position(i, j);
5234

53-
// only keep edge if it neighbours on a strong edge
54-
output = threshold ? output : 0;
35+
if (outofbounds) {
36+
output_fifo.write(0);
37+
return;
38+
}
5539

56-
output_fifo.write(output);
40+
// check stencil for strong edges where the two most
41+
// significant bits are set to one (& 0xC0)
42+
int threshold = 0;
43+
for (unsigned int m = 0; m < HF_KERNEL_SIZE; m++) {
44+
for (unsigned int n = 0; n < HF_KERNEL_SIZE; n++) {
45+
threshold = (line_buffer.window[m][n] & 0xC0) ? 1 : threshold;
46+
}
5747
}
48+
49+
// strengthen edge by a factor of 2
50+
unsigned int center = HF_KERNEL_SIZE / 2;
51+
int output = line_buffer.window[center][center] * 2;
52+
output = (output > 255) ? 255 : output;
53+
54+
// only keep edge if it neighbours on a strong edge
55+
output = threshold ? output : 0;
56+
57+
output_fifo.write(output);
5858
}
59+

0 commit comments

Comments
 (0)