blob: 2ba10ec6516e185a79b1d0cbe54541ac06c81412 [file] [log] [blame]
Georgios Pinitas8795ffb2017-12-01 16:13:40 +00001/*
Georgios Pinitas69af6cf2018-02-14 19:23:44 +00002 * Copyright (c) 2017-2018 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});
54const auto PermuteInputLayout = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC });
55const auto PermuteParametersSmall = concat(concat(datasets::Small2DShapes(), datasets::Small3DShapes()), datasets::Small4DShapes()) * PermuteInputLayout * PermuteVectors;
56const auto PermuteParametersLarge = datasets::Large4DShapes() * PermuteInputLayout * PermuteVectors;
57
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000058} // namespace
59TEST_SUITE(CPP)
60TEST_SUITE(Permute)
61
62DATA_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 })),
63 shape, data_type)
64{
65 // Define permutation vector
66 const PermutationVector perm(2U, 0U, 1U);
67
68 // Permute shapes
69 TensorShape output_shape = shape;
70 permute(output_shape, perm);
71
72 // Create tensors
73 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
74 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
75
76 // Create and Configure function
77 CPPPermute perm_func;
78 perm_func.configure(&ref_src, &dst, perm);
79
80 // Validate valid region
81 const ValidRegion valid_region = shape_to_valid_region(output_shape);
82 validate(dst.info()->valid_region(), valid_region);
83}
84
85template <typename T>
86using CPPPermuteFixture = PermuteValidationFixture<Tensor, Accessor, CPPPermute, T>;
87
88TEST_SUITE(U8)
Pablo Tello35767bc2018-12-05 17:36:30 +000089FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
90 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U8))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000091{
92 // Validate output
93 validate(Accessor(_target), _reference);
94}
Pablo Tello35767bc2018-12-05 17:36:30 +000095
96FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
97 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U8))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000098{
99 // Validate output
100 validate(Accessor(_target), _reference);
101}
Pablo Tello35767bc2018-12-05 17:36:30 +0000102
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000103TEST_SUITE_END()
104
105TEST_SUITE(U16)
Pablo Tello35767bc2018-12-05 17:36:30 +0000106FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT,
107 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U16))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000108{
109 // Validate output
110 validate(Accessor(_target), _reference);
111}
Pablo Tello35767bc2018-12-05 17:36:30 +0000112
113FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY,
114 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U16))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000115{
116 // Validate output
117 validate(Accessor(_target), _reference);
118}
119TEST_SUITE_END()
120
121TEST_SUITE(U32)
Pablo Tello35767bc2018-12-05 17:36:30 +0000122FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT,
123 PermuteParametersSmall * framework::dataset::make("DataType", DataType::U32))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000124{
125 // Validate output
126 validate(Accessor(_target), _reference);
127}
Pablo Tello35767bc2018-12-05 17:36:30 +0000128
129FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY,
130 PermuteParametersLarge * framework::dataset::make("DataType", DataType::U32))
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000131{
132 // Validate output
133 validate(Accessor(_target), _reference);
134}
135TEST_SUITE_END()
136
137TEST_SUITE_END()
138TEST_SUITE_END()
139} // namespace validation
140} // namespace test
141} // namespace arm_compute