blob: 0239a6890384dcfb3a69500276b908340054114e [file] [log] [blame]
Kurtis Charnock9afc41a2019-11-11 17:24:37 +00001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2019, 2023 Arm Limited.
Kurtis Charnock9afc41a2019-11-11 17:24:37 +00003 *
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_FILL_FIXTURE
25#define ARM_COMPUTE_TEST_FILL_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
34
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
41template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
42class FillFixture : public framework::Fixture
43{
44public:
Kurtis Charnock9afc41a2019-11-11 17:24:37 +000045 void setup(TensorShape input_shape, DataType data_type)
46 {
47 _target = compute_target(input_shape, data_type);
48 _reference = compute_reference(input_shape, data_type);
49 }
50
51protected:
52 TensorType compute_target(const TensorShape &input_shape, DataType data_type)
53 {
54 // Create tensors
55 TensorType input = create_tensor<TensorType>(input_shape, data_type);
56
57 // Allocate tensors
58 input.allocator()->allocate();
59
60 // Fill tensor with an initial value
61 library->fill_tensor_uniform(AccessorType(input), 0);
62
63 // Create and configure function
64 FunctionType fill;
65 const T constant_value {1};
66 fill.configure(&input, constant_value);
67
68 // Compute function with a distinct, second value
69 fill.run();
70
71 return input;
72 }
73
74 SimpleTensor<T> compute_reference(const TensorShape &input_shape, DataType data_type)
75 {
76 // Create reference
77 SimpleTensor<T> input{ input_shape, data_type };
78
79 // Fill tensor
80 const T constant_value {1};
81 for(int i = 0; i < input.num_elements(); ++i)
82 {
83 input[i] = constant_value;
84 }
85
86 return input;
87 }
88
89 TensorType _target{};
90 SimpleTensor<T> _reference{};
91};
92} // namespace validation
93} // namespace test
94} // namespace arm_compute
95#endif /* ARM_COMPUTE_TEST_FILL_FIXTURE */