1
Fork 0
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:
Alessandro Capotondi 2022-12-19 00:00:31 +01:00
parent 7a6770f785
commit 7cab92df26
5 changed files with 524360 additions and 0 deletions

View 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)

View 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;
}

File diff suppressed because it is too large Load diff

View 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)));
}
}
}

View 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