aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGian Marco Iodice <gianmarco.iodice@arm.com>2018-12-07 11:18:09 +0000
committerGian Marco Iodice <gianmarco.iodice@arm.com>2018-12-11 14:55:03 +0000
commit3b0a2654034714c16f5930d2b24936d8be7b18a6 (patch)
tree2a3ed3703a4f454ef42084363049aba3bf54ebd6 /tests
parentff0bccfb4697c591d569db9c2dc223f2e311a7d3 (diff)
downloadComputeLibrary-3b0a2654034714c16f5930d2b24936d8be7b18a6.tar.gz
COMPMID-1775: Implement CLGEMMReshapeRHSMatrixKernel to reshape the RHS matrix of GEMM/GEMMLowp
Change-Id: I77f2bfcc5d170bcc2428a2f27104942c1ec877d7 Reviewed-on: https://review.mlplatform.org/375 Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/validation/CL/GEMMReshapeRHSMatrix.cpp330
-rw-r--r--tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h128
-rw-r--r--tests/validation/reference/GEMMReshapeRHSMatrix.cpp111
-rw-r--r--tests/validation/reference/GEMMReshapeRHSMatrix.h44
4 files changed, 613 insertions, 0 deletions
diff --git a/tests/validation/CL/GEMMReshapeRHSMatrix.cpp b/tests/validation/CL/GEMMReshapeRHSMatrix.cpp
new file mode 100644
index 0000000000..e886b7bd43
--- /dev/null
+++ b/tests/validation/CL/GEMMReshapeRHSMatrix.cpp
@@ -0,0 +1,330 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
+#include "arm_compute/runtime/CL/CLTensor.h"
+#include "arm_compute/runtime/CL/CLTensorAllocator.h"
+#include "tests/CL/CLAccessor.h"
+#include "tests/CL/Helper.h"
+#include "tests/PaddingCalculator.h"
+#include "tests/datasets/ShapeDatasets.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+// *INDENT-OFF*
+// clang-format off
+/** Data types */
+const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
+
+/** Batch size values to test */
+const auto b_values = framework::dataset::make("batchsize", 1, 3);
+
+/** N0 values to test */
+const auto n0_values = framework::dataset::make("N0", { 2, 4, 8, 16 });
+
+/** H0 values to test */
+const auto h0_values = framework::dataset::make("H0", 1, 4);
+
+/** Interleave values to test */
+const auto i_values = framework::dataset::make("interleave", { true, false });
+
+} // namespace
+
+using namespace arm_compute::misc::shape_calculator;
+
+// Initialize the output tensor with zero and fill the border with zero
+using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>;
+
+template <typename T>
+using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>;
+
+TEST_SUITE(CL)
+TEST_SUITE(GEMMReshapeRHSMatrix)
+
+// This configuration tests only transpose = true
+DATA_TEST_CASE(Configuration0, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ data_types),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+shape_in, b_value, data_type, n0_value, k0_value, h0_value, i_value)
+{
+ GEMMRHSMatrixInfo rhs_info;
+ rhs_info.n0 = n0_value;
+ rhs_info.k0 = k0_value;
+ rhs_info.h0 = h0_value;
+ rhs_info.interleave = i_value;
+ rhs_info.transpose = true;
+
+ const TensorShape shape_src(shape_in[0], shape_in[1], b_value);
+ const TensorShape shape_dst = compute_rhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), rhs_info);
+
+ // Create tensors
+ CLTensor src = create_tensor<CLTensor>(shape_src, data_type);
+ CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
+
+ ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Create and configure function
+ CLGEMMReshapeRHSMatrixKernel reshape_rhs;
+ reshape_rhs.configure(&src, &dst, rhs_info);
+}
+
+// This configuration tests only transpose = false
+DATA_TEST_CASE(Configuration1, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ data_types),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+shape_in, b_value, data_type, n0_value, k0_value, h0_value, i_value)
+{
+ GEMMRHSMatrixInfo rhs_info;
+ rhs_info.n0 = n0_value;
+ rhs_info.k0 = k0_value;
+ rhs_info.h0 = h0_value;
+ rhs_info.interleave = i_value;
+ rhs_info.transpose = false;
+
+ const TensorShape shape_src(shape_in[0], shape_in[1], b_value);
+ const TensorShape shape_dst = compute_rhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), rhs_info);
+
+ // Create tensors
+ CLTensor src = create_tensor<CLTensor>(shape_src, data_type);
+ CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
+
+ ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Create and configure function
+ CLGEMMReshapeRHSMatrixKernel reshape_rhs;
+ reshape_rhs.configure(&src, &dst, rhs_info);
+}
+
+TEST_SUITE(S32)
+// RunSmall tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S32)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunSmall tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S32)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S32)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S32)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // S32
+
+TEST_SUITE(S16)
+// RunSmall tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S16)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunSmall tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S16)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S16)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S16)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // S16
+
+TEST_SUITE(S8)
+// RunSmall tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S8)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunSmall tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
+ combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S8)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = false
+FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S8)),
+ n0_values),
+ framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", false)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+
+// RunLarge tests only for transpose = true
+FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::NIGHTLY,
+ combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
+ b_values),
+ framework::dataset::make("DataType", DataType::S8)),
+ n0_values),
+ framework::dataset::make("K0", { 4, 8, 16 })),
+ h0_values),
+ i_values),
+ framework::dataset::make("transpose", true)))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // S8
+TEST_SUITE_END() // GEMMReshapeRHSMatrix
+TEST_SUITE_END() // CL
+} // namespace validation
+} // namespace test
+} // namespace arm_compute \ No newline at end of file
diff --git a/tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h b/tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h
new file mode 100644
index 0000000000..e03c4f39b8
--- /dev/null
+++ b/tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_FIXTURE
+#define ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_FIXTURE
+
+#include "arm_compute/core/TensorShape.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
+#include "tests/AssetsLibrary.h"
+#include "tests/Globals.h"
+#include "tests/IAccessor.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Fixture.h"
+#include "tests/validation/Helpers.h"
+#include "tests/validation/reference/GEMMReshapeRHSMatrix.h"
+#include "tests/validation/reference/Utils.h"
+
+#include <random>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+using namespace arm_compute::misc::shape_calculator;
+
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+class GEMMReshapeRHSMatrixValidationFixture : public framework::Fixture
+{
+public:
+ template <typename...>
+ 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)
+ {
+ GEMMRHSMatrixInfo rhs_info;
+ rhs_info.n0 = n0;
+ rhs_info.k0 = k0;
+ rhs_info.h0 = h0;
+ rhs_info.interleave = interleave;
+ rhs_info.transpose = transpose;
+
+ // Set the tensor shape
+ const TensorShape shape_src(shape_in[0],
+ shape_in[1],
+ batch_size);
+
+ _target = compute_target(shape_src, data_type, rhs_info);
+ _reference = compute_reference(shape_src, data_type, rhs_info);
+ }
+
+protected:
+ template <typename U>
+ void fill(U &&tensor)
+ {
+ library->fill_tensor_uniform(tensor, 0);
+ }
+
+ TensorType compute_target(TensorShape input_shape, DataType data_type, const GEMMRHSMatrixInfo &rhs_info)
+ {
+ // Create tensors
+ TensorType src = create_tensor<TensorType>(input_shape, data_type, 1);
+ TensorType dst;
+
+ // The output tensor will be auto-initialized within the function
+
+ // Create and configure function
+ FunctionType gemm_rhs_reshape;
+ gemm_rhs_reshape.configure(&src, &dst, rhs_info);
+
+ ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Allocate tensors
+ src.allocator()->allocate();
+ dst.allocator()->allocate();
+
+ ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Fill tensors
+ fill(AccessorType(src));
+
+ // Compute GEMM RHS matrix reshape function
+ gemm_rhs_reshape.run();
+
+ return dst;
+ }
+
+ SimpleTensor<T> compute_reference(const TensorShape &input_shape, DataType data_type, const GEMMRHSMatrixInfo &rhs_info)
+ {
+ // Create reference
+ SimpleTensor<T> src{ input_shape, data_type, 1 };
+
+ // Fill reference
+ fill(src);
+
+ TensorShape output_shape = compute_rhs_reshaped_shape(TensorInfo(input_shape, 1, data_type), rhs_info);
+
+ return reference::gemm_reshape_rhs_matrix<T>(src, output_shape, rhs_info);
+ }
+
+ TensorType _target{};
+ SimpleTensor<T> _reference{};
+};
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_FIXTURE */ \ No newline at end of file
diff --git a/tests/validation/reference/GEMMReshapeRHSMatrix.cpp b/tests/validation/reference/GEMMReshapeRHSMatrix.cpp
new file mode 100644
index 0000000000..0224c5c67c
--- /dev/null
+++ b/tests/validation/reference/GEMMReshapeRHSMatrix.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "GEMMReshapeRHSMatrix.h"
+
+#include "arm_compute/core/Types.h"
+
+#include "tests/validation/Helpers.h"
+
+#include <algorithm>
+#include <cmath>
+#include <cstring>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<T> gemm_reshape_rhs_matrix(const SimpleTensor<T> &in, const TensorShape &output_shape, const GEMMRHSMatrixInfo &rhs_info)
+{
+ ARM_COMPUTE_ERROR_ON(in.shape().num_dimensions() > 3);
+
+ SimpleTensor<T> out{ output_shape, in.data_type() };
+
+ // Initialize the output tensor with zero
+ std::memset(&out[0], 0, out.num_elements() * sizeof(T));
+
+ const unsigned int N = in.shape()[0];
+ const unsigned int K = in.shape()[1];
+ const unsigned int B = in.shape()[2];
+
+ const unsigned int num_tiles_x = std::ceil(N / static_cast<float>(rhs_info.n0));
+ const unsigned int num_tiles_y = std::ceil(K / static_cast<float>(rhs_info.k0));
+
+ const TensorShape tile_dims(rhs_info.n0, rhs_info.k0);
+ const TensorShape tile_dims_transposed(rhs_info.k0, rhs_info.n0);
+
+ // Simple tensor for the input tile
+ SimpleTensor<T> src_tile{ tile_dims, in.data_type() };
+
+ // Simple tensor for the input tile
+ SimpleTensor<T> src_tile_transposed{ tile_dims_transposed, in.data_type() };
+
+ // Simple tensor to use when storing the values
+ SimpleTensor<T> *tile_to_use = rhs_info.transpose ? &src_tile_transposed : &src_tile;
+
+ const unsigned int offset_output_x = rhs_info.interleave ? tile_to_use->shape()[0] : tile_to_use->shape()[0] * tile_to_use->shape()[1];
+ const unsigned int step_output_x = rhs_info.interleave ? tile_to_use->shape()[0] * rhs_info.h0 : tile_to_use->shape()[0];
+
+ for(unsigned int z = 0; z < B; ++z)
+ {
+ for(unsigned int y = 0; y < num_tiles_y; ++y)
+ {
+ for(unsigned int x = 0; x < num_tiles_x; ++x)
+ {
+ // Get the tile from the input tensor
+ get_tile<T>(in, src_tile, Coordinates(x * rhs_info.n0, y * rhs_info.k0, z, 0));
+
+ if(rhs_info.transpose)
+ {
+ // Transpose matrix
+ transpose_matrix<T>(src_tile, src_tile_transposed);
+ }
+
+ // Store
+ const unsigned int offset_output = (y * rhs_info.k0 * rhs_info.n0 * rhs_info.h0) + ((x % rhs_info.h0) * offset_output_x) + ((x / rhs_info.h0) * out.shape()[0]) + (z * out.shape()[0] * out.shape()[1]);
+
+ for(unsigned int i = 0; i < tile_to_use->shape()[1]; ++i)
+ {
+ const unsigned int offset_tile = i * tile_to_use->shape()[0];
+
+ // Copy per row
+ std::copy(&(*tile_to_use)[offset_tile], &(*tile_to_use)[offset_tile + tile_to_use->shape()[0]], &out[offset_output + i * step_output_x]);
+ }
+ }
+ }
+ }
+
+ return out;
+}
+template SimpleTensor<int> gemm_reshape_rhs_matrix(const SimpleTensor<int> &in, const TensorShape &output_shape, const GEMMRHSMatrixInfo &rhs_info);
+template SimpleTensor<short> gemm_reshape_rhs_matrix(const SimpleTensor<short> &in, const TensorShape &output_shape, const GEMMRHSMatrixInfo &rhs_info);
+template SimpleTensor<char> gemm_reshape_rhs_matrix(const SimpleTensor<char> &in, const TensorShape &output_shape, const GEMMRHSMatrixInfo &rhs_info);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute \ No newline at end of file
diff --git a/tests/validation/reference/GEMMReshapeRHSMatrix.h b/tests/validation/reference/GEMMReshapeRHSMatrix.h
new file mode 100644
index 0000000000..8edcfd67fa
--- /dev/null
+++ b/tests/validation/reference/GEMMReshapeRHSMatrix.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_H__
+#define __ARM_COMPUTE_TEST_GEMMRESHAPERHSMATRIX_H__
+
+#include "tests/SimpleTensor.h"
+#include "tests/validation/Helpers.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<T> gemm_reshape_rhs_matrix(const SimpleTensor<T> &in, const TensorShape &output_shape, const GEMMRHSMatrixInfo &rhs_info);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_TEST_GEMMRESHAPERHS_MATRIX_H__ */ \ No newline at end of file