tiny_dnn 1.0.0
A header only, dependency-free deep learning framework in C++11
Loading...
Searching...
No Matches
fully_connected_grad_op.h
1/*
2 COPYRIGHT
3
4 All contributions by Taiga Nomi
5 Copyright (c) 2013, Taiga Nomi
6 All rights reserved.
7
8 All other contributions:
9 Copyright (c) 2013-2016, the respective contributors.
10 All rights reserved.
11
12 Each contributor holds copyright over their respective contributions.
13 The project versioning (Git) records all such contribution source information.
14
15 LICENSE
16
17 The BSD 3-Clause License
18
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22
23 * Redistributions of source code must retain the above copyright notice, this
24 list of conditions and the following disclaimer.
25
26 * Redistributions in binary form must reproduce the above copyright notice,
27 this list of conditions and the following disclaimer in the documentation
28 and/or other materials provided with the distribution.
29
30 * Neither the name of tiny-dnn nor the names of its
31 contributors may be used to endorse or promote products derived from
32 this software without specific prior written permission.
33
34 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44*/
45#pragma once
46
47#include "tiny_dnn/core/framework/op_kernel.h"
48
49#include "tiny_dnn/core/kernels/fully_connected_op_avx.h"
50#include "tiny_dnn/core/kernels/fully_connected_op_internal.h"
51
52namespace tiny_dnn {
53
55 public:
58
59 void compute(const core::OpKernelContext& context) override {
60 auto params = OpKernel::params_->fully();
61
62 // incoming/outcoming data
63 const tensor_t& prev_out = context.input(0);
64 const tensor_t& W = context.input(1);
65 tensor_t& dW = context.input_grad(1);
66 tensor_t* db = params.has_bias_ ? &context.input_grad(2) : nullptr;
67 tensor_t& prev_delta = context.input_grad(0);
68 tensor_t& curr_delta = context.output_grad(1);
69 tensor_t dummy; // need lvalue for non-const reference
70
71 // initialize outputs
72 fill_tensor(prev_delta, float_t(0));
73
74 // call the algorithm depending on the selected engine type
75
76 const core::backend_t engine = context.engine();
77
78 if (engine == core::backend_t::internal) {
79 kernels::fully_connected_op_internal(
81 W[0],
82 dW,
83 params.has_bias_ ? *db : dummy,
86 params,
87 context.parallelize());
88 }
89 else if (engine == core::backend_t::avx) {
90 kernels::fully_connected_op_avx(
92 W[0],
93 dW,
94 params.has_bias_ ? *db : dummy,
97 params,
98 context.parallelize());
99 }
100 else {
101 throw nn_error("Not supported engine: " + to_string(engine));
102 }
103 }
104};
105
106} // namespace tiny_dnn
Definition fully_connected_grad_op.h:54
Definition op_kernel.h:55
Definition op_kernel.h:72
Definition op_kernel.h:175
Simple image utility class.
Definition image.h:94
error exception class for tiny-dnn
Definition nn_error.h:37