-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmm_testbed.c
74 lines (67 loc) · 2.26 KB
/
mm_testbed.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
** PROGRAM: Matrix Multiplication test bed
**
** PURPOSE: This program will test various methods for
** multiplying matrices.
**
** C += A * B
**
** Basic parameters and function prototypes can
** be found in the include file mm_utils.h
**
** We test rectangular matrices of two different
** types: a constant matrix and one called a progression
** matrix where we modify matrix elements by a progression
** of matrix index values.
**
** USAGE: Run wtihout arguments to use default SIZE set in the
** mm_utils.h include file ... for example
** mm_testbed
**
** Run with a single argument to generare rectangular matrices
** and use fixed ratios of matrix dimensions ... for example
** mm_testbed 25
**
** Specify dimensions of matrices A(n,p),B(p,m) and C (n,m)
** for example for n=23, m=67 and p=213
** mm_testbed 23 67 213
**
** HISTORY: Written by Tim Mattson, Feb 2013
** Adapted by Tom Deakin, Nov 2024
*/
#include "mm_utils.h"
#define SIZE 400
#define NTRIALS 5
//#define DEBUG 1
// matrix multiplication test cases
void mm_gpu(int Ndim, int Mdim, int Pdim, TYPE *A, TYPE *B, TYPE *C);
int main(int argc, char **argv)
{
int Ndim, Mdim, Pdim; /* A[N][P], B[P][M], C[N][M] */
int Matrix_size;
TYPE *A, *B, *C;
// set matrix dimensions and allocate memory for matrices
if(argc ==2){
Matrix_size = atoi(argv[1]);
Ndim = Matrix_size;
Pdim = 2*Matrix_size;
Mdim = 3*Matrix_size;
}
else if(argc ==4){
Ndim = atoi(argv[1]);
Mdim = atoi(argv[2]);
Pdim = atoi(argv[3]);
}
else{
Ndim = SIZE;
Pdim = 2*SIZE;
Mdim = 3*SIZE;
}
A = (TYPE *) malloc(Ndim*Pdim*sizeof(TYPE));
B = (TYPE *) malloc(Pdim*Mdim*sizeof(TYPE));
C = (TYPE *) malloc(Ndim*Mdim*sizeof(TYPE));
printf("\n==================================================\n");
printf(" ijk on a GPU %d %d %d\n", Ndim, Mdim, Pdim);
mm_tst_cases(NTRIALS, Ndim, Mdim, Pdim, A, B, C, &mm_gpu);
printf("\n==================================================\n");
}