blob: 488324dcc8b8242668e82c4d5329ae7ff8a30dce [file] [log] [blame]
Pablo Tellobf2fb952017-09-29 16:43:25 +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_GEMM_INTERLEAVE_BLOCKED_FIXTURE
25#define ARM_COMPUTE_TEST_GEMM_INTERLEAVE_BLOCKED_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"
Pablo Tellobf2fb952017-09-29 16:43:25 +010034#include "tests/validation/Helpers.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000035#include "tests/validation/reference/GEMMInterleaveBlocked.h"
Pablo Tellobf2fb952017-09-29 16:43:25 +010036
37#include <random>
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename FunctionType, bool Transposed = false>
46class GEMMInterleaveBlockedValidationFixture : public framework::Fixture
47{
48public:
49 template <typename...>
50 void setup(size_t x, size_t y, int int_by, int block)
51 {
52 const float interleave_by_f32 = int_by;
53 const TensorShape shape_a(x, y);
54 const TensorShape shape_b(static_cast<size_t>(x * interleave_by_f32), static_cast<size_t>(std::ceil(y / interleave_by_f32)));
55 _target = compute_target(shape_a, shape_b, int_by, block);
56 _reference = compute_reference(shape_a, shape_b, int_by, block);
57 }
58
59protected:
60 template <typename U>
61 void fill(U &&tensor, int i)
62 {
63 ARM_COMPUTE_ERROR_ON(tensor.data_type() != DataType::U8);
64 std::uniform_int_distribution<> distribution(0, 255);
65 library->fill(tensor, distribution, i);
66 }
67
68 TensorType compute_target(const TensorShape &shape_a, const TensorShape &shape_b, int int_by, int block)
69 {
70 // Create tensors
71 TensorType a = create_tensor<TensorType>(shape_a, DataType::U8, 1);
72 TensorType b = create_tensor<TensorType>(shape_b, DataType::U8, 1);
73
74 // Create and configure function
75 FunctionType f;
76 f.configure(&a, &b, int_by, block, Transposed);
77
78 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
80
81 // Allocate tensors
82 a.allocator()->allocate();
83 b.allocator()->allocate();
84
85 ARM_COMPUTE_EXPECT(!a.info()->is_resizable(), framework::LogLevel::ERRORS);
86 ARM_COMPUTE_EXPECT(!b.info()->is_resizable(), framework::LogLevel::ERRORS);
87
88 // Fill tensors
89 fill(AccessorType(a), 0);
90
91 // Compute GEMM function
92 f.run();
93 return b;
94 }
95
96 SimpleTensor<uint8_t> compute_reference(const TensorShape &shape_a, const TensorShape &shape_b, int int_by, int block)
97 {
98 // Create reference
99 SimpleTensor<uint8_t> a{ shape_a, DataType::U8, 1 };
100 SimpleTensor<uint8_t> b{ shape_b, DataType::U8, 1 };
101
102 // Fill reference
103 fill(a, 0);
104 return reference::gemm_interleave_blocked<uint8_t>(a, b, int_by, block, Transposed);
105 }
106
107 TensorType _target{};
108 SimpleTensor<uint8_t> _reference{};
109};
110
111} // namespace validation
112} // namespace test
113} // namespace arm_compute
114#endif /* ARM_COMPUTE_TEST_GEMM_INTERLEAVE_BLOCKED_FIXTURE */