blob: 41825a5dcbbb96ed5c9e663368b076db2380b940 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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 "Globals.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010026#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "TensorLibrary.h"
28#include "TypePrinter.h"
29#include "Utils.h"
30#include "validation/Datasets.h"
31#include "validation/Reference.h"
32#include "validation/Validation.h"
33
34#include "arm_compute/core/Helpers.h"
35#include "arm_compute/core/Types.h"
36#include "arm_compute/runtime/NEON/functions/NEBitwiseXor.h"
37#include "arm_compute/runtime/Tensor.h"
38#include "arm_compute/runtime/TensorAllocator.h"
39
40#include "boost_wrapper.h"
41
42#include <random>
43#include <string>
44
45using namespace arm_compute;
46using namespace arm_compute::test;
47using namespace arm_compute::test::neon;
48using namespace arm_compute::test::validation;
49
50namespace
51{
52/** Compute Neon bitwise xor function.
53 *
54 * @param[in] shape Shape of the input and output tensors.
55 *
56 * @return Computed output tensor.
57 */
58Tensor compute_bitwise_xor(const TensorShape &shape)
59{
60 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010061 Tensor src1 = create_tensor<Tensor>(shape, DataType::U8);
62 Tensor src2 = create_tensor<Tensor>(shape, DataType::U8);
63 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064
65 // Create xor configure function
66 NEBitwiseXor bxor;
67 bxor.configure(&src1, &src2, &dst);
68
69 // Allocate tensors
70 src1.allocator()->allocate();
71 src2.allocator()->allocate();
72 dst.allocator()->allocate();
73
74 BOOST_TEST(!src1.info()->is_resizable());
75 BOOST_TEST(!src2.info()->is_resizable());
76 BOOST_TEST(!dst.info()->is_resizable());
77
78 // Fill tensors
79 library->fill_tensor_uniform(NEAccessor(src1), 0);
80 library->fill_tensor_uniform(NEAccessor(src2), 1);
81
82 // Compute function
83 bxor.run();
84
85 return dst;
86}
87} // namespace
88
89#ifndef DOXYGEN_SKIP_THIS
90BOOST_AUTO_TEST_SUITE(NEON)
91BOOST_AUTO_TEST_SUITE(BitwiseXor)
92
93BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
94BOOST_DATA_TEST_CASE(Configuration, SmallShapes() + LargeShapes(), shape)
95{
96 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010097 Tensor src1 = create_tensor<Tensor>(shape, DataType::U8);
98 Tensor src2 = create_tensor<Tensor>(shape, DataType::U8);
99 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100
101 BOOST_TEST(src1.info()->is_resizable());
102 BOOST_TEST(src2.info()->is_resizable());
103 BOOST_TEST(dst.info()->is_resizable());
104
105 // Create xor configure function
106 NEBitwiseXor bxor;
107 bxor.configure(&src1, &src2, &dst);
108
109 // Validate valid region
110 const ValidRegion valid_region = shape_to_valid_region(shape);
111 validate(src1.info()->valid_region(), valid_region);
112 validate(src2.info()->valid_region(), valid_region);
113 validate(dst.info()->valid_region(), valid_region);
114
115 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100116 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100117 validate(src1.info()->padding(), padding);
118 validate(src2.info()->padding(), padding);
119 validate(dst.info()->padding(), padding);
120}
121
122BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
123BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
124{
125 // Compute function
126 Tensor dst = compute_bitwise_xor(shape);
127
128 // Compute reference
129 RawTensor ref_dst = Reference::compute_reference_bitwise_xor(shape);
130
131 // Validate output
132 validate(NEAccessor(dst), ref_dst);
133}
134
135BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
136BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape)
137{
138 // Compute function
139 Tensor dst = compute_bitwise_xor(shape);
140
141 // Compute reference
142 RawTensor ref_dst = Reference::compute_reference_bitwise_xor(shape);
143
144 // Validate output
145 validate(NEAccessor(dst), ref_dst);
146}
147
148BOOST_AUTO_TEST_SUITE_END()
149BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100150#endif /* DOXYGEN_SKIP_THIS */