Skip to content

Merge dev to main for release 2023.2 #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3c2197
Rename LEGUP_ROOT_DIR to SHLS_ROOT_DIR
siupakmok Apr 3, 2023
89892ce
Merge pull request #32 from MicrochipTech/rename_siu_pak
duc-tran-mchp Apr 13, 2023
7ec4f1b
Update Sobel Tutorial part 3 to use loop pipelining
SHLegupMCHP Apr 11, 2023
f655557
Merge pull request #33 from MicrochipTech/update_sobel_part3
SHLegupMCHP May 2, 2023
4b71abe
Update SmartHLS projects for section 12.2, 13 and 14 to use loop pipe…
SHLegupMCHP May 3, 2023
c29de6b
Increased FIFO depths for Bayer filter, no filter, and Gaussian filte…
jennifermah76 Jun 1, 2023
2e69c5d
adding digit recoginition dataflow version
angelayu-mchp Jun 6, 2023
168152c
updated path for .tcl files
angelayu-mchp Jun 6, 2023
731b744
Updated training documents for Training 1, Training 3, and Sobel
jennifermah76 Jun 9, 2023
9bc677c
Merge pull request #36 from MicrochipTech/training1_loop_pipeline
SHLegupMCHP Jun 9, 2023
2cfede2
Merge pull request #35 from MicrochipTech/Training_Doc_Update
SHLegupMCHP Jun 9, 2023
1f37c08
updating training 2 document
angelayu-mchp Jun 16, 2023
679084c
Merge pull request #37 from MicrochipTech/training2_dataflow
SHLegupMCHP Jun 16, 2023
9c8ad2b
Updated cores versions in Training1;Fixed tcl path errors in Training3
ShuranXuMCHP Jul 12, 2023
482ea80
Merge pull request #40 from MicrochipTech/update_trainings_shuran
duc-tran-mchp Jul 14, 2023
34aac94
- Sobel: Switched shls_ide command to shls -g
jennifermah76 Jun 6, 2023
b38a91e
Merge pull request #41 from MicrochipTech/training_doc_update_2023_2
jennifermah76 Jul 17, 2023
ae65ea8
Added Training 4 doc updated for 2023.2
jennifermah76 Jul 17, 2023
dd68d14
Update README.md
jennifermah76 Aug 10, 2023
74126f9
Merge pull request #42 from MicrochipTech/training_4_doc
jennifermah76 Aug 10, 2023
e18018b
Updated PF_XCVR_ERM to 3.1.205
ShuranXuMCHP Aug 17, 2023
4c11152
Merge pull request #45 from MicrochipTech/update_trainings_shuran
ShuranXuMCHP Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Example | Description
[Training1](./Training1)|SmartHLS™ Training Session 1: Image Processing on the PolarFire® Video Kit
[Training2](./Training2)|SmartHLS™ Training Session 2: Multi-threaded Digit Recognition on the PolarFire® Video Kit
[Training3](./Training3)|SmartHLS™ Training Session 3: AXI Interfaces to DDR & Mi-V Soft Processor on the PolarFire® Video Kit
[Training4](./Training4)|SmartHLS™ Training Session 4: SmartHLS™ Training for Microchip PolarFire® SoC Flow

## Examples of HLS Features

Expand Down
4 changes: 2 additions & 2 deletions Training1/Canny/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ NAME = Canny
LOCAL_CONFIG = -legup-config=config.tcl
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
GUI_BASE_DIR =
LEVEL = $(LEGUP_ROOT_DIR)/examples
LEVEL = $(SHLS_ROOT_DIR)/examples


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

