Skip to content

Commit d762f3e

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

File tree

79 files changed

+1685
-658
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

+1685
-658
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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
1718

1819
## Examples of HLS Features
1920

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 = $(LEGUP_ROOT_DIR)/examples
7+
LEVEL = $(SHLS_ROOT_DIR)/examples
88

99

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

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

Training1/Canny/canny.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ 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
1118
hls::FIFO<unsigned char> output_fifo_gf(/* depth = */ 2);
1219
hls::FIFO<unsigned short> output_fifo_sf(/* depth = */ 2);
1320
hls::FIFO<unsigned char> output_fifo_nm(/* depth = */ 2);
14-
21+
#endif
1522
gaussian_filter(input_fifo, output_fifo_gf);
1623
sobel_filter(output_fifo_gf, output_fifo_sf);
1724
nonmaximum_suppression(output_fifo_sf, output_fifo_nm);
@@ -75,17 +82,17 @@ int main() {
7582
unsigned char b = input_channel->b;
7683
unsigned grayscale = (r + g + b) / 3;
7784
input_fifo.write(grayscale);
78-
canny(input_fifo, output_fifo);
7985
input_channel++;
8086
}
8187
}
8288

8389
// Give more inputs to flush out all pixels.
8490
for (i = 0; i < GF_KERNEL_SIZE * WIDTH + GF_KERNEL_SIZE; i++) {
8591
input_fifo.write(0);
86-
canny(input_fifo, output_fifo);
8792
}
8893

94+
canny(input_fifo, output_fifo);
95+
8996
// output validation
9097
for (i = 0; i < HEIGHT; i++) {
9198
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(LEGUP_ROOT_DIR)/examples/legup.tcl
4+
source $env(SHLS_ROOT_DIR)/examples/legup.tcl
55
set_project PolarFire MPF300 MiV_SoC
66
set_parameter CLOCK_PERIOD 10

Training1/Canny/gaussian_filter.cpp

+37-39
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,49 @@ 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
1615

17-
if (input_fifo.empty())
18-
return;
19-
20-
unsigned char input_pixel = input_fifo.read();
21-
22-
static hls::LineBuffer<unsigned char, WIDTH, GF_KERNEL_SIZE> line_buffer;
23-
24-
line_buffer.ShiftInPixel(input_pixel);
25-
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;
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+
}
3634

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);
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);
4039

41-
// update i, j for next iteration
42-
update_image_position(i, j);
40+
// update x, y for next iteration
41+
update_image_position(y, x);
4342

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;
49-
}
43+
if (out_of_bounds) {
44+
output_fifo.write(line_buffer.window[center][center]);
45+
continue;
46+
}
5047

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];
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+
}
5554
}
56-
}
5755

58-
int output = sum / DIVISOR;
56+
sum /= DIVISOR;
5957

60-
output_fifo.write(output);
58+
output_fifo.write((unsigned char)sum);
59+
}
6160
}
62-

Training1/Canny/hysteresis_filter.cpp

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

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

8-
if (input_fifo.empty())
9-
return;
10-
11-
unsigned char input_pixel = input_fifo.read();
12-
13-
static hls::LineBuffer<unsigned char, WIDTH, HF_KERNEL_SIZE> line_buffer;
14-
15-
line_buffer.ShiftInPixel(input_pixel);
16-
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;
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+
}
2725

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);
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);
3130

32-
// update i, j for next iteration
33-
update_image_position(i, j);
31+
// update x, y for next iteration
32+
update_image_position(y, x);
3433

35-
if (outofbounds) {
36-
output_fifo.write(0);
37-
return;
38-
}
34+
if (out_of_bounds) {
35+
output_fifo.write(0);
36+
continue;
37+
}
3938

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;
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+
}
4646
}
47-
}
4847

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;
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;
5352

54-
// only keep edge if it neighbours on a strong edge
55-
output = threshold ? output : 0;
53+
// only keep edge if it neighbours on a strong edge
54+
output = threshold ? output : 0;
5655

57-
output_fifo.write(output);
56+
output_fifo.write(output);
57+
}
5858
}
59-

0 commit comments

Comments
 (0)