-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmlp3.c
86 lines (70 loc) · 2.23 KB
/
mlp3.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
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#ifndef BAREMETAL
#include <sys/mman.h>
#endif
#include "include/gemmini.h"
#include "include/gemmini_nn.h"
#include "parameters3.h"
int main (int argc, char * argv[]) {
#ifndef BAREMETAL
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
perror("mlockall failed");
exit(1);
}
#endif
gemmini_flush(0);
enum tiled_matmul_type_t tiled_matmul_type;
if (argc < 2) {
tiled_matmul_type = WS;
} else if (strcmp(argv[1], "cpu") == 0) {
tiled_matmul_type = CPU;
} else if (strcmp(argv[1], "os") == 0) {
tiled_matmul_type = OS;
} else if (strcmp(argv[1], "ws") == 0) {
tiled_matmul_type = WS;
} else if (strcmp(argv[1], "-h") == 0) {
printf("usage: %s [-h] matmul_option [check]\n matmul_option may be 'os', 'ws', or cpu'\n", argv[0]);
exit(0);
} else {
printf("Unknown command-line argument\n");
printf("usage: %s [-h] matmul_option [check]\n matmul_option may be 'os', 'ws', or cpu'\n", argv[0]);
exit(1);
}
bool check;
if (argc < 3) {
check = false;
} else if (strcmp(argv[2], "check") == 0) {
check = true;
} else {
printf("Unknown command-line argument\n");
printf("usage: %s [-h] matmul_option [check]\n matmul_option may be 'os', 'ws', or cpu'\n", argv[0]);
exit(1);
}
uint64_t cycles[2]={0};
uint64_t start,end;
/* matmul number: 0 */
start = read_cycles();
tiled_matmul_nn_auto(64, 512, 448,
input_mat, weights0, NULL, inter_results0,
RELU, 0, false,
tiled_matmul_type, check, "layer_0");
end = read_cycles();
cycles[0] = end-start;
/* matmul number: 1 */
start = read_cycles();
tiled_matmul_nn_auto(64, 448, 512,
inter_results0, weights1, NULL, inter_results1,
RELU, 0, false,
tiled_matmul_type, check, "layer_1");
end = read_cycles();
cycles[1] = end-start;
uint64_t overall_cycles = 0;
for(int cyc = 0; cyc < 2 ; cyc++){
overall_cycles += cycles[cyc];
printf("Cycles taken in layer %d: %llu\n", cyc,cycles[cyc]);
}
printf("Overall cycles taken: %llu\n",overall_cycles);
return 0;
}