forked from hemalshahX/kerasify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeras_model_test.cc
More file actions
181 lines (138 loc) · 4.69 KB
/
Copy pathkeras_model_test.cc
File metadata and controls
181 lines (138 loc) · 4.69 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
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
#include "keras_model.h"
#include <stdio.h>
#include <iostream>
namespace kerasify {
#include "test_benchmark.h"
#include "test_conv_2x2.h"
#include "test_conv_3x3.h"
#include "test_conv_3x3x3.h"
#include "test_conv_softplus_2x2.h"
#include "test_dense_10x1.h"
#include "test_dense_10x10.h"
#include "test_dense_10x10x10.h"
#include "test_dense_1x1.h"
#include "test_dense_2x2.h"
#include "test_dense_relu_10.h"
#include "test_elu_10.h"
#include "test_func_conv_2x2.h"
#include "test_func_conv_2x2_multi_in_out.h"
#include "test_func_dense_1x1.h"
#include "test_func_dense_1x1_multi_in.h"
#include "test_func_dense_1x1_multi_in_out.h"
#include "test_func_dense_1x1_multi_out.h"
#include "test_func_maxpool2d_3x3x3.h"
#include "test_func_merge_1x1.h"
#include "test_maxpool2d_1x1.h"
#include "test_maxpool2d_2x2.h"
#include "test_maxpool2d_3x2x2.h"
#include "test_maxpool2d_3x3x3.h"
#include "test_relu_10.h"
bool tensor_test() {
{
const int i = 3;
const int j = 5;
const int k = 10;
Tensor t(i, j, k);
float c = 1.f;
for (int ii = 0; ii < i; ii++) {
for (int jj = 0; jj < j; jj++) {
for (int kk = 0; kk < k; kk++) {
t(ii, jj, kk) = c;
c += 1.f;
}
}
}
c = 1.f;
int cc = 0;
for (int ii = 0; ii < i; ii++) {
for (int jj = 0; jj < j; jj++) {
for (int kk = 0; kk < k; kk++) {
KASSERT_EQ(t(ii, jj, kk), c, 1e-9);
KASSERT_EQ(t.data_[cc], c, 1e-9);
c += 1.f;
cc++;
}
}
}
}
{
const int i = 2;
const int j = 3;
const int k = 4;
const int l = 5;
Tensor t(i, j, k, l);
float c = 1.f;
for (int ii = 0; ii < i; ii++) {
for (int jj = 0; jj < j; jj++) {
for (int kk = 0; kk < k; kk++) {
for (int ll = 0; ll < l; ll++) {
t(ii, jj, kk, ll) = c;
c += 1.f;
}
}
}
}
c = 1.f;
int cc = 0;
for (int ii = 0; ii < i; ii++) {
for (int jj = 0; jj < j; jj++) {
for (int kk = 0; kk < k; kk++) {
for (int ll = 0; ll < l; ll++) {
KASSERT_EQ(t(ii, jj, kk, ll), c, 1e-9);
KASSERT_EQ(t.data_[cc], c, 1e-9);
c += 1.f;
cc++;
}
}
}
}
}
return true;
}
} // namespace kerasify
int main() {
double load_time = 0.0;
double apply_time = 0.0;
if (!kerasify::tensor_test()) return 1;
if (!kerasify::test_conv_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_1x1(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_10x1(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_10x10(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_10x10x10(&load_time, &apply_time)) return 1;
if (!kerasify::test_conv_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_conv_3x3(&load_time, &apply_time)) return 1;
if (!kerasify::test_conv_3x3x3(&load_time, &apply_time)) return 1;
if (!kerasify::test_elu_10(&load_time, &apply_time)) return 1;
if (!kerasify::test_relu_10(&load_time, &apply_time)) return 1;
if (!kerasify::test_dense_relu_10(&load_time, &apply_time)) return 1;
if (!kerasify::test_conv_softplus_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_maxpool2d_1x1(&load_time, &apply_time)) return 1;
if (!kerasify::test_maxpool2d_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_maxpool2d_3x2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_maxpool2d_3x3x3(&load_time, &apply_time)) return 1;
if (!kerasify::test_func_dense_1x1(&load_time, &apply_time)) return 1;
if (!kerasify::test_func_conv_2x2(&load_time, &apply_time)) return 1;
if (!kerasify::test_func_maxpool2d_3x3x3(&load_time, &apply_time)) return 1;
if (!kerasify::test_func_merge_1x1(&load_time, &apply_time)) return 1;
if (!kerasify::test_func_dense_1x1_multi_in(&load_time, &apply_time))
return 1;
if (!kerasify::test_func_dense_1x1_multi_out(&load_time, &apply_time))
return 1;
if (!kerasify::test_func_dense_1x1_multi_in_out(&load_time,
&apply_time))
return 1;
if (!kerasify::test_func_conv_2x2_multi_in_out(&load_time, &apply_time))
return 1;
// Run benchmark 5 times and report duration.
double total_load_time = 0.0;
double total_apply_time = 0.0;
for (int i = 0; i < 5; i++) {
if (!kerasify::test_benchmark(&load_time, &apply_time)) return 1;
total_load_time += load_time;
total_apply_time += apply_time;
}
printf("Benchmark network loads in %fs\n", total_load_time / 5);
printf("Benchmark network runs in %fs\n", total_apply_time / 5);
return 0;
}