blob: d5e3aee3639bbc5d9d258ffa24ab995119b5fdce [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
2 * Copyright (c) 2017 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/core/Types.h"
25#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010028#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/datasets/LargeGEMMDataset.h"
31#include "tests/datasets/SmallGEMMDataset.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/GEMMFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
47constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
48
49/** CNN data types */
50const auto CNNDataTypes = framework::dataset::make("DataType",
51{
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010052#ifdef ARM_COMPUTE_AARCH64_V8_2
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010053 DataType::F16,
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010054#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010055 DataType::F32,
56 DataType::QS8,
57 DataType::QS16,
58});
59} // namespace
60
61TEST_SUITE(NEON)
62TEST_SUITE(GEMM)
63
64DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes),
65 shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type)
66{
67 // Set fixed point position data type allowed
68 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
69
70 // Create tensors
71 Tensor a = create_tensor<Tensor>(shape_a, data_type, 1, fixed_point_position);
72 Tensor b = create_tensor<Tensor>(shape_b, data_type, 1, fixed_point_position);
73 Tensor c = create_tensor<Tensor>(shape_c, data_type, 1, fixed_point_position);
74 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
75
76 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
80
81 // Create and configure function
82 NEGEMM gemm;
83 gemm.configure(&a, &b, &c, &dst, alpha, beta);
84
85 //TODO(COMPMID-415): Validate valid region
86}
87
88template <typename T>
89using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
90
91TEST_SUITE(Float)
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010092#ifdef ARM_COMPUTE_AARCH64_V8_2
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010093TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +010094FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010095{
96 // Validate output
97 validate(Accessor(_target), _reference, tolerance_f);
98}
Georgios Pinitas583137c2017-08-31 18:12:42 +010099FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType",
100 DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100101{
102 // Validate output
103 validate(Accessor(_target), _reference, tolerance_f);
104}
105TEST_SUITE_END()
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100106#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100107
108TEST_SUITE(FP32)
109FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
110{
111 // Validate output
112 validate(Accessor(_target), _reference, tolerance_f);
113}
114FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
115{
116 // Validate output
117 validate(Accessor(_target), _reference, tolerance_f);
118}
119TEST_SUITE_END()
120TEST_SUITE_END()
121
122template <typename T>
123using NEGEMMFixedPointFixture = GEMMValidationFixedPointFixture<Tensor, Accessor, NEGEMM, T>;
124
125TEST_SUITE(Quantized)
126TEST_SUITE(QS8)
127FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
128 framework::dataset::make("DataType",
129 DataType::QS8)),
130 framework::dataset::make("FractionalBits", 1, 7)))
131{
132 // Validate output
133 validate(Accessor(_target), _reference, tolerance_q);
134}
135FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
136 framework::dataset::make("DataType",
137 DataType::QS8)),
138 framework::dataset::make("FractionalBits", 1, 7)))
139{
140 // Validate output
141 validate(Accessor(_target), _reference, tolerance_q);
142}
143TEST_SUITE_END()
144
145TEST_SUITE(QS16)
146FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
147 framework::dataset::make("DataType",
148 DataType::QS16)),
149 framework::dataset::make("FractionalBits", 1, 14)))
150{
151 // Validate output
152 validate(Accessor(_target), _reference, tolerance_q);
153}
154FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
155 framework::dataset::make("DataType",
156 DataType::QS16)),
157 framework::dataset::make("FractionalBits", 1, 14)))
158{
159 // Validate output
160 validate(Accessor(_target), _reference, tolerance_q);
161}
162TEST_SUITE_END()
163TEST_SUITE_END()
164
165TEST_SUITE_END()
166TEST_SUITE_END()
167} // namespace validation
168} // namespace test
169} // namespace arm_compute