aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Rossini <giuseppe.rossini@arm.com>2018-08-22 12:07:48 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:54 +0000
commit84797636b0ad44c16838df4177cf5a05aa929781 (patch)
tree28570365dca0eb915ec29eec85441c9c2833b76f
parent77589b58d55a181d49d5d94126c7e204af2835bc (diff)
downloadComputeLibrary-84797636b0ad44c16838df4177cf5a05aa929781.tar.gz
[COMPMID-1483] Add validate method to CLReshapeLayer
Change-Id: I33079e07acad83e0740c87b06546cc0f0f51301c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/145164 Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
-rw-r--r--arm_compute/core/CL/kernels/CLReshapeLayerKernel.h9
-rw-r--r--arm_compute/runtime/CL/functions/CLReshapeLayer.h9
-rw-r--r--src/core/CL/kernels/CLReshapeLayerKernel.cpp46
-rw-r--r--src/runtime/CL/functions/CLReshapeLayer.cpp7
-rw-r--r--tests/validation/CL/ReshapeLayer.cpp32
-rw-r--r--tests/validation/NEON/ReshapeLayer.cpp32
6 files changed, 116 insertions, 19 deletions
diff --git a/arm_compute/core/CL/kernels/CLReshapeLayerKernel.h b/arm_compute/core/CL/kernels/CLReshapeLayerKernel.h
index b253d66f4f..7bf5e6efb4 100644
--- a/arm_compute/core/CL/kernels/CLReshapeLayerKernel.h
+++ b/arm_compute/core/CL/kernels/CLReshapeLayerKernel.h
@@ -54,6 +54,15 @@ public:
*/
void configure(const ICLTensor *input, ICLTensor *output);
+ /** Static function to check if given info will lead to a valid configuration of @ref CLReshapeLayerKernel
+ *
+ * @param[in] input Source tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
+ * @param[in] output Destination tensor info. Data type supported: Same as @p input
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input, const ITensorInfo *output);
+
// Inherited methods overridden:
void run(const Window &window, cl::CommandQueue &queue) override;
diff --git a/arm_compute/runtime/CL/functions/CLReshapeLayer.h b/arm_compute/runtime/CL/functions/CLReshapeLayer.h
index cf5f7e5e15..82daa236c1 100644
--- a/arm_compute/runtime/CL/functions/CLReshapeLayer.h
+++ b/arm_compute/runtime/CL/functions/CLReshapeLayer.h
@@ -40,6 +40,15 @@ public:
* @param[out] output Output tensor. Data type supported: Same as @p input
*/
void configure(const ICLTensor *input, ICLTensor *output);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref CLReshapeLayer
+ *
+ * @param[in] input First tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
+ * @param[in] output Output tensor info. Data type supported: Same as @p input
+ *
+ * @return a status
+ */
+ static Status validate(const ITensorInfo *input, const ITensorInfo *output);
};
}
#endif /*__ARM_COMPUTE_CLRESHAPELAYER_H__ */
diff --git a/src/core/CL/kernels/CLReshapeLayerKernel.cpp b/src/core/CL/kernels/CLReshapeLayerKernel.cpp
index c7efa9a82d..a275e9e874 100644
--- a/src/core/CL/kernels/CLReshapeLayerKernel.cpp
+++ b/src/core/CL/kernels/CLReshapeLayerKernel.cpp
@@ -39,6 +39,25 @@
using namespace arm_compute;
+namespace
+{
+Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QASYMM8,
+ DataType::U16, DataType::S16,
+ DataType::U32, DataType::S32, DataType::F16, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
+
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().total_size() != output->tensor_shape().total_size());
+
+ return Status{};
+}
+
+} // namespace
+
CLReshapeLayerKernel::CLReshapeLayerKernel()
: _input(nullptr), _output(nullptr)
{
@@ -46,20 +65,12 @@ CLReshapeLayerKernel::CLReshapeLayerKernel()
void CLReshapeLayerKernel::configure(const ICLTensor *input, ICLTensor *output)
{
- ARM_COMPUTE_ERROR_ON_F16_UNSUPPORTED(input);
- ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QASYMM8,
- DataType::U16, DataType::S16,
- DataType::U32, DataType::S32, DataType::F16, DataType::F32);
- ARM_COMPUTE_ERROR_ON_NULLPTR(output);
- ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- ARM_COMPUTE_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output);
- ARM_COMPUTE_ERROR_ON(input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size());
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
_input = input;
_output = output;
- constexpr unsigned int num_elems_processed_per_iteration = 1;
-
// Create kernel
std::set<std::string> build_opts = { "-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()) };
_kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("reshape_layer", build_opts));
@@ -84,15 +95,18 @@ void CLReshapeLayerKernel::configure(const ICLTensor *input, ICLTensor *output)
_kernel.setArg<cl_int2>(idx++, output_shape);
// Configure kernel window
- Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
+ Window win = calculate_max_window(*input->info());
- AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
- AccessWindowStatic output_access(output->info(), 0, 0, output->info()->tensor_shape().x(), output->info()->tensor_shape().y());
- update_window_and_padding(win, input_access, output_access);
+ // Set the output valid region
+ output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
+ ICLKernel::configure_internal(win);
+}
- output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
+Status CLReshapeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
+{
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
- ICLKernel::configure_internal(win);
+ return Status{};
}
void CLReshapeLayerKernel::run(const Window &window, cl::CommandQueue &queue)
diff --git a/src/runtime/CL/functions/CLReshapeLayer.cpp b/src/runtime/CL/functions/CLReshapeLayer.cpp
index 2ce83dceb4..b1ca7a821d 100644
--- a/src/runtime/CL/functions/CLReshapeLayer.cpp
+++ b/src/runtime/CL/functions/CLReshapeLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -35,3 +35,8 @@ void CLReshapeLayer::configure(const ICLTensor *input, ICLTensor *output)
k->configure(input, output);
_kernel = std::move(k);
}
+
+Status CLReshapeLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
+{
+ return CLReshapeLayerKernel::validate(input, output);
+}
diff --git a/tests/validation/CL/ReshapeLayer.cpp b/tests/validation/CL/ReshapeLayer.cpp
index 740b53ebe0..0c27084065 100644
--- a/tests/validation/CL/ReshapeLayer.cpp
+++ b/tests/validation/CL/ReshapeLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -44,6 +44,36 @@ namespace validation
TEST_SUITE(CL)
TEST_SUITE(ReshapeLayer)
+// *INDENT-OFF*
+// clang-format off
+
+DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
+ framework::dataset::make("InputInfo",
+{
+ TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32), // mismatching dimensions
+ TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F16), // mismatching types
+}),
+framework::dataset::make("OutputInfo",
+{
+ TensorInfo(TensorShape(9U, 5U, 21U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 24U, 4U), 1, DataType::F32),
+ TensorInfo(TensorShape(192U, 192U), 1, DataType::F32),
+ TensorInfo(TensorShape(9U, 5U, 21U), 1, DataType::F32),
+})),
+framework::dataset::make("Expected", { true, true, false, false })),
+input_info, output_info, expected)
+{
+ // Create Fully Connected layer info
+ Status status = CLReshapeLayer::validate(&input_info.clone()->set_is_resizable(false),
+ &output_info.clone()->set_is_resizable(false));
+ ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
+}
+
+// clang-format on
+// *INDENT-ON*
+
template <typename T>
using CLReshapeLayerFixture = ReshapeLayerValidationFixture<CLTensor, CLAccessor, CLReshapeLayer, T>;
diff --git a/tests/validation/NEON/ReshapeLayer.cpp b/tests/validation/NEON/ReshapeLayer.cpp
index 0ad65119e7..3d1e0e618b 100644
--- a/tests/validation/NEON/ReshapeLayer.cpp
+++ b/tests/validation/NEON/ReshapeLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -44,6 +44,36 @@ namespace validation
TEST_SUITE(NEON)
TEST_SUITE(ReshapeLayer)
+// *INDENT-OFF*
+// clang-format off
+
+DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
+ framework::dataset::make("InputInfo",
+{
+ TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32), // mismatching dimensions
+ TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F16), // mismatching types
+}),
+framework::dataset::make("OutputInfo",
+{
+ TensorInfo(TensorShape(9U, 5U, 21U), 1, DataType::F32),
+ TensorInfo(TensorShape(8U, 24U, 4U), 1, DataType::F32),
+ TensorInfo(TensorShape(192U, 192U), 1, DataType::F32),
+ TensorInfo(TensorShape(9U, 5U, 21U), 1, DataType::F32),
+})),
+framework::dataset::make("Expected", { true, true, false, false })),
+input_info, output_info, expected)
+{
+ // Create Fully Connected layer info
+ Status status = NEReshapeLayer::validate(&input_info.clone()->set_is_resizable(false),
+ &output_info.clone()->set_is_resizable(false));
+ ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
+}
+
+// clang-format on
+// *INDENT-ON*
+
template <typename T>
using NEReshapeLayerFixture = ReshapeLayerValidationFixture<Tensor, Accessor, NEReshapeLayer, T>;