aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/fixtures/ConvolutionFixture.h
diff options
context:
space:
mode:
authorSanghoon Lee <sanghoon.lee@arm.com>2017-12-13 11:28:50 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commitd7ba5397b676c966cb5069c7187a12a0c35305f5 (patch)
treeab95a7e64c44b3505eec3e845a5fe049ae5ba66d /tests/validation/fixtures/ConvolutionFixture.h
parent6db0ff5b4bb49f834c7caa532a7feab228df10f9 (diff)
downloadComputeLibrary-d7ba5397b676c966cb5069c7187a12a0c35305f5.tar.gz
COMPMID-727 - Implement reference and CL/NEON validation for CustomConvolutionRectangle
Change-Id: I108a48ad5e6dc3f331fd5ceb38ced8ccdb31d81a Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/113130 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests/validation/fixtures/ConvolutionFixture.h')
-rw-r--r--tests/validation/fixtures/ConvolutionFixture.h130
1 files changed, 92 insertions, 38 deletions
diff --git a/tests/validation/fixtures/ConvolutionFixture.h b/tests/validation/fixtures/ConvolutionFixture.h
index 8bf6ea26a8..114d38a21a 100644
--- a/tests/validation/fixtures/ConvolutionFixture.h
+++ b/tests/validation/fixtures/ConvolutionFixture.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017, 2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -41,44 +41,40 @@ namespace test
{
namespace validation
{
-template <typename TensorType, typename AccessorType, typename FunctionType, typename T, const unsigned int filter_size>
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
class ConvolutionValidationFixture : public framework::Fixture
{
-public:
+protected:
template <typename...>
- void setup(TensorShape shape, DataType data_type, BorderMode border_mode)
+ void setup(TensorShape shape, DataType data_type, BorderMode border_mode, const unsigned int width, const unsigned int height)
{
std::mt19937 gen(library->seed());
std::uniform_int_distribution<uint8_t> distribution(0, 255);
const uint8_t constant_border_value = distribution(gen);
- // Generate random scale value between 0 and 255.
- const uint32_t scale = distribution(gen);
+ // Generate random scale value between 1 and 255.
+ std::uniform_int_distribution<uint8_t> distribution_scale(1, 255);
+ const uint32_t scale = distribution_scale(gen);
- switch(filter_size)
- {
- case 3:
- case 5:
- case 7:
- case 9:
- int16_t conv[filter_size * filter_size];
- create_conv(conv);
-
- _target = compute_target(shape, data_type, conv, scale, border_mode, constant_border_value);
- _reference = compute_reference(shape, data_type, conv, scale, border_mode, constant_border_value);
- break;
- default:
- ARM_COMPUTE_ERROR("Filter Size Not Supported");
- }
+ ARM_COMPUTE_ERROR_ON(3 != width && 5 != width && 7 != width && 9 != width);
+ ARM_COMPUTE_ERROR_ON(3 != height && 5 != height && 7 != height && 9 != height);
+
+ int16_t conv[width * height];
+ create_conv(conv);
+
+ _width = width;
+ _height = height;
+ _target = compute_target(shape, data_type, conv, scale, border_mode, constant_border_value);
+ _reference = compute_reference(shape, data_type, conv, scale, border_mode, constant_border_value);
}
-protected:
- void create_conv(int16_t *conv)
+ void
+ create_conv(int16_t *conv)
{
std::mt19937 gen(library->seed());
std::uniform_int_distribution<int16_t> distribution_int16(-32768, 32767);
- for(unsigned int i = 0; i < filter_size * filter_size; ++i)
+ for(unsigned int i = 0; i < _width * _height; ++i)
{
conv[i] = distribution_int16(gen);
}
@@ -90,6 +86,40 @@ protected:
library->fill_tensor_uniform(tensor, i);
}
+ SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value)
+ {
+ ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
+
+ // Create reference
+ SimpleTensor<T> src{ shape, data_type };
+
+ // Fill reference
+ fill(src, 0);
+
+ // Compute reference
+ return reference::convolution<T>(src, conv, scale, border_mode, constant_border_value, _width, _height);
+ }
+
+ virtual TensorType compute_target(const TensorShape &shape, DataType data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value) = 0;
+
+ BorderMode _border_mode{};
+ TensorType _target{};
+ SimpleTensor<T> _reference{};
+ unsigned int _width{};
+ unsigned int _height{};
+};
+
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+class ConvolutionSquareValidationFixture : public ConvolutionValidationFixture<TensorType, AccessorType, FunctionType, T>
+{
+public:
+ template <typename...>
+ void setup(TensorShape shape, DataType data_type, BorderMode border_mode, const unsigned int width)
+ {
+ ConvolutionValidationFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type, border_mode, width, width);
+ }
+
+protected:
TensorType compute_target(const TensorShape &shape, DataType data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value)
{
// Create tensors
@@ -111,32 +141,56 @@ protected:
ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
// Fill tensors
- fill(AccessorType(src), 0);
- fill(AccessorType(dst), 1);
+ this->fill(AccessorType(src), 0);
+ this->fill(AccessorType(dst), 1);
// Compute function
convolution.run();
return dst;
}
+};
- SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value)
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+class ConvolutionRectangleValidationFixture : public ConvolutionValidationFixture<TensorType, AccessorType, FunctionType, T>
+{
+public:
+ template <typename...>
+ void setup(TensorShape shape, DataType data_type, BorderMode border_mode, const unsigned int width, const unsigned int height)
{
- ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
+ ConvolutionValidationFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type, border_mode, width, height);
+ }
- // Create reference
- SimpleTensor<T> src{ shape, data_type };
+protected:
+ TensorType compute_target(const TensorShape &shape, DataType data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value)
+ {
+ // Create tensors
+ TensorType src = create_tensor<TensorType>(shape, data_type);
+ TensorType dst = create_tensor<TensorType>(shape, data_type);
- // Fill reference
- fill(src, 0);
+ // Create and configure function
+ FunctionType convolution;
+ convolution.configure(&src, &dst, conv, this->_width, this->_height, scale, border_mode, constant_border_value);
- // Compute reference
- return reference::convolution<T>(src, conv, scale, border_mode, constant_border_value, filter_size);
- }
+ ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
- BorderMode _border_mode{};
- TensorType _target{};
- SimpleTensor<T> _reference{};
+ // 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
+ this->fill(AccessorType(src), 0);
+ this->fill(AccessorType(dst), 1);
+
+ // Compute function
+ convolution.run();
+
+ return dst;
+ }
};
} // namespace validation
} // namespace test