blob: 7f27f3cfff0371c2e603033b2a5344d2bdd45659 [file] [log] [blame]
Georgios Pinitas8795ffb2017-12-01 16:13:40 +00001/*
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/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{
45const auto PermuteParametersSmall = combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()),
46 framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U) }));
47const auto PermuteParametersLarge = combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()),
48 framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U) }));
49} // namespace
50TEST_SUITE(CPP)
51TEST_SUITE(Permute)
52
53DATA_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 })),
54 shape, data_type)
55{
56 // Define permutation vector
57 const PermutationVector perm(2U, 0U, 1U);
58
59 // Permute shapes
60 TensorShape output_shape = shape;
61 permute(output_shape, perm);
62
63 // Create tensors
64 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
65 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
66
67 // Create and Configure function
68 CPPPermute perm_func;
69 perm_func.configure(&ref_src, &dst, perm);
70
71 // Validate valid region
72 const ValidRegion valid_region = shape_to_valid_region(output_shape);
73 validate(dst.info()->valid_region(), valid_region);
74}
75
76template <typename T>
77using CPPPermuteFixture = PermuteValidationFixture<Tensor, Accessor, CPPPermute, T>;
78
79TEST_SUITE(U8)
80FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U8)))
81{
82 // Validate output
83 validate(Accessor(_target), _reference);
84}
85FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U8)))
86{
87 // Validate output
88 validate(Accessor(_target), _reference);
89}
90TEST_SUITE_END()
91
92TEST_SUITE(U16)
93FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U16)))
94{
95 // Validate output
96 validate(Accessor(_target), _reference);
97}
98FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U16)))
99{
100 // Validate output
101 validate(Accessor(_target), _reference);
102}
103TEST_SUITE_END()
104
105TEST_SUITE(U32)
106FIXTURE_DATA_TEST_CASE(RunSmall, CPPPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U32)))
107{
108 // Validate output
109 validate(Accessor(_target), _reference);
110}
111FIXTURE_DATA_TEST_CASE(RunLarge, CPPPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U32)))
112{
113 // Validate output
114 validate(Accessor(_target), _reference);
115}
116TEST_SUITE_END()
117
118TEST_SUITE_END()
119TEST_SUITE_END()
120} // namespace validation
121} // namespace test
122} // namespace arm_compute