mirror of
https://github.com/Steffo99/unimore-hpc-assignments.git
synced 2024-11-26 10:04:23 +00:00
Added HLS Assignments
This commit is contained in:
parent
7a6770f785
commit
7cab92df26
5 changed files with 524360 additions and 0 deletions
9
hls/assignment/sobel/generate_image.py
Normal file
9
hls/assignment/sobel/generate_image.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import random
|
||||||
|
l = "uint8_t input[512*512] = {\n"
|
||||||
|
for i in range((512*512)-1):
|
||||||
|
l += str(random.randint(0,255))
|
||||||
|
l += ",\n"
|
||||||
|
l += str(random.randint(0,255))
|
||||||
|
l += "};\n"
|
||||||
|
|
||||||
|
print(l)
|
23
hls/assignment/sobel/main_testbench.cpp
Normal file
23
hls/assignment/sobel/main_testbench.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "sobel.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
uint8_t output[HEIGHT*WIDTH];
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
|
sobel(output, input, HEIGHT, WIDTH);
|
||||||
|
|
||||||
|
// Check errors
|
||||||
|
for(int i = 0; i < HEIGHT*WIDTH; i++)
|
||||||
|
if(output[i] != g_output[i])
|
||||||
|
errors++;
|
||||||
|
|
||||||
|
printf("Correctness: %.2f %% (%d Errors)\n", (1.0 - ((float) errors / (float)(HEIGHT*WIDTH)))*100.0, errors);
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
524296
hls/assignment/sobel/main_testbench.h
Normal file
524296
hls/assignment/sobel/main_testbench.h
Normal file
File diff suppressed because it is too large
Load diff
24
hls/assignment/sobel/sobel.cpp
Normal file
24
hls/assignment/sobel/sobel.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <math.h>
|
||||||
|
#include "sobel.h"
|
||||||
|
|
||||||
|
void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, int width, int height)
|
||||||
|
{
|
||||||
|
int sobelFilter[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
|
||||||
|
|
||||||
|
for (int y = 1; y < height - 1; y++)
|
||||||
|
{
|
||||||
|
for (int x = 1; x < width - 1; x++)
|
||||||
|
{
|
||||||
|
int dx = 0, dy = 0;
|
||||||
|
for (int k = 0; k < 3; k++)
|
||||||
|
{
|
||||||
|
for (int z = 0; z < 3; z++)
|
||||||
|
{
|
||||||
|
dx += sobelFilter[k][z] * in[(y + k - 1) * width + x + z - 1];
|
||||||
|
dy += sobelFilter[z][k] * in[(y + k - 1) * width + x + z - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out[y * width + x] = sqrt((float)((dx * dx) + (dy * dy)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
hls/assignment/sobel/sobel.h
Normal file
8
hls/assignment/sobel/sobel.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef SOBEL_H
|
||||||
|
#define SOBEL_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, int width, int height);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue