Q6: profiling info and preperation
This commit is contained in:
parent
a4fbbdd9d6
commit
5719ab0b46
@ -112,7 +112,7 @@ debug: $(BUILD_DIR)/$(TARGET)
|
|||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: CFLAGS += $(REL_FLAGS)
|
release: CFLAGS += $(REL_FLAGS)
|
||||||
release: clean $(BUILD_DIR)/$(TARGET)
|
release: $(BUILD_DIR)/$(TARGET)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
9
Q6-cache/info.txt
Normal file
9
Q6-cache/info.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Επεξεργαστής: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
|
||||||
|
Συχνότητα επεξεργαστή: 800 - 2600 MHz
|
||||||
|
Μέγεθος μνήμης L1: 192 KiB / 192 KiB (L1d/L1i)
|
||||||
|
Μέγεθος μνήμης L2: 1.5 MiB
|
||||||
|
Μέγεθος μνήμης L3: 12 MiB
|
||||||
|
Μέγεθος μνήμης RAM: 31893MiB
|
||||||
|
Έκδοση gcc: 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)
|
||||||
|
Έκδοση Λειτουργικού Συστήματος: Ubuntu 19.10 x86_64
|
||||||
|
|
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
\author Nikos Pitsianis
|
\author Nikos Pitsianis
|
||||||
\author Dimitris Floros
|
\author Dimitris Floros
|
||||||
|
\author Christos Choutouridis 8997 <cchoutou@ece.auth.gr>
|
||||||
\date 2020-05-05
|
\date 2020-05-05
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -17,59 +17,67 @@
|
|||||||
#define MAX_ITER 10
|
#define MAX_ITER 10
|
||||||
#define sub2ind(i,j,n) (j) + (i)*(n)
|
#define sub2ind(i,j,n) (j) + (i)*(n)
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
* matrixMult - Matrix multiplication
|
* Square Matrix multiplication
|
||||||
|
* \param C pointer to output matrix
|
||||||
|
* \param A pointer to input matrix A
|
||||||
|
* \param B pointer to input matrix B
|
||||||
|
* \param n Size of matrices (both sizes)
|
||||||
|
* \return none
|
||||||
|
*
|
||||||
|
* \note
|
||||||
|
* This version executes row major order ijk
|
||||||
*/
|
*/
|
||||||
void matrixMult(float * const C, /* output matrix */
|
void matrixMult(float * const C, float const * const A, float const * const B, int const n) {
|
||||||
float const * const A, /* first matrix */
|
|
||||||
float const * const B, /* second matrix */
|
|
||||||
int const n) { /* number of rows/cols */
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) { /* rows */
|
for (int i = 0; i < n; i++) { /* rows */
|
||||||
for (int j = 0; j < n; j++) { /* cols */
|
for (int j = 0; j < n; j++) { /* cols */
|
||||||
|
C[ sub2ind(i,j,n) ] = 0; /* initialize output value */
|
||||||
/* initialize output value */
|
for (int k = 0; k < n; k++) { /* accumulate products */
|
||||||
C[ sub2ind(i,j,n) ] = 0;
|
C[ sub2ind(i,j,n) ] +=
|
||||||
|
A[ sub2ind(i,k,n) ] * B[ sub2ind(k,j,n) ];
|
||||||
for (int k = 0; k < n; k++) { /* accumulate products */
|
}
|
||||||
C[ sub2ind(i,j,n) ] +=
|
|
||||||
A[ sub2ind(i,k,n) ] * B[ sub2ind(k,j,n) ];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end function 'matrixMult'
|
|
||||||
|
|
||||||
/*
|
}
|
||||||
* matrixInitAdd:
|
|
||||||
* Initialize matrix with random indices and return the matrix
|
/*!
|
||||||
* pointer.
|
* Initialize matrix with random indices and return the matrix pointer.
|
||||||
*
|
*
|
||||||
|
* \param n The size of the matrix (both of them)
|
||||||
|
* \return Pointer to allocated and initialized matrix
|
||||||
*/
|
*/
|
||||||
float * matrixInit(int const n) {
|
float * matrixInit(int const n) {
|
||||||
|
|
||||||
float *M = (float *) malloc( n*n*sizeof(float) );
|
float *M = (float *) malloc( n*n*sizeof(float) );
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) /* rows */
|
|
||||||
for (int j = 0; j < n; j++) /* cols */
|
|
||||||
M[ sub2ind(i,j,n) ] = (float)rand()/(float)(RAND_MAX);
|
|
||||||
|
|
||||||
return M;
|
for (int i = 0; i < n; i++) /* rows */
|
||||||
|
for (int j = 0; j < n; j++) /* cols */
|
||||||
} // end function 'matrixInitAdd'
|
M[ sub2ind(i,j,n) ] = (float)rand()/(float)(RAND_MAX);
|
||||||
|
|
||||||
|
return M;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmpfunc (const void * a, const void * b) {
|
||||||
|
double v =*(double*)a - *(double*)b;
|
||||||
|
return (v < 0) ? -1 : (v > 0) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* A unit testing like main function to profile our code
|
||||||
|
*/
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct timeval start, end; /* time structs */
|
struct timeval start, end; /* time structs */
|
||||||
double time = 0.0; /* execution time in ms */
|
double time[MAX_ITER] = {0.0}; /* execution time array in ms */
|
||||||
float *A, *B, *C; /* matrix declarations */
|
float *A, *B, *C; /* matrix declarations */
|
||||||
int n; /* matrix size */
|
int n; /* matrix size */
|
||||||
|
|
||||||
/* read matrix size (or use default) */
|
/* read matrix size (or use default) */
|
||||||
if (argc != 2){
|
if (argc != 2){
|
||||||
fprintf( stderr, "Uasge:\n %s n\n where n is the matrix size.\n",
|
fprintf( stderr, "Usage:\n %s n\n where n is the matrix size.\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -86,13 +94,13 @@ int main(int argc, char **argv)
|
|||||||
matrixMult( C, A, B, n );
|
matrixMult( C, A, B, n );
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
|
|
||||||
time = ( (end.tv_sec - start.tv_sec) * 1000.0 + /* sec to ms */
|
time[it] = (end.tv_sec - start.tv_sec) * 1000.0 + /* sec to ms */
|
||||||
(end.tv_usec - start.tv_usec) / 1000.0 ); /* us to ms */
|
(end.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
|
||||||
|
|
||||||
printf("Iter: %d Time: %f ms\n", it, time);
|
printf("Iter: %d Time: %f ms\n", it, time[it]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we noeed to use the result -- verify it */
|
/* we need to use the result -- verify it */
|
||||||
for (int i = 0; i < n; i++) { /* rows */
|
for (int i = 0; i < n; i++) { /* rows */
|
||||||
for (int j = 0; j < n; j++) { /* cols */
|
for (int j = 0; j < n; j++) { /* cols */
|
||||||
|
|
||||||
@ -106,5 +114,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// median calculation
|
||||||
|
qsort ((void*)time, MAX_ITER, sizeof(time[0]), cmpfunc);
|
||||||
|
printf("Median: %f [msec]\n", (MAX_ITER % 2) ?
|
||||||
|
time[MAX_ITER/2] :
|
||||||
|
(time[MAX_ITER/2] + time[MAX_ITER/2 -1]) /2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user