blob: 0af6f8ea00dd391386cff1be797ab1c86bd6e7dd [file] [log] [blame]
Michalis Spyrou36a559e2018-03-20 10:30:58 +00001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
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 "arm_compute/runtime/CL/functions/CLRNNLayer.h"
25#include "tests/CL/CLAccessor.h"
26#include "tests/PaddingCalculator.h"
27#include "tests/datasets/RNNLayerDataset.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Macros.h"
30#include "tests/framework/datasets/Datasets.h"
31#include "tests/validation/Validation.h"
32#include "tests/validation/fixtures/RNNLayerFixture.h"
33
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
40namespace
41{
42RelativeTolerance<float> tolerance_f32(0.001f);
43RelativeTolerance<half> tolerance_f16(half(0.1));
44} // namespace
45
46TEST_SUITE(CL)
47TEST_SUITE(RNNLayer)
48
49// *INDENT-OFF*
50// clang-format off
51DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
52 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::U8, 0), // Wrong data type
53 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Wrong input size
54 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32, 0), // Wrong weights size
55 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32, 0), // Wrong recurrent weights size
56 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32, 0), // Wrong bias size
57 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32, 0), // Wrong output size
58 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32, 0), // Wrong hidden output size
59 }),
60 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
61 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
62 TensorInfo(TensorShape(27U, 11U, 2U), 1, DataType::F32, 0),
63 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
64 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
65 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
66 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32, 0),
67 })),
68 framework::dataset::make("RecurrentWeightsInfo", { TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
69 TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
70 TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
71 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
72 TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
73 TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
74 TensorInfo(TensorShape(11U, 11U), 1, DataType::F32, 0),
75 })),
76 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
77 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
78 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
79 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
80 TensorInfo(TensorShape(30U), 1, DataType::F32, 0),
81 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
82 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
83 })),
84 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
85 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
86 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
87 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
88 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
89 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
90 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
91 })),
92 framework::dataset::make("HiddenStateInfo", { TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
93 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
94 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
95 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
96 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
97 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
98 TensorInfo(TensorShape(11U, 13U, 2U), 1, DataType::F32, 0),
99 })),
100 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
101 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
102 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
103 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
104 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
105 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
106 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
107 })),
108 framework::dataset::make("Expected", { false, false, false, false, false, false, false })),
109 input_info, weights_info, recurrent_weights_info, bias_info, output_info, hidden_output_info, info, expected)
110{
111 ARM_COMPUTE_EXPECT(bool(CLRNNLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &recurrent_weights_info.clone()->set_is_resizable(false), &bias_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), &hidden_output_info.clone()->set_is_resizable(false), info)) == expected, framework::LogLevel::ERRORS);
112}
113// clang-format on
114// *INDENT-ON*
115
116template <typename T>
117using CLRNNLayerFixture = RNNLayerValidationFixture<CLTensor, CLAccessor, CLRNNLayer, T>;
118
119TEST_SUITE(FP32)
120FIXTURE_DATA_TEST_CASE(RunSmall, CLRNNLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallRNNLayerDataset(), framework::dataset::make("DataType", DataType::F32)))
121{
122 // Validate output
123 validate(CLAccessor(_target), _reference, tolerance_f32);
124}
125TEST_SUITE_END() // FP32
126
127TEST_SUITE(FP16)
128FIXTURE_DATA_TEST_CASE(RunSmall, CLRNNLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallRNNLayerDataset(), framework::dataset::make("DataType", DataType::F16)))
129{
130 // Validate output
131 validate(CLAccessor(_target), _reference, tolerance_f16);
132}
133TEST_SUITE_END() // FP16
134TEST_SUITE_END() // RNNLayer
135TEST_SUITE_END() // CL
136} // namespace validation
137} // namespace test
138} // namespace arm_compute