This commit is contained in:
rdgarce
2023-08-13 16:00:34 +02:00
parent fa1af3ade8
commit 4b3127d84d
21 changed files with 87 additions and 896 deletions
+84
View File
@@ -0,0 +1,84 @@
#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../src/lina.h"
#define A_ROWS 1000llu
#define A_COLS 146llu
#define B_ROWS 146llu
#define B_COLS 1024llu
uint64_t nanos();
int main()
{
uint64_t ops = A_ROWS*B_COLS*2*A_COLS;
uint64_t start,stop,lina_dot_time, lina_dot_mod1_time, lina_dot_mod1_1_time, lina_dot_mod2_time;
double *A = (double *)malloc(sizeof(double)*A_ROWS*A_COLS);
double *B = (double *)malloc(sizeof(double)*B_ROWS*B_COLS);
double *C1 = (double *)malloc(sizeof(double)*A_ROWS*B_COLS);
double *C2 = (double *)malloc(sizeof(double)*A_ROWS*B_COLS);
double *C3 = (double *)malloc(sizeof(double)*A_ROWS*B_COLS);
double *C4 = (double *)malloc(sizeof(double)*A_ROWS*B_COLS);
for (int i = 0; i < A_ROWS*A_COLS; i++)
A[i] = (double)(rand()%10);
for (int i = 0; i < B_ROWS*B_COLS; i++)
B[i] = (double)(rand()%10);
for (int i = 0; i < A_ROWS*B_COLS; i++)
{
C1[i] = (double)(rand()%10);
C2[i] = (double)(rand()%10);
C3[i] = (double)(rand()%10);
C4[i] = (double)(rand()%10);
}
start = nanos();
lina_dot(A,B,C1,A_ROWS,A_COLS,B_COLS);
stop = nanos();
lina_dot_time = stop-start;
start = nanos();
lina_dot_mod1(A,B,C2,A_ROWS,A_COLS,B_COLS);
stop = nanos();
lina_dot_mod1_time = stop-start;
start = nanos();
lina_dot_mod2(A,B,C3,A_ROWS,A_COLS,B_COLS);
stop = nanos();
lina_dot_mod2_time = stop-start;
start = nanos();
lina_dot_mod2_old(A,B,C4,A_ROWS,A_COLS,B_COLS);
stop = nanos();
lina_dot_mod1_1_time = stop-start;
if(!memcmp(C1,C2,sizeof(double)*A_ROWS*B_COLS) && !memcmp(C2,C3,sizeof(double)*A_ROWS*B_COLS) && !memcmp(C3,C4,sizeof(double)*A_ROWS*B_COLS))
{
printf( "lina_dot : %f GFLOPS\n"
"lina_dot_mod1: %f GFLOPS\n"
"lina_dot_mod2: %f GFLOPS\n"
"lina_dot_mod2_old: %f GFLOPS\n", (double)ops/lina_dot_time,
(double)ops/lina_dot_mod1_time,
(double)ops/lina_dot_mod2_time,
(double)ops/lina_dot_mod1_1_time);
}
else
printf("ERRORE: i prodotti matriciali sono diversi!\n");
free(A);
free(B);
free(C1);
free(C2);
free(C3);
free(C4);
}
-87
View File
@@ -1,87 +0,0 @@
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "lina.h"
/* This program compares the lina_transpose
** implementation against the naive implementation.
** Build it with:
** $ gcc time.c lina.c -o time -Wall -Wextra -O3
*/
#define check assert
static void naive_transpose(double *A, double *B, int m, int n)
{
assert(m > 0 && n > 0);
assert(A != NULL && B != NULL);
double *support;
if(A == B)
{
support = malloc(sizeof(*support) * m * n);
check(support != NULL);
memcpy(support, A, sizeof(*support) * m * n);
}
else
{
support = A;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
B[j*n + i] = support[i*m + j];
if(support != A)
free(support);
}
// Wrap transposing functions and return their
// execution time.
static double time_transposition(void (*callback)(double*, double*, int, int), double *A, double *B, int m, int n)
{
clock_t begin = clock();
callback(A, B, m, n);
clock_t end = clock();
return (double) (end - begin) / CLOCKS_PER_SEC;
}
int main()
{
int m = 1000;
int n = 100000;
double *big = malloc(sizeof(double) * m * n);
check(big != NULL);
memset(big, 0, sizeof(double) * m * n);
printf("lina_transpose took %gms (in-place)\n",
1000 * time_transposition(lina_transpose, big, big, m, n));
printf("naive_transpose took %gms (in-place)\n",
1000 * time_transposition(naive_transpose, big, big, m, n));
double *big2 = malloc(sizeof(double) * m * n);
check(big2 != NULL);
printf("lina_transpose took %gms\n",
1000 * time_transposition(lina_transpose, big, big2, m, n));
printf("naive_transpose took %gms\n",
1000 * time_transposition(naive_transpose, big, big2, m, n));
free(big);
free(big2);
return 0;
}