@@ -18,6 +18,7 @@ limitations under the License.
18
18
#include < cstdio>
19
19
#include < limits>
20
20
21
+ #include " playground_util/murmurhash.h"
21
22
#include " tensorflow/lite/kernels/internal/common.h"
22
23
#include " tensorflow/lite/kernels/internal/reference/integer_ops/pooling_accel.h"
23
24
@@ -84,40 +85,11 @@ inline bool AveragePool(const PoolParams& params,
84
85
return true ;
85
86
}
86
87
87
- inline void MaxPool (const PoolParams& params, const RuntimeShape& input_shape,
88
- const int8_t * input_data, const RuntimeShape& output_shape,
89
- int8_t * output_data) {
90
- #if SHOW_MAX_POOL_PARAMS
91
- // padding_width, padding_height,
92
- // stride_width, stride_height, filter_height, filter_width,
93
- // quantized_activation_min, quantized_activation_max,
94
- // input_shape[0], input_shape[1], input_shape[2], input_shape[3],
95
- // output_shape[0], output_shape[1], output_shape[2], output_shape[3]
96
- printf (" \n " );
97
- const auto & padding = params.padding_values ;
98
- printf (" %d, %d, " , padding.width , padding.height );
99
- printf (" %d, %d, %d, %d, " , params.stride_height , params.stride_width ,
100
- params.filter_height , params.filter_width );
101
- printf (" %ld, %ld, " , params.quantized_activation_min ,
102
- params.quantized_activation_max );
103
- printf (" %ld, %ld, %ld, %ld, " , input_shape.Dims (0 ), input_shape.Dims (1 ),
104
- input_shape.Dims (2 ), input_shape.Dims (3 ));
105
- printf (" %ld, %ld, %ld, %ld, " , output_shape.Dims (0 ), output_shape.Dims (1 ),
106
- output_shape.Dims (2 ), output_shape.Dims (3 ));
107
-
108
- printf (" \n " );
109
- #endif
110
-
111
- #ifdef ACCEL_MAX_POOL
112
- #if GATEWARE_GEN != 2
113
- #error MAX_POOL op requires gateware gen 2
114
- #endif
115
- if (CanAccelerateMaxPool (params, input_shape, output_shape)) {
116
- return AccelerateMaxPool (params, input_shape, input_data, output_shape,
117
- output_data);
118
- }
119
- #endif
120
-
88
+ inline void UnacceleratedMaxPool (const PoolParams& params,
89
+ const RuntimeShape& input_shape,
90
+ const int8_t * input_data,
91
+ const RuntimeShape& output_shape,
92
+ int8_t * output_data) {
121
93
TFLITE_DCHECK_LE (params.quantized_activation_min ,
122
94
params.quantized_activation_max );
123
95
TFLITE_DCHECK_GE (params.quantized_activation_min ,
@@ -172,6 +144,58 @@ inline void MaxPool(const PoolParams& params, const RuntimeShape& input_shape,
172
144
}
173
145
}
174
146
147
+ inline void MaxPool (const PoolParams& params, const RuntimeShape& input_shape,
148
+ const int8_t * input_data, const RuntimeShape& output_shape,
149
+ int8_t * output_data) {
150
+ #if SHOW_MAX_POOL_PARAMS
151
+ // padding_width, padding_height,
152
+ // stride_width, stride_height, filter_height, filter_width,
153
+ // quantized_activation_min, quantized_activation_max,
154
+ // input_shape[0], input_shape[1], input_shape[2], input_shape[3],
155
+ // output_shape[0], output_shape[1], output_shape[2], output_shape[3]
156
+ printf (" \n " );
157
+ const auto & padding = params.padding_values ;
158
+ printf (" %d, %d, " , padding.width , padding.height );
159
+ printf (" %d, %d, %d, %d, " , params.stride_height , params.stride_width ,
160
+ params.filter_height , params.filter_width );
161
+ printf (" %ld, %ld, " , params.quantized_activation_min ,
162
+ params.quantized_activation_max );
163
+ printf (" %ld, %ld, %ld, %ld, " , input_shape.Dims (0 ), input_shape.Dims (1 ),
164
+ input_shape.Dims (2 ), input_shape.Dims (3 ));
165
+ printf (" %ld, %ld, %ld, %ld, " , output_shape.Dims (0 ), output_shape.Dims (1 ),
166
+ output_shape.Dims (2 ), output_shape.Dims (3 ));
167
+
168
+ printf (" \n " );
169
+ #endif
170
+
171
+ bool accelerated = false ;
172
+
173
+ #ifdef ACCEL_MAX_POOL
174
+ #if GATEWARE_GEN != 2
175
+ #error MAX_POOL op requires gateware gen 2
176
+ #endif
177
+ accelerated = CanAccelerateMaxPool (params, input_shape, output_shape);
178
+ if (accelerated) {
179
+ AccelerateMaxPool (params, input_shape, input_data, output_shape,
180
+ output_data);
181
+ }
182
+ #endif
183
+ if (!accelerated) {
184
+ UnacceleratedMaxPool (params, input_shape, input_data, output_shape,
185
+ output_data);
186
+ }
187
+
188
+ #ifdef SHOW_POOL_HASHES
189
+ static int hash_layer = 0 ;
190
+ int32_t input_hash = murmurhash3_32 (reinterpret_cast <const uint8_t *>(input_data),
191
+ input_shape.FlatSize ());
192
+ int32_t output_hash = murmurhash3_32 (reinterpret_cast <const uint8_t *>(output_data),
193
+ output_shape.FlatSize ());
194
+ printf (" %3d, %08lx, %08lx\n " , hash_layer, input_hash, output_hash);
195
+ hash_layer++;
196
+ #endif
197
+ }
198
+
175
199
inline bool AveragePool (const PoolParams& params,
176
200
const RuntimeShape& input_shape,
177
201
const int16_t * input_data,
0 commit comments