-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
187 lines (156 loc) · 5.06 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* File: main.c
This file contains the framework to acquire memory run the benchmark and report the result.
*/
#include "benchmark.h"
uint8_t list_memblk[TOTAL_DATA_SIZE] = {0};
uint8_t mat_memblk[TOTAL_DATA_SIZE] = {0};
uint8_t conv_memblk[TOTAL_DATA_SIZE] = {0};
// result
uint16_t result[RESULT_SIZE] = {0};
volatile sint16_t list_seed = 0x66;
volatile sint32_t mat_seed = 0x11;
volatile sint32_t conv_seed = 0x7;
#define TIMESTRUCT clock_t
TIMESTRUCT time_start;
TIMESTRUCT time_end;
float time_run;
uint32_t num_iterate = NUM_ITERATE;
void
start_time(){
time_start = 0;
time_end = 0;
time_run = 0.0;
time_start = clock();
return;
}
void
stop_time(){
time_end = clock();
return;
}
void
run_time(){
time_run = (time_end - time_start) * 1.0 /CLOCKS_PER_SEC;
}
/* Function: report
report the result.
*/
void
report(){
printf("--------------------------------------------------------------\n");
printf("DataSize/Bytes:\n");
printf("%ld\n", TOTAL_DATA_SIZE * sizeof(uint8_t) * 3);
printf("DataDim:\n");
printf("%d\n", DATA_DIM);
printf("DataType:\n");
#if TEST_TYPE == INT_TYPE
printf("INT_TYPE\n");
#elif TEST_TYPE == FP32_TYPE
printf("FP32_TYPE\n");
#elif TEST_TYPE == FP64_TYPE
printf("FP64_TYPE\n");
#endif
printf("TotalTicks/Ticks:\n");
printf("%ld\n", time_end - time_start);
printf("TotalTime/Secs:\n");
printf("%f\n", time_run);
printf("Iterations:\n");
printf("%d\n",num_iterate);
printf("Iterations/Secs:\n");
printf("%f\n",num_iterate/time_run);
printf("--------------------------------------------------------------\n");
return;
}
/* Function: main
This function consists of the following steps:
1 - initialize memory block. -- benchmark.h
2 - run benchmark and record the time.
3 - report the result.
*/
int
main(){
/*base on subspace*/
/*initialize*/
list_node *memblk = list_init(TOTAL_DATA_SIZE, (list_node *)list_memblk, list_seed);
mat_params mat_p[1] = {0};
uint32_t mat_size = matrix_init(TOTAL_DATA_SIZE, (DATA_TYPE *)mat_memblk, mat_seed, mat_p);
conv_params conv_p[1] = {0};
conv_init(TOTAL_DATA_SIZE, (DATA_TYPE *)conv_memblk, conv_seed, conv_p);
/*TEST*/
list_data info;
#if TEST_TYPE==INT_TYPE
#if DATA_DIM == 1
for(int i = 0; i < DIM_X; i++){
info.data[i] = (list_seed) ^ (i);
}
#elif DATA_DIM == 2
for(int i = 0; i < DIM_X; i++){
for(int j = 0; j < DIM_Y; j++){
info.data[i][j] = (list_seed) ^ (i + j);
}
}
#elif DATA_DIM == 3
for(int i = 0; i < DIM_X; i++){
for(int j = 0; j < DIM_Y; j++){
for(int k = 0; k < DIM_Z; k++){
info.data[i][j][k] = (list_seed) ^ (i + j + k);
}
}
}
#endif
#else
#if DATA_DIM == 1
for(int i = 0; i < DIM_X; i++){
info.data[i] = (((list_seed << 16) | list_seed) + i)/((list_seed << 10) * 1.3);
}
#elif DATA_DIM == 2
for(int i = 0; i < DIM_X; i++){
for(int j = 0; j < DIM_Y; j++){
info.data[i][j] = (((list_seed << 16) | list_seed) + (i^j))/((list_seed << 10) * 1.3);
}
}
#elif DATA_DIM == 3
for(int i = 0; i < DIM_X; i++){
for(int j = 0; j < DIM_Y; j++){
for(int k = 0; k < DIM_Z; k++){
info.data[i][j][k] = (((list_seed << 16) | list_seed) + (i^j^k))/((list_seed << 10) * 1.3);
}
}
}
#endif
#endif
info.idx = 5;
#if TEST_TYPE == INT_TYPE
uint32_t val = 2;
#else
float val = 2.1;
#endif
/*iterate*/
start_time();
for(int i = 0; i < /*num_iterate*/ NUM_ITERATE; i++){
/*list_search_sort*/
list_search_all(memblk, &info);
if(SORT_METHOD == MERGESORT){
memblk = list_mergesort(memblk, DATA_CMP);
memblk = list_mergesort(memblk, IDX_CMP);
}
//list_search(memblk. &info, IDX_FIND);
/*matrix*/
matrix_add_const(mat_p->N, mat_p->A, val);
matrix_mul_const(mat_p->N, mat_p->A, val, mat_p->C);
matrix_mul_matrix(mat_p->N, mat_p->A, mat_p->B, mat_p->C);
/*conv*/
#if CONV_DIM==2
conv2D(conv_p->in, conv_p->out, conv_p->InChannel, conv_p->InWidth, conv_p->InHeight, conv_p->filter, conv_p->filter_size, conv_p->stride, conv_p->bias, conv_p->OutChannel);
#elif CONV_DIM==1
conv1D(conv_p->in, conv_p->out, conv_p->InChannel, conv_p->InWidth, conv_p->filter, conv_p->filter_size, conv_p->stride, conv_p->bias, conv_p->OutChannel);
#elif CONV_DIM==3
conv3D(conv_p->in, conv_p->out, conv_p->InChannel, conv_p->InWidth, conv_p->InHeight, conv_p->InDepth, conv_p->filter, conv_p->filter_size, conv_p->stride, conv_p->bias, conv_p->OutChannel);
#endif
}
stop_time();
run_time();
/*report result*/
report();
return 0;
}