06dde4fc47f5185df05ad91cc4d9b2ac962d75c8
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / LogSoftMaxLayer.cc
1 /*
2  * Copyright (c) 2020 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 #include "LogSoftMaxLayer.h"
18
19 #include "OperationUtils.h"
20
21 #include <cker/operation/LogSoftMax.h>
22
23 namespace onert
24 {
25 namespace backend
26 {
27 namespace cpu
28 {
29 namespace ops
30 {
31
32 LogSoftMaxLayer::LogSoftMaxLayer() : _input(nullptr), _output(nullptr), _beta(0.0), _axis(0)
33 {
34   // DO NOTHING
35 }
36
37 void LogSoftMaxLayer::logsoftmaxFloat32()
38 {
39   nnfw::cker::SoftmaxParams op_params;
40   op_params.beta = _beta;
41   op_params.axis = _axis;
42   nnfw::cker::LogSoftmax(op_params, getTensorShape(_input),
43                          reinterpret_cast<const float *>(_input->buffer()), getTensorShape(_output),
44                          reinterpret_cast<float *>(_output->buffer()));
45 }
46
47 void LogSoftMaxLayer::logsoftmaxQuant8()
48 {
49   // NYI
50 }
51
52 void LogSoftMaxLayer::configure(const IPortableTensor *input, const float beta, const int axis,
53                                 IPortableTensor *output)
54 {
55   _input = input;
56   _output = output;
57   _beta = beta;
58   _axis = axis;
59 }
60
61 void LogSoftMaxLayer::run()
62 {
63   if (_input->data_type() == OperandType::FLOAT32)
64   {
65     logsoftmaxFloat32();
66   }
67   else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
68   {
69     throw std::runtime_error{"LogSoftmax : NYI"};
70   }
71   else
72   {
73     throw std::runtime_error{"LogSoftmax : unsupported data type"};
74   }
75 }
76
77 } // namespace ops
78 } // namespace cpu
79 } // namespace backend
80 } // namespace onert