blob: a75b8cf9cd1ff4ac4a078c8ab1c7df9b1a35ca07 [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{
Pablo Tello35767bc2018-12-05 17:36:30 +000045const auto PermuteVectors = framework::dataset::make("PermutationVector",
46{
47 PermutationVector(2U, 0U, 1U),
48 PermutationVector(1U, 2U, 0U),
49 PermutationVector(3U, 2U, 0U, 1U)
50});
51const auto PermuteInputLayout = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC });
52const auto PermuteParametersSmall = concat(concat(datasets::Small2DShapes(), datasets::Small3DShapes()), datasets::Small4DShapes()) * PermuteInputLayout * PermuteVectors;
53const auto PermuteParametersLarge = datasets::Large4DShapes() * PermuteInputLayout * PermuteVectors;
54
Michalis Spyrou5237e012018-01-17 09:40:27 +000055} // namespace
56TEST_SUITE(CL)
57TEST_SUITE(Permute)
58
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000059// *INDENT-OFF*
60// clang-format off
61DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010062 framework::dataset::make("InputInfo",{
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000063 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
64 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
65 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported
66 TensorInfo(TensorShape(1U, 7U), 1, DataType::U8), // invalid input size
67 TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // valid
68 TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid
69 TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid
70 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8), // permutation not supported
71 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported
72 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported
73 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::U16), // permutation not supported
74 }),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010075 framework::dataset::make("OutputInfo", {
76 TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16),
77 TensorInfo(TensorShape(5U, 5U, 7U, 3U), 1, DataType::U16),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000078 TensorInfo(TensorShape(7U, 7U, 7U, 3U), 1, DataType::U16),
79 TensorInfo(TensorShape(5U, 7U), 1, DataType::U8),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010080 TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16),
81 TensorInfo(TensorShape(13U, 37U, 27U, 2U), 1, DataType::F32),
82 TensorInfo(TensorShape(2U, 37U, 27U, 13U), 1, DataType::F32),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000083 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8),
84 TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010085 TensorInfo(TensorShape(21U, 64U, 2U, 128U), 1, DataType::F32),
86 TensorInfo(TensorShape(2U, 21U, 64U, 128U), 1, DataType::U16),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000087 })),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010088 framework::dataset::make("PermutationVector", {
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000089 PermutationVector(2U, 1U, 0U),
90 PermutationVector(2U, 2U, 1U),
91 PermutationVector(1U, 1U, 1U),
92 PermutationVector(2U, 0U, 1U),
Anthony Barbiera8a4d9e2018-05-14 14:43:29 +010093 PermutationVector(2U, 0U, 1U),
94 PermutationVector(1U, 2U, 0U),
95 PermutationVector(3U, 2U, 0U, 1U),
Isabella Gottardiaad9f2c2018-02-21 11:51:23 +000096 PermutationVector(2U, 3U, 1U, 0U),
97 PermutationVector(1U, 1U, 1U, 1U),
98 PermutationVector(2U, 1U, 3U, 0U),
99 PermutationVector(3U, 2U, 1U, 0U),
100 })),
101 framework::dataset::make("Expected", { false, false, false, false, true, true, true, false, false, false, false })),
102 input_info, output_info, perm_vect, expected)
103{
104 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);
105}
106// clang-format on
107// *INDENT-ON*
108
Michalis Spyrou5237e012018-01-17 09:40:27 +0000109DATA_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 })),
110 shape, data_type)
111{
112 // Define permutation vector
113 const PermutationVector perm(2U, 0U, 1U);
114
115 // Permute shapes
116 TensorShape output_shape = shape;
117 permute(output_shape, perm);
118
119 // Create tensors
120 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
121 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type);
122
123 // Create and Configure function
124 CLPermute perm_func;
125 perm_func.configure(&ref_src, &dst, perm);
126
127 // Validate valid region
128 const ValidRegion valid_region = shape_to_valid_region(output_shape);
129 validate(dst.info()->valid_region(), valid_region);
130}
131
132template <typename T>
133using CLPermuteFixture = PermuteValidationFixture<CLTensor, CLAccessor, CLPermute, T>;
134
135TEST_SUITE(U8)
136FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U8)))
137{
138 // Validate output
139 validate(CLAccessor(_target), _reference);
140}
141FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U8)))
142{
143 // Validate output
144 validate(CLAccessor(_target), _reference);
145}
146TEST_SUITE_END()
147
148TEST_SUITE(U16)
149FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U16)))
150{
151 // Validate output
152 validate(CLAccessor(_target), _reference);
153}
154FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U16)))
155{
156 // Validate output
157 validate(CLAccessor(_target), _reference);
158}
159TEST_SUITE_END()
160
161TEST_SUITE(U32)
162FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U32)))
163{
164 // Validate output
165 validate(CLAccessor(_target), _reference);
166}
167FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U32)))
168{
169 // Validate output
170 validate(CLAccessor(_target), _reference);
171}
172TEST_SUITE_END()
173
174TEST_SUITE_END()
175TEST_SUITE_END()
176} // namespace validation
177} // namespace test
178} // namespace arm_compute