Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 1 | /* |
| 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_FULLYCONNECTEDLAYERFIXTURE |
| 25 | #define ARM_COMPUTE_TEST_FULLYCONNECTEDLAYERFIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 29 | #include "tests/Globals.h" |
| 30 | #include "tests/Utils.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/framework/Fixture.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 32 | |
Frank Lei | b9d38ee | 2017-12-05 10:43:33 +0800 | [diff] [blame] | 33 | #ifdef ARM_COMPUTE_GC |
| 34 | #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" |
| 35 | #include "tests/GLES_COMPUTE/Helper.h" |
| 36 | |
| 37 | using namespace arm_compute::test::gles_compute; |
| 38 | #endif /* ARM_COMPUTE_GC */ |
| 39 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | /** Fixture that can be used for NEON and CL */ |
| 45 | template <typename TensorType, typename Function, typename Accessor> |
| 46 | class FullyConnectedLayerFixture : public framework::Fixture |
| 47 | { |
| 48 | public: |
Moritz Pflanzer | b6c8d24 | 2017-07-18 13:42:54 +0100 | [diff] [blame] | 49 | template <typename...> |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 50 | void setup(TensorShape src_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape dst_shape, 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(src_shape.num_dimensions() /* batch */, batches); |
| 55 | dst_shape.set(dst_shape.num_dimensions() /* 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 | fc_layer.configure(&src, &weights, &biases, &dst); |
| 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 | fc_layer.run(); |
Frank Lei | b9d38ee | 2017-12-05 10:43:33 +0800 | [diff] [blame] | 81 | #ifdef ARM_COMPUTE_GC |
| 82 | if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value) |
| 83 | { |
| 84 | force_sync_tensor(dst); |
| 85 | } |
| 86 | #endif /* ARM_COMPUTE_GC */ |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void teardown() |
| 90 | { |
| 91 | src.allocator()->free(); |
| 92 | weights.allocator()->free(); |
| 93 | biases.allocator()->free(); |
| 94 | dst.allocator()->free(); |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | TensorType src{}; |
| 99 | TensorType weights{}; |
| 100 | TensorType biases{}; |
| 101 | TensorType dst{}; |
| 102 | Function fc_layer{}; |
| 103 | }; |
| 104 | } // namespace test |
| 105 | } // namespace arm_compute |
| 106 | #endif /* ARM_COMPUTE_TEST_FULLYCONNECTEDLAYERFIXTURE */ |