From f0cb1c1bedadbccd33bd302d181e995fb16cf4cc Mon Sep 17 00:00:00 2001 From: Gattopandacorno Date: Mon, 19 Dec 2022 11:38:30 +0100 Subject: [PATCH] Use a three-line circular buffer Co-authored-by: Fabio Zanichelli <274956@studenti.unimore.it> Co-authored-by: Stefano Pigozzi <256895@studenti.unimore.it> --- hls/assignment/sobel/sobel.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hls/assignment/sobel/sobel.cpp b/hls/assignment/sobel/sobel.cpp index 6b1c2a8..00d9720 100644 --- a/hls/assignment/sobel/sobel.cpp +++ b/hls/assignment/sobel/sobel.cpp @@ -1,3 +1,4 @@ +#include #include #include "sobel.h" @@ -14,6 +15,10 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, {-1, 0, 1} }; + // Carica le prime tre righe nel buffer + uint8_t inBuffer[3*height]; + memcpy(inBuffer, in, 3*height*sizeof(uint8_t)); + esternoY: for (int y = 0; y < height - 2; y++) { @@ -30,7 +35,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, { #pragma HLS UNROLL - const int inYOffset = (y + k) * width; + const int inYOffset = ((y + k) % 3) * width; internoX: for (int z = 0; z < 3; z++) @@ -40,7 +45,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, const int inXOffset = x + z; const int inOffset = inYOffset + inXOffset; - const int inElement = in[inOffset]; + const int inElement = inBuffer[inOffset]; dx += sobelFilter[k][z] * inElement; dy += sobelFilter[z][k] * inElement; @@ -53,5 +58,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, out[outOffset] = sqrt((float)((dx * dx) + (dy * dy))); } + + memcpy(inBuffer, in + (y % 3) * height, height*sizeof(uint8_t)); } }