29 #include "tiny_dnn/core/backend.h"
30 #include "tiny_dnn/core/kernels/nnp_deconv2d_kernel.h"
42 std::function<
void(
const tensor_t&)> f1,
45 , conv_layer_worker_storage_(ptr)
46 , copy_and_pad_input(f1) { init_nnp_engine(); }
50 : params_d_(params) { init_nnp_engine(); }
54 : params_m_(params) { init_nnp_engine(); }
58 : params_f_(params) { init_nnp_engine(); }
64 void conv2d(
const std::vector<tensor_t*>& in_data,
65 std::vector<tensor_t*>& out_data)
override {
66 if (params_c_)
return;
67 if (params_f_)
return;
68 if (params_d_)
return;
69 if (conv_layer_worker_storage_)
return;
70 if (deconv_layer_worker_storage_)
return;
94 void conv2d_q(
const std::vector<tensor_t*>& in_data,
95 std::vector<tensor_t*>& out_data)
override {
96 throw nn_error(
"not implemented yet.");
99 void conv2d_eq(
const std::vector<tensor_t*>& in_data,
100 std::vector<tensor_t*>& out_data)
override {
101 throw nn_error(
"not implemented yet.");
104 void conv2d(
const std::vector<tensor_t*>& in_data,
105 const std::vector<tensor_t*>& out_data,
106 std::vector<tensor_t*>& out_grad,
107 std::vector<tensor_t*>& in_grad)
override {
108 throw nn_error(
"NNPACK does not support back propagation.");
111 void conv2d_q(
const std::vector<tensor_t*>& in_data,
112 const std::vector<tensor_t*>& out_data,
113 std::vector<tensor_t*>& out_grad,
114 std::vector<tensor_t*>& in_grad)
override {
115 throw nn_error(
"NNPACK does not support back propagation.");
118 void deconv2d(
const std::vector<tensor_t*>& in_data,
119 std::vector<tensor_t*>& out_data)
override {
122 void deconv2d_q(
const std::vector<tensor_t*>& in_data,
123 std::vector<tensor_t*>& out_data)
override {
124 throw nn_error(
"not implemented yet.");
127 void deconv2d_eq(
const std::vector<tensor_t*>& in_data,
128 std::vector<tensor_t*>& out_data)
override {
129 throw nn_error(
"not implemented yet.");
132 void deconv2d(
const std::vector<tensor_t*>& in_data,
133 const std::vector<tensor_t*>& out_data,
134 std::vector<tensor_t*>& out_grad,
135 std::vector<tensor_t*>& in_grad)
override {
136 throw nn_error(
"NNPACK does not support back propagation.");
139 void deconv2d_q(
const std::vector<tensor_t*>& in_data,
140 const std::vector<tensor_t*>& out_data,
141 std::vector<tensor_t*>& out_grad,
142 std::vector<tensor_t*>& in_grad)
override {
143 throw nn_error(
"NNPACK does not support back propagation.");
146 void maxpool(
const std::vector<tensor_t*>& in_data,
147 std::vector<tensor_t*>& out_data)
override {
165 void maxpool(
const std::vector<tensor_t*>& in_data,
166 const std::vector<tensor_t*>& out_data,
167 std::vector<tensor_t*>& out_grad,
168 std::vector<tensor_t*>& in_grad)
override {
169 throw nn_error(
"NNPACK does not support back propagation.");
172 void fully(
const std::vector<tensor_t*>& in_data,
173 std::vector<tensor_t*>& out_data)
override {
183 void fully_q(
const std::vector<tensor_t*>& in_data,
184 std::vector<tensor_t*>& out_data)
override {
185 throw nn_error(
"not implemented yet.");
188 void fully_eq(
const std::vector<tensor_t*>& in_data,
189 std::vector<tensor_t*>& out_data)
override {
190 throw nn_error(
"not implemented yet.");
193 void fully(
const std::vector<tensor_t*>& in_data,
194 const std::vector<tensor_t*>& out_data,
195 std::vector<tensor_t*>& out_grad,
196 std::vector<tensor_t*>& in_grad)
override {
197 throw nn_error(
"NNPACK does not support back propagation.");
200 void fully_q(
const std::vector<tensor_t*>& in_data,
201 const std::vector<tensor_t*>& out_data,
202 std::vector<tensor_t*>& out_grad,
203 std::vector<tensor_t*>& in_grad)
override {
204 throw nn_error(
"NNPACK does not support back propagation.");
207 backend_t type()
const override {
return backend_t::nnpack; }
211 conv_params* params_c_;
212 deconv_params* params_d_;
213 maxpool_params* params_m_;
214 fully_params* params_f_;
217 conv_layer_worker_specific_storage* conv_layer_worker_storage_;
218 deconv_layer_worker_specific_storage* deconv_layer_worker_storage_;
221 std::function<void(
const tensor_t&)> copy_and_pad_input;
222 std::function<void(
const tensor_t&, tensor_t&)> copy_and_pad_delta;
224 void init_nnp_engine() {
225 #ifdef CNN_USE_NNPACK
226 nnp_status init_status = nnp_initialize();
227 check_nnp_status(init_status);
229 if (init_status != nnp_status_success) {
230 throw nn_error(
"Could not initialize NNPACK.");
233 throw nn_error(
"Tiny-cnn has not been compiled with NNPACK support.");
237 #ifdef CNN_USE_NNPACK
238 void check_nnp_status(nnp_status status) {
240 case nnp_status_success:
242 case nnp_status_invalid_batch_size:
243 nn_warn(
"NNPACK function was called with batch_size == 0");
245 case nnp_status_invalid_channels:
246 nn_warn(
"NNPACK function was called with channels == 0.");
248 case nnp_status_invalid_input_channels:
249 nn_warn(
"NNPACK function was called with input_channels == 0.");
251 case nnp_status_invalid_output_channels:
252 nn_warn(
"NNPACK function was called with output_channels == 0.");
254 case nnp_status_invalid_input_size:
255 nn_warn(
" NNPACK function was called with input_size.height == 0 or input_size.width == 0.");
257 case nnp_status_invalid_input_stride:
258 nn_warn(
" NNPACK function was called with input_stride.height == 0 or input_stride.width == 0.");
260 case nnp_status_invalid_input_padding:
261 nn_warn(
"NNPACK function was called with input_padding not less than respective kernel (or pooling) size.");
263 case nnp_status_invalid_kernel_size:
264 nn_warn(
"NNPACK function was called with kernel_size.height == 0 or kernel_size.width == 0.");
266 case nnp_status_invalid_pooling_size:
267 nn_warn(
"NNPACK function was called with pooling_size.height == 0 or pooling_size.width == 0.");
272 case nnp_status_invalid_algorithm:
273 nn_warn(
"NNPACK function was called with convolution algorithm not in nnp_convolution_algorithm enumeration.");
275 case nnp_status_unsupported_input_size:
276 nn_warn(
"NNPACK does not support the particular input size for the function.");
278 case nnp_status_unsupported_input_stride:
279 nn_warn(
"NNPACK does not support the particular input sride for the function.");
281 case nnp_status_unsupported_input_padding:
282 nn_warn(
"NNPACK does not support the particular input padding for the function.");
284 case nnp_status_unsupported_kernel_size:
285 nn_warn(
"NNPACK does not support the particular kernel size for the function.");
287 case nnp_status_unsupported_pooling_size:
288 nn_warn(
"NNPACK does not support the particular pooling size for the function.");
290 case nnp_status_unsupported_pooling_stride:
291 nn_warn(
"NNPACK does not support the particular pooling stride for the function .");
293 case nnp_status_unsupported_algorithm:
294 nn_warn(
"NNPACK does not support the particular convolution algorithm for the function.");
296 case nnp_status_uninitialized:
297 nn_warn(
"NNPACK function was called before the library was initialized.");
299 case nnp_status_unsupported_hardware:
300 nn_warn(
"NNPACK does not implement this function for the host CPU.");
302 case nnp_status_out_of_memory:
303 nn_warn(
"NNPACK failed to allocate memory for temporary buffers.");
Definition: conv_params.h:92
Definition: fully_params.h:34
Definition: maxpool_params.h:33
Definition: backend_nnp.h:35
void maxpool(const std::vector< tensor_t * > &in_data, std::vector< tensor_t * > &out_data) override
Definition: backend_nnp.h:146
error exception class for tiny-dnn
Definition: nn_error.h:37
Definition: conv_params.h:34
Definition: deconv_params.h:39