blob: b526cc3870f14dbf22afeaa6cdeca610b293b6c2 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +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#ifndef ARM_COMPUTE_TEST_CONVOLUTIONLAYERFIXTURE
25#define ARM_COMPUTE_TEST_CONVOLUTIONLAYERFIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010029#include "tests/Globals.h"
30#include "tests/Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/framework/Fixture.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010032
Anthony Barbier7068f992017-10-26 15:23:08 +010033#ifdef ARM_COMPUTE_GC
34#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
35#include "tests/GLES_COMPUTE/Helper.h"
36
37using namespace arm_compute::test::gles_compute;
38#endif /* ARM_COMPUTE_GC */
39
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010040namespace arm_compute
41{
42namespace test
43{
44/** Fixture that can be used for NEON and CL */
45template <typename TensorType, typename Function, typename Accessor>
46class ConvolutionLayerFixture : public framework::Fixture
47{
48public:
Moritz Pflanzerb6c8d242017-07-18 13:42:54 +010049 template <typename...>
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010050 void setup(TensorShape src_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape dst_shape, PadStrideInfo info, DataType data_type, int batches)
51 {
52 // Set batched in source and destination shapes
53 const unsigned int fixed_point_position = 4;
54 src_shape.set(3 /* batch */, batches);
55 dst_shape.set(3 /* batch */, batches);
56
57 // Create tensors
58 src = create_tensor<TensorType>(src_shape, data_type, 1, fixed_point_position);
59 weights = create_tensor<TensorType>(weights_shape, data_type, 1, fixed_point_position);
60 biases = create_tensor<TensorType>(biases_shape, data_type, 1, fixed_point_position);
61 dst = create_tensor<TensorType>(dst_shape, data_type, 1, fixed_point_position);
62
63 // Create and configure function
64 conv_layer.configure(&src, &weights, &biases, &dst, info);
65
66 // Allocate tensors
67 src.allocator()->allocate();
68 weights.allocator()->allocate();
69 biases.allocator()->allocate();
70 dst.allocator()->allocate();
71
72 // Fill tensors
73 library->fill_tensor_uniform(Accessor(src), 0);
74 library->fill_tensor_uniform(Accessor(weights), 1);
75 library->fill_tensor_uniform(Accessor(biases), 2);
76 }
77
78 void run()
79 {
80 conv_layer.run();
Anthony Barbier7068f992017-10-26 15:23:08 +010081#ifdef ARM_COMPUTE_GC
82 if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
83 {
Anthony Barbier7068f992017-10-26 15:23:08 +010084 force_sync_tensor(dst);
85 }
86#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010087 }
88
89 void teardown()
90 {
91 src.allocator()->free();
92 weights.allocator()->free();
93 biases.allocator()->free();
94 dst.allocator()->free();
95 }
96
97private:
98 TensorType src{};
99 TensorType weights{};
100 TensorType biases{};
101 TensorType dst{};
102 Function conv_layer{};
103};
104} // namespace test
105} // namespace arm_compute
106#endif /* ARM_COMPUTE_TEST_CONVOLUTIONLAYERFIXTURE */