ONE - On-device Neural Engine
Loading...
Searching...
No Matches
FullyConnectedLayer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ONERT_BACKEND_TRAIN_OPS_FULLYCONNECTEDLAYER_H__
18#define __ONERT_BACKEND_TRAIN_OPS_FULLYCONNECTEDLAYER_H__
19
20#include "../ExternalContext.h"
21#include "../Tensor.h"
22
24#include <ops/FullyConnectedLayer.h>
25
26namespace onert
27{
28namespace backend
29{
30namespace train
31{
32namespace ops
33{
34
37{
38public:
41
42public:
43 void configureBackward(const IPortableTensor *input, const IPortableTensor *weights,
44 IPortableTensor *output, IPortableTensor *back_prop_input,
45 IPortableTensor *grad_weights, IPortableTensor *grad_bias,
46 const IPortableTensor *back_prop_output, ir::Activation activation,
47 ir::FullyConnectedWeightsFormat weights_format);
48
49 void forward(bool training) override;
50 void backward() override;
51
52private:
53 void backwardFloat32();
54
55private:
56 IPortableTensor *_grad_weights;
57 IPortableTensor *_grad_bias;
58 IPortableTensor *_back_prop_input;
59 const IPortableTensor *_back_prop_output;
60
61 // TODO Optimize memory
62 std::unique_ptr<Tensor> _transposed_weights;
63 std::unique_ptr<Tensor> _transposed_input;
64 std::unique_ptr<Tensor> _transposed_back_prop_output;
65 std::unique_ptr<Tensor> _act_back_prop_output;
66};
67
68} // namespace ops
69} // namespace train
70} // namespace backend
71} // namespace onert
72
73#endif // __ONERT_BACKEND_TRAIN_OPS_FULLYCONNECTEDLAYER_H__
A tensor class that is portable for other backends.
void configureBackward(const IPortableTensor *input, const IPortableTensor *weights, IPortableTensor *output, IPortableTensor *back_prop_input, IPortableTensor *grad_weights, IPortableTensor *grad_bias, const IPortableTensor *back_prop_output, ir::Activation activation, ir::FullyConnectedWeightsFormat weights_format)
FullyConnectedWeightsFormat