Skip to content

Commit

Permalink
Update XC app to show performance of library
Browse files Browse the repository at this point in the history
Useful to see when it's worth parallelising matrix ops.
Will help guide optimisation efforts.
  • Loading branch information
Steve Kerrison committed Nov 17, 2011
1 parent 98a546d commit 5d67a98
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app_matrix_c_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ int main(void)
MATRIX_PRINT("A",A);
MATRIX_PRINT("B",B);
MATRIX_PRINT("C",C);
printf("Ops: %u\n",ops);
printf("MATRIX_NTHREADS: %u, Ops: %u\n",MATRIX_NTHREADS,ops);
return 0;
}
56 changes: 55 additions & 1 deletion app_matrix_xc_demo/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#include <stdio.h>
#include "matrix.h"

void perfcheck(void);

int main(void)
{
#ifndef SKIP_BASIC_DEMO
MATRIX_CREATE(A,8,8, 1, 4, 3, 1, 5, 1, 2, 1,
1, 0, 3, 1, 3, 3, 3, 5,
4, 4, 4, 0, 2, 2, 2, 3,
Expand Down Expand Up @@ -42,11 +45,62 @@ int main(void)
ops += matrix_sca_op(MUL,MATRIX_REF(B),1798,MATRIX_NULL(),0);
/* Matrix-multiplication into destination matrix */
ops += matrix_mul(MATRIX_REF(A),MATRIX_REF(B),MATRIX_REF(C),0);
ops += matrix_arr_op(ADD,MATRIX_REF(A),MATRIX_REF(B),MATRIX_NULL(),0);
t :> tvB;
MATRIX_PRINT("A",A);
MATRIX_PRINT("B",B);
MATRIX_PRINT("C",C);
printf("Ticks: %u, Ops: %u\n",tvB - tvA, ops);
#endif
/* That was a basic demo. Now let's compare performance */
perfcheck();
return 0;
}

void perfcheck(void)
{
/* The greatest irony of the performance check is that it doesn't
reuse memory or resources from the basic demo. Good job it's only
a demonstration of computational speed, then. */
MATRIX_CREATE(A,16,16, 1, 4, 3, 1, 5, 1, 2, 1, 1, 4, 3, 1, 5, 1, 2, 1,
1, 0, 3, 1, 3, 3, 3, 5, 1, 0, 3, 1, 3, 3, 3, 5,
4, 4, 4, 0, 2, 2, 2, 3, 4, 4, 4, 0, 2, 2, 2, 3,
3, 4, 3, 2, 2, 1, 0, 2, 3, 4, 3, 2, 2, 1, 0, 2,
2, 3, 3, 2, 2, 0, 1, 4, 2, 3, 3, 2, 2, 0, 1, 4,
4, 2, 2, 2, 4, 4, 3, 0, 4, 2, 2, 2, 4, 4, 3, 0,
3, 4, 2, 5, 0, 4, 2, 5, 3, 4, 2, 5, 0, 4, 2, 5,
4, 2, 1, 0, 1, 2, 4, 0, 4, 2, 1, 0, 1, 2, 4, 0,
1, 4, 3, 1, 5, 1, 2, 1, 1, 4, 3, 1, 5, 1, 2, 1,
1, 0, 3, 1, 3, 3, 3, 5, 1, 0, 3, 1, 3, 3, 3, 5,
4, 4, 4, 0, 2, 2, 2, 3, 4, 4, 4, 0, 2, 2, 2, 3,
3, 4, 3, 2, 2, 1, 0, 2, 3, 4, 3, 2, 2, 1, 0, 2,
2, 3, 3, 2, 2, 0, 1, 4, 2, 3, 3, 2, 2, 0, 1, 4,
4, 2, 2, 2, 4, 4, 3, 0, 4, 2, 2, 2, 4, 4, 3, 0,
3, 4, 2, 5, 0, 4, 2, 5, 3, 4, 2, 5, 0, 4, 2, 5,
4, 2, 1, 0, 1, 2, 4, 0, 4, 2, 1, 0, 1, 2, 4, 0 );
MATRIX_CREATE(B,16,16,0);
timer t;
unsigned int tvA, tvB;
int r,c;
printf("MATRIX_NTHREADS: %u\n",MATRIX_NTHREADS);
for (int i = 1, ops = 0; i <= 16; i++, ops = 0)
{
MATRIX_REDIM(A,i,i);
printf("\nMatrix size: %dx%d\n",i,i);
/* Scalar multiplication by 2 */
t :> tvA;
for (r = 0; r < MATRIX_ROWS(A); r += 1)
{
for (c = 0; c < MATRIX_COLS(A); c += 1)
{
B[r * c] = A[r * c] * 2;
ops += 1;
}
}
t :> tvB;
printf("By-hand scalar * 2 :: Ticks: %u, Ops: %u\n",tvB - tvA, ops);
t :> tvA;
ops = matrix_sca_op(MUL,MATRIX_REF(A),2,MATRIX_REF(B),0);
t :> tvB;
printf("sc_matrix scalar * 2 :: Ticks: %u, Ops: %u\n",tvB - tvA, ops);
}
}
2 changes: 1 addition & 1 deletion module_matrix/src/matrix.xc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

int matrix_redim(short dims[4],short rows, short columns)
{
if (dims[2] > rows || dims[3] > columns)
if (dims[2] < rows || dims[3] < columns)
{
return -1; //Larger than initial size
}
Expand Down
2 changes: 0 additions & 2 deletions module_matrix/src/matrix_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/

#include "matrix_worker.h"


#include <stdio.h>

void matrix_mul_worker(int ptA, int ptDimA, int ptB, int ptDimB, int ptC,
Expand Down

0 comments on commit 5d67a98

Please sign in to comment.