-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
98 lines (90 loc) · 2.61 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include <string.h>
// #include "SimpleMatrixMultiplication.h"
#include "matrix/StrassenMatrixMultiplication.h"
// #include "CacheObliviousMatrixMultiplication.h"
// #include "StrassenMatrixMultiplication.h"
#include "util.h"
const unsigned int M_default = 16;
const unsigned int N_default = 16;
const unsigned int K_default = 16;
const unsigned int spacingFactor = 1;
int main(int argc, char** argv) {
int M, N, K;
if (argc < 4) {
fprintf(stderr, "M, N, K not given, use the default values\n");
M = M_default;
N = N_default;
K = K_default;
}
else{
M = atoi(argv[1]);
N = atoi(argv[2]);
K = atoi(argv[3]);
}
int incRowA = K * spacingFactor;
int incRowB = N * spacingFactor;
int incRowC = N * spacingFactor;
Dtype* A = (Dtype*)malloc(sizeof(Dtype)*M*incRowA);
Dtype* B = (Dtype*)malloc(sizeof(Dtype)*K*incRowB);
Dtype* C = (Dtype*)malloc(sizeof(Dtype)*M*incRowC);
for(int i = 0; i < M; i++){
for(int j = 0; j < K; j++){
A[i*incRowA+j] = 1;
}
}
for(int i = 0; i < K; i++){
for(int j = 0; j < N; j++){
B[i*incRowB+j] = 1;
}
}
for(int i = 0; i < M; i++){
for(int j = 0; j < N; j++){
C[i*incRowC+j] = 0;
}
}
uint64_t start_time = timestamp_us();
// SimpleMatrixMultiplication(
// M, N, K,
// A, incRowA,
// B, incRowB,
// C, incRowC);
// cblas_gemm(
// M, N, K,
// A, incRowA,
// B, incRowB,
// C, incRowC);
// cache_oblivious_matrix_multiplication(
// M, N, K,
// A, incRowA,
// B, incRowB,
// C, incRowC);
strassen_matrix_multiplication(
M, N, K,
A, incRowA,
B, incRowB,
C, incRowC);
uint64_t end_time = timestamp_us();
double m_second_taken = (double)(end_time - start_time) / 1000.0;
int error = 0;
for(int i = 0; i < M; i++){
// // fprintf(stderr, "%d \n", fix16_to_int(M3[i]));
for(int j = 0; j < N; j++){
if(C[i*incRowC+j] != K){
error++;
fprintf(stderr, "%d %d %d \n", i, j, C[i*incRowC+j]);
}
// fprintf(stderr, "%d ", (int)C[i*incRowC+j]);
}
// fprintf(stderr, "\n");
}
// print_matrix(C, M, N, N);
// printf("M, N, K, error, Time taken \n");
printf("%d, %d, %d, %d, %f \n", M, N, K, error, m_second_taken);
}