forked from twaclaw/matmult
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatmult_tb.cpp
More file actions
63 lines (45 loc) · 1.24 KB
/
matmult_tb.cpp
File metadata and controls
63 lines (45 loc) · 1.24 KB
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
#include "matmult.h"
#include <stdio.h>
#include <stdlib.h>
typedef float T;
void mmult_sw(T a[N][N], T b[N][N], T out[N][N]) {
// matrix multiplication of a A*B matrix
for (int ia = 0; ia < N; ++ia)
for (int ib = 0; ib < N; ++ib) {
float sum = 0;
for (int id = 0; id < N; ++id)
sum += a[ia][id] * b[id][ib];
out[ia][ib] = sum;
}
}
int main(void) {
int ret_val = 0;
int i, j, err;
T matOp1[N][N];
T matOp2[N][N];
T matMult_sw[N][N];
T matMult_hw[N][N];
/** Matrix Initiation */
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
matOp1[i][j] = (float)(i + j);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
matOp2[i][j] = (float)(i * j);
/** End of Initiation */
printf("NORMAL MODE\r\n");
mmult_hw(matOp1, matOp2, matMult_hw);
/* reference Matrix Multiplication */
mmult_sw(matOp1, matOp2, matMult_sw);
/** Matrix comparison */
err = 0;
for (i = 0; (i < N && !err); i++)
for (j = 0; (j < N && !err); j++)
if (matMult_sw[i][j] != matMult_hw[i][j])
err++;
if (err == 0)
printf("Matrixes identical ... Test successful!\r\n");
else
printf("Test failed!\r\n");
return err;
}