blob: 1371e717e71c6e3c313f7cc2251a2385ea946c62 [file] [log] [blame]
Michalis Spyrou5237e012018-01-17 09:40:27 +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/core/Types.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLPermute.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/PermuteFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45const auto PermuteParametersSmall = combine(datasets::Small4DShapes(),
46 framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U), PermutationVector(3U, 2U, 0U, 1U) }));
47const auto PermuteParametersLarge = combine(datasets::Large4DShapes(),
48 framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U), PermutationVector(3U, 2U, 0U, 1U) }));
49} // namespace
50TEST_SUITE(CL)
51TEST_SUITE(Permute)
52
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000053// *INDENT-OFF*
54// clang-format off
55DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010056 framework::dataset::make("InputInfo",{
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000057 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
58 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
59 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
60 TensorInfo(TensorShape(1U, 7U), 1, DataType::U8), // invalid input size
61 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // valid
62 TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid
63 TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid
64 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8), // permutation not supported
65 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported
66 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported
67 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::U16), // permutation not supported
68 }),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010069 framework::dataset::make("OutputInfo", {
70 TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16),
71 TensorInfo(TensorShape(5U, 5U, 7U, 3U), 1, DataType::U16),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000072 TensorInfo(TensorShape(7U, 7U, 7U, 3U), 1, DataType::U16),
73 TensorInfo(TensorShape(5U, 7U), 1, DataType::U8),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010074 TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16),
75 TensorInfo(TensorShape(13U, 37U, 27U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(2U, 37U, 27U, 13U), 1, DataType::F32),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000077 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8),
78 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010079 TensorInfo(TensorShape(21U, 64U, 2U, 128U), 1, DataType::F32),
80 TensorInfo(TensorShape(2U, 21U, 64U, 128U), 1, DataType::U16),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000081 })),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010082 framework::dataset::make("PermutationVector", {
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000083 PermutationVector(2U, 1U, 0U),
84 PermutationVector(2U, 2U, 1U),
85 PermutationVector(1U, 1U, 1U),
86 PermutationVector(2U, 0U, 1U),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010087 PermutationVector(2U, 0U, 1U),
88 PermutationVector(1U, 2U, 0U),
89 PermutationVector(3U, 2U, 0U, 1U),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000090 PermutationVector(2U, 3U, 1U, 0U),
91 PermutationVector(1U, 1U, 1U, 1U),
92 PermutationVector(2U, 1U, 3U, 0U),
93 PermutationVector(3U, 2U, 1U, 0U),
94 })),
95 framework::dataset::make("Expected", { false, false, false, false, true, true, true, false, false, false, false })),
96 input_info, output_info, perm_vect, expected)
97{
98 ARM_COMPUTE_EXPECT(bool(CLPermute::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), perm_vect)) == expected, framework::LogLevel::ERRORS);
99}
100// clang-format on
101// *INDENT-ON*
102
Michalis Spyrou5237e012018-01-17 09:40:27 +0000103DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::Small4DShapes(), framework::dataset::make("DataType", { DataType::S8, DataType::U8, DataType::S16, DataType::U16, DataType::U32, DataType::S32, DataType::F16, DataType::F32 })),
104 shape, data_type)
105{
106 // Define permutation vector
107 const PermutationVector perm(2U, 0U, 1U);
108
109 // Permute shapes
110 TensorShape output_shape = shape;
111 permute(output_shape, perm);
112
113 // Create tensors
114 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
115 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type);
116
117 // Create and Configure function
118 CLPermute perm_func;
119 perm_func.configure(&ref_src, &dst, perm);
120
121 // Validate valid region
122 const ValidRegion valid_region = shape_to_valid_region(output_shape);
123 validate(dst.info()->valid_region(), valid_region);
124}
125
126template <typename T>
127using CLPermuteFixture = PermuteValidationFixture<CLTensor, CLAccessor, CLPermute, T>;
128
129TEST_SUITE(U8)
130FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U8)))
131{
132 // Validate output
133 validate(CLAccessor(_target), _reference);
134}
135FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U8)))
136{
137 // Validate output
138 validate(CLAccessor(_target), _reference);
139}
140TEST_SUITE_END()
141
142TEST_SUITE(U16)
143FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U16)))
144{
145 // Validate output
146 validate(CLAccessor(_target), _reference);
147}
148FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U16)))
149{
150 // Validate output
151 validate(CLAccessor(_target), _reference);
152}
153TEST_SUITE_END()
154
155TEST_SUITE(U32)
156FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U32)))
157{
158 // Validate output
159 validate(CLAccessor(_target), _reference);
160}
161FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U32)))
162{
163 // Validate output
164 validate(CLAccessor(_target), _reference);
165}
166TEST_SUITE_END()
167
168TEST_SUITE_END()
169TEST_SUITE_END()
170} // namespace validation
171} // namespace test
172} // namespace arm_compute