blob: f573d12df8f131ff92d6aa29509f6d42666edc35 [file] [log] [blame]
Moritz Pflanzer572ade72017-07-21 17:36:33 +01001/*
Georgios Pinitas4b3fba12019-06-04 17:31:46 +01002 * Copyright (c) 2017-2019 ARM Limited.
Moritz Pflanzer572ade72017-07-21 17:36:33 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "ActivationLayer.h"
25
Georgios Pinitas583137c2017-08-31 18:12:42 +010026#include "arm_compute/core/Types.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010027#include "tests/validation/Helpers.h"
Moritz Pflanzer572ade72017-07-21 17:36:33 +010028
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
Isabella Gottardi651540f2018-09-13 15:33:35 +010037template <typename T>
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010038SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info)
Moritz Pflanzer572ade72017-07-21 17:36:33 +010039{
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010040 ARM_COMPUTE_UNUSED(oq_info);
41
Moritz Pflanzer572ade72017-07-21 17:36:33 +010042 // Create reference
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010043 SimpleTensor<T> dst{ src.shape(), src.data_type(), 1 };
Moritz Pflanzer572ade72017-07-21 17:36:33 +010044
45 // Compute reference
46 const T a(info.a());
47 const T b(info.b());
48
49 for(int i = 0; i < src.num_elements(); ++i)
50 {
Giorgio Arena73023022018-09-04 14:55:55 +010051 dst[i] = activate_float<T>(src[i], a, b, info.activation());
Moritz Pflanzer572ade72017-07-21 17:36:33 +010052 }
53
54 return dst;
55}
56
Michel Iwaniec66cc12f2017-12-07 17:26:40 +000057template <>
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010058SimpleTensor<uint8_t> activation_layer<uint8_t>(const SimpleTensor<uint8_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info)
Michel Iwaniec66cc12f2017-12-07 17:26:40 +000059{
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010060 const QuantizationInfo dst_qinfo = oq_info.empty() ? src.quantization_info() : oq_info;
61
Michel Iwaniec66cc12f2017-12-07 17:26:40 +000062 SimpleTensor<float> src_tmp = convert_from_asymmetric(src);
63 SimpleTensor<float> dst_tmp = activation_layer<float>(src_tmp, info);
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010064 SimpleTensor<uint8_t> dst = convert_to_asymmetric(dst_tmp, dst_qinfo);
Michel Iwaniec66cc12f2017-12-07 17:26:40 +000065 return dst;
66}
67
giuros01c9573f32019-06-20 10:30:17 +010068template <>
69SimpleTensor<int16_t> activation_layer<int16_t>(const SimpleTensor<int16_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info)
70{
71 const QuantizationInfo dst_qinfo = oq_info.empty() ? src.quantization_info() : oq_info;
72
73 SimpleTensor<float> src_tmp = convert_from_symmetric(src);
74 SimpleTensor<float> dst_tmp = activation_layer<float>(src_tmp, info);
75 SimpleTensor<int16_t> dst = convert_to_symmetric<int16_t>(dst_tmp, dst_qinfo);
76 return dst;
77}
78
Georgios Pinitas4b3fba12019-06-04 17:31:46 +010079template SimpleTensor<float> activation_layer(const SimpleTensor<float> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info);
80template SimpleTensor<half> activation_layer(const SimpleTensor<half> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info);
Moritz Pflanzer572ade72017-07-21 17:36:33 +010081} // namespace reference
82} // namespace validation
83} // namespace test
84} // namespace arm_compute