blob: f0f5346aa7cd69b14f9c48eb3875adfdf79d83ba [file] [log] [blame]
Georgios Pinitas8795ffb2017-12-01 16:13:40 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Georgios Pinitas8795ffb2017-12-01 16:13:40 +00003 *
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/CPP/functions/CPPPermute.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.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(0U, 1U, 2U),
50 PermutationVector(0U, 2U, 1U),
51 PermutationVector(1U, 0U, 2U),
52 PermutationVector(2U, 1U, 0U),
53});
Michalis Spyrou6bff1952019-10-02 17:22:11 +010054const auto PermuteParametersSmall = concat(concat(datasets::Small2DShapes(), datasets::Small3DShapes()), datasets::Small4DShapes()) * PermuteVectors;
55const auto PermuteParametersLarge = datasets::Large4DShapes() * PermuteVectors;
Pablo Tello35767bc2018-12-05 17:36:30 +000056
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000057} // namespace
58TEST_SUITE(CPP)
59TEST_SUITE(Permute)
60
Sheri Zhanga0352d32020-03-16 14:20:56 +000061DATA_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, DataType::QASYMM8_SIGNED })),
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000062 shape, data_type)
63{
64 // Define permutation vector
65 const PermutationVector perm(2U, 0U, 1U);
66
67 // Permute shapes
68 TensorShape output_shape = shape;
69 permute(output_shape, perm);
70
71 // Create tensors
72 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
73 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
74
75 // Create and Configure function
76 CPPPermute perm_func;
77 perm_func.configure(&ref_src, &dst, perm);
78
79 // Validate valid region
80 const ValidRegion valid_region = shape_to_valid_region(output_shape);
81 validate(dst.info()->valid_region(), valid_region);
82}
83
84template <typename T>
85using CPPPermuteFixture = PermuteValidationFixture<Tensor, Accessor, CPPPermute, T>;
86
87TEST_SUITE(U8)
Pablo Tello35767bc2018-12-05 17:36:30 +000088FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
89 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U8))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000090{
91 // Validate output
92 validate(Accessor(_target), _reference);
93}
Pablo Tello35767bc2018-12-05 17:36:30 +000094
95FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
96 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U8))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000097{
98 // Validate output
99 validate(Accessor(_target), _reference);
100}
Pablo Tello35767bc2018-12-05 17:36:30 +0000101
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000102TEST_SUITE_END()
103
104TEST_SUITE(U16)
Pablo Tello35767bc2018-12-05 17:36:30 +0000105FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT,
106 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U16))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000107{
108 // Validate output
109 validate(Accessor(_target), _reference);
110}
Pablo Tello35767bc2018-12-05 17:36:30 +0000111
112FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY,
113 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U16))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000114{
115 // Validate output
116 validate(Accessor(_target), _reference);
117}
118TEST_SUITE_END()
119
120TEST_SUITE(U32)
Pablo Tello35767bc2018-12-05 17:36:30 +0000121FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT,
122 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U32))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000123{
124 // Validate output
125 validate(Accessor(_target), _reference);
126}
Pablo Tello35767bc2018-12-05 17:36:30 +0000127
128FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY,
129 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U32))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000130{
131 // Validate output
132 validate(Accessor(_target), _reference);
133}
134TEST_SUITE_END()
135
Sheri Zhanga0352d32020-03-16 14:20:56 +0000136TEST_SUITE(QASYMM8_SINGED)
137FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
138 PermuteParametersSmall * framework::dataset::make("DataType", DataType::QASYMM8_SIGNED))
139{
140 // Validate output
141 validate(Accessor(_target), _reference);
142}
143
144TEST_SUITE_END() // QASYMM8_SINGED
145
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000146TEST_SUITE_END()
147TEST_SUITE_END()
148} // namespace validation
149} // namespace test
150} // namespace arm_compute