blob: cdb3ec3944ac79ee60b8b2bca3f0a1690831a69a [file] [log] [blame]
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001/*
Giorgio Arena63825e82021-03-25 14:54:50 +00002 * Copyright (c) 2018-2021 Arm Limited.
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +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_GEMMRESHAPERHSMATRIX_FIXTURE
25#define ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/core/utils/misc/ShapeCalculator.h"
30#include "tests/AssetsLibrary.h"
31#include "tests/Globals.h"
32#include "tests/IAccessor.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Fixture.h"
35#include "tests/validation/Helpers.h"
36#include "tests/validation/reference/GEMMReshapeRHSMatrix.h"
37#include "tests/validation/reference/Utils.h"
38
39#include <random>
40
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
47using namespace arm_compute::misc::shape_calculator;
48
Georgios Pinitas856f66e2021-04-22 21:13:21 +010049template <typename TensorType, typename AccessorType, typename OperatorType, typename T>
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000050class GEMMReshapeRHSMatrixValidationFixture : public framework::Fixture
51{
52public:
53 template <typename...>
54 void setup(TensorShape shape_in, unsigned int batch_size, DataType data_type, unsigned int n0, unsigned int k0, unsigned int h0, bool interleave, bool transpose)
55 {
56 GEMMRHSMatrixInfo rhs_info;
57 rhs_info.n0 = n0;
58 rhs_info.k0 = k0;
59 rhs_info.h0 = h0;
60 rhs_info.interleave = interleave;
61 rhs_info.transpose = transpose;
62
63 // Set the tensor shape
64 const TensorShape shape_src(shape_in[0],
65 shape_in[1],
66 batch_size);
67
68 _target = compute_target(shape_src, data_type, rhs_info);
69 _reference = compute_reference(shape_src, data_type, rhs_info);
70 }
71
72protected:
73 template <typename U>
74 void fill(U &&tensor)
75 {
76 library->fill_tensor_uniform(tensor, 0);
77 }
78
79 TensorType compute_target(TensorShape input_shape, DataType data_type, const GEMMRHSMatrixInfo &rhs_info)
80 {
81 // Create tensors
82 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1);
83 TensorType dst;
84
85 // The output tensor will be auto-initialized within the function
86
87 // Create and configure function
Georgios Pinitas856f66e2021-04-22 21:13:21 +010088 OperatorType gemm_rhs_reshape;
89 gemm_rhs_reshape.configure(src.info(), dst.info(), rhs_info);
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000090
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010091 ARM_COMPUTE_ASSERT(src.info()->is_resizable());
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000092
Giorgio Arena63825e82021-03-25 14:54:50 +000093 add_padding_x({ &src, &dst });
94
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000095 // Allocate tensors
96 src.allocator()->allocate();
97 dst.allocator()->allocate();
98
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010099 ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
100 ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000101
102 // Fill tensors
103 fill(AccessorType(src));
104
105 // Compute GEMM RHS matrix reshape function
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100106 ITensorPack tensors = { { ACL_SRC, &src }, { ACL_DST, &dst } };
107 gemm_rhs_reshape.run(tensors);
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000108
109 return dst;
110 }
111
112 SimpleTensor<T> compute_reference(const TensorShape &input_shape, DataType data_type, const GEMMRHSMatrixInfo &rhs_info)
113 {
114 // Create reference
115 SimpleTensor<T> src{ input_shape, data_type, 1 };
116
117 // Fill reference
118 fill(src);
119
120 TensorShape output_shape = compute_rhs_reshaped_shape(TensorInfo(input_shape, 1, data_type), rhs_info);
121
122 return reference::gemm_reshape_rhs_matrix<T>(src, output_shape, rhs_info);
123 }
124
125 TensorType _target{};
126 SimpleTensor<T> _reference{};
127};
128} // namespace validation
129} // namespace test
130} // namespace arm_compute
131#endif /* ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_FIXTURE */