ifneq ("$(wildcard $(GUI_BASE_DIR)Makefile.user)","")
include $(GUI_BASE_DIR)Makefile.user
Expand Down
13 changes: 10 additions & 3 deletions Training1/Canny/canny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ void canny(hls::FIFO<unsigned char> &input_fifo,
#pragma HLS function top
#pragma HLS function dataflow


#ifndef __SYNTHESIS__
// For software, the fifo depth has to be larger.
hls::FIFO<unsigned char> output_fifo_gf(WIDTH * HEIGHT * 2);
hls::FIFO<unsigned short> output_fifo_sf(WIDTH * HEIGHT * 2);
hls::FIFO<unsigned char> output_fifo_nm(WIDTH * HEIGHT * 2);
#else
hls::FIFO<unsigned char> output_fifo_gf(/* depth = */ 2);
hls::FIFO<unsigned short> output_fifo_sf(/* depth = */ 2);
hls::FIFO<unsigned char> output_fifo_nm(/* depth = */ 2);

#endif
gaussian_filter(input_fifo, output_fifo_gf);
sobel_filter(output_fifo_gf, output_fifo_sf);
nonmaximum_suppression(output_fifo_sf, output_fifo_nm);
Expand Down Expand Up @@ -75,17 +82,17 @@ int main() {
unsigned char b = input_channel->b;
unsigned grayscale = (r + g + b) / 3;
input_fifo.write(grayscale);
canny(input_fifo, output_fifo);
input_channel++;
}
}

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

canny(input_fifo, output_fifo);

