From 2213d4b334567d0cb7f283090d42b5fb1b70f66b Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Fri, 27 Apr 2018 10:39:06 +0100 Subject: COMPMID-1096 - Add fast_math flag to CLConvolutionLayer COMPMID-1103 - CLWinogradConvolutionLayer mismatches Change-Id: Iceaa9482a1790ec39d2720c220261aaea8043978 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129398 Tested-by: Jenkins Reviewed-by: Giorgio Arena Reviewed-by: Georgios Pinitas --- .../fixtures/WinogradConvolutionLayerFixture.h | 122 ++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) (limited to 'tests/validation/fixtures/WinogradConvolutionLayerFixture.h') diff --git a/tests/validation/fixtures/WinogradConvolutionLayerFixture.h b/tests/validation/fixtures/WinogradConvolutionLayerFixture.h index 249f9d5649..e15931eafb 100644 --- a/tests/validation/fixtures/WinogradConvolutionLayerFixture.h +++ b/tests/validation/fixtures/WinogradConvolutionLayerFixture.h @@ -35,6 +35,7 @@ #include "tests/validation/Helpers.h" #include "tests/validation/reference/ActivationLayer.h" #include "tests/validation/reference/ConvolutionLayer.h" +#include "tests/validation/reference/GEMM.h" #include "tests/validation/reference/Utils.h" #include "tests/validation/reference/Winograd.h" @@ -152,6 +153,123 @@ protected: SimpleTensor _reference{}; }; +template +class WinogradConvolutionLayerFastMathValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, DataType data_type, ActivationLayerInfo act_info) + { + ARM_COMPUTE_UNUSED(dilation); + + _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info); + _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info); + } + +protected: + template + void fill(U &&tensor, int i, float min, float max) + { + switch(tensor.data_type()) + { + case DataType::F32: + { + std::uniform_real_distribution<> distribution(min, max); + library->fill(tensor, distribution, i); + break; + } + default: + { + ARM_COMPUTE_ERROR("Not supported"); + library->fill_tensor_uniform(tensor, i); + break; + } + } + } + + TensorType compute_target(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, + DataType data_type, ActivationLayerInfo act_info) + { + // Create tensors + TensorType src = create_tensor(input_shape, data_type, 1); + TensorType weights = create_tensor(weights_shape, data_type, 1); + TensorType bias = create_tensor(bias_shape, data_type, 1); + TensorType dst = create_tensor(output_shape, data_type, 1); + + // Create and configure function + FunctionType conv; + ARM_COMPUTE_EXPECT(static_cast(conv.validate(src.info(), weights.info(), bias.info(), dst.info(), info, act_info, true /* Enable fast math */)), framework::LogLevel::ERRORS); + conv.configure(&src, &weights, &bias, &dst, info, act_info, true /* Enable fast math */); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + weights.allocator()->allocate(); + dst.allocator()->allocate(); + bias.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!bias.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src), 0, -1.f, 1.f); + fill(AccessorType(weights), 1, -1.f, 1.f); + fill(AccessorType(bias), 2, -1.f, 1.f); + + // Compute Winograd Convolution function + conv.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, + DataType data_type, ActivationLayerInfo act_info) + { + // Create reference + SimpleTensor src{ input_shape, data_type, 1 }; + SimpleTensor weights{ weights_shape, data_type, 1 }; + SimpleTensor bias{ bias_shape, data_type, 1 }; + + // Fill reference + fill(src, 0, -1.f, 1.f); + fill(weights, 1, -1.f, 1.f); + fill(bias, 2, -1.f, 1.f); + + WinogradInfo winograd_info(Size2D(4U, 4U), + Size2D(weights_shape[0], weights_shape[1]), + Size2D(input_shape[0], input_shape[1]), + info, + src.data_layout()); + + // Compute tensor shapes for input, filter and output transforms + TensorShape input_transform_shape = compute_winograd_input_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); + TensorShape filter_transform_shape = compute_winograd_filter_transform_shape(TensorInfo(weights_shape, 1, data_type), winograd_info); + TensorShape batched_gemm_shape = input_transform_shape; + batched_gemm_shape[0] = filter_transform_shape[0]; + TensorShape output_transform_shape = compute_winograd_output_transform_shape(TensorInfo(batched_gemm_shape, 1, data_type), winograd_info); + + // Dummy matrix C to perform matrix multiplication + SimpleTensor dummy_c{ batched_gemm_shape, data_type, 1 }; + + // Compute Winograd-based convolution + SimpleTensor input_transform_out = reference::winograd_input_transform(src, input_transform_shape, winograd_info); + SimpleTensor filter_transform_out = reference::winograd_filter_transform(weights, filter_transform_shape, winograd_info); + SimpleTensor batched_gemm = reference::gemm(input_transform_out, filter_transform_out, dummy_c, 1.0f, 0.0f); + SimpleTensor conv_out = reference::winograd_output_transform(batched_gemm, bias, output_transform_shape, winograd_info); + + return (act_info.enabled()) ? reference::activation_layer(conv_out, act_info) : conv_out; + } + + TensorType _target{}; + SimpleTensor _reference{}; +}; + template class WinogradInputTransformValidationFixture : public framework::Fixture { @@ -373,11 +491,13 @@ protected: { // Create reference SimpleTensor src{ input_shape, data_type }; + SimpleTensor bias{ TensorShape(input_shape[0]), data_type }; // Fill reference fill(src, 0, -1.f, 1.f); + fill(bias, 1, 0.0f, 0.0f); // Fill with zeros as we validate just the output transform without bias contribution - return reference::winograd_output_transform(src, output_shape, winograd_info); + return reference::winograd_output_transform(src, bias, output_shape, winograd_info); } TensorType _target{}; -- cgit v1.2.1