blob: 18e400d542eb2b28810e21156f6e9304bf278b97 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Matthew Bentham92046462020-03-07 22:15:55 +00002 * Copyright (c) 2017-2020 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TEST_NEON_HELPER_H
25#define ARM_COMPUTE_TEST_NEON_HELPER_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010027#include "arm_compute/runtime/Array.h"
Pablo Tellobf2fb952017-09-29 16:43:25 +010028#include "arm_compute/runtime/NEON/INESimpleFunction.h"
Matthew Bentham92046462020-03-07 22:15:55 +000029#include "support/MemorySupport.h"
Pablo Tello8fda1cb2017-07-05 15:20:38 +010030#include "tests/Globals.h"
Moritz Pflanzer94450f12017-06-30 12:48:43 +010031
32#include <algorithm>
Pablo Tello8fda1cb2017-07-05 15:20:38 +010033#include <array>
Pablo Tello221f3812017-06-28 17:27:56 +010034#include <vector>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035
36namespace arm_compute
37{
38namespace test
39{
Pablo Tello8fda1cb2017-07-05 15:20:38 +010040template <typename D, typename T, typename... Ts>
41void fill_tensors(D &&dist, std::initializer_list<int> seeds, T &&tensor, Ts &&... other_tensors)
42{
43 const std::array < T, 1 + sizeof...(Ts) > tensors{ { std::forward<T>(tensor), std::forward<Ts>(other_tensors)... } };
44 std::vector<int> vs(seeds);
45 ARM_COMPUTE_ERROR_ON(vs.size() != tensors.size());
46 int k = 0;
47 for(auto tp : tensors)
48 {
49 library->fill(Accessor(*tp), std::forward<D>(dist), vs[k++]);
50 }
51}
52
Alex Gildayc357c472018-03-21 13:54:09 +000053/** This template synthetizes an INESimpleFunction which runs the given kernel K */
Pablo Tellobf2fb952017-09-29 16:43:25 +010054template <typename K>
55class NESynthetizeFunction : public INESimpleFunction
56{
57public:
Alex Gildayc357c472018-03-21 13:54:09 +000058 /** Configure the kernel.
59 *
60 * @param[in] args Configuration arguments.
61 */
Pablo Tellobf2fb952017-09-29 16:43:25 +010062 template <typename... Args>
63 void configure(Args &&... args)
64 {
65 auto k = arm_compute::support::cpp14::make_unique<K>();
66 k->configure(std::forward<Args>(args)...);
67 _kernel = std::move(k);
68 }
Sheri Zhang45198c82020-04-14 22:29:36 +010069 /** Validate input arguments
70 *
71 * @param[in] args Configuration arguments.
72 */
73 template <typename... Args>
74 static Status validate(Args &&... args)
75 {
76 return K::validate(std::forward<Args>(args)...);
77 }
Pablo Tellobf2fb952017-09-29 16:43:25 +010078};
79
Alex Gildayc357c472018-03-21 13:54:09 +000080/** As above but this also setups a Zero border on the input tensor of the specified bordersize */
Pablo Tello2fdc4092017-11-23 15:50:08 +000081template <typename K, int bordersize>
82class NESynthetizeFunctionWithZeroConstantBorder : public INESimpleFunction
83{
84public:
Alex Gildayc357c472018-03-21 13:54:09 +000085 /** Configure the kernel.
86 *
87 * @param[in] first First configuration argument.
88 * @param[in] args Rest of the configuration arguments.
89 */
Pablo Tello2fdc4092017-11-23 15:50:08 +000090 template <typename T, typename... Args>
91 void configure(T first, Args &&... args)
92 {
93 auto k = arm_compute::support::cpp14::make_unique<K>();
94 k->configure(first, std::forward<Args>(args)...);
95 _kernel = std::move(k);
Manuel Bottini55e16782019-01-15 13:21:57 +000096 _border_handler.configure(first, BorderSize(bordersize), BorderMode::CONSTANT, PixelValue());
Pablo Tello2fdc4092017-11-23 15:50:08 +000097 }
98};
99
Giorgio Arena44f55722019-07-12 14:49:49 +0100100/** As above but this also setups a Zero border on the input tensor of the kernel's bordersize */
101template <typename K>
102class NESynthetizeFunctionWithZeroConstantKernelBorder : public INESimpleFunction
103{
104public:
105 /** Configure the kernel.
106 *
107 * @param[in] first First configuration argument.
108 * @param[in] args Rest of the configuration arguments.
109 */
110 template <typename T, typename... Args>
111 void configure(T first, Args &&... args)
112 {
113 auto k = arm_compute::support::cpp14::make_unique<K>();
114 k->configure(first, std::forward<Args>(args)...);
115 _kernel = std::move(k);
116 _border_handler.configure(first, BorderSize(_kernel->border_size()), BorderMode::CONSTANT, PixelValue());
117 }
118};
119
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100120} // namespace test
121} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000122#endif /* ARM_COMPUTE_TEST_NEON_HELPER_H */