// output validation
for (i = 0; i < HEIGHT; i++) {
for (j = 0; j < WIDTH; j++) {
Expand Down
2 changes: 1 addition & 1 deletion Training1/Canny/config.tcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
########## This file is automatically generated. Any changes to this file will be lost. ##########
########## If you have your own constraints tcl file, please add it to the project ##########
########## by using the "Set custom config file" constraint in the HLS Constraints dialog. ##########
source $env(LEGUP_ROOT_DIR)/examples/legup.tcl
source $env(SHLS_ROOT_DIR)/examples/legup.tcl
set_project PolarFire MPF300 MiV_SoC
set_parameter CLOCK_PERIOD 10
76 changes: 37 additions & 39 deletions Training1/Canny/gaussian_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,49 @@ const unsigned int DIVISOR = 128;

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

if (input_fifo.empty())
return;

unsigned char input_pixel = input_fifo.read();

static hls::LineBuffer<unsigned char, WIDTH, GF_KERNEL_SIZE> line_buffer;

line_buffer.ShiftInPixel(input_pixel);

// keep track of how many pixels we have shifted into the line_buffer to
// tell when it is filled
static int count = 0;
if (!is_filled(GF_KERNEL_SIZE, count)) {
count++;
return;
}

// i, j to track the position we are at while processing each input frame
static unsigned int i = 0, j = 0;
hls::LineBuffer<unsigned char, WIDTH, GF_KERNEL_SIZE> line_buffer;
const unsigned center = GF_KERNEL_SIZE / 2;
const unsigned LineBufferFillCount = center * WIDTH + center;
// track the position we are at while processing each input frame
unsigned int x = 0, y = 0;

#pragma HLS loop pipeline
for (unsigned int i = 0; i < (HEIGHT * WIDTH + LineBufferFillCount); i++) {
unsigned char input_pixel = 0;
if (i < HEIGHT * WIDTH)
input_pixel = input_fifo.read();
line_buffer.ShiftInPixel(input_pixel);

// keep track of how many pixels we have shifted into the line_buffer to
// tell when it is filled
if (!is_filled(GF_KERNEL_SIZE, i)) {
continue;
}

// calculate if the kernel is currently out of bounds, i.e. the kernel
// overlaps with pixels outside of the current input frame
bool outofbounds = is_out_of_bounds(GF_KERNEL_SIZE, i, j);
// calculate if the kernel is currently out of bounds, i.e. the kernel
// overlaps with pixels outside of the current input frame
bool out_of_bounds =
is_out_of_bounds(GF_KERNEL_SIZE, y, x);

// update i, j for next iteration
update_image_position(i, j);
// update x, y for next iteration
update_image_position(y, x);

if (outofbounds) {
unsigned int center = GF_KERNEL_SIZE / 2;
unsigned char current_pixel = line_buffer.window[center][center];
output_fifo.write(current_pixel);
return;
}
if (out_of_bounds) {
output_fifo.write(line_buffer.window[center][center]);
continue;
}

unsigned int sum = 0;
for (unsigned int m = 0; m < GF_KERNEL_SIZE; m++) {
for (unsigned int n = 0; n < GF_KERNEL_SIZE; n++) {
sum += ((unsigned int)line_buffer.window[m][n]) * GAUSSIAN[m][n];
unsigned int sum = 0;
for (unsigned int m = 0; m < GF_KERNEL_SIZE; m++) {
for (unsigned int n = 0; n < GF_KERNEL_SIZE; n++) {
sum +=
((unsigned int)line_buffer.window[m][n] * GAUSSIAN[m][n]);
}
}
}

int output = sum / DIVISOR;
sum /= DIVISOR;

output_fifo.write(output);
output_fifo.write((unsigned char)sum);
}
}

87 changes: 43 additions & 44 deletions Training1/Canny/hysteresis_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,56 @@

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

if (input_fifo.empty())
return;

unsigned char input_pixel = input_fifo.read();

static hls::LineBuffer<unsigned char, WIDTH, HF_KERNEL_SIZE> line_buffer;

line_buffer.ShiftInPixel(input_pixel);

// keep track of how many pixels we have shifted into the line_buffer to
// tell when it is filled
static int count = 0;
if (!is_filled(HF_KERNEL_SIZE, count)) {
count++;
return;
}

// i, j to track the position we are at while processing each input frame
static unsigned int i = 0, j = 0;
hls::LineBuffer<unsigned char, WIDTH, HF_KERNEL_SIZE> line_buffer;
const unsigned center = HF_KERNEL_SIZE / 2;
const unsigned LineBufferFillCount = center * WIDTH + center;
// track the position we are at while processing each input frame
unsigned int x = 0, y = 0;

#pragma HLS loop pipeline
for (unsigned int i = 0; i < (HEIGHT * WIDTH + LineBufferFillCount); i++) {
unsigned char input_pixel = 0;
if (i < HEIGHT * WIDTH)
input_pixel = input_fifo.read();
line_buffer.ShiftInPixel(input_pixel);

// keep track of how many pixels we have shifted into the line_buffer to
// tell when it is filled
if (!is_filled(HF_KERNEL_SIZE, i)) {
continue;
}

// calculate if the kernel is currently out of bounds, i.e. the kernel
// overlaps with pixels outside of the current input frame
bool outofbounds = is_out_of_bounds(HF_KERNEL_SIZE, i, j);
// calculate if the kernel is currently out of bounds, i.e. the kernel
// overlaps with pixels outside of the current input frame
bool out_of_bounds =
is_out_of_bounds(HF_KERNEL_SIZE, y, x);

// update i, j for next iteration
update_image_position(i, j);
// update x, y for next iteration
update_image_position(y, x);

if (outofbounds) {
output_fifo.write(0);
return;
}
if (out_of_bounds) {
output_fifo.write(0);
continue;
}

// check stencil for strong edges where the two most
// significant bits are set to one (& 0xC0)
int threshold = 0;
for (unsigned int m = 0; m < HF_KERNEL_SIZE; m++) {
for (unsigned int n = 0; n < HF_KERNEL_SIZE; n++) {
threshold = (line_buffer.window[m][n] & 0xC0) ? 1 : threshold;
// check stencil for strong edges where the two most
// significant bits are set to one (& 0xC0)
int threshold = 0;
for (unsigned int m = 0; m < HF_KERNEL_SIZE; m++) {
for (unsigned int n = 0; n < HF_KERNEL_SIZE; n++) {
threshold = (line_buffer.window[m][n] & 0xC0) ? 1 : threshold;
}
}
}

// strengthen edge by a factor of 2
unsigned int center = HF_KERNEL_SIZE / 2;
int output = line_buffer.window[center][center] * 2;
output = (output > 255) ? 255 : output;
// strengthen edge by a factor of 2
unsigned int center = HF_KERNEL_SIZE / 2;
int output = line_buffer.window[center][center] * 2;
output = (output > 255) ? 255 : output;

// only keep edge if it neighbours on a strong edge
output = threshold ? output : 0;
// only keep edge if it neighbours on a strong edge
output = threshold ? output : 0;

output_fifo.write(output);
output_fifo.write(output);
}
}

Loading