From 5a7e776eee2e9147eab12631f5717847fb6cac5c Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 1 Dec 2017 16:27:29 +0000 Subject: COMPMID-556: Rename CPP folder to reference Change-Id: I147644349547c4e3804a80b564a9ad95131ad2d0 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/111560 Reviewed-by: Michalis Spyrou Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com --- tests/SConscript | 2 +- tests/validation/CL/WarpAffine.cpp | 2 +- tests/validation/CPP/AbsoluteDifference.cpp | 60 ---- tests/validation/CPP/AbsoluteDifference.h | 44 --- tests/validation/CPP/Accumulate.cpp | 103 ------- tests/validation/CPP/Accumulate.h | 50 ---- tests/validation/CPP/ActivationLayer.cpp | 164 ----------- tests/validation/CPP/ActivationLayer.h | 47 ---- tests/validation/CPP/ArithmeticAddition.cpp | 63 ----- tests/validation/CPP/ArithmeticAddition.h | 44 --- tests/validation/CPP/ArithmeticSubtraction.cpp | 64 ----- tests/validation/CPP/ArithmeticSubtraction.h | 44 --- tests/validation/CPP/BatchNormalizationLayer.cpp | 125 --------- tests/validation/CPP/BatchNormalizationLayer.h | 49 ---- tests/validation/CPP/BitwiseAnd.cpp | 51 ---- tests/validation/CPP/BitwiseAnd.h | 43 --- tests/validation/CPP/BitwiseNot.cpp | 51 ---- tests/validation/CPP/BitwiseNot.h | 43 --- tests/validation/CPP/BitwiseOr.cpp | 51 ---- tests/validation/CPP/BitwiseOr.h | 43 --- tests/validation/CPP/BitwiseXor.cpp | 51 ---- tests/validation/CPP/BitwiseXor.h | 43 --- tests/validation/CPP/Box3x3.cpp | 55 ---- tests/validation/CPP/Box3x3.h | 43 --- tests/validation/CPP/ConvolutionLayer.cpp | 293 -------------------- tests/validation/CPP/ConvolutionLayer.h | 44 --- tests/validation/CPP/DeconvolutionLayer.cpp | 107 -------- tests/validation/CPP/DeconvolutionLayer.h | 55 ---- tests/validation/CPP/DepthConcatenateLayer.cpp | 103 ------- tests/validation/CPP/DepthConcatenateLayer.h | 45 --- tests/validation/CPP/DepthConvertLayer.cpp | 157 ----------- tests/validation/CPP/DepthConvertLayer.h | 56 ---- tests/validation/CPP/DepthwiseConvolutionLayer.cpp | 195 ------------- tests/validation/CPP/DepthwiseConvolutionLayer.h | 44 --- .../CPP/DepthwiseSeparableConvolutionLayer.cpp | 62 ----- .../CPP/DepthwiseSeparableConvolutionLayer.h | 47 ---- tests/validation/CPP/DequantizationLayer.cpp | 67 ----- tests/validation/CPP/DequantizationLayer.h | 44 --- tests/validation/CPP/Dilate.cpp | 81 ------ tests/validation/CPP/Dilate.h | 43 --- tests/validation/CPP/Erode.cpp | 81 ------ tests/validation/CPP/Erode.h | 43 --- tests/validation/CPP/FixedPoint.cpp | 83 ------ tests/validation/CPP/FixedPoint.h | 44 --- .../CPP/FixedPointPixelWiseMultiplication.cpp | 85 ------ .../CPP/FixedPointPixelWiseMultiplication.h | 43 --- tests/validation/CPP/FlattenLayer.cpp | 58 ---- tests/validation/CPP/FlattenLayer.h | 44 --- tests/validation/CPP/Floor.cpp | 57 ---- tests/validation/CPP/Floor.h | 44 --- tests/validation/CPP/FullyConnectedLayer.cpp | 201 -------------- tests/validation/CPP/FullyConnectedLayer.h | 44 --- tests/validation/CPP/GEMM.cpp | 122 --------- tests/validation/CPP/GEMM.h | 47 ---- tests/validation/CPP/GEMMInterleave4x4.h | 89 ------ tests/validation/CPP/GEMMInterleaveBlocked.h | 82 ------ tests/validation/CPP/GEMMLowp.cpp | 208 -------------- tests/validation/CPP/GEMMLowp.h | 65 ----- tests/validation/CPP/Gaussian3x3.cpp | 55 ---- tests/validation/CPP/Gaussian3x3.h | 43 --- tests/validation/CPP/Gaussian5x5.cpp | 61 ----- tests/validation/CPP/Gaussian5x5.h | 43 --- tests/validation/CPP/GaussianPyramidHalf.cpp | 67 ----- tests/validation/CPP/GaussianPyramidHalf.h | 43 --- tests/validation/CPP/HarrisCornerDetector.cpp | 205 -------------- tests/validation/CPP/HarrisCornerDetector.h | 47 ---- tests/validation/CPP/Histogram.cpp | 65 ----- tests/validation/CPP/Histogram.h | 43 --- tests/validation/CPP/IntegralImage.cpp | 86 ------ tests/validation/CPP/IntegralImage.h | 43 --- tests/validation/CPP/L2NormalizeLayer.cpp | 88 ------ tests/validation/CPP/L2NormalizeLayer.h | 44 --- tests/validation/CPP/Magnitude.cpp | 68 ----- tests/validation/CPP/Magnitude.h | 43 --- tests/validation/CPP/MeanStdDev.cpp | 57 ---- tests/validation/CPP/MeanStdDev.h | 43 --- tests/validation/CPP/Median3x3.cpp | 76 ------ tests/validation/CPP/Median3x3.h | 43 --- tests/validation/CPP/MinMaxLocation.cpp | 92 ------- tests/validation/CPP/MinMaxLocation.h | 44 --- tests/validation/CPP/NonLinearFilter.cpp | 104 ------- tests/validation/CPP/NonLinearFilter.h | 44 --- tests/validation/CPP/NonMaximaSuppression.cpp | 75 ----- tests/validation/CPP/NonMaximaSuppression.h | 44 --- tests/validation/CPP/NormalizationLayer.cpp | 275 ------------------- tests/validation/CPP/NormalizationLayer.h | 47 ---- tests/validation/CPP/Phase.cpp | 66 ----- tests/validation/CPP/Phase.h | 43 --- tests/validation/CPP/PixelWiseMultiplication.cpp | 100 ------- tests/validation/CPP/PixelWiseMultiplication.h | 43 --- tests/validation/CPP/PoolingLayer.cpp | 302 --------------------- tests/validation/CPP/PoolingLayer.h | 47 ---- tests/validation/CPP/QuantizationLayer.cpp | 87 ------ tests/validation/CPP/QuantizationLayer.h | 44 --- tests/validation/CPP/ReductionOperation.cpp | 93 ------- tests/validation/CPP/ReductionOperation.h | 44 --- tests/validation/CPP/Remap.cpp | 106 -------- tests/validation/CPP/Remap.h | 44 --- tests/validation/CPP/ReshapeLayer.cpp | 57 ---- tests/validation/CPP/ReshapeLayer.h | 43 --- tests/validation/CPP/Scale.cpp | 182 ------------- tests/validation/CPP/Scale.h | 44 --- tests/validation/CPP/Scharr.cpp | 105 ------- tests/validation/CPP/Scharr.h | 44 --- tests/validation/CPP/Sobel.cpp | 152 ----------- tests/validation/CPP/Sobel.h | 45 --- tests/validation/CPP/SoftmaxLayer.cpp | 134 --------- tests/validation/CPP/SoftmaxLayer.h | 47 ---- tests/validation/CPP/TableLookup.cpp | 54 ---- tests/validation/CPP/TableLookup.h | 44 --- tests/validation/CPP/Threshold.cpp | 76 ------ tests/validation/CPP/Threshold.h | 43 --- tests/validation/CPP/Transpose.cpp | 66 ----- tests/validation/CPP/Transpose.h | 43 --- tests/validation/CPP/Utils.cpp | 112 -------- tests/validation/CPP/Utils.h | 143 ---------- tests/validation/CPP/UtilsQuantizedAsymm.h | 57 ---- tests/validation/CPP/WarpAffine.cpp | 135 --------- tests/validation/CPP/WarpAffine.h | 43 --- tests/validation/CPP/WarpPerspective.cpp | 132 --------- tests/validation/CPP/WarpPerspective.h | 43 --- tests/validation/NEON/GaussianPyramid.cpp | 2 +- tests/validation/NEON/WarpAffine.cpp | 2 +- .../fixtures/AbsoluteDifferenceFixture.h | 2 +- tests/validation/fixtures/AccumulateFixture.h | 2 +- tests/validation/fixtures/ActivationLayerFixture.h | 2 +- .../fixtures/ArithmeticAdditionFixture.h | 2 +- .../fixtures/ArithmeticSubtractionFixture.h | 2 +- .../fixtures/BatchNormalizationLayerFixture.h | 2 +- tests/validation/fixtures/BitwiseAndFixture.h | 2 +- tests/validation/fixtures/BitwiseNotFixture.h | 2 +- tests/validation/fixtures/BitwiseOrFixture.h | 2 +- tests/validation/fixtures/BitwiseXorFixture.h | 2 +- tests/validation/fixtures/Box3x3Fixture.h | 2 +- .../validation/fixtures/ConvolutionLayerFixture.h | 4 +- .../fixtures/DeconvolutionLayerFixture.h | 2 +- .../fixtures/DepthConcatenateLayerFixture.h | 2 +- .../validation/fixtures/DepthConvertLayerFixture.h | 2 +- .../fixtures/DepthwiseConvolutionLayerFixture.h | 2 +- .../DepthwiseSeparableConvolutionLayerFixture.h | 2 +- .../fixtures/DequantizationLayerFixture.h | 2 +- tests/validation/fixtures/DilateFixture.h | 2 +- .../fixtures/DirectConvolutionLayerFixture.h | 2 +- tests/validation/fixtures/ErodeFixture.h | 2 +- tests/validation/fixtures/FixedPointFixture.h | 2 +- .../FixedPointPixelWiseMultiplicationFixture.h | 2 +- tests/validation/fixtures/FlattenLayerFixture.h | 2 +- tests/validation/fixtures/FloorFixture.h | 2 +- .../fixtures/FullyConnectedLayerFixture.h | 4 +- tests/validation/fixtures/GEMMFixture.h | 2 +- .../validation/fixtures/GEMMInterleave4x4Fixture.h | 2 +- .../fixtures/GEMMInterleaveBlockedFixture.h | 2 +- .../validation/fixtures/GEMMLowpAssemblyFixture.h | 2 +- tests/validation/fixtures/GEMMLowpFixture.h | 2 +- tests/validation/fixtures/Gaussian3x3Fixture.h | 2 +- tests/validation/fixtures/Gaussian5x5Fixture.h | 2 +- .../fixtures/GaussianPyramidHalfFixture.h | 2 +- tests/validation/fixtures/HarrisCornersFixture.h | 2 +- tests/validation/fixtures/HistogramFixture.h | 2 +- tests/validation/fixtures/IntegralImageFixture.h | 2 +- .../validation/fixtures/L2NormalizeLayerFixture.h | 2 +- tests/validation/fixtures/MagnitudeFixture.h | 2 +- tests/validation/fixtures/MeanStdDevFixture.h | 2 +- tests/validation/fixtures/Median3x3Fixture.h | 2 +- tests/validation/fixtures/MinMaxLocationFixture.h | 2 +- tests/validation/fixtures/NonLinearFilterFixture.h | 2 +- .../fixtures/NormalizationLayerFixture.h | 2 +- tests/validation/fixtures/PhaseFixture.h | 2 +- .../fixtures/PixelWiseMultiplicationFixture.h | 2 +- tests/validation/fixtures/PoolingLayerFixture.h | 2 +- .../validation/fixtures/QuantizationLayerFixture.h | 2 +- .../fixtures/ReductionOperationFixture.h | 2 +- tests/validation/fixtures/RemapFixture.h | 2 +- tests/validation/fixtures/ReshapeLayerFixture.h | 2 +- tests/validation/fixtures/ScaleFixture.h | 2 +- tests/validation/fixtures/ScharrFixture.h | 2 +- tests/validation/fixtures/SobelFixture.h | 2 +- tests/validation/fixtures/SoftmaxLayerFixture.h | 2 +- tests/validation/fixtures/TableLookupFixture.h | 2 +- tests/validation/fixtures/ThresholdFixture.h | 2 +- tests/validation/fixtures/TransposeFixture.h | 2 +- tests/validation/fixtures/WarpAffineFixture.h | 4 +- tests/validation/fixtures/WarpPerspectiveFixture.h | 4 +- tests/validation/fixtures/WinogradLayerFixture.h | 4 +- tests/validation/reference/AbsoluteDifference.cpp | 60 ++++ tests/validation/reference/AbsoluteDifference.h | 44 +++ tests/validation/reference/Accumulate.cpp | 103 +++++++ tests/validation/reference/Accumulate.h | 50 ++++ tests/validation/reference/ActivationLayer.cpp | 164 +++++++++++ tests/validation/reference/ActivationLayer.h | 47 ++++ tests/validation/reference/ArithmeticAddition.cpp | 63 +++++ tests/validation/reference/ArithmeticAddition.h | 44 +++ .../validation/reference/ArithmeticSubtraction.cpp | 64 +++++ tests/validation/reference/ArithmeticSubtraction.h | 44 +++ .../reference/BatchNormalizationLayer.cpp | 125 +++++++++ .../validation/reference/BatchNormalizationLayer.h | 49 ++++ tests/validation/reference/BitwiseAnd.cpp | 51 ++++ tests/validation/reference/BitwiseAnd.h | 43 +++ tests/validation/reference/BitwiseNot.cpp | 51 ++++ tests/validation/reference/BitwiseNot.h | 43 +++ tests/validation/reference/BitwiseOr.cpp | 51 ++++ tests/validation/reference/BitwiseOr.h | 43 +++ tests/validation/reference/BitwiseXor.cpp | 51 ++++ tests/validation/reference/BitwiseXor.h | 43 +++ tests/validation/reference/Box3x3.cpp | 55 ++++ tests/validation/reference/Box3x3.h | 43 +++ tests/validation/reference/ConvolutionLayer.cpp | 293 ++++++++++++++++++++ tests/validation/reference/ConvolutionLayer.h | 44 +++ tests/validation/reference/DeconvolutionLayer.cpp | 107 ++++++++ tests/validation/reference/DeconvolutionLayer.h | 55 ++++ .../validation/reference/DepthConcatenateLayer.cpp | 103 +++++++ tests/validation/reference/DepthConcatenateLayer.h | 45 +++ tests/validation/reference/DepthConvertLayer.cpp | 157 +++++++++++ tests/validation/reference/DepthConvertLayer.h | 56 ++++ .../reference/DepthwiseConvolutionLayer.cpp | 195 +++++++++++++ .../reference/DepthwiseConvolutionLayer.h | 44 +++ .../DepthwiseSeparableConvolutionLayer.cpp | 62 +++++ .../reference/DepthwiseSeparableConvolutionLayer.h | 47 ++++ tests/validation/reference/DequantizationLayer.cpp | 67 +++++ tests/validation/reference/DequantizationLayer.h | 44 +++ tests/validation/reference/Dilate.cpp | 81 ++++++ tests/validation/reference/Dilate.h | 43 +++ tests/validation/reference/Erode.cpp | 81 ++++++ tests/validation/reference/Erode.h | 43 +++ tests/validation/reference/FixedPoint.cpp | 83 ++++++ tests/validation/reference/FixedPoint.h | 44 +++ .../FixedPointPixelWiseMultiplication.cpp | 85 ++++++ .../reference/FixedPointPixelWiseMultiplication.h | 43 +++ tests/validation/reference/FlattenLayer.cpp | 58 ++++ tests/validation/reference/FlattenLayer.h | 44 +++ tests/validation/reference/Floor.cpp | 57 ++++ tests/validation/reference/Floor.h | 44 +++ tests/validation/reference/FullyConnectedLayer.cpp | 201 ++++++++++++++ tests/validation/reference/FullyConnectedLayer.h | 44 +++ tests/validation/reference/GEMM.cpp | 122 +++++++++ tests/validation/reference/GEMM.h | 47 ++++ tests/validation/reference/GEMMInterleave4x4.h | 89 ++++++ tests/validation/reference/GEMMInterleaveBlocked.h | 82 ++++++ tests/validation/reference/GEMMLowp.cpp | 208 ++++++++++++++ tests/validation/reference/GEMMLowp.h | 65 +++++ tests/validation/reference/Gaussian3x3.cpp | 55 ++++ tests/validation/reference/Gaussian3x3.h | 43 +++ tests/validation/reference/Gaussian5x5.cpp | 61 +++++ tests/validation/reference/Gaussian5x5.h | 43 +++ tests/validation/reference/GaussianPyramidHalf.cpp | 67 +++++ tests/validation/reference/GaussianPyramidHalf.h | 43 +++ .../validation/reference/HarrisCornerDetector.cpp | 205 ++++++++++++++ tests/validation/reference/HarrisCornerDetector.h | 47 ++++ tests/validation/reference/Histogram.cpp | 65 +++++ tests/validation/reference/Histogram.h | 43 +++ tests/validation/reference/IntegralImage.cpp | 86 ++++++ tests/validation/reference/IntegralImage.h | 43 +++ tests/validation/reference/L2NormalizeLayer.cpp | 88 ++++++ tests/validation/reference/L2NormalizeLayer.h | 44 +++ tests/validation/reference/Magnitude.cpp | 68 +++++ tests/validation/reference/Magnitude.h | 43 +++ tests/validation/reference/MeanStdDev.cpp | 57 ++++ tests/validation/reference/MeanStdDev.h | 43 +++ tests/validation/reference/Median3x3.cpp | 76 ++++++ tests/validation/reference/Median3x3.h | 43 +++ tests/validation/reference/MinMaxLocation.cpp | 92 +++++++ tests/validation/reference/MinMaxLocation.h | 44 +++ tests/validation/reference/NonLinearFilter.cpp | 104 +++++++ tests/validation/reference/NonLinearFilter.h | 44 +++ .../validation/reference/NonMaximaSuppression.cpp | 75 +++++ tests/validation/reference/NonMaximaSuppression.h | 44 +++ tests/validation/reference/NormalizationLayer.cpp | 275 +++++++++++++++++++ tests/validation/reference/NormalizationLayer.h | 47 ++++ tests/validation/reference/Phase.cpp | 66 +++++ tests/validation/reference/Phase.h | 43 +++ .../reference/PixelWiseMultiplication.cpp | 100 +++++++ .../validation/reference/PixelWiseMultiplication.h | 43 +++ tests/validation/reference/PoolingLayer.cpp | 302 +++++++++++++++++++++ tests/validation/reference/PoolingLayer.h | 47 ++++ tests/validation/reference/QuantizationLayer.cpp | 87 ++++++ tests/validation/reference/QuantizationLayer.h | 44 +++ tests/validation/reference/ReductionOperation.cpp | 93 +++++++ tests/validation/reference/ReductionOperation.h | 44 +++ tests/validation/reference/Remap.cpp | 106 ++++++++ tests/validation/reference/Remap.h | 44 +++ tests/validation/reference/ReshapeLayer.cpp | 57 ++++ tests/validation/reference/ReshapeLayer.h | 43 +++ tests/validation/reference/Scale.cpp | 182 +++++++++++++ tests/validation/reference/Scale.h | 44 +++ tests/validation/reference/Scharr.cpp | 105 +++++++ tests/validation/reference/Scharr.h | 44 +++ tests/validation/reference/Sobel.cpp | 152 +++++++++++ tests/validation/reference/Sobel.h | 45 +++ tests/validation/reference/SoftmaxLayer.cpp | 134 +++++++++ tests/validation/reference/SoftmaxLayer.h | 47 ++++ tests/validation/reference/TableLookup.cpp | 54 ++++ tests/validation/reference/TableLookup.h | 44 +++ tests/validation/reference/Threshold.cpp | 76 ++++++ tests/validation/reference/Threshold.h | 43 +++ tests/validation/reference/Transpose.cpp | 66 +++++ tests/validation/reference/Transpose.h | 43 +++ tests/validation/reference/Utils.cpp | 112 ++++++++ tests/validation/reference/Utils.h | 143 ++++++++++ tests/validation/reference/UtilsQuantizedAsymm.h | 57 ++++ tests/validation/reference/WarpAffine.cpp | 135 +++++++++ tests/validation/reference/WarpAffine.h | 43 +++ tests/validation/reference/WarpPerspective.cpp | 132 +++++++++ tests/validation/reference/WarpPerspective.h | 43 +++ 303 files changed, 9135 insertions(+), 9135 deletions(-) delete mode 100644 tests/validation/CPP/AbsoluteDifference.cpp delete mode 100644 tests/validation/CPP/AbsoluteDifference.h delete mode 100644 tests/validation/CPP/Accumulate.cpp delete mode 100644 tests/validation/CPP/Accumulate.h delete mode 100644 tests/validation/CPP/ActivationLayer.cpp delete mode 100644 tests/validation/CPP/ActivationLayer.h delete mode 100644 tests/validation/CPP/ArithmeticAddition.cpp delete mode 100644 tests/validation/CPP/ArithmeticAddition.h delete mode 100644 tests/validation/CPP/ArithmeticSubtraction.cpp delete mode 100644 tests/validation/CPP/ArithmeticSubtraction.h delete mode 100644 tests/validation/CPP/BatchNormalizationLayer.cpp delete mode 100644 tests/validation/CPP/BatchNormalizationLayer.h delete mode 100644 tests/validation/CPP/BitwiseAnd.cpp delete mode 100644 tests/validation/CPP/BitwiseAnd.h delete mode 100644 tests/validation/CPP/BitwiseNot.cpp delete mode 100644 tests/validation/CPP/BitwiseNot.h delete mode 100644 tests/validation/CPP/BitwiseOr.cpp delete mode 100644 tests/validation/CPP/BitwiseOr.h delete mode 100644 tests/validation/CPP/BitwiseXor.cpp delete mode 100644 tests/validation/CPP/BitwiseXor.h delete mode 100644 tests/validation/CPP/Box3x3.cpp delete mode 100644 tests/validation/CPP/Box3x3.h delete mode 100644 tests/validation/CPP/ConvolutionLayer.cpp delete mode 100644 tests/validation/CPP/ConvolutionLayer.h delete mode 100644 tests/validation/CPP/DeconvolutionLayer.cpp delete mode 100644 tests/validation/CPP/DeconvolutionLayer.h delete mode 100644 tests/validation/CPP/DepthConcatenateLayer.cpp delete mode 100644 tests/validation/CPP/DepthConcatenateLayer.h delete mode 100644 tests/validation/CPP/DepthConvertLayer.cpp delete mode 100644 tests/validation/CPP/DepthConvertLayer.h delete mode 100644 tests/validation/CPP/DepthwiseConvolutionLayer.cpp delete mode 100644 tests/validation/CPP/DepthwiseConvolutionLayer.h delete mode 100644 tests/validation/CPP/DepthwiseSeparableConvolutionLayer.cpp delete mode 100644 tests/validation/CPP/DepthwiseSeparableConvolutionLayer.h delete mode 100644 tests/validation/CPP/DequantizationLayer.cpp delete mode 100644 tests/validation/CPP/DequantizationLayer.h delete mode 100644 tests/validation/CPP/Dilate.cpp delete mode 100644 tests/validation/CPP/Dilate.h delete mode 100644 tests/validation/CPP/Erode.cpp delete mode 100644 tests/validation/CPP/Erode.h delete mode 100644 tests/validation/CPP/FixedPoint.cpp delete mode 100644 tests/validation/CPP/FixedPoint.h delete mode 100644 tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp delete mode 100644 tests/validation/CPP/FixedPointPixelWiseMultiplication.h delete mode 100644 tests/validation/CPP/FlattenLayer.cpp delete mode 100644 tests/validation/CPP/FlattenLayer.h delete mode 100644 tests/validation/CPP/Floor.cpp delete mode 100644 tests/validation/CPP/Floor.h delete mode 100644 tests/validation/CPP/FullyConnectedLayer.cpp delete mode 100644 tests/validation/CPP/FullyConnectedLayer.h delete mode 100644 tests/validation/CPP/GEMM.cpp delete mode 100644 tests/validation/CPP/GEMM.h delete mode 100644 tests/validation/CPP/GEMMInterleave4x4.h delete mode 100644 tests/validation/CPP/GEMMInterleaveBlocked.h delete mode 100644 tests/validation/CPP/GEMMLowp.cpp delete mode 100644 tests/validation/CPP/GEMMLowp.h delete mode 100644 tests/validation/CPP/Gaussian3x3.cpp delete mode 100644 tests/validation/CPP/Gaussian3x3.h delete mode 100644 tests/validation/CPP/Gaussian5x5.cpp delete mode 100644 tests/validation/CPP/Gaussian5x5.h delete mode 100644 tests/validation/CPP/GaussianPyramidHalf.cpp delete mode 100644 tests/validation/CPP/GaussianPyramidHalf.h delete mode 100644 tests/validation/CPP/HarrisCornerDetector.cpp delete mode 100644 tests/validation/CPP/HarrisCornerDetector.h delete mode 100644 tests/validation/CPP/Histogram.cpp delete mode 100644 tests/validation/CPP/Histogram.h delete mode 100644 tests/validation/CPP/IntegralImage.cpp delete mode 100644 tests/validation/CPP/IntegralImage.h delete mode 100644 tests/validation/CPP/L2NormalizeLayer.cpp delete mode 100644 tests/validation/CPP/L2NormalizeLayer.h delete mode 100644 tests/validation/CPP/Magnitude.cpp delete mode 100644 tests/validation/CPP/Magnitude.h delete mode 100644 tests/validation/CPP/MeanStdDev.cpp delete mode 100644 tests/validation/CPP/MeanStdDev.h delete mode 100644 tests/validation/CPP/Median3x3.cpp delete mode 100644 tests/validation/CPP/Median3x3.h delete mode 100644 tests/validation/CPP/MinMaxLocation.cpp delete mode 100644 tests/validation/CPP/MinMaxLocation.h delete mode 100644 tests/validation/CPP/NonLinearFilter.cpp delete mode 100644 tests/validation/CPP/NonLinearFilter.h delete mode 100644 tests/validation/CPP/NonMaximaSuppression.cpp delete mode 100644 tests/validation/CPP/NonMaximaSuppression.h delete mode 100644 tests/validation/CPP/NormalizationLayer.cpp delete mode 100644 tests/validation/CPP/NormalizationLayer.h delete mode 100644 tests/validation/CPP/Phase.cpp delete mode 100644 tests/validation/CPP/Phase.h delete mode 100644 tests/validation/CPP/PixelWiseMultiplication.cpp delete mode 100644 tests/validation/CPP/PixelWiseMultiplication.h delete mode 100644 tests/validation/CPP/PoolingLayer.cpp delete mode 100644 tests/validation/CPP/PoolingLayer.h delete mode 100644 tests/validation/CPP/QuantizationLayer.cpp delete mode 100644 tests/validation/CPP/QuantizationLayer.h delete mode 100644 tests/validation/CPP/ReductionOperation.cpp delete mode 100644 tests/validation/CPP/ReductionOperation.h delete mode 100644 tests/validation/CPP/Remap.cpp delete mode 100644 tests/validation/CPP/Remap.h delete mode 100644 tests/validation/CPP/ReshapeLayer.cpp delete mode 100644 tests/validation/CPP/ReshapeLayer.h delete mode 100644 tests/validation/CPP/Scale.cpp delete mode 100644 tests/validation/CPP/Scale.h delete mode 100644 tests/validation/CPP/Scharr.cpp delete mode 100644 tests/validation/CPP/Scharr.h delete mode 100644 tests/validation/CPP/Sobel.cpp delete mode 100644 tests/validation/CPP/Sobel.h delete mode 100644 tests/validation/CPP/SoftmaxLayer.cpp delete mode 100644 tests/validation/CPP/SoftmaxLayer.h delete mode 100644 tests/validation/CPP/TableLookup.cpp delete mode 100644 tests/validation/CPP/TableLookup.h delete mode 100644 tests/validation/CPP/Threshold.cpp delete mode 100644 tests/validation/CPP/Threshold.h delete mode 100644 tests/validation/CPP/Transpose.cpp delete mode 100644 tests/validation/CPP/Transpose.h delete mode 100644 tests/validation/CPP/Utils.cpp delete mode 100644 tests/validation/CPP/Utils.h delete mode 100644 tests/validation/CPP/UtilsQuantizedAsymm.h delete mode 100644 tests/validation/CPP/WarpAffine.cpp delete mode 100644 tests/validation/CPP/WarpAffine.h delete mode 100644 tests/validation/CPP/WarpPerspective.cpp delete mode 100644 tests/validation/CPP/WarpPerspective.h create mode 100644 tests/validation/reference/AbsoluteDifference.cpp create mode 100644 tests/validation/reference/AbsoluteDifference.h create mode 100644 tests/validation/reference/Accumulate.cpp create mode 100644 tests/validation/reference/Accumulate.h create mode 100644 tests/validation/reference/ActivationLayer.cpp create mode 100644 tests/validation/reference/ActivationLayer.h create mode 100644 tests/validation/reference/ArithmeticAddition.cpp create mode 100644 tests/validation/reference/ArithmeticAddition.h create mode 100644 tests/validation/reference/ArithmeticSubtraction.cpp create mode 100644 tests/validation/reference/ArithmeticSubtraction.h create mode 100644 tests/validation/reference/BatchNormalizationLayer.cpp create mode 100644 tests/validation/reference/BatchNormalizationLayer.h create mode 100644 tests/validation/reference/BitwiseAnd.cpp create mode 100644 tests/validation/reference/BitwiseAnd.h create mode 100644 tests/validation/reference/BitwiseNot.cpp create mode 100644 tests/validation/reference/BitwiseNot.h create mode 100644 tests/validation/reference/BitwiseOr.cpp create mode 100644 tests/validation/reference/BitwiseOr.h create mode 100644 tests/validation/reference/BitwiseXor.cpp create mode 100644 tests/validation/reference/BitwiseXor.h create mode 100644 tests/validation/reference/Box3x3.cpp create mode 100644 tests/validation/reference/Box3x3.h create mode 100644 tests/validation/reference/ConvolutionLayer.cpp create mode 100644 tests/validation/reference/ConvolutionLayer.h create mode 100644 tests/validation/reference/DeconvolutionLayer.cpp create mode 100644 tests/validation/reference/DeconvolutionLayer.h create mode 100644 tests/validation/reference/DepthConcatenateLayer.cpp create mode 100644 tests/validation/reference/DepthConcatenateLayer.h create mode 100644 tests/validation/reference/DepthConvertLayer.cpp create mode 100644 tests/validation/reference/DepthConvertLayer.h create mode 100644 tests/validation/reference/DepthwiseConvolutionLayer.cpp create mode 100644 tests/validation/reference/DepthwiseConvolutionLayer.h create mode 100644 tests/validation/reference/DepthwiseSeparableConvolutionLayer.cpp create mode 100644 tests/validation/reference/DepthwiseSeparableConvolutionLayer.h create mode 100644 tests/validation/reference/DequantizationLayer.cpp create mode 100644 tests/validation/reference/DequantizationLayer.h create mode 100644 tests/validation/reference/Dilate.cpp create mode 100644 tests/validation/reference/Dilate.h create mode 100644 tests/validation/reference/Erode.cpp create mode 100644 tests/validation/reference/Erode.h create mode 100644 tests/validation/reference/FixedPoint.cpp create mode 100644 tests/validation/reference/FixedPoint.h create mode 100644 tests/validation/reference/FixedPointPixelWiseMultiplication.cpp create mode 100644 tests/validation/reference/FixedPointPixelWiseMultiplication.h create mode 100644 tests/validation/reference/FlattenLayer.cpp create mode 100644 tests/validation/reference/FlattenLayer.h create mode 100644 tests/validation/reference/Floor.cpp create mode 100644 tests/validation/reference/Floor.h create mode 100644 tests/validation/reference/FullyConnectedLayer.cpp create mode 100644 tests/validation/reference/FullyConnectedLayer.h create mode 100644 tests/validation/reference/GEMM.cpp create mode 100644 tests/validation/reference/GEMM.h create mode 100644 tests/validation/reference/GEMMInterleave4x4.h create mode 100644 tests/validation/reference/GEMMInterleaveBlocked.h create mode 100644 tests/validation/reference/GEMMLowp.cpp create mode 100644 tests/validation/reference/GEMMLowp.h create mode 100644 tests/validation/reference/Gaussian3x3.cpp create mode 100644 tests/validation/reference/Gaussian3x3.h create mode 100644 tests/validation/reference/Gaussian5x5.cpp create mode 100644 tests/validation/reference/Gaussian5x5.h create mode 100644 tests/validation/reference/GaussianPyramidHalf.cpp create mode 100644 tests/validation/reference/GaussianPyramidHalf.h create mode 100644 tests/validation/reference/HarrisCornerDetector.cpp create mode 100644 tests/validation/reference/HarrisCornerDetector.h create mode 100644 tests/validation/reference/Histogram.cpp create mode 100644 tests/validation/reference/Histogram.h create mode 100644 tests/validation/reference/IntegralImage.cpp create mode 100644 tests/validation/reference/IntegralImage.h create mode 100644 tests/validation/reference/L2NormalizeLayer.cpp create mode 100644 tests/validation/reference/L2NormalizeLayer.h create mode 100644 tests/validation/reference/Magnitude.cpp create mode 100644 tests/validation/reference/Magnitude.h create mode 100644 tests/validation/reference/MeanStdDev.cpp create mode 100644 tests/validation/reference/MeanStdDev.h create mode 100644 tests/validation/reference/Median3x3.cpp create mode 100644 tests/validation/reference/Median3x3.h create mode 100644 tests/validation/reference/MinMaxLocation.cpp create mode 100644 tests/validation/reference/MinMaxLocation.h create mode 100644 tests/validation/reference/NonLinearFilter.cpp create mode 100644 tests/validation/reference/NonLinearFilter.h create mode 100644 tests/validation/reference/NonMaximaSuppression.cpp create mode 100644 tests/validation/reference/NonMaximaSuppression.h create mode 100644 tests/validation/reference/NormalizationLayer.cpp create mode 100644 tests/validation/reference/NormalizationLayer.h create mode 100644 tests/validation/reference/Phase.cpp create mode 100644 tests/validation/reference/Phase.h create mode 100644 tests/validation/reference/PixelWiseMultiplication.cpp create mode 100644 tests/validation/reference/PixelWiseMultiplication.h create mode 100644 tests/validation/reference/PoolingLayer.cpp create mode 100644 tests/validation/reference/PoolingLayer.h create mode 100644 tests/validation/reference/QuantizationLayer.cpp create mode 100644 tests/validation/reference/QuantizationLayer.h create mode 100644 tests/validation/reference/ReductionOperation.cpp create mode 100644 tests/validation/reference/ReductionOperation.h create mode 100644 tests/validation/reference/Remap.cpp create mode 100644 tests/validation/reference/Remap.h create mode 100644 tests/validation/reference/ReshapeLayer.cpp create mode 100644 tests/validation/reference/ReshapeLayer.h create mode 100644 tests/validation/reference/Scale.cpp create mode 100644 tests/validation/reference/Scale.h create mode 100644 tests/validation/reference/Scharr.cpp create mode 100644 tests/validation/reference/Scharr.h create mode 100644 tests/validation/reference/Sobel.cpp create mode 100644 tests/validation/reference/Sobel.h create mode 100644 tests/validation/reference/SoftmaxLayer.cpp create mode 100644 tests/validation/reference/SoftmaxLayer.h create mode 100644 tests/validation/reference/TableLookup.cpp create mode 100644 tests/validation/reference/TableLookup.h create mode 100644 tests/validation/reference/Threshold.cpp create mode 100644 tests/validation/reference/Threshold.h create mode 100644 tests/validation/reference/Transpose.cpp create mode 100644 tests/validation/reference/Transpose.h create mode 100644 tests/validation/reference/Utils.cpp create mode 100644 tests/validation/reference/Utils.h create mode 100644 tests/validation/reference/UtilsQuantizedAsymm.h create mode 100644 tests/validation/reference/WarpAffine.cpp create mode 100644 tests/validation/reference/WarpAffine.h create mode 100644 tests/validation/reference/WarpPerspective.cpp create mode 100644 tests/validation/reference/WarpPerspective.h (limited to 'tests') diff --git a/tests/SConscript b/tests/SConscript index 3a6422d87b..37ec95f589 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -81,7 +81,7 @@ files_benchmark = Glob('benchmark/*.cpp') files_validation = Glob('validation/*.cpp') # Always compile reference for validation -files_validation += Glob('validation/CPP/*.cpp') +files_validation += Glob('validation/reference/*.cpp') # Add unit tests files_validation += Glob('validation/UNIT/*/*.cpp') diff --git a/tests/validation/CL/WarpAffine.cpp b/tests/validation/CL/WarpAffine.cpp index 9db2ccaacc..7f3001cb57 100644 --- a/tests/validation/CL/WarpAffine.cpp +++ b/tests/validation/CL/WarpAffine.cpp @@ -35,9 +35,9 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Validation.h" #include "tests/validation/fixtures/WarpAffineFixture.h" +#include "tests/validation/reference/Utils.h" namespace arm_compute { diff --git a/tests/validation/CPP/AbsoluteDifference.cpp b/tests/validation/CPP/AbsoluteDifference.cpp deleted file mode 100644 index f518e67324..0000000000 --- a/tests/validation/CPP/AbsoluteDifference.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2017 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 "AbsoluteDifference.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type) -{ - SimpleTensor result(src1.shape(), dst_data_type); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - for(int i = 0; i < src1.num_elements(); ++i) - { - intermediate_type val = std::abs(static_cast(src1[i]) - static_cast(src2[i])); - result[i] = saturate_cast(val); - } - - return result; -} - -template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); -template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); -template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/AbsoluteDifference.h b/tests/validation/CPP/AbsoluteDifference.h deleted file mode 100644 index b14da157df..0000000000 --- a/tests/validation/CPP/AbsoluteDifference.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_ABSOLUTE_DIFFERENCE_H__ -#define __ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_H__ */ diff --git a/tests/validation/CPP/Accumulate.cpp b/tests/validation/CPP/Accumulate.cpp deleted file mode 100644 index 29a2007bbd..0000000000 --- a/tests/validation/CPP/Accumulate.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017 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 "Accumulate.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type) -{ - SimpleTensor dst{ src.shape(), output_data_type }; - - library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - for(int i = 0; i < src.num_elements(); ++i) - { - intermediate_type val = static_cast(src[i]) + static_cast(dst[i]); - dst[i] = saturate_cast(val); - } - - return dst; -} - -template -SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type) -{ - ARM_COMPUTE_ERROR_ON_MSG(alpha < 0.f || alpha > 1.f, "Weight (alpha) specified in accumulate_weighted must be within the range [0, 1]"); - - SimpleTensor dst{ src.shape(), output_data_type }; - - library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - for(int i = 0; i < src.num_elements(); ++i) - { - double val = (1. - static_cast(alpha)) * static_cast(dst[i]) + static_cast(alpha) * static_cast(src[i]); - dst[i] = static_cast(val); - } - - return dst; -} - -template -SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type) -{ - ARM_COMPUTE_ERROR_ON_MSG(shift > 15, "Shift in accumulate_squared must be within the range [0, 15]"); - - SimpleTensor dst{ src.shape(), output_data_type }; - - library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - intermediate_type denom = 1 << shift; - - for(int i = 0; i < src.num_elements(); ++i) - { - intermediate_type val = static_cast(dst[i]) + (static_cast(src[i]) * static_cast(src[i]) / denom); - dst[i] = saturate_cast(val); - } - - return dst; -} - -template SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type); -template SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type); -template SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Accumulate.h b/tests/validation/CPP/Accumulate.h deleted file mode 100644 index faa570bd05..0000000000 --- a/tests/validation/CPP/Accumulate.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2017 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_ACCUMULATE_H__ -#define __ARM_COMPUTE_TEST_ACCUMULATE_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type); - -template -SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type); - -template -SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ACCUMULATE_H__ */ diff --git a/tests/validation/CPP/ActivationLayer.cpp b/tests/validation/CPP/ActivationLayer.cpp deleted file mode 100644 index 2243e6ff59..0000000000 --- a/tests/validation/CPP/ActivationLayer.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2017 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 "ActivationLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info) -{ - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const T a(info.a()); - const T b(info.b()); - - for(int i = 0; i < src.num_elements(); ++i) - { - T x = src[i]; - - switch(info.activation()) - { - case ActivationLayerInfo::ActivationFunction::ABS: - dst[i] = std::abs(x); - break; - case ActivationLayerInfo::ActivationFunction::LINEAR: - dst[i] = a * x + b; - break; - case ActivationLayerInfo::ActivationFunction::LOGISTIC: - dst[i] = static_cast(1) / (static_cast(1) + std::exp(-x)); - break; - case ActivationLayerInfo::ActivationFunction::RELU: - dst[i] = std::max(static_cast(0), x); - break; - case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: - dst[i] = std::min(a, std::max(static_cast(0), x)); - break; - case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: - dst[i] = std::min(a, std::max(b, x)); - break; - case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: - dst[i] = (x > 0) ? x : a * x; - break; - case ActivationLayerInfo::ActivationFunction::SOFT_RELU: - dst[i] = std::log(static_cast(1) + std::exp(x)); - break; - case ActivationLayerInfo::ActivationFunction::SQRT: - dst[i] = std::sqrt(x); - break; - case ActivationLayerInfo::ActivationFunction::SQUARE: - dst[i] = x * x; - break; - case ActivationLayerInfo::ActivationFunction::TANH: - dst[i] = a * std::tanh(b * x); - break; - default: - ARM_COMPUTE_ERROR("Unsupported activation function"); - } - } - - return dst; -} - -template ::value, int>::type> -SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info) -{ - using namespace fixed_point_arithmetic; - - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const int fixed_point_position = src.fixed_point_position(); - const fixed_point a(info.a(), fixed_point_position); - const fixed_point b(info.b(), fixed_point_position); - const fixed_point const_0(0, fixed_point_position); - const fixed_point const_1(1, fixed_point_position); - - for(int i = 0; i < src.num_elements(); ++i) - { - fixed_point x(src[i], fixed_point_position, true); - - switch(info.activation()) - { - case ActivationLayerInfo::ActivationFunction::ABS: - dst[i] = abs(x).raw(); - break; - case ActivationLayerInfo::ActivationFunction::LINEAR: - dst[i] = add(b, mul(a, x)).raw(); - break; - case ActivationLayerInfo::ActivationFunction::LOGISTIC: - dst[i] = (const_1 / (const_1 + exp(-x))).raw(); - break; - case ActivationLayerInfo::ActivationFunction::RELU: - dst[i] = max(const_0, x).raw(); - break; - case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: - dst[i] = min(a, max(const_0, x)).raw(); - break; - case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: - dst[i] = min(a, max(b, x)).raw(); - break; - case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: - dst[i] = (x > const_0) ? x.raw() : mul(a, x).raw(); - break; - case ActivationLayerInfo::ActivationFunction::SOFT_RELU: - dst[i] = log(const_1 + exp(x)).raw(); - break; - case ActivationLayerInfo::ActivationFunction::SQRT: - dst[i] = (const_1 / inv_sqrt(x)).raw(); - break; - case ActivationLayerInfo::ActivationFunction::SQUARE: - dst[i] = mul(x, x).raw(); - break; - case ActivationLayerInfo::ActivationFunction::TANH: - dst[i] = mul(a, tanh(mul(b, x))).raw(); - break; - default: - ARM_COMPUTE_ERROR("Unsupported activation function"); - } - } - - return dst; -} - -template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); -template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); -template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); -template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ActivationLayer.h b/tests/validation/CPP/ActivationLayer.h deleted file mode 100644 index 09f602ffa1..0000000000 --- a/tests/validation/CPP/ActivationLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_ACTIVATION_LAYER_H__ -#define __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); - -template ::value, int>::type = 0> -SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ */ diff --git a/tests/validation/CPP/ArithmeticAddition.cpp b/tests/validation/CPP/ArithmeticAddition.cpp deleted file mode 100644 index 82dd1437cd..0000000000 --- a/tests/validation/CPP/ArithmeticAddition.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2017 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 "ArithmeticAddition.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy) -{ - SimpleTensor result(src1.shape(), dst_data_type); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - for(int i = 0; i < src1.num_elements(); ++i) - { - intermediate_type val = static_cast(src1[i]) + static_cast(src2[i]); - result[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); - } - - return result; -} - -template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, - ConvertPolicy convert_policy); -template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ArithmeticAddition.h b/tests/validation/CPP/ArithmeticAddition.h deleted file mode 100644 index 5902a6f529..0000000000 --- a/tests/validation/CPP/ArithmeticAddition.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_ARITHMETIC_ADDITION_H__ -#define __ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_H__ */ diff --git a/tests/validation/CPP/ArithmeticSubtraction.cpp b/tests/validation/CPP/ArithmeticSubtraction.cpp deleted file mode 100644 index bed2d37090..0000000000 --- a/tests/validation/CPP/ArithmeticSubtraction.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2017 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 "ArithmeticSubtraction.h" - -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy) -{ - SimpleTensor result(src1.shape(), dst_data_type); - - using intermediate_type = typename common_promoted_signed_type= sizeof(T2), T1, T2>::type >::intermediate_type; - - for(int i = 0; i < src1.num_elements(); ++i) - { - intermediate_type val = static_cast(src1[i]) - static_cast(src2[i]); - result[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); - } - - return result; -} - -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ArithmeticSubtraction.h b/tests/validation/CPP/ArithmeticSubtraction.h deleted file mode 100644 index 9308314bda..0000000000 --- a/tests/validation/CPP/ArithmeticSubtraction.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_ARITHMETIC_SUBTRACTION_H__ -#define __ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_H__ */ diff --git a/tests/validation/CPP/BatchNormalizationLayer.cpp b/tests/validation/CPP/BatchNormalizationLayer.cpp deleted file mode 100644 index e4446d1694..0000000000 --- a/tests/validation/CPP/BatchNormalizationLayer.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2017 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 "BatchNormalizationLayer.h" - -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -// Batch Normalization Layer for fixed point type -template ::value, int>::type *> -SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, - int fixed_point_position) -{ - SimpleTensor result(src.shape(), src.data_type()); - - const auto cols = static_cast(src.shape()[0]); - const auto rows = static_cast(src.shape()[1]); - const auto depth = static_cast(src.shape()[2]); - const int upper_dims = src.shape().total_size() / (cols * rows * depth); - - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < depth; ++i) - { - for(int k = 0; k < rows; ++k) - { - for(int l = 0; l < cols; ++l) - { - const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; - - fixed_point_arithmetic::fixed_point src_qs(src[pos], fixed_point_position, true); - fixed_point_arithmetic::fixed_point var_qs(var[i], fixed_point_position, true); - fixed_point_arithmetic::fixed_point mean_qs(mean[i], fixed_point_position, true); - fixed_point_arithmetic::fixed_point beta_qs(beta[i], fixed_point_position, true); - fixed_point_arithmetic::fixed_point gamma_qs(gamma[i], fixed_point_position, true); - fixed_point_arithmetic::fixed_point epsilon_qs(epsilon, fixed_point_position); - - auto denominator = fixed_point_arithmetic::inv_sqrt(var_qs + epsilon_qs); - auto numerator = src_qs - mean_qs; - auto x_bar = numerator * denominator; - x_bar = beta_qs + x_bar * gamma_qs; - result[pos] = x_bar.raw(); - } - } - } - } - - return result; -} - -// Batch Normalization Layer for floating point type -template ::value, int>::type *> -SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, - int fixed_point_position) -{ - ARM_COMPUTE_UNUSED(fixed_point_position); - - SimpleTensor result(src.shape(), src.data_type()); - - const auto cols = static_cast(src.shape()[0]); - const auto rows = static_cast(src.shape()[1]); - const auto depth = static_cast(src.shape()[2]); - const int upper_dims = src.shape().total_size() / (cols * rows * depth); - - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < depth; ++i) - { - for(int k = 0; k < rows; ++k) - { - for(int l = 0; l < cols; ++l) - { - const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; - const float denominator = sqrt(var[i] + epsilon); - const float numerator = src[pos] - mean[i]; - const float x_bar = numerator / denominator; - result[pos] = beta[i] + x_bar * gamma[i]; - } - } - } - } - return result; -} -template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, - const SimpleTensor &gamma, float epsilon, int fixed_point_position); -template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, - const SimpleTensor &gamma, float epsilon, int fixed_point_position); -template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, - const SimpleTensor &gamma, float epsilon, int fixed_point_position); -template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, - const SimpleTensor &beta, - const SimpleTensor &gamma, float epsilon, int fixed_point_position); - -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/BatchNormalizationLayer.h b/tests/validation/CPP/BatchNormalizationLayer.h deleted file mode 100644 index 1a554adf7e..0000000000 --- a/tests/validation/CPP/BatchNormalizationLayer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017 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_BATCH_NORMALIZATION_LAYER_H__ -#define __ARM_COMPUTE_TEST_BATCH_NORMALIZATION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type * = nullptr> -SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, - int fixed_point_position); - -template ::value, int>::type * = nullptr> -SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, - int fixed_point_position); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BATCH_NORMALIZATION_LAYER_H__ */ diff --git a/tests/validation/CPP/BitwiseAnd.cpp b/tests/validation/CPP/BitwiseAnd.cpp deleted file mode 100644 index 6fc46b402b..0000000000 --- a/tests/validation/CPP/BitwiseAnd.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017 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 "BitwiseAnd.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2) -{ - SimpleTensor dst(src1.shape(), src1.data_type()); - - for(int i = 0; i < src1.num_elements(); ++i) - { - dst[i] = src1[i] & src2[i]; - } - - return dst; -} - -template SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/BitwiseAnd.h b/tests/validation/CPP/BitwiseAnd.h deleted file mode 100644 index eba2fd695f..0000000000 --- a/tests/validation/CPP/BitwiseAnd.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_BITWISE_AND_H__ -#define __ARM_COMPUTE_TEST_BITWISE_AND_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BITWISE_AND_H__ */ diff --git a/tests/validation/CPP/BitwiseNot.cpp b/tests/validation/CPP/BitwiseNot.cpp deleted file mode 100644 index 5a6a13b56c..0000000000 --- a/tests/validation/CPP/BitwiseNot.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017 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 "BitwiseNot.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_not(const SimpleTensor &src) -{ - SimpleTensor dst(src.shape(), src.data_type()); - - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = ~src[i]; - } - - return dst; -} - -template SimpleTensor bitwise_not(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/BitwiseNot.h b/tests/validation/CPP/BitwiseNot.h deleted file mode 100644 index b4206f9388..0000000000 --- a/tests/validation/CPP/BitwiseNot.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_BITWISE_NOT_H__ -#define __ARM_COMPUTE_TEST_BITWISE_NOT_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_not(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BITWISE_NOT_H__ */ diff --git a/tests/validation/CPP/BitwiseOr.cpp b/tests/validation/CPP/BitwiseOr.cpp deleted file mode 100644 index fc258d54f1..0000000000 --- a/tests/validation/CPP/BitwiseOr.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017 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 "BitwiseOr.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2) -{ - SimpleTensor dst(src1.shape(), src1.data_type()); - - for(int i = 0; i < src1.num_elements(); ++i) - { - dst[i] = src1[i] | src2[i]; - } - - return dst; -} - -template SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/BitwiseOr.h b/tests/validation/CPP/BitwiseOr.h deleted file mode 100644 index 39158cb411..0000000000 --- a/tests/validation/CPP/BitwiseOr.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_BITWISE_OR_H__ -#define __ARM_COMPUTE_TEST_BITWISE_OR_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BITWISE_OR_H__ */ diff --git a/tests/validation/CPP/BitwiseXor.cpp b/tests/validation/CPP/BitwiseXor.cpp deleted file mode 100644 index b8d275d8b5..0000000000 --- a/tests/validation/CPP/BitwiseXor.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017 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 "BitwiseXor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2) -{ - SimpleTensor dst(src1.shape(), src1.data_type()); - - for(int i = 0; i < src1.num_elements(); ++i) - { - dst[i] = src1[i] ^ src2[i]; - } - - return dst; -} - -template SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/BitwiseXor.h b/tests/validation/CPP/BitwiseXor.h deleted file mode 100644 index 3e7721e843..0000000000 --- a/tests/validation/CPP/BitwiseXor.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_BITWISE_XOR_H__ -#define __ARM_COMPUTE_TEST_BITWISE_XOR_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BITWISE_XOR_H__ */ diff --git a/tests/validation/CPP/Box3x3.cpp b/tests/validation/CPP/Box3x3.cpp deleted file mode 100644 index 8d304a8236..0000000000 --- a/tests/validation/CPP/Box3x3.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Box3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - const std::array filter{ { 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; - const float scale = 1.f / static_cast(filter.size()); - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Box3x3.h b/tests/validation/CPP/Box3x3.h deleted file mode 100644 index 80ac451b93..0000000000 --- a/tests/validation/CPP/Box3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_BOX3X3_H__ -#define __ARM_COMPUTE_TEST_BOX3X3_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BOX3X3_H__ */ diff --git a/tests/validation/CPP/ConvolutionLayer.cpp b/tests/validation/CPP/ConvolutionLayer.cpp deleted file mode 100644 index 3884a930a2..0000000000 --- a/tests/validation/CPP/ConvolutionLayer.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2017 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 "ConvolutionLayer.h" - -#include "tests/validation/CPP/Utils.h" -#include "tests/validation/CPP/UtilsQuantizedAsymm.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -#include "tests/framework/Asserts.h" - -#include "arm_compute/core/utils/quantization/AsymmHelpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -inline bool is_valid_pixel(int i, int min, int max) -{ - return (i >= min && i < max); -} - -// 3D convolution for floating point type -template < typename T, typename TB, typename std::enable_if < is_floating_point::value &&is_floating_point::value, int >::type = 0 > -void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, - int i_offset, int w_offset, int b_offset, int o_offset, - int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) -{ - const T *in_ptr = in.data() + i_offset; - const T *w_ptr = weights.data() + w_offset; - const TB *b_ptr = bias.data() + b_offset; - T *out_ptr = out.data() + o_offset; - - const int half_width_weights = width_weights / 2; - const int half_height_weights = height_weights / 2; - - // Reset accumulator - T acc(0); - - // Compute a 2D convolution for each IFM and accumulate the result - for(int ifm = 0; ifm < depth_in; ++ifm) - { - // Compute the offset for the input slice - const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; - - // Compute 2D convolution - for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) - { - for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) - { - // Check if the pixel is out-of-bound - if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) - { - const int idx = xk + half_width_weights; - const int idy = yk + half_height_weights; - - const T i_value = in_ptr[offset_slice_in + xk + yk * width_in]; - const T w_value = w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights]; - - acc += i_value * w_value; - } - } - } - } - - // Accumulate the bias and store the result - *out_ptr = acc + (*b_ptr); -} - -// 3D convolution for fixed point type -template < typename T, typename TB, typename std::enable_if < std::is_integral::value &&std::is_integral::value, int >::type = 0 > -void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, - int i_offset, int w_offset, int b_offset, int o_offset, - int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) -{ - const T *in_ptr = in.data() + i_offset; - const T *w_ptr = weights.data() + w_offset; - const T *b_ptr = bias.data() + b_offset; - T *out_ptr = out.data() + o_offset; - int fixed_point_position = in.fixed_point_position(); - - const int half_width_weights = width_weights / 2; - const int half_height_weights = height_weights / 2; - - using namespace fixed_point_arithmetic; - using promoted_type = fixed_point_arithmetic::traits::promote_t; - - // Reset accumulator - fixed_point acc(0, fixed_point_position); - - // Compute a 2D convolution for each IFM and accumulate the result - for(int ifm = 0; ifm < depth_in; ++ifm) - { - // Compute the offset for the input slice - const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; - - // Compute 2D convolution - for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) - { - for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) - { - // Check if the pixel is out-of-bound - if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) - { - const int idx = xk + half_width_weights; - const int idy = yk + half_height_weights; - - const fixed_point i_value(in_ptr[offset_slice_in + xk + yk * width_in], fixed_point_position, true); - const fixed_point w_value(w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights], fixed_point_position, true); - const fixed_point iw = i_value * w_value; - acc = iw + acc; - } - } - } - } - - // Get the bias - const fixed_point b(*b_ptr, fixed_point_position, true); - - // Accumulate the bias and covert back - acc = acc + b; - fixed_point res(acc); - *out_ptr = res.raw(); -} - -// 3D convolution for QASYMM8 type -template <> -void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, - int i_offset, int w_offset, int b_offset, int o_offset, - int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) -{ - const uint8_t *in_ptr = in.data() + i_offset; - const uint8_t *w_ptr = weights.data() + w_offset; - const int32_t *b_ptr = bias.data() + b_offset; - uint8_t *out_ptr = out.data() + o_offset; - - const int input_offset = -in.quantization_info().offset; - const float input_scale = in.quantization_info().scale; - const int weights_offset = -weights.quantization_info().offset; - const float weights_scale = weights.quantization_info().scale; - const int output_offset = out.quantization_info().offset; - const float output_scale = out.quantization_info().scale; - - int output_multiplier = 0; - int output_shift = 0; - const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); - - const int half_width_weights = width_weights / 2; - const int half_height_weights = height_weights / 2; - - // Reset accumulator - int32_t acc(0); - - // Compute a 2D convolution for each IFM and accumulate the result - for(int ifm = 0; ifm < depth_in; ++ifm) - { - // Compute the offset for the input slice - const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; - - // Compute 2D convolution - for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) - { - for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) - { - // Check if the pixel is out-of-bound - if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) - { - const int idx = xk + half_width_weights; - const int idy = yk + half_height_weights; - - const uint8_t i_value = in_ptr[offset_slice_in + xk + yk * width_in]; - const uint8_t w_value = w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights]; - - acc += (i_value + input_offset) * (w_value + weights_offset); - } - } - } - } - - // Accumulate the bias - acc += (*b_ptr); - - acc = asymm_rounding_divide_by_pow2(asymm_int_mult(acc, output_multiplier), output_shift); - acc += output_offset; - acc = clamp(acc, 0, 255); - - // Store the result - *out_ptr = acc; -} -} // namespace - -template -SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info) -{ - // Create reference - SimpleTensor dst{ output_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; - - // Compute reference - const int width_in = src.shape().x(); - const int height_in = src.shape().y(); - const int depth_in = src.shape().z(); - const int width_out = dst.shape().x(); - const int height_out = dst.shape().y(); - const int depth_out = dst.shape().z(); - const int width_weights = weights.shape().x(); - const int height_weights = weights.shape().y(); - const int depth_weights = weights.shape().z(); - const int pad_left = std::min(static_cast(info.pad_left()), width_weights / 2); - const int pad_top = std::min(static_cast(info.pad_top()), height_weights / 2); - const int pad_right = std::min(static_cast(info.pad_right()), width_weights / 2); - const int pad_bottom = std::min(static_cast(info.pad_bottom()), height_weights / 2); - - const int start_xi = width_weights / 2 - pad_left; - const int start_yi = height_weights / 2 - pad_top; - const int end_xi = width_in + pad_left - width_weights / 2 + pad_right - width_weights / 2; - const int end_yi = height_in + pad_top - height_weights / 2 + pad_bottom - height_weights / 2; - const int stride_xi = info.stride().first; - const int stride_yi = info.stride().second; - const int num_batches = src.shape().total_size() / (width_in * height_in * depth_in); - - for(int r = 0; r < num_batches; ++r) - { - for(int yi = start_yi; yi < start_yi + end_yi; yi += stride_yi) - { - for(int xi = start_xi; xi < start_xi + end_xi; xi += stride_xi) - { - for(int ofm = 0; ofm < depth_out; ++ofm) - { - // Compute input and output offsets - const int offset_in = r * width_in * height_in * depth_in; - const int xo = (xi - start_xi) / stride_xi; - const int yo = (yi - start_yi) / stride_yi; - const int offset_out = xo + yo * width_out + ofm * width_out * height_out + r * width_out * height_out * depth_out; - - ARM_COMPUTE_ASSERT(xo < width_out); - ARM_COMPUTE_ASSERT(yo < height_out); - - // Compute 3D convolution - convolution3d(src, weights, bias, dst, - offset_in, ofm * width_weights * height_weights * depth_weights, ofm, offset_out, - xi, yi, - width_in, height_in, depth_in, - width_weights, height_weights); - } - } - } - } - - return dst; -} - -template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ConvolutionLayer.h b/tests/validation/CPP/ConvolutionLayer.h deleted file mode 100644 index 57455ba401..0000000000 --- a/tests/validation/CPP/ConvolutionLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_CONVOLUTION_LAYER_H__ -#define __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/CPP/DeconvolutionLayer.cpp b/tests/validation/CPP/DeconvolutionLayer.cpp deleted file mode 100644 index 82c2188ade..0000000000 --- a/tests/validation/CPP/DeconvolutionLayer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2017 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 "ConvolutionLayer.h" - -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info, const std::pair &a) -{ - // Create reference - TensorShape scaled_shape = src.shape(); - scaled_shape.set(0, output_shape.x()); - scaled_shape.set(1, output_shape.y()); - SimpleTensor scaled{ scaled_shape, src.data_type(), 1, src.fixed_point_position() }; - - const int width_in = src.shape().x(); - const int height_in = src.shape().y(); - const int width_scaled = scaled.shape().x(); - const int height_scaled = scaled.shape().y(); - const int num_2d_slices = src.shape().total_size() / (width_in * height_in); - const float width_ratio = static_cast(width_in) / static_cast(width_scaled); - const float height_ratio = static_cast(height_in) / static_cast(height_scaled); - const int ax = a.first; // The number of zeros added to right edge of the input. - const int ay = a.second; // The number of zeros added to bottom edge of the input. - const unsigned int kernel_size = weights.shape().x(); - ARM_COMPUTE_ERROR_ON(info.pad().first > (kernel_size - 1)); - const int transposed_convolution_padx = kernel_size - info.pad().first - 1; - const int transposed_convolution_pady = kernel_size - info.pad().second - 1; - const int stridex = info.stride().first; - const int stridey = info.stride().second; - for(int j = 0; j < scaled.num_elements(); ++j) - { - scaled[j] = T(0); - } - - for(int slice = 0; slice < num_2d_slices; ++slice) - { - const int offset_slice_in = slice * width_in * height_in; - const int offset_slice_out = slice * width_scaled * height_scaled; - for(int yi = ay; yi < height_scaled; yi += stridey) - { - for(int xi = transposed_convolution_padx; xi < width_scaled; xi += stridex) - { - const float x_src = (xi + 0.5f) * width_ratio - 0.5f; - const float y_src = (yi + 0.5f) * height_ratio - 0.5f; - T *out = scaled.data() + offset_slice_out + xi + yi * width_scaled; - const bool in_bounds = x_src > -1 && y_src > -1 && x_src < width_in && y_src < height_in; - const bool in_axy = xi < transposed_convolution_padx || xi >= (width_scaled - ax) // this is checking if the x coordinate is in the padded left/right area - || yi < ay || yi >= (height_scaled - transposed_convolution_pady); // like above but top and bottom padding in the upscaled XY plane - if(!in_axy) - { - if(in_bounds) - { - const int in_scaled_x = (x_src < 0.f) ? static_cast(x_src - 0.5f) : static_cast(x_src + 0.5f); - const int in_scaled_y = (y_src < 0.f) ? static_cast(y_src - 0.5f) : static_cast(y_src + 0.5f); - const T *in = src.data() + offset_slice_in + in_scaled_x + in_scaled_y * width_in; - *out = *in; - } - else - { - *out = T(0); - } - } - } - } - } - const PadStrideInfo conv_info(1, 1, 1, 1, DimensionRoundingType::CEIL); - return convolution_layer(scaled, weights, bias, output_shape, conv_info); -} - -template SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, - const PadStrideInfo &info, const std::pair &a); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DeconvolutionLayer.h b/tests/validation/CPP/DeconvolutionLayer.h deleted file mode 100644 index 8222e32027..0000000000 --- a/tests/validation/CPP/DeconvolutionLayer.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017 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_DECONVOLUTION_LAYER_H__ -#define __ARM_COMPUTE_TEST_DECONVOLUTION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -/** Deconvolution reference implementation. - * - * src Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F32. - * weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input. - * bias Optional, ignored if NULL. The biases have one dimension. Data type supported: Same as @p input. - * output_shape Output tensor shape. The output has the same number of dimensions as the @p input. - * info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. - * a The number of zeros added to right edge of the input. - * - */ -template -SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info, - const std::pair &a); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DECONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/CPP/DepthConcatenateLayer.cpp b/tests/validation/CPP/DepthConcatenateLayer.cpp deleted file mode 100644 index 9a7248493d..0000000000 --- a/tests/validation/CPP/DepthConcatenateLayer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017 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 "DepthConcatenateLayer.h" - -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor depthconcatenate_layer(const std::vector> &srcs) -{ - // Create reference - std::vector shapes; - - for(const auto &src : srcs) - { - shapes.emplace_back(src.shape()); - } - - DataType dst_type = srcs.empty() ? DataType::UNKNOWN : srcs[0].data_type(); - TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); - SimpleTensor dst(dst_shape, dst_type); - - // Compute reference - int depth_offset = 0; - const int width_out = dst.shape().x(); - const int height_out = dst.shape().y(); - const int depth_out = dst.shape().z(); - const int out_stride_z = width_out * height_out; - const int batches = dst.shape().total_size_upper(3); - - // Set output tensor to 0 - std::fill_n(dst.data(), dst.num_elements(), 0); - - for(const auto &src : srcs) - { - ARM_COMPUTE_ERROR_ON(depth_offset >= depth_out); - ARM_COMPUTE_ERROR_ON(batches != static_cast(src.shape().total_size_upper(3))); - - const int width = src.shape().x(); - const int height = src.shape().y(); - const int depth = src.shape().z(); - const int x_diff = (width_out - width) / 2; - const int y_diff = (height_out - height) / 2; - - const T *src_ptr = src.data(); - - for(int b = 0; b < batches; ++b) - { - const size_t offset_to_first_element = b * out_stride_z * depth_out + depth_offset * out_stride_z + y_diff * width_out + x_diff; - - for(int d = 0; d < depth; ++d) - { - for(int r = 0; r < height; ++r) - { - std::copy(src_ptr, src_ptr + width, dst.data() + offset_to_first_element + d * out_stride_z + r * width_out); - src_ptr += width; - } - } - } - - depth_offset += depth; - } - - return dst; -} - -template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); -template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); -template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); -template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DepthConcatenateLayer.h b/tests/validation/CPP/DepthConcatenateLayer.h deleted file mode 100644 index 3c486a8015..0000000000 --- a/tests/validation/CPP/DepthConcatenateLayer.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017 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_DEPTHCONCATENATE_LAYER_H__ -#define __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ - -#include "tests/SimpleTensor.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor depthconcatenate_layer(const std::vector> &srcs); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ */ diff --git a/tests/validation/CPP/DepthConvertLayer.cpp b/tests/validation/CPP/DepthConvertLayer.cpp deleted file mode 100644 index dd095b8912..0000000000 --- a/tests/validation/CPP/DepthConvertLayer.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2017 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 "DepthConvertLayer.h" - -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_floating_point::value, int >::type > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) -{ - ARM_COMPUTE_UNUSED(policy); - ARM_COMPUTE_UNUSED(shift); - - using namespace fixed_point_arithmetic; - SimpleTensor result(src.shape(), dt_out); - - const int fixed_point_position = src.fixed_point_position(); - - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = static_cast(fixed_point(src[i], fixed_point_position, true)); - } - - return result; -} - -template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&std::is_integral::value, int >::type > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) -{ - ARM_COMPUTE_UNUSED(policy); - ARM_COMPUTE_UNUSED(shift); - - using namespace fixed_point_arithmetic; - SimpleTensor result(src.shape(), dt_out, 1, src.fixed_point_position()); - - const int fixed_point_position = result.fixed_point_position(); - - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = fixed_point(src[i], fixed_point_position).raw(); - } - - return result; -} - -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&!std::is_same::value, int >::type > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) -{ - SimpleTensor result(src.shape(), dt_out); - - // Up-casting - if(src.data_type() <= dt_out) - { - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = src[i] << shift; - } - } - // Down-casting - else - { - for(int i = 0; i < src.num_elements(); ++i) - { - T1 val = src[i] >> shift; - result[i] = (policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); - } - } - return result; -} - -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&std::is_same::value, int >::type > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) -{ - ARM_COMPUTE_UNUSED(policy); - - using namespace fixed_point_arithmetic; - - SimpleTensor result(src.shape(), dt_out); - - bool is_in_place = (&src == &result); - - const int fixed_point_position_in = src.fixed_point_position(); - const int fixed_point_position_out = (is_in_place) ? static_cast(shift) : result.fixed_point_position(); - - if(!is_in_place || (fixed_point_position_in != fixed_point_position_out)) - { - for(int i = 0; i < src.num_elements(); ++i) - { - auto x = fixed_point(src[i], fixed_point_position_in, true); - x.resacle(fixed_point_position_out); - result[i] = x.raw(); - } - } - - return result; -} - -template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&is_floating_point::value, int >::type > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) -{ - ARM_COMPUTE_UNUSED(policy); - ARM_COMPUTE_UNUSED(shift); - - SimpleTensor result(src.shape(), dt_out); - - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = static_cast(src[i]); - } -} - -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DepthConvertLayer.h b/tests/validation/CPP/DepthConvertLayer.h deleted file mode 100644 index 1446bfda5b..0000000000 --- a/tests/validation/CPP/DepthConvertLayer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2017 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_DEPTH_CONVERT_H__ -#define __ARM_COMPUTE_TEST_DEPTH_CONVERT_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_floating_point::value, int >::type = 0 > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); - -template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&std::is_integral::value, int >::type = 0 > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); - -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&!std::is_same::value, int >::type = 0 > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); - -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&std::is_same::value, int >::type = 0 > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); - -template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&is_floating_point::value, int >::type = 0 > -SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DEPTH_CONVERT_H__ */ diff --git a/tests/validation/CPP/DepthwiseConvolutionLayer.cpp b/tests/validation/CPP/DepthwiseConvolutionLayer.cpp deleted file mode 100644 index 99baa4b3c7..0000000000 --- a/tests/validation/CPP/DepthwiseConvolutionLayer.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2017 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 "DepthwiseConvolutionLayer.h" - -#include "ConvolutionLayer.h" -#include "Utils.h" - -#include "tests/validation/CPP/Utils.h" -#include "tests/validation/CPP/UtilsQuantizedAsymm.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -#include "arm_compute/core/utils/quantization/AsymmHelpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -/** Perform a depthwise convolution - * - * - Three dimensions tensors - * - Third dimention is number of channels - * - Depths of input tensor and filter are equals - * - Padding, stride and output shape "match" - * - */ -template -SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info) -{ - // Create reference - SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const int filter_width = weights.shape().x(); - const int filter_height = weights.shape().y(); - const int filter_plane = filter_width * filter_height; - const int input_width = src.shape().x(); - const int input_height = src.shape().y(); - const int input_depth = src.shape().z(); - const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); - - const int filter_half_width = filter_width / 2; - const int filter_half_height = filter_height / 2; - - const int pad_left = std::min(static_cast(conv_info.pad_left()), filter_half_width); - const int pad_top = std::min(static_cast(conv_info.pad_top()), filter_half_height); - const int pad_right = std::min(static_cast(conv_info.pad_right()), filter_half_width); - const int pad_bottom = std::min(static_cast(conv_info.pad_bottom()), filter_half_height); - - const int minimum_x = -pad_left + filter_half_width; - const int minimum_y = -pad_top + filter_half_height; - const int maximum_x = input_width + pad_left - filter_half_width + pad_right - filter_half_width; - const int maximum_y = input_height + pad_top - filter_half_height + pad_bottom - filter_half_height; - - int out_pos = 0; - for(int r = 0; r < num_batches; ++r) - { - for(int z = 0; z < input_depth; ++z) - { - for(int y = minimum_y; y < minimum_y + maximum_y; y += conv_info.stride().second) - { - for(int x = minimum_x; x < minimum_x + maximum_x; x += conv_info.stride().first) - { - Coordinates coords(static_cast(x), static_cast(y), static_cast(z), static_cast(r)); - size_t filter_offset = filter_plane * z; - - T val = 0; - for(int j = y - filter_half_height; j <= static_cast(y + filter_half_height); ++j) - { - for(int i = x - filter_half_width; i <= static_cast(x + filter_half_width); ++i) - { - coords.set(0, i); - coords.set(1, j); - val += *(weights.data() + filter_offset) * tensor_elem_at(src, coords, BorderMode::CONSTANT, 0.f); - ++filter_offset; - } - } - coords.set(0, x); - coords.set(1, y); - dst[out_pos++] = saturate_cast(val + *static_cast(biases(Coordinates(z)))); - } - } - } - } - - return dst; -} - -template <> -SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info) -{ - // Create reference - SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; - - const int input_offset = -src.quantization_info().offset; - const float input_scale = src.quantization_info().scale; - const int weights_offset = -weights.quantization_info().offset; - const float weights_scale = weights.quantization_info().scale; - const int output_offset = dst.quantization_info().offset; - const float output_scale = dst.quantization_info().scale; - - int output_multiplier; - int output_shift; - const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); - - // Compute reference - const int filter_width = weights.shape().x(); - const int filter_height = weights.shape().y(); - const int filter_plane = filter_width * filter_height; - const int input_width = src.shape().x(); - const int input_height = src.shape().y(); - const int input_depth = src.shape().z(); - const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); - - const int filter_half_size = filter_width / 2; - const int pad_x = std::min(filter_half_size, static_cast(conv_info.pad().first)); - const int pad_y = std::min(filter_half_size, static_cast(conv_info.pad().second)); - const int minimum_x = -pad_x + filter_half_size; - const int minimum_y = -pad_y + filter_half_size; - - int out_pos = 0; - for(int r = 0; r < num_batches; ++r) - { - for(int z = 0; z < input_depth; ++z) - { - int32_t bias_val = *static_cast(biases(Coordinates(z))); - for(int y = minimum_y; y < input_height + pad_y - filter_half_size; y += conv_info.stride().second) - { - for(int x = minimum_x; x < input_width + pad_x - filter_half_size; x += conv_info.stride().first) - { - Coordinates coords(x, y, z); - int filter_offset = filter_plane * z; - - uint32_t val = 0; - for(int j = y - filter_half_size; j <= (y + filter_half_size); ++j) - { - for(int i = x - filter_half_size; i <= (x + filter_half_size); ++i) - { - coords.set(0, i); - coords.set(1, j); - auto in_val = tensor_elem_at(src, coords, BorderMode::CONSTANT, 0); - uint8_t w_val = *(weights.data() + filter_offset); - val += (in_val + input_offset) * (w_val + weights_offset); - ++filter_offset; - } - } - val += bias_val; - val = asymm_rounding_divide_by_pow2(asymm_int_mult(val, output_multiplier), output_shift); - val += output_offset; - val = std::max(val, 0); - val = std::min(val, 255); - - // Store the result - dst[out_pos++] = val; - } - } - } - } - - return dst; -} - -template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DepthwiseConvolutionLayer.h b/tests/validation/CPP/DepthwiseConvolutionLayer.h deleted file mode 100644 index df743a5b8e..0000000000 --- a/tests/validation/CPP/DepthwiseConvolutionLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_DEPTHWISE_CONVOLUTION_H__ -#define __ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.cpp b/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.cpp deleted file mode 100644 index ca6c168114..0000000000 --- a/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017 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 "DepthwiseConvolutionLayer.h" - -#include "DepthwiseSeparableConvolutionLayer.h" - -#include "ConvolutionLayer.h" -#include "Utils.h" - -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -// Depthwise separable convolution layer -template -SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &src, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, - const TensorShape &depthwise_out_shape, - const SimpleTensor &pointwise_weights, - const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, const PadStrideInfo &depthwise_conv_info, const PadStrideInfo &pointwise_conv_info) -{ - // Compute reference - SimpleTensor depthwise_out = depthwise_convolution(src, depthwise_weights, depthwise_biases, depthwise_out_shape, depthwise_conv_info); - SimpleTensor dst = convolution_layer(depthwise_out, pointwise_weights, pointwise_biases, dst_shape, pointwise_conv_info); - - return dst; -} - -template SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &in, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, - const TensorShape &depthwise_out_shape, - const SimpleTensor &pointwise_weights, const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, const PadStrideInfo &depthwise_conv_info, - const PadStrideInfo &pointwise_conv_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.h b/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.h deleted file mode 100644 index 0fcce2c964..0000000000 --- a/tests/validation/CPP/DepthwiseSeparableConvolutionLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ -#define __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &src, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, - const TensorShape &depthwise_out_shape, - const SimpleTensor &pointwise_weights, const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, - const PadStrideInfo &depthwise_conv_info, const PadStrideInfo &pointwise_conv_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/CPP/DequantizationLayer.cpp b/tests/validation/CPP/DequantizationLayer.cpp deleted file mode 100644 index 33096a1d81..0000000000 --- a/tests/validation/CPP/DequantizationLayer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017 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 "DequantizationLayer.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max) -{ - // Create reference - SimpleTensor dst{ src.shape(), DataType::F32 }; - - // Compute reference - const int width = src.shape().x(); - const int height = src.shape().y(); - const int depth = src.shape().z(); - const int stride_w = width * height * depth; - const int num_batches = min_max.shape().total_size_upper(1); - - for(int k = 0; k < num_batches; ++k) - { - const float min = min_max[k * 2 + 0]; - const float max = min_max[k * 2 + 1]; - const float range = max - min; - const float scaling = range / 255.0f; - - for(int i = 0; i < stride_w; ++i) - { - dst[i + k * stride_w] = (static_cast(src[i + k * stride_w]) * scaling) + min; - } - } - - return dst; -} - -template SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/DequantizationLayer.h b/tests/validation/CPP/DequantizationLayer.h deleted file mode 100644 index 1a8adcf9d8..0000000000 --- a/tests/validation/CPP/DequantizationLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_DEQUANTIZATION_LAYER_H__ -#define __ARM_COMPUTE_TEST_DEQUANTIZATION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DEQUANTIZATION_LAYER_H__ */ diff --git a/tests/validation/CPP/Dilate.cpp b/tests/validation/CPP/Dilate.cpp deleted file mode 100644 index 0683a0a9a1..0000000000 --- a/tests/validation/CPP/Dilate.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2017 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 "Dilate.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - /* - -1 x +1 - -1 [tl][tc][tr] -1 - y [ml][xy][mr] y - +1 [bl][bc][br] +1 - -1 x +1 - dilate: - dst(x, y) = max[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = max({tl, tc, tr, ml, xy, mr, bl, bc, br}) - */ - SimpleTensor dst(src.shape(), src.data_type()); - - for(int i = 0; i < src.num_elements(); ++i) - { - Coordinates coord = index2coord(src.shape(), i); - const int x = coord.x(); - const int y = coord.y(); - - std::array neighbours = { { 0 } }; - for(int row = y - 1, j = 0; row <= y + 1; ++row) - { - for(int col = x - 1; col <= x + 1; ++col, ++j) - { - coord.set(0, col); - coord.set(1, row); - neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); - } - } - - dst[i] = *std::max_element(neighbours.cbegin(), neighbours.cend()); - } - - return dst; -} - -template SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Dilate.h b/tests/validation/CPP/Dilate.h deleted file mode 100644 index 6586cbf841..0000000000 --- a/tests/validation/CPP/Dilate.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_DILATE_H__ -#define __ARM_COMPUTE_TEST_DILATE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_DILATE_H__ */ diff --git a/tests/validation/CPP/Erode.cpp b/tests/validation/CPP/Erode.cpp deleted file mode 100644 index 5e8b36f47b..0000000000 --- a/tests/validation/CPP/Erode.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2017 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 "Erode.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - /* - -1 x +1 - -1 [tl][tc][tr] -1 - y [ml][xy][mr] y - +1 [bl][bc][br] +1 - -1 x +1 - erode: - dst(x, y) = min[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = min({tl, tc, tr, ml, xy, mr, bl, bc, br}) - */ - SimpleTensor dst(src.shape(), src.data_type()); - - for(int i = 0; i < src.num_elements(); ++i) - { - Coordinates coord = index2coord(src.shape(), i); - const int x = coord.x(); - const int y = coord.y(); - - std::array neighbours = { { 0 } }; - for(int row = y - 1, j = 0; row <= y + 1; ++row) - { - for(int col = x - 1; col <= x + 1; ++col, ++j) - { - coord.set(0, col); - coord.set(1, row); - neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); - } - } - - dst[i] = *std::min_element(neighbours.cbegin(), neighbours.cend()); - } - - return dst; -} - -template SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Erode.h b/tests/validation/CPP/Erode.h deleted file mode 100644 index 5e27513471..0000000000 --- a/tests/validation/CPP/Erode.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_ERODE_H__ -#define __ARM_COMPUTE_TEST_ERODE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_ERODE_H__ */ diff --git a/tests/validation/CPP/FixedPoint.cpp b/tests/validation/CPP/FixedPoint.cpp deleted file mode 100644 index a016093ed6..0000000000 --- a/tests/validation/CPP/FixedPoint.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2017 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 "FixedPoint.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op) -{ - SimpleTensor result(src.shape(), src.data_type()); - - const int p = src.fixed_point_position(); - switch(op) - { - case FixedPointOp::EXP: - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = fixed_point_arithmetic::exp(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); - } - break; - case FixedPointOp::LOG: - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = fixed_point_arithmetic::log(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); - } - break; - case FixedPointOp::INV_SQRT: - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = fixed_point_arithmetic::inv_sqrt(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); - } - break; - case FixedPointOp::RECIPROCAL: - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = fixed_point_arithmetic::div(fixed_point_arithmetic::fixed_point(1, p), fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); - } - break; - default: - ARM_COMPUTE_ERROR("Fixed point operation not supported"); - break; - } - - return result; -} - -template SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); -template SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPoint.h b/tests/validation/CPP/FixedPoint.h deleted file mode 100644 index f0117f9dd0..0000000000 --- a/tests/validation/CPP/FixedPoint.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_FIXED_POINT_OPERATION_H__ -#define __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ */ diff --git a/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp b/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp deleted file mode 100644 index 636919b1ff..0000000000 --- a/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2017 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, - * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "FixedPointPixelWiseMultiplication.h" - -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy) -{ - using namespace fixed_point_arithmetic; - - SimpleTensor dst(src2.shape(), src2.data_type(), 1, src2.fixed_point_position()); - - const int fixed_point_position = src1.fixed_point_position(); - - ARM_COMPUTE_ERROR_ON_MSG(src1.data_type() != src2.data_type() || src1.data_type() != dst.data_type(), - "Tensors must all have the same DataType"); - ARM_COMPUTE_ERROR_ON_MSG(fixed_point_position != src2.fixed_point_position() || fixed_point_position != dst.fixed_point_position(), - "Fixed-point position must be the same for both inputs and outputs"); - - // Validate fixed_point_position - ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS8) && (fixed_point_position == 0 || fixed_point_position > 7)); - ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS16) && (fixed_point_position == 0 || fixed_point_position > 15)); - - const fixed_point fp_scale(scale, fixed_point_position); - const bool is_sat = convert_policy == ConvertPolicy::SATURATE; - - for(int i = 0; i < src1.num_elements(); ++i) - { - const fixed_point val1(src1[i], fixed_point_position, true); - fixed_point res(src2[i], fixed_point_position, true); - if(is_sat) - { - res = mul(mul(res, val1), fp_scale); - } - else - { - res = mul(mul(res, val1), fp_scale); - } - dst[i] = res.raw(); - } - - return dst; -} - -// *INDENT-OFF* -// clang-format off -template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); -template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); -// *INDENT-ON* -// clang-format on - -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPointPixelWiseMultiplication.h b/tests/validation/CPP/FixedPointPixelWiseMultiplication.h deleted file mode 100644 index 124a33c9da..0000000000 --- a/tests/validation/CPP/FixedPointPixelWiseMultiplication.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ -#define __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/CPP/FlattenLayer.cpp b/tests/validation/CPP/FlattenLayer.cpp deleted file mode 100644 index 611701d8cf..0000000000 --- a/tests/validation/CPP/FlattenLayer.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2017 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 "FlattenLayer.h" - -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor flatten_layer(const SimpleTensor &src) -{ - TensorShape shape_flatten(src.shape()); - shape_flatten.set(0, src.shape()[0] * src.shape()[1] * src.shape()[2]); - shape_flatten.remove_dimension(1); - shape_flatten.remove_dimension(1); - SimpleTensor dst(shape_flatten, src.data_type(), 1, src.fixed_point_position()); - - // Note: Since the reference implementation does not use padding bytes, we can copy directly the content of the source tensor - std::copy(src.data(), src.data() + src.num_elements(), dst.data()); - - return dst; -} - -template SimpleTensor flatten_layer(const SimpleTensor &src); -template SimpleTensor flatten_layer(const SimpleTensor &src); -template SimpleTensor flatten_layer(const SimpleTensor &src); -template SimpleTensor flatten_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/FlattenLayer.h b/tests/validation/CPP/FlattenLayer.h deleted file mode 100644 index b1286fe2bd..0000000000 --- a/tests/validation/CPP/FlattenLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_FLATTEN_LAYER_H__ -#define __ARM_COMPUTE_TEST_FLATTEN_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor flatten_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FLATTEN_LAYER_H__ */ diff --git a/tests/validation/CPP/Floor.cpp b/tests/validation/CPP/Floor.cpp deleted file mode 100644 index 1c739448b7..0000000000 --- a/tests/validation/CPP/Floor.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 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 "Floor.h" - -#include "tests/validation/Helpers.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor floor_layer(const SimpleTensor &src) -{ - // Create reference - SimpleTensor dst{ src.shape(), src.data_type() }; - - // Compute reference - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = std::floor(src[i]); - } - - return dst; -} - -template SimpleTensor floor_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Floor.h b/tests/validation/CPP/Floor.h deleted file mode 100644 index d95ee303fc..0000000000 --- a/tests/validation/CPP/Floor.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_FLOOR_H__ -#define __ARM_COMPUTE_TEST_FLOOR_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor floor_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FLOOR_H__ */ diff --git a/tests/validation/CPP/FullyConnectedLayer.cpp b/tests/validation/CPP/FullyConnectedLayer.cpp deleted file mode 100644 index 6b618a955c..0000000000 --- a/tests/validation/CPP/FullyConnectedLayer.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2017 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 "FullyConnectedLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/CPP/UtilsQuantizedAsymm.h" -#include "tests/validation/FixedPoint.h" - -#include "arm_compute/core/utils/quantization/AsymmHelpers.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -// Vector matrix multiply for floating point -template < typename T, typename TB, typename std::enable_if < is_floating_point::value &&is_floating_point::value, int >::type = 0 > -void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, int cols_weights, - int rows_weights, uint8_t fixed_point_position) -{ - ARM_COMPUTE_UNUSED(fixed_point_position); - - const T *src_ptr = src.data() + offset_src; - const T *weights_ptr = weights.data(); - const TB *bias_ptr = bias.data(); - T *dst_ptr = dst.data() + offset_dst; - - for(int y = 0; y < rows_weights; ++y) - { - dst_ptr[y] = std::inner_product(src_ptr, src_ptr + cols_weights, weights_ptr, static_cast(0)) + bias_ptr[y]; - weights_ptr += cols_weights; - } -} - -// Vector matrix multiply for fixed point type -template < typename T, typename TB, typename std::enable_if < std::is_integral::value &&std::is_integral::value, int >::type = 0 > -void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, int cols_weights, - int rows_weights, uint8_t fixed_point_position) -{ - const T *src_ptr = src.data() + offset_src; - const T *weights_ptr = weights.data(); - const TB *bias_ptr = bias.data(); - T *dst_ptr = dst.data() + offset_dst; - - using namespace fixed_point_arithmetic; - using promoted_type = fixed_point_arithmetic::traits::promote_t; - - for(int y = 0; y < rows_weights; ++y) - { - // Reset accumulator - fixed_point acc(0, fixed_point_position); - - for(int x = 0; x < cols_weights; ++x) - { - const fixed_point i_value(src_ptr[x], fixed_point_position, true); - const fixed_point w_value(weights_ptr[x], fixed_point_position, true); - acc = acc + i_value * w_value; - } - - // Get the bias - const fixed_point b(bias_ptr[y], fixed_point_position, true); - - // Convert back and accumulate the bias - fixed_point res(acc); - res = res + b; - - // Store the result - dst_ptr[y] = res.raw(); - - weights_ptr += cols_weights; - } -} - -// Vector matrix multiply for quantized type -template <> -void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, - int cols_weights, int rows_weights, uint8_t fixed_point_position) -{ - ARM_COMPUTE_UNUSED(fixed_point_position); - - const uint8_t *src_ptr = src.data() + offset_src; - const uint8_t *weights_ptr = weights.data(); - const int32_t *bias_ptr = bias.data(); - uint8_t *dst_ptr = dst.data() + offset_dst; - - const int input_offset = -src.quantization_info().offset; - const float input_scale = src.quantization_info().scale; - const int weights_offset = -weights.quantization_info().offset; - const float weights_scale = weights.quantization_info().scale; - const int output_offset = dst.quantization_info().offset; - const float output_scale = dst.quantization_info().scale; - - int output_multiplier = 0; - int output_shift = 0; - const float multiplier = input_scale * weights_scale / output_scale; - arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); - - for(int y = 0; y < rows_weights; ++y) - { - // Reset accumulator - int32_t acc = 0; - - for(int x = 0; x < cols_weights; ++x) - { - acc += (src_ptr[x] + input_offset) * (weights_ptr[x] + weights_offset); - } - - // Accumulate the bias - acc += bias_ptr[y]; - - acc = asymm_rounding_divide_by_pow2(asymm_int_mult(acc, output_multiplier), output_shift); - acc += output_offset; - acc = clamp(acc, 0, 255); - - // Store the result - dst_ptr[y] = static_cast(acc); - - weights_ptr += cols_weights; - } -} -} // namespace - -template -SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape) -{ - // Create reference - SimpleTensor dst{ TensorShape{ dst_shape }, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; - - // Sanity checks - const int num_batch_dimensions = std::max(0, static_cast(dst_shape.num_dimensions()) - 1); - const int num_input_dimensions = src.shape().num_dimensions() - num_batch_dimensions; - const unsigned int linear_input_size = src.shape().total_size_lower(num_input_dimensions); - - ARM_COMPUTE_UNUSED(num_batch_dimensions); - ARM_COMPUTE_UNUSED(num_input_dimensions); - ARM_COMPUTE_UNUSED(linear_input_size); - ARM_COMPUTE_ERROR_ON(weights.shape().x() != linear_input_size); - ARM_COMPUTE_ERROR_ON(weights.shape().y() != bias.shape().x()); - ARM_COMPUTE_ERROR_ON(weights.shape().y() != dst.shape().x()); - - // Compute reference - const int cols_weights = weights.shape().x(); - const int rows_weights = weights.shape().y(); - const int num_batches = dst_shape.total_size_upper(1); - - for(int k = 0; k < num_batches; ++k) - { - const int offset_in = k * cols_weights; - const int offset_out = k * rows_weights; - - vector_matrix_multiply(src, - weights, - bias, - dst, - offset_in, - offset_out, - cols_weights, - rows_weights, - src.fixed_point_position()); - } - - return dst; -} - -template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/FullyConnectedLayer.h b/tests/validation/CPP/FullyConnectedLayer.h deleted file mode 100644 index 1dfb496924..0000000000 --- a/tests/validation/CPP/FullyConnectedLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_FULLY_CONNECTED_LAYER_H__ -#define __ARM_COMPUTE_TEST_FULLY_CONNECTED_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FULLY_CONNECTED_LAYER_H__ */ diff --git a/tests/validation/CPP/GEMM.cpp b/tests/validation/CPP/GEMM.cpp deleted file mode 100644 index 77d025ec8e..0000000000 --- a/tests/validation/CPP/GEMM.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2017 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 "GEMM.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta) -{ - // Create reference - SimpleTensor dst{ c.shape(), c.data_type(), 1, c.fixed_point_position() }; - - // Compute reference - const int M = dst.shape().y(); - const int N = dst.shape().x(); - const int K = a.shape().x(); - - for(int row = 0; row < M; ++row) - { - for(int col = 0; col < N; ++col) - { - T acc(0); - - for(int k = 0; k < K; ++k) - { - acc += a[row * K + k] * b[k * N + col]; - } - - // Finalize the result: alpha * A * B + beta * C - dst[col + row * N] = alpha * acc + beta * c[col + row * N]; - } - } - - return dst; -} - -template ::value, int>::type> -SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta) -{ - using namespace fixed_point_arithmetic; - - // Create reference - SimpleTensor dst{ c.shape(), c.data_type(), 1, c.fixed_point_position() }; - - // Compute reference - using promoted_type = fixed_point_arithmetic::traits::promote_t; - - const int M = dst.shape().y(); - const int N = dst.shape().x(); - const int K = a.shape().x(); - const int fixed_point_position = a.fixed_point_position(); - - const fixed_point alpha_q(alpha, fixed_point_position); - const fixed_point beta_q(beta, fixed_point_position); - - for(int row = 0; row < M; ++row) - { - for(int col = 0; col < N; ++col) - { - fixed_point acc_q(0, fixed_point_position); - - for(int k = 0; k < K; ++k) - { - const fixed_point a0_q(a[row * K + k], fixed_point_position, true); - const fixed_point b0_q(b[k * N + col], fixed_point_position, true); - - acc_q = acc_q + (a0_q * b0_q); - } - - // Finalize the result: alpha * A * B + beta * C - const fixed_point c0_q(c[col + row * N], fixed_point_position, true); - - fixed_point res_q(acc_q); - res_q = alpha_q * res_q; - res_q = res_q + (beta_q * c0_q); - - // Store the result - dst[col + row * N] = res_q.raw(); - } - } - - return dst; -} - -template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); -template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); -template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); -template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/GEMM.h b/tests/validation/CPP/GEMM.h deleted file mode 100644 index cda792bf8b..0000000000 --- a/tests/validation/CPP/GEMM.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_GEMM_H__ -#define __ARM_COMPUTE_TEST_GEMM_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); - -template ::value, int>::type = 0> -SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_GEMM_H__ */ diff --git a/tests/validation/CPP/GEMMInterleave4x4.h b/tests/validation/CPP/GEMMInterleave4x4.h deleted file mode 100644 index e6b09afb9a..0000000000 --- a/tests/validation/CPP/GEMMInterleave4x4.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2017 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 "GEMM.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gemm_interleave_4x4(const SimpleTensor &in, SimpleTensor &out) -{ - const T *mtx_in = reinterpret_cast(in.data()); - T *mtx_ref = reinterpret_cast(out.data()); - const int32_t in_rows = in.shape().y(); - const int32_t in_cols = in.shape().x(); - const int32_t out_stride = out.shape().x(); - int32_t y = 0; - for(; y <= (in_rows - 4); y += 4) - { - const T *in_ptr = &mtx_in[y * in_cols]; - - for(int32_t x = 0; x < in_cols; x++) - { - const T tmp[4] = { in_ptr[x + 0 * in_cols], - in_ptr[x + 1 * in_cols], - in_ptr[x + 2 * in_cols], - in_ptr[x + 3 * in_cols] - }; - - T *dst = &mtx_ref[static_cast(x * 4.f) + static_cast(std::ceil(y / 4.f)) * out_stride]; - memcpy(dst, tmp, sizeof(T) * 4); - } - } - - // Leftover along the Y direction - const int32_t leftover_y = in_rows - y; - - if(leftover_y != 0) - { - const T *in_ptr = &mtx_in[y * in_cols]; - - for(int32_t x = 0; x < in_cols; x++) - { - T tmp[4] = { 0, 0, 0, 0 }; - - for(int32_t k = 0; k < leftover_y; k++) - { - tmp[k] = in_ptr[k * in_cols + x]; - } - T *dst = &mtx_ref[static_cast(x * 4.f) + static_cast(std::ceil(y / 4.f)) * out_stride]; - memcpy(dst, tmp, sizeof(T) * 4); - } - } - - return out; -} - -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/GEMMInterleaveBlocked.h b/tests/validation/CPP/GEMMInterleaveBlocked.h deleted file mode 100644 index ff5a0d647c..0000000000 --- a/tests/validation/CPP/GEMMInterleaveBlocked.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2017 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 "GEMM.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -T safe_read(const SimpleTensor &t, int y, int x) -{ - const int stride = t.shape().x(); - const int M = t.shape().y(); - const int N = t.shape().x(); - if((y < M) && (x < N)) - { - return t[y * stride + x]; - } - return 0; -} - -template -SimpleTensor gemm_interleave_blocked(const SimpleTensor &in, SimpleTensor &out, int int_by, int block, bool transposed) -{ - const int M = out.shape().y(); - const int N = out.shape().x(); - for(int y = 0; y < M; y++) - { - T *out_ptr = &out[y * N]; - for(int x = 0; x < (N / int_by); x += block) - { - for(int z = 0; z < int_by; z++) - { - for(int a = 0; (out_ptr <= &out[y * N + (N - 1)]) && a < block; a++) - { - if(!transposed) - *out_ptr++ = safe_read(in, (y * int_by) + z, x + a); - else - { - const T value = safe_read(in, x + a, (y * int_by) + z); - *out_ptr++ = value; - } - } - } - } - } - return out; -} - -template SimpleTensor gemm_interleave_blocked(const SimpleTensor &in, SimpleTensor &out, int int_by, int block, bool transposed); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/GEMMLowp.cpp b/tests/validation/CPP/GEMMLowp.cpp deleted file mode 100644 index 92878947c8..0000000000 --- a/tests/validation/CPP/GEMMLowp.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2017 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 "GEMMLowp.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/CPP/UtilsQuantizedAsymm.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template -void quantize_down_int32_to_uint8_scale(const SimpleTensor *in, const SimpleTensor *bias, SimpleTensor *dst, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, - int32_t min, int32_t max) -{ - const int cols_in = in->shape().x(); - - for(int i = 0; i < in->num_elements(); ++i) - { - int32_t result = ((*in)[i] + result_offset); - - if(bias != nullptr) - { - result += (*bias)[i % cols_in]; - } - - result *= result_mult_int; - - result >>= result_shift; - - // Bounded ReLu - if(min != max) - { - result = std::max(min, std::min(max, result)); - } - - (*dst)[i] = static_cast(std::max(0, std::min(255, result))); - } -} - -template -void quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor *in, const SimpleTensor *bias, SimpleTensor *dst, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, int32_t min, int32_t max) -{ - const int cols_in = in->shape().x(); - - for(int i = 0; i < in->num_elements(); ++i) - { - int32_t result = (*in)[i]; - - if(bias != nullptr) - { - result += (*bias)[i % cols_in]; - } - - // Fixed point multiplication - result = asymm_rounding_divide_by_pow2(asymm_int_mult(result, result_fixedpoint_multiplier), result_shift); - result += result_offset_after_shift; - - // Bounded ReLu - if(min != max) - { - result = std::max(min, std::min(max, result)); - } - - (*dst)[i] = static_cast(std::max(0, std::min(255, result))); - } -} -} // namespace - -template -SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset) -{ - static_assert(std::is_same::type, int32_t>::value, "Only int32_t is allowed for the output"); - - TensorShape shape(b.shape()[0], a.shape()[1]); - DataType dt = std::is_same::value ? DataType::S32 : DataType::U32; - SimpleTensor c(shape, dt); - - const int K = a.shape().x(); - const int b_width = b.shape().x(); - const int rows = c.shape().y(); //M - const int cols = c.shape().x(); //N - - std::vector acc; - acc.resize(cols); - - for(int i = 0; i < rows; ++i) - { - for(int j = 0; j < cols; ++j) - { - acc[j] = 0; - } - for(int k = 0; k < K; ++k) - { - const T_out tmp_a = a_offset + static_cast(a[k + i * K]); - for(int j = 0; j < b_width; ++j) - { - const T_out tmp_b = b_offset + static_cast(b[j + k * b_width]); - const T_out mult_as_int = tmp_a * tmp_b; - acc[j] += mult_as_int; - } - } - for(int j = 0; j < cols; ++j) - { - c[j + i * cols] = acc[j]; - } - } - - return c; -} - -// used to validate assembly kernels which don't know anything about offsets -template -SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b) -{ - return gemmlowp_matrix_multiply_core(a, b, 0, 0); -} - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min, int32_t max) -{ - SimpleTensor dst(in.shape(), DataType::QASYMM8); - - quantize_down_int32_to_uint8_scale(&in, nullptr, &dst, result_offset, result_mult_int, result_shift, min, max); - - return dst; -} - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, - int32_t min, int32_t max) -{ - SimpleTensor dst(in.shape(), DataType::QASYMM8); - - quantize_down_int32_to_uint8_scale(&in, &bias, &dst, result_offset, result_mult_int, result_shift, min, max); - - return dst; -} - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, int32_t min, - int32_t max) -{ - SimpleTensor dst(in.shape(), DataType::QASYMM8); - - quantize_down_int32_to_uint8_scale_by_fixedpoint(&in, nullptr, &dst, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); - - return dst; -} - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, int32_t min, int32_t max) -{ - SimpleTensor dst(in.shape(), DataType::QASYMM8); - - quantize_down_int32_to_uint8_scale_by_fixedpoint(&in, &bias, &dst, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); - - return dst; -} - -template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &a, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, int32_t min, int32_t max); -template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &a, const SimpleTensor &b, int32_t result_fixedpoint_multiplier, - int32_t result_shift, int32_t result_offset_after_shift, int32_t min, int32_t max); -template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &a, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min, - int32_t max); -template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &a, const SimpleTensor &b, int32_t result_offset, int32_t result_mult_int, - int32_t result_shift, int32_t min, int32_t max); -template SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); -template SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); -template SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); -template SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/GEMMLowp.h b/tests/validation/CPP/GEMMLowp.h deleted file mode 100644 index a3d0bebe3f..0000000000 --- a/tests/validation/CPP/GEMMLowp.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 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_GEMMLOWP_H__ -#define __ARM_COMPUTE_TEST_GEMMLOWP_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min = 0, int32_t max = 0); -template -SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift); - -template -SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, - int32_t min = 0, int32_t max = 0); - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, - int32_t min = 0, int32_t max = 0); - -template -SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_fixedpoint_multiplier, int32_t result_shift, - int32_t result_offset_after_shift, int32_t min = 0, int32_t max = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_GEMMLOWP_H__ */ diff --git a/tests/validation/CPP/Gaussian3x3.cpp b/tests/validation/CPP/Gaussian3x3.cpp deleted file mode 100644 index c71eade5c1..0000000000 --- a/tests/validation/CPP/Gaussian3x3.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Gaussian3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - const std::array filter{ { 1, 2, 1, 2, 4, 2, 1, 2, 1 } }; - const float scale = 1.f / 16.f; - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Gaussian3x3.h b/tests/validation/CPP/Gaussian3x3.h deleted file mode 100644 index 85a7acdbfc..0000000000 --- a/tests/validation/CPP/Gaussian3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_GAUSSIAN3X3_H__ -#define __ARM_COMPUTE_TEST_GAUSSIAN3X3_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_GAUSSIAN3X3_H__ */ diff --git a/tests/validation/CPP/Gaussian5x5.cpp b/tests/validation/CPP/Gaussian5x5.cpp deleted file mode 100644 index 55bb287fbe..0000000000 --- a/tests/validation/CPP/Gaussian5x5.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Gaussian5x5.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - const std::array filter{ { - 1, 4, 6, 4, 1, - 4, 16, 24, 16, 4, - 6, 24, 36, 24, 6, - 4, 16, 24, 16, 4, - 1, 4, 6, 4, 1 - } }; - const float scale = 1.f / 256.f; - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(5U, 5U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Gaussian5x5.h b/tests/validation/CPP/Gaussian5x5.h deleted file mode 100644 index df981c70b0..0000000000 --- a/tests/validation/CPP/Gaussian5x5.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_GAUSSIAN5X5_H__ -#define __ARM_COMPUTE_TEST_GAUSSIAN5X5_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_GAUSSIAN5X5_H__ */ diff --git a/tests/validation/CPP/GaussianPyramidHalf.cpp b/tests/validation/CPP/GaussianPyramidHalf.cpp deleted file mode 100644 index 0a68dedaee..0000000000 --- a/tests/validation/CPP/GaussianPyramidHalf.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017 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 "GaussianPyramidHalf.h" - -#include "arm_compute/core/Helpers.h" - -#include "Gaussian5x5.h" -#include "Scale.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels) -{ - std::vector> dst; - - // Level0 is equal to src - dst.push_back(src); - - for(size_t i = 1; i < num_levels; ++i) - { - // Gaussian Filter - const SimpleTensor out_gaus5x5 = reference::gaussian5x5(dst[i - 1], border_mode, constant_border_value); - - // Scale down by 2 with nearest interpolation - const SimpleTensor out = reference::scale(out_gaus5x5, SCALE_PYRAMID_HALF, SCALE_PYRAMID_HALF, InterpolationPolicy::NEAREST_NEIGHBOR, border_mode, constant_border_value, SamplingPolicy::CENTER, - true); - - dst.push_back(out); - } - - return dst; -} - -template std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/GaussianPyramidHalf.h b/tests/validation/CPP/GaussianPyramidHalf.h deleted file mode 100644 index abd29e1700..0000000000 --- a/tests/validation/CPP/GaussianPyramidHalf.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_GAUSSIAN_PYRAMID_HALF_H__ -#define __ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H__ */ \ No newline at end of file diff --git a/tests/validation/CPP/HarrisCornerDetector.cpp b/tests/validation/CPP/HarrisCornerDetector.cpp deleted file mode 100644 index 6cfcd8ecc5..0000000000 --- a/tests/validation/CPP/HarrisCornerDetector.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2017 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 "HarrisCornerDetector.h" - -#include "Utils.h" -#include "tests/validation/CPP/NonMaximaSuppression.h" -#include "tests/validation/CPP/Sobel.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template -std::tuple, SimpleTensor, float> compute_sobel(const SimpleTensor &src, int gradient_size, int block_size, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor grad_x; - SimpleTensor grad_y; - float norm_factor = 0.f; - - std::tie(grad_x, grad_y) = sobel(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - switch(gradient_size) - { - case 3: - norm_factor = 1.f / (4 * 255 * block_size); - break; - case 5: - norm_factor = 1.f / (16 * 255 * block_size); - break; - case 7: - norm_factor = 1.f / (64 * 255 * block_size); - break; - default: - ARM_COMPUTE_ERROR("Gradient size not supported."); - } - - return std::make_tuple(grad_x, grad_y, norm_factor); -} - -template -std::vector harris_corner_detector_impl(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - U constant_border_value) -{ - ARM_COMPUTE_ERROR_ON(block_size != 3 && block_size != 5 && block_size != 7); - - SimpleTensor grad_x; - SimpleTensor grad_y; - float norm_factor = 0.f; - - // Sobel - std::tie(grad_x, grad_y, norm_factor) = compute_sobel(src, gradient_size, block_size, border_mode, constant_border_value); - - SimpleTensor scores(src.shape(), DataType::F32); - ValidRegion scores_region = shape_to_valid_region(scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2)); - - // Calculate scores - for(int i = 0; i < scores.num_elements(); ++i) - { - Coordinates src_coord = index2coord(src.shape(), i); - Coordinates block_top_left{ src_coord.x() - block_size / 2, src_coord.y() - block_size / 2 }; - Coordinates block_bottom_right{ src_coord.x() + block_size / 2, src_coord.y() + block_size / 2 }; - - if(!is_in_valid_region(scores_region, src_coord)) - { - scores[i] = 0.f; - continue; - } - - float Gx2 = 0.f; - float Gy2 = 0.f; - float Gxy = 0.f; - - // Calculate Gx^2, Gy^2 and Gxy within the given window - for(int y = src_coord.y() - block_size / 2; y <= src_coord.y() + block_size / 2; ++y) - { - for(int x = src_coord.x() - block_size / 2; x <= src_coord.x() + block_size / 2; ++x) - { - Coordinates block_coord(x, y); - - const float norm_x = tensor_elem_at(grad_x, block_coord, border_mode, static_cast(constant_border_value)) * norm_factor; - const float norm_y = tensor_elem_at(grad_y, block_coord, border_mode, static_cast(constant_border_value)) * norm_factor; - - Gx2 += std::pow(norm_x, 2); - Gy2 += std::pow(norm_y, 2); - Gxy += norm_x * norm_y; - } - } - - const float trace2 = std::pow(Gx2 + Gy2, 2); - const float det = Gx2 * Gy2 - std::pow(Gxy, 2); - const float response = det - sensitivity * trace2; - - if(response > threshold) - { - scores[i] = response; - } - else - { - scores[i] = 0.f; - } - } - - // Suppress non-maxima candidates - SimpleTensor suppressed_scores = non_maxima_suppression(scores, border_mode != BorderMode::UNDEFINED ? BorderMode::CONSTANT : BorderMode::UNDEFINED, 0.f); - ValidRegion suppressed_scores_region = shape_to_valid_region(suppressed_scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2 + 1)); - - // Create vector of candidate corners - std::vector corner_candidates; - - for(int i = 0; i < suppressed_scores.num_elements(); ++i) - { - Coordinates coord = index2coord(suppressed_scores.shape(), i); - - if(is_in_valid_region(suppressed_scores_region, coord) && suppressed_scores[i] > 0.f) - { - KeyPoint corner; - corner.x = coord.x(); - corner.y = coord.y(); - corner.tracking_status = 1; - corner.strength = suppressed_scores[i]; - corner.scale = 0.f; - corner.orientation = 0.f; - corner.error = 0.f; - - corner_candidates.emplace_back(corner); - } - } - - // Sort descending by strength - std::sort(corner_candidates.begin(), corner_candidates.end(), [](const KeyPoint & a, const KeyPoint & b) - { - return a.strength > b.strength; - }); - - std::vector corners; - corners.reserve(corner_candidates.size()); - - // Only add corner if there is no stronger within min_dist - for(const KeyPoint &point : corner_candidates) - { - const auto strongest = std::find_if(corners.begin(), corners.end(), [&](const KeyPoint & other) - { - return std::sqrt((std::pow(point.x - other.x, 2) + std::pow(point.y - other.y, 2))) < min_dist; - }); - - if(strongest == corners.end()) - { - corners.emplace_back(point); - } - } - - corners.shrink_to_fit(); - - return corners; -} -} // namespace - -template -std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - T constant_border_value) -{ - if(gradient_size < 7) - { - return harris_corner_detector_impl(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } - else - { - return harris_corner_detector_impl(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } -} - -template std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/HarrisCornerDetector.h b/tests/validation/CPP/HarrisCornerDetector.h deleted file mode 100644 index 042e8570c2..0000000000 --- a/tests/validation/CPP/HarrisCornerDetector.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_HARRIS_CORNER_DETECTOR_H__ -#define __ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H__ - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H__ */ diff --git a/tests/validation/CPP/Histogram.cpp b/tests/validation/CPP/Histogram.cpp deleted file mode 100644 index 594c4fb81f..0000000000 --- a/tests/validation/CPP/Histogram.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 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 "Histogram.h" - -#include "Utils.h" -#include "arm_compute/core/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range) -{ - SimpleTensor dst(TensorShape(num_bins), DataType::U32); - - // Clear the distribution - for(size_t element_idx = 0; element_idx < num_bins; ++element_idx) - { - dst[element_idx] = 0; - } - - // Create the histogram - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - if((offset <= src[element_idx]) && (src[element_idx] < (offset + range))) - { - const int index = (src[element_idx] - offset) * num_bins / range; - dst[index]++; - } - } - - return dst; -} - -template SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Histogram.h b/tests/validation/CPP/Histogram.h deleted file mode 100644 index 7ec16693aa..0000000000 --- a/tests/validation/CPP/Histogram.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_HISTOGRAM_H__ -#define __ARM_COMPUTE_TEST_HISTOGRAM_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_HISTOGRAM_H__ */ diff --git a/tests/validation/CPP/IntegralImage.cpp b/tests/validation/CPP/IntegralImage.cpp deleted file mode 100644 index 8d07e995b5..0000000000 --- a/tests/validation/CPP/IntegralImage.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017 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 "IntegralImage.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor integral_image(const SimpleTensor &src) -{ - SimpleTensor dst(src.shape(), DataType::U32); - - // Length of dimensions - const size_t width = src.shape().x(); - const size_t height = src.shape().y(); - const size_t depth = src.shape().total_size_upper(2); - - const size_t image_size = width * height; - - for(size_t z = 0; z < depth; ++z) - { - size_t current_image = z * image_size; - - //First element of each image - dst[current_image] = src[current_image]; - - // First row of each image (add only pixel on the left) - for(size_t x = 1; x < width; ++x) - { - dst[current_image + x] = static_cast(src[current_image + x]) + dst[current_image + x - 1]; - } - - // Subsequent rows - for(size_t y = 1; y < height; ++y) - { - size_t current_row = current_image + (width * y); - - // First element of each row (add only pixel up) - dst[current_row] = static_cast(src[current_row]) + dst[current_row - width]; - - // Following row elements - for(size_t x = 1; x < width; ++x) - { - size_t current_pixel = current_row + x; - - // out = in + up(out) + left(out) - up_left(out) - dst[current_pixel] = static_cast(src[current_pixel]) + dst[current_pixel - 1] - + dst[current_pixel - width] - dst[current_pixel - width - 1]; - } - } - } - - return dst; -} - -template SimpleTensor integral_image(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/IntegralImage.h b/tests/validation/CPP/IntegralImage.h deleted file mode 100644 index c766aae89e..0000000000 --- a/tests/validation/CPP/IntegralImage.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_INTEGRAL_IMAGE_H__ -#define __ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor integral_image(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H__ */ diff --git a/tests/validation/CPP/L2NormalizeLayer.cpp b/tests/validation/CPP/L2NormalizeLayer.cpp deleted file mode 100644 index 99f4e8a6e6..0000000000 --- a/tests/validation/CPP/L2NormalizeLayer.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2017 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 "L2NormalizeLayer.h" -#include "ReductionOperation.h" - -#include "tests/validation/Helpers.h" - -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -TensorShape get_output_shape(TensorShape shape, unsigned int axis) -{ - TensorShape output_shape(shape); - output_shape.set(axis, 1); - return output_shape; -} -} // namespace - -template -SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon) -{ - // Create reference - SimpleTensor dst{ src.shape(), src.data_type() }; - - // Reduce across given axis - SimpleTensor sum = reduction_operation(src, get_output_shape(src.shape(), axis), axis, ReductionOperation::SUM_SQUARE); - - // Compute reference - const int elems = src.shape()[axis]; - const int upper_dims = src.shape().total_size_upper(axis + 1); - - for(int du = 0; du < upper_dims; ++du) - { - if(axis == 0) - { - const T *src_row_ptr = src.data() + du * elems; - T *dst_row_ptr = dst.data() + du * elems; - const T normalization_value = std::sqrt(std::max(sum[du], epsilon)); - std::transform(src_row_ptr, src_row_ptr + elems, dst_row_ptr, [normalization_value](T val) - { - return val / normalization_value; - }); - } - else - { - ARM_COMPUTE_ERROR("Unsupported normalization axis"); - } - } - - return dst; -} - -template SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/L2NormalizeLayer.h b/tests/validation/CPP/L2NormalizeLayer.h deleted file mode 100644 index 1db3ae6174..0000000000 --- a/tests/validation/CPP/L2NormalizeLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_L2NORMALIZE_H__ -#define __ARM_COMPUTE_TEST_L2NORMALIZE_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_L2NORMALIZE_H__ */ diff --git a/tests/validation/CPP/Magnitude.cpp b/tests/validation/CPP/Magnitude.cpp deleted file mode 100644 index f0002bfb33..0000000000 --- a/tests/validation/CPP/Magnitude.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017 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 "Magnitude.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type) -{ - SimpleTensor mag(gx.shape(), gx.data_type()); - - using intermediate_type = typename common_promoted_unsigned_type::intermediate_type; - - for(int i = 0; i < gx.num_elements(); ++i) - { - double val = 0.f; - - if(magnitude_type == MagnitudeType::L1NORM) - { - val = static_cast(std::abs(gx[i])) + static_cast(std::abs(gy[i])); - } - else // MagnitudeType::L2NORM - { - // Note: kernel saturates to uint32_t instead of intermediate_type for S32 format - auto sum = static_cast(gx[i] * gx[i]) + static_cast(gy[i] * gy[i]); - val = std::sqrt(sum) + 0.5f; - } - - mag[i] = saturate_cast(val); - } - - return mag; -} - -template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); -template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); -template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Magnitude.h b/tests/validation/CPP/Magnitude.h deleted file mode 100644 index 75620712e3..0000000000 --- a/tests/validation/CPP/Magnitude.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_MAGNITUDE_H__ -#define __ARM_COMPUTE_TEST_MAGNITUDE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_MAGNITUDE_H__ */ diff --git a/tests/validation/CPP/MeanStdDev.cpp b/tests/validation/CPP/MeanStdDev.cpp deleted file mode 100644 index 4a39b13d56..0000000000 --- a/tests/validation/CPP/MeanStdDev.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 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 "MeanStdDev.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::pair mean_and_standard_deviation(const SimpleTensor &in) -{ - const int num_elements = in.num_elements(); - - // Calculate mean - float mean = std::accumulate(in.data(), in.data() + num_elements, 0.f) / num_elements; - - // Calculate standard deviation - float std_dev = std::accumulate(in.data(), in.data() + num_elements, 0.f, [&mean](float a, float b) - { - return a + (mean - b) * (mean - b); - }); - - std_dev = std::sqrt(std_dev / num_elements); - - return std::make_pair(mean, std_dev); -} - -template std::pair mean_and_standard_deviation(const SimpleTensor &in); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/MeanStdDev.h b/tests/validation/CPP/MeanStdDev.h deleted file mode 100644 index 6b89ae0656..0000000000 --- a/tests/validation/CPP/MeanStdDev.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_STD_MEAN_DEV_H__ -#define __ARM_COMPUTE_TEST_STD_MEAN_DEV_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::pair mean_and_standard_deviation(const SimpleTensor &in); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_STD_MEAN_DEV_H__ */ diff --git a/tests/validation/CPP/Median3x3.cpp b/tests/validation/CPP/Median3x3.cpp deleted file mode 100644 index 91a787a0a3..0000000000 --- a/tests/validation/CPP/Median3x3.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Median3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -constexpr unsigned int filter_size = 3; /* Size of the kernel/filter in number of elements. */ -constexpr BorderSize border_size(filter_size / 2); /* Border size of the kernel/filter around its central element. */ -} // namespace - -template -SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - const int size_tot_filter = filter_size * filter_size; - - for(int src_idx = 0; src_idx < src.num_elements(); ++src_idx) - { - std::array filter_elems = { { 0 } }; - Coordinates id = index2coord(src.shape(), src_idx); - const int x = id.x(); - const int y = id.y(); - - for(int j = y - static_cast(border_size.top), index = 0; j <= y + static_cast(border_size.bottom); ++j) - { - for(int i = x - static_cast(border_size.left); i <= x + static_cast(border_size.right); ++i, ++index) - { - id.set(0, i); - id.set(1, j); - filter_elems[index] = tensor_elem_at(src, id, border_mode, constant_border_value); - } - } - std::sort(filter_elems.begin(), filter_elems.end()); - dst[src_idx] = filter_elems[size_tot_filter / 2]; - } - - return dst; -} - -template SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Median3x3.h b/tests/validation/CPP/Median3x3.h deleted file mode 100644 index 8345daa5e0..0000000000 --- a/tests/validation/CPP/Median3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_MEDIAN3X3_H__ -#define __ARM_COMPUTE_TEST_MEDIAN3X3_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_MEDIAN3X3_H__ */ diff --git a/tests/validation/CPP/MinMaxLocation.cpp b/tests/validation/CPP/MinMaxLocation.cpp deleted file mode 100644 index 427adebc61..0000000000 --- a/tests/validation/CPP/MinMaxLocation.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "MinMaxLocation.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -void compute_min_max(const SimpleTensor &src, T &min, T &max) -{ - // Set min and max to first pixel - min = src[0]; - max = src[0]; - - ARM_COMPUTE_ERROR_ON(src.num_elements() == 0); - - // Look for min and max values - for(int i = 1; i < src.num_elements(); ++i) - { - if(src[i] < min) - { - min = src[i]; - } - if(src[i] > max) - { - max = src[i]; - } - } -} - -template -MinMaxLocationValues min_max_location(const SimpleTensor &src) -{ - MinMaxLocationValues dst; - - const size_t width = src.shape().x(); - - compute_min_max(src, dst.min, dst.max); - - Coordinates2D coord{ 0, 0 }; - - for(int i = 0; i < src.num_elements(); ++i) - { - coord.x = static_cast(i % width); - coord.y = static_cast(i / width); - - if(src[i] == dst.min) - { - dst.min_loc.push_back(coord); - } - if(src[i] == dst.max) - { - dst.max_loc.push_back(coord); - } - } - - return dst; -} - -template MinMaxLocationValues min_max_location(const SimpleTensor &src); -template MinMaxLocationValues min_max_location(const SimpleTensor &src); -template MinMaxLocationValues min_max_location(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/MinMaxLocation.h b/tests/validation/CPP/MinMaxLocation.h deleted file mode 100644 index ebaf90b131..0000000000 --- a/tests/validation/CPP/MinMaxLocation.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_MIN_MAX_LOCATION_H__ -#define __ARM_COMPUTE_TEST_MIN_MAX_LOCATION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -MinMaxLocationValues min_max_location(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_MIN_MAX_LOCATION_H__ */ diff --git a/tests/validation/CPP/NonLinearFilter.cpp b/tests/validation/CPP/NonLinearFilter.cpp deleted file mode 100644 index 8669c9c776..0000000000 --- a/tests/validation/CPP/NonLinearFilter.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NonLinearFilter.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - - ARM_COMPUTE_ERROR_ON(pattern == MatrixPattern::OTHER && mask == nullptr); - ARM_COMPUTE_UNUSED(pattern); - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - const int sq_mask_size = mask_size * mask_size; - const int half_mask_size = mask_size / 2; - std::vector vals(sq_mask_size); - intermediate_type current_value = 0; - - const ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(half_mask_size)); - - for(int element_idx = 0, count = 0, index = 0; element_idx < src.num_elements(); ++element_idx, count = 0, index = 0) - { - Coordinates id = index2coord(src.shape(), element_idx); - if(is_in_valid_region(valid_region, id)) - { - int idx = id.x(); - int idy = id.y(); - for(int y = idy - half_mask_size; y <= idy + half_mask_size; ++y) - { - for(int x = idx - half_mask_size; x <= idx + half_mask_size; ++x, ++index) - { - id.set(0, x); - id.set(1, y); - current_value = tensor_elem_at(src, id, border_mode, constant_border_value); - - if(mask[index] == 255) - { - vals[count] = static_cast(current_value); - ++count; - } - } - } - std::sort(vals.begin(), vals.begin() + count); - - ARM_COMPUTE_ERROR_ON(count == 0); - - switch(function) - { - case NonLinearFilterFunction::MIN: - dst[element_idx] = saturate_cast(vals[0]); - break; - case NonLinearFilterFunction::MAX: - dst[element_idx] = saturate_cast(vals[count - 1]); - break; - case NonLinearFilterFunction::MEDIAN: - dst[element_idx] = saturate_cast(vals[count / 2]); - break; - default: - ARM_COMPUTE_ERROR("Unsupported NonLinearFilter function."); - } - } - } - - return dst; -} - -template SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/NonLinearFilter.h b/tests/validation/CPP/NonLinearFilter.h deleted file mode 100644 index 1df47c85be..0000000000 --- a/tests/validation/CPP/NonLinearFilter.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_BITWISE_NOT_H__ -#define __ARM_COMPUTE_TEST_BITWISE_NOT_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_BITWISE_NOT_H__ */ diff --git a/tests/validation/CPP/NonMaximaSuppression.cpp b/tests/validation/CPP/NonMaximaSuppression.cpp deleted file mode 100644 index eab5cecfc8..0000000000 --- a/tests/validation/CPP/NonMaximaSuppression.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2017 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 "NonMaximaSuppression.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) -{ - constexpr int block_size = 3; - SimpleTensor dst(src.shape(), src.data_type(), src.num_channels()); - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(block_size / 2)); - - for(int i = 0; i < src.num_elements(); ++i) - { - Coordinates coord = index2coord(src.shape(), i); - int x = coord.x(); - int y = coord.y(); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - if(src[i] >= tensor_elem_at(src, Coordinates(x - 1, y - 1), border_mode, constant_border_value) && src[i] >= tensor_elem_at(src, Coordinates(x, y - 1), border_mode, constant_border_value) - && src[i] >= tensor_elem_at(src, Coordinates(x + 1, y - 1), border_mode, constant_border_value) && src[i] >= tensor_elem_at(src, Coordinates(x - 1, y), border_mode, constant_border_value) - && src[i] > tensor_elem_at(src, Coordinates(x + 1, y), border_mode, constant_border_value) && src[i] > tensor_elem_at(src, Coordinates(x - 1, y + 1), border_mode, constant_border_value) - && src[i] > tensor_elem_at(src, Coordinates(x, y + 1), border_mode, constant_border_value) && src[i] > tensor_elem_at(src, Coordinates(x + 1, y + 1), border_mode, constant_border_value)) - { - dst[i] = src[i]; - } - else - { - dst[i] = T(0); - } - } - - return dst; -} - -template SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, float constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/NonMaximaSuppression.h b/tests/validation/CPP/NonMaximaSuppression.h deleted file mode 100644 index 2086abfe83..0000000000 --- a/tests/validation/CPP/NonMaximaSuppression.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_NON_MAXIMA_SUPPRESSION_H__ -#define __ARM_COMPUTE_TEST_NON_MAXIMA_SUPPRESSION_H__ - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_NON_MAXIMA_SUPPRESSION_H__ */ diff --git a/tests/validation/CPP/NormalizationLayer.cpp b/tests/validation/CPP/NormalizationLayer.cpp deleted file mode 100644 index 226af96fe3..0000000000 --- a/tests/validation/CPP/NormalizationLayer.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (c) 2017 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 "NormalizationLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info) -{ - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const uint32_t norm_size = info.norm_size(); - NormType type = info.type(); - float beta = info.beta(); - uint32_t kappa = info.kappa(); - - const int cols = src.shape()[0]; - const int rows = src.shape()[1]; - const int depth = src.shape()[2]; - int upper_dims = src.shape().total_size() / (cols * rows); - - float coeff = info.scale_coeff(); - int radius_cols = norm_size / 2; - - // IN_MAP_1D and CROSS_MAP normalize over a single axis only - int radius_rows = (NormType::IN_MAP_2D == type) ? norm_size / 2 : 0; - - if(type == NormType::CROSS_MAP) - { - // Remove also depth from upper dimensions since it is the dimension we - // want to use for normalization - upper_dims /= depth; - - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < rows; ++i) - { - for(int k = 0; k < cols; ++k) - { - for(int l = 0; l < depth; ++l) - { - float accumulated_scale = 0.f; - - for(int j = -radius_cols; j <= radius_cols; ++j) - { - const int z = l + j; - - if(z >= 0 && z < depth) - { - const T value = src[k + i * cols + z * rows * cols + r * cols * rows * depth]; - accumulated_scale += value * value; - } - } - - dst[k + i * cols + l * rows * cols + r * cols * rows * depth] = kappa + accumulated_scale * coeff; - } - } - } - } - } - else - { - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < rows; ++i) - { - for(int k = 0; k < cols; ++k) - { - float accumulated_scale = 0.f; - - for(int j = -radius_rows; j <= radius_rows; ++j) - { - const int y = i + j; - for(int l = -radius_cols; l <= radius_cols; ++l) - { - const int x = k + l; - - if((x >= 0 && y >= 0) && (x < cols && y < rows)) - { - const T value = src[x + y * cols + r * cols * rows]; - accumulated_scale += value * value; - } - } - } - - dst[k + i * cols + r * cols * rows] = kappa + accumulated_scale * coeff; - } - } - } - } - - if(beta == 1.f) - { - for(int i = 0; i < dst.num_elements(); ++i) - { - dst[i] = src[i] / dst[i]; - } - } - else if(beta == 0.5f) - { - for(int i = 0; i < dst.num_elements(); ++i) - { - dst[i] = src[i] / std::sqrt(dst[i]); - } - } - else - { - for(int i = 0; i < dst.num_elements(); ++i) - { - dst[i] = src[i] * std::exp(std::log(dst[i]) * -beta); - } - } - - return dst; -} - -template ::value, int>::type> -SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info) -{ - using namespace fixed_point_arithmetic; - - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const int fixed_point_position = src.fixed_point_position(); - - const uint32_t norm_size = info.norm_size(); - NormType type = info.type(); - fixed_point beta(info.beta(), fixed_point_position); - fixed_point kappa(info.kappa(), fixed_point_position); - - const int cols = src.shape()[0]; - const int rows = src.shape()[1]; - const int depth = src.shape()[2]; - int upper_dims = src.shape().total_size() / (cols * rows); - - fixed_point coeff(info.scale_coeff(), fixed_point_position); - int radius_cols = norm_size / 2; - - // IN_MAP_1D and CROSS_MAP normalize over a single axis only - int radius_rows = (NormType::IN_MAP_2D == type) ? norm_size / 2 : 0; - - if(type == NormType::CROSS_MAP) - { - // Remove also depth from upper dimensions since it is the dimension we - // want to use for normalization - upper_dims /= depth; - - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < rows; ++i) - { - for(int k = 0; k < cols; ++k) - { - for(int l = 0; l < depth; ++l) - { - fixed_point accumulated_scale(0.f, fixed_point_position); - - for(int j = -radius_cols; j <= radius_cols; ++j) - { - const int z = l + j; - - if(z >= 0 && z < depth) - { - const T value = src[k + i * cols + z * rows * cols + r * cols * rows * depth]; - const fixed_point fp_value(value, fixed_point_position, true); - accumulated_scale = add(accumulated_scale, mul(fp_value, fp_value)); - } - } - - accumulated_scale = add(kappa, mul(accumulated_scale, coeff)); - dst[k + i * cols + l * rows * cols + r * cols * rows * depth] = accumulated_scale.raw(); - } - } - } - } - } - else - { - for(int r = 0; r < upper_dims; ++r) - { - for(int i = 0; i < rows; ++i) - { - for(int k = 0; k < cols; ++k) - { - fixed_point accumulated_scale(0.f, fixed_point_position); - - for(int j = -radius_rows; j <= radius_rows; ++j) - { - const int y = i + j; - - for(int l = -radius_cols; l <= radius_cols; ++l) - { - const int x = k + l; - - if((x >= 0 && y >= 0) && (x < cols && y < rows)) - { - const T value = src[x + y * cols + r * cols * rows]; - const fixed_point fp_value(value, fixed_point_position, true); - accumulated_scale = add(accumulated_scale, mul(fp_value, fp_value)); - } - } - } - - accumulated_scale = add(kappa, mul(accumulated_scale, coeff)); - dst[k + i * cols + r * cols * rows] = accumulated_scale.raw(); - } - } - } - } - - if(info.beta() == 1.f) - { - for(int i = 0; i < dst.num_elements(); ++i) - { - fixed_point res = div(fixed_point(src[i], fixed_point_position, true), fixed_point(dst[i], fixed_point_position, true)); - dst[i] = res.raw(); - } - } - else - { - const fixed_point beta(info.beta(), fixed_point_position); - - for(int i = 0; i < dst.num_elements(); ++i) - { - fixed_point res = pow(fixed_point(dst[i], fixed_point_position, true), beta); - res = div(fixed_point(src[i], fixed_point_position, true), res); - dst[i] = res.raw(); - } - } - - return dst; -} - -template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); -template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); -template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); -template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/NormalizationLayer.h b/tests/validation/CPP/NormalizationLayer.h deleted file mode 100644 index 3f624ff30a..0000000000 --- a/tests/validation/CPP/NormalizationLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_NORMALIZATION_LAYER_H__ -#define __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); - -template ::value, int>::type = 0> -SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ */ diff --git a/tests/validation/CPP/Phase.cpp b/tests/validation/CPP/Phase.cpp deleted file mode 100644 index 7827cd2989..0000000000 --- a/tests/validation/CPP/Phase.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017 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 "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type) -{ - const float PI = std::atan(1) * 4; - SimpleTensor phase(gx.shape(), DataType::U8); - - if(phase_type == PhaseType::UNSIGNED) // unsigned: map to [0-255) - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_deg = (std::atan2(float(gy[i]), float(gx[i])) / PI) * 180.0f; - phase[i] = (angle_deg < 0.0f) ? 180.f + angle_deg : angle_deg; - } - } - else // signed: map to [0-180) degrees - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_pi = std::atan2(gy[i], gx[i]) / PI; - angle_pi = (angle_pi < 0.0f) ? 2 + angle_pi : angle_pi; - phase[i] = lround(angle_pi * 128) & 0xFFu; - } - } - - return phase; -} - -template SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); -template SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Phase.h b/tests/validation/CPP/Phase.h deleted file mode 100644 index d322d53e02..0000000000 --- a/tests/validation/CPP/Phase.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_PHASE_H__ -#define __ARM_COMPUTE_TEST_PHASE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_PHASE_H__ */ diff --git a/tests/validation/CPP/PixelWiseMultiplication.cpp b/tests/validation/CPP/PixelWiseMultiplication.cpp deleted file mode 100644 index b3647fc9ce..0000000000 --- a/tests/validation/CPP/PixelWiseMultiplication.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2017 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, - * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "PixelWiseMultiplication.h" - -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -struct is_floating_point - : std::integral_constant < bool, - std::is_same::type>::value || std::is_same::type>::value - || std::is_same::type>::value || std::is_same::type>::value > -{ -}; - -template -SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) -{ - SimpleTensor dst(src2.shape(), src2.data_type()); - - if(scale < 0) - { - ARM_COMPUTE_ERROR("Scale of pixel-wise multiplication must be non-negative"); - } - - using intermediate_type = typename common_promoted_signed_type::intermediate_type; - - for(int i = 0; i < src1.num_elements(); ++i) - { - double val = static_cast(src1[i]) * static_cast(src2[i]) * static_cast(scale); - if(is_floating_point::value) - { - dst[i] = val; - } - else - { - double rounded_val = 0; - switch(rounding_policy) - { - case(RoundingPolicy::TO_ZERO): - rounded_val = support::cpp11::trunc(val); - break; - case(RoundingPolicy::TO_NEAREST_UP): - rounded_val = round_half_up(val); - break; - case(RoundingPolicy::TO_NEAREST_EVEN): - rounded_val = round_half_even(val); - break; - default: - ARM_COMPUTE_ERROR("Unsupported rounding policy"); - } - - dst[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(rounded_val) : static_cast(rounded_val); - } - } - - return dst; -} - -// *INDENT-OFF* -// clang-format off -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -// clang-format on -// *INDENT-ON* -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/PixelWiseMultiplication.h b/tests/validation/CPP/PixelWiseMultiplication.h deleted file mode 100644 index 1dce154719..0000000000 --- a/tests/validation/CPP/PixelWiseMultiplication.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_PIXEL_WISE_MULTIPLICATION_H__ -#define __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/CPP/PoolingLayer.cpp b/tests/validation/CPP/PoolingLayer.cpp deleted file mode 100644 index 1a7dd4cbb7..0000000000 --- a/tests/validation/CPP/PoolingLayer.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2017 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 "PoolingLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -TensorShape calculate_output_shape(TensorShape shape, PoolingLayerInfo info) -{ - TensorShape dst_shape = shape; - const int pool_size = info.is_global_pooling() ? shape.x() : info.pool_size(); - const std::pair scaled_dims = arm_compute::scaled_dimensions(shape.x(), - shape.y(), - pool_size, - pool_size, - info.pad_stride_info()); - dst_shape.set(0, scaled_dims.first); - dst_shape.set(1, scaled_dims.second); - - return dst_shape; -} -} // namespace - -template ::value, int>::type> -SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) -{ - ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); - - const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); - PoolingType type = info.pool_type(); - int pool_stride_x = info.pad_stride_info().stride().first; - int pool_stride_y = info.pad_stride_info().stride().second; - int pad_x = info.pad_stride_info().pad().first; - int pad_y = info.pad_stride_info().pad().second; - bool exclude_padding = info.exclude_padding(); - - const auto w_src = static_cast(src.shape()[0]); - const auto h_src = static_cast(src.shape()[1]); - const int upper_dims = src.shape().total_size() / (w_src * h_src); - - // Create reference - SimpleTensor dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; - - const auto w_dst = static_cast(dst.shape()[0]); - const auto h_dst = static_cast(dst.shape()[1]); - - if(type == PoolingType::MAX) - { - for(int r = 0; r < upper_dims; ++r) - { - for(int h = 0; h < h_dst; ++h) - { - for(int w = 0; w < w_dst; ++w) - { - int wstart = w * pool_stride_x - pad_x; - int hstart = h * pool_stride_y - pad_y; - int wend = std::min(wstart + pool_size, w_src); - int hend = std::min(hstart + pool_size, h_src); - wstart = std::max(wstart, 0); - hstart = std::max(hstart, 0); - - T max_val = std::numeric_limits::lowest(); - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - const T val = src[r * h_src * w_src + y * w_src + x]; - if(val > max_val) - { - max_val = val; - } - } - } - - dst[r * h_dst * w_dst + h * w_dst + w] = max_val; - } - } - } - } - else // Average or l2 pooling - { - for(int r = 0; r < upper_dims; ++r) - { - for(int h = 0; h < h_dst; ++h) - { - for(int w = 0; w < w_dst; ++w) - { - T avg_val(0); - int wstart = w * pool_stride_x - pad_x; - int hstart = h * pool_stride_y - pad_y; - int wend = std::min(wstart + pool_size, w_src + pad_x); - int hend = std::min(hstart + pool_size, h_src + pad_y); - int pool = (hend - hstart) * (wend - wstart); - wstart = std::max(wstart, 0); - hstart = std::max(hstart, 0); - wend = std::min(wend, w_src); - hend = std::min(hend, h_src); - // Exclude padding pixels from the average - if(exclude_padding) - { - pool = (hend - hstart) * (wend - wstart); - } - - if(type == PoolingType::AVG) - { - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - avg_val += src[r * h_src * w_src + y * w_src + x]; - } - } - dst[r * h_dst * w_dst + h * w_dst + w] = avg_val / pool; - } - else - { - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - const T val = src[r * h_src * w_src + y * w_src + x]; - avg_val += val * val; - } - } - dst[r * h_dst * w_dst + h * w_dst + w] = std::sqrt(avg_val / pool); - } - } - } - } - } - - return dst; -} - -template ::value, int>::type> -SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) -{ - ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); - - const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); - PoolingType type = info.pool_type(); - int pool_stride_x = info.pad_stride_info().stride().first; - int pool_stride_y = info.pad_stride_info().stride().second; - int pad_x = info.pad_stride_info().pad().first; - int pad_y = info.pad_stride_info().pad().second; - bool exclude_padding = info.exclude_padding(); - - const auto w_src = static_cast(src.shape()[0]); - const auto h_src = static_cast(src.shape()[1]); - const int upper_dims = src.shape().total_size() / (w_src * h_src); - - // Create reference - SimpleTensor dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; - - const auto w_dst = static_cast(dst.shape()[0]); - const auto h_dst = static_cast(dst.shape()[1]); - - if(type == PoolingType::MAX) - { - for(int r = 0; r < upper_dims; ++r) - { - for(int h = 0; h < h_dst; ++h) - { - for(int w = 0; w < w_dst; ++w) - { - int wstart = w * pool_stride_x - pad_x; - int hstart = h * pool_stride_y - pad_y; - int wend = std::min(wstart + pool_size, w_src); - int hend = std::min(hstart + pool_size, h_src); - wstart = std::max(wstart, 0); - hstart = std::max(hstart, 0); - - T max_val = std::numeric_limits::lowest(); - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - const T val = src[r * h_src * w_src + y * w_src + x]; - if(val > max_val) - { - max_val = val; - } - } - } - - dst[r * h_dst * w_dst + h * w_dst + w] = max_val; - } - } - } - } - else // Average or l2 pooling - { - for(int r = 0; r < upper_dims; ++r) - { - for(int h = 0; h < h_dst; ++h) - { - for(int w = 0; w < w_dst; ++w) - { - int wstart = w * pool_stride_x - pad_x; - int hstart = h * pool_stride_y - pad_y; - int wend = std::min(wstart + pool_size, w_src + pad_x); - int hend = std::min(hstart + pool_size, h_src + pad_y); - int pool = (hend - hstart) * (wend - wstart); - wstart = std::max(wstart, 0); - hstart = std::max(hstart, 0); - wend = std::min(wend, w_src); - hend = std::min(hend, h_src); - // Exclude padding pixels from the average - if(exclude_padding) - { - pool = (hend - hstart) * (wend - wstart); - } - - using namespace fixed_point_arithmetic; - - const int fixed_point_position = src.fixed_point_position(); - const fixed_point const_1(1, fixed_point_position); - const fixed_point invpool_fp(1.f / static_cast(pool), fixed_point_position); - fixed_point avg_val(0, fixed_point_position, true); - - if(type == PoolingType::AVG) - { - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - const fixed_point in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); - avg_val = add(avg_val, in_fp); - } - } - dst[r * h_dst * w_dst + h * w_dst + w] = mul(avg_val, invpool_fp).raw(); - } - else - { - for(int y = hstart; y < hend; ++y) - { - for(int x = wstart; x < wend; ++x) - { - const fixed_point in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); - avg_val = add(avg_val, mul(in_fp, in_fp)); - } - } - auto res = div(const_1, (inv_sqrt(mul(avg_val, invpool_fp)))); - dst[r * h_dst * w_dst + h * w_dst + w] = res.raw(); - } - } - } - } - } - - return dst; -} - -template <> -SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) -{ - SimpleTensor src_tmp = convert_from_asymmetric(src); - SimpleTensor dst_tmp = pooling_layer(src_tmp, info); - SimpleTensor dst = convert_to_asymmetric(dst_tmp, src.quantization_info()); - return dst; -} - -template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); -template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); -template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); -template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/PoolingLayer.h b/tests/validation/CPP/PoolingLayer.h deleted file mode 100644 index 334054a0eb..0000000000 --- a/tests/validation/CPP/PoolingLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_POOLING_LAYER_H__ -#define __ARM_COMPUTE_TEST_POOLING_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); - -template ::value, int>::type = 0> -SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_POOLING_LAYER_H__ */ diff --git a/tests/validation/CPP/QuantizationLayer.cpp b/tests/validation/CPP/QuantizationLayer.cpp deleted file mode 100644 index d7ce490209..0000000000 --- a/tests/validation/CPP/QuantizationLayer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2017 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 "QuantizationLayer.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor quantization_layer(const SimpleTensor &src) -{ - // Create reference - SimpleTensor dst{ src.shape(), DataType::U8 }; - - const int width = src.shape().x(); - const int height = src.shape().y(); - const int depth = src.shape().z(); - const int stride_w = width * height * depth; - const int num_batches = src.shape().total_size_upper(3); - - for(int k = 0; k < num_batches; ++k) - { - // Compute min and max of the 3D tensor - float min = src[k * stride_w]; - float max = src[k * stride_w]; - - // Look for min and max values - for(int i = 1; i < stride_w; ++i) - { - float val = src[i + k * stride_w]; - min = std::min(min, val); - max = std::max(max, val); - } - - // Saturate the result in case min = max - if(min == max) - { - min = 0.0f; - max = 1.0f; - } - - const float range = max - min; - - for(int i = 0; i < stride_w; ++i) - { - // map values to range [0.0, 1.0] - float val = src[i + k * stride_w]; - const float normalized = (val - min) / range; - dst[i + k * stride_w] = static_cast(std::min(255.0f, normalized * 256.0f)); - } - } - - return dst; -} - -template SimpleTensor quantization_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/QuantizationLayer.h b/tests/validation/CPP/QuantizationLayer.h deleted file mode 100644 index 7c5572ccf8..0000000000 --- a/tests/validation/CPP/QuantizationLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_QUANTIZATION_LAYER_H__ -#define __ARM_COMPUTE_TEST_QUANTIZATION_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor quantization_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_QUANTIZATION_LAYER_H__ */ diff --git a/tests/validation/CPP/ReductionOperation.cpp b/tests/validation/CPP/ReductionOperation.cpp deleted file mode 100644 index acfcc09cea..0000000000 --- a/tests/validation/CPP/ReductionOperation.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2017 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 "ReductionOperation.h" - -#include "tests/validation/Helpers.h" - -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template -struct square -{ - T operator()(const T &lhs, const T &rhs) const - { - return (lhs + rhs * rhs); - } -}; - -template -T reduce_operation(T *ptr, int reduce_elements, ReductionOperation op) -{ - switch(op) - { - case ReductionOperation::SUM_SQUARE: - return std::accumulate(ptr, ptr + reduce_elements, 0.f, square()); - default: - ARM_COMPUTE_ERROR("Unsupported reduction operation"); - } -} -} // namespace - -template -SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) -{ - // Create reference - SimpleTensor dst{ dst_shape, src.data_type() }; - - // Compute reference - const int reduce_elems = src.shape()[axis]; - const int upper_dims = src.shape().total_size_upper(axis + 1); - - for(int du = 0; du < upper_dims; ++du) - { - if(axis == 0) - { - const T *src_row_ptr = src.data() + du * reduce_elems; - dst[du] = reduce_operation(src_row_ptr, reduce_elems, op); - } - else - { - ARM_COMPUTE_ERROR("Unsupported reduction axis"); - } - } - - return dst; -} - -template SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ReductionOperation.h b/tests/validation/CPP/ReductionOperation.h deleted file mode 100644 index 6da6436686..0000000000 --- a/tests/validation/CPP/ReductionOperation.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_REDUCTION_OPERATION_H__ -#define __ARM_COMPUTE_TEST_REDUCTION_OPERATION_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_FLOOR_H__ */ diff --git a/tests/validation/CPP/Remap.cpp b/tests/validation/CPP/Remap.cpp deleted file mode 100644 index bef5962fbf..0000000000 --- a/tests/validation/CPP/Remap.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017 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 "Remap.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor remap(const SimpleTensor &in, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, BorderMode border_mode, - T constant_border_value) -{ - ARM_COMPUTE_ERROR_ON_MSG(border_mode == BorderMode::REPLICATE, "BorderMode not supported"); - - SimpleTensor out(in.shape(), in.data_type()); - - const int width = in.shape().x(); - const int height = in.shape().y(); - - for(int idx = 0; idx < out.num_elements(); idx++) - { - valid_mask[idx] = 1; - Coordinates src_idx; - src_idx.set(0, static_cast(std::floor(map_x[idx]))); - src_idx.set(1, static_cast(std::floor(map_y[idx]))); - if((0 <= map_y[idx]) && (map_y[idx] < height) && (0 <= map_x[idx]) && (map_x[idx] < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - out[idx] = tensor_elem_at(in, src_idx, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(map_x[idx], map_y[idx], width, height, border_mode)) ? out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value) : valid_mask[idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - out[idx] = constant_border_value; - break; - case InterpolationPolicy::BILINEAR: - out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - break; - } - } - } - } - - return out; -} - -template SimpleTensor remap(const SimpleTensor &src, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, - BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Remap.h b/tests/validation/CPP/Remap.h deleted file mode 100644 index 918ba95d3c..0000000000 --- a/tests/validation/CPP/Remap.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_REMAP_H__ -#define __ARM_COMPUTE_TEST_REMAP_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor remap(const SimpleTensor &in, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, BorderMode border_mode, - T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_REMAP_H__ */ diff --git a/tests/validation/CPP/ReshapeLayer.cpp b/tests/validation/CPP/ReshapeLayer.cpp deleted file mode 100644 index 42f06e4f5a..0000000000 --- a/tests/validation/CPP/ReshapeLayer.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 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 "ReshapeLayer.h" - -#include "arm_compute/core/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape) -{ - ARM_COMPUTE_ERROR_ON(src.shape().total_size() != output_shape.total_size()); - - SimpleTensor dst(output_shape, src.data_type()); - std::copy_n(src.data(), src.num_elements(), dst.data()); - return dst; -} - -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/ReshapeLayer.h b/tests/validation/CPP/ReshapeLayer.h deleted file mode 100644 index fc6c716d7a..0000000000 --- a/tests/validation/CPP/ReshapeLayer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_RESHAPE_LAYER_H__ -#define __ARM_COMPUTE_TEST_RESHAPE_LAYER_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_RESHAPE_LAYER_H__ */ diff --git a/tests/validation/CPP/Scale.cpp b/tests/validation/CPP/Scale.cpp deleted file mode 100644 index 727325f675..0000000000 --- a/tests/validation/CPP/Scale.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Scale.h" -#include "Utils.h" -#include "support/ToolchainSupport.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor scale(const SimpleTensor &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale) -{ - // Add 1 if ceil_policy_scale is true - const size_t round_value = ceil_policy_scale ? 1U : 0U; - TensorShape shape_scaled(in.shape()); - shape_scaled.set(0, (in.shape()[0] + round_value) * scale_x); - shape_scaled.set(1, (in.shape()[1] + round_value) * scale_y); - SimpleTensor out(shape_scaled, in.data_type()); - - // Compute the ratio between source width/height and destination width/height - const auto wr = static_cast(in.shape()[0]) / static_cast(out.shape()[0]); - const auto hr = static_cast(in.shape()[1]) / static_cast(out.shape()[1]); - - const auto width = static_cast(in.shape().x()); - const auto height = static_cast(in.shape().y()); - - // Determine border size - const int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1; - - // Area interpolation behaves as Nearest Neighbour in case of up-sampling - if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) - { - policy = InterpolationPolicy::NEAREST_NEIGHBOR; - } - - for(int element_idx = 0, count = 0; element_idx < out.num_elements(); ++element_idx, ++count) - { - Coordinates id = index2coord(out.shape(), element_idx); - int idx = id.x(); - int idy = id.y(); - float x_src = 0; - float y_src = 0; - - switch(sampling_policy) - { - case SamplingPolicy::TOP_LEFT: - x_src = idx * wr; - y_src = idy * hr; - break; - case SamplingPolicy::CENTER: - x_src = (idx + 0.5f) * wr - 0.5f; - y_src = (idy + 0.5f) * hr - 0.5f; - break; - default: - ARM_COMPUTE_ERROR("Unsupported sampling policy."); - break; - } - - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - { - //Calculate the source coords without -0.5f is equivalent to round the x_scr/y_src coords - x_src = (idx + 0.5f) * wr; - y_src = (idy + 0.5f) * hr; - id.set(0, x_src); - id.set(1, y_src); - - // If coordinates in range of tensor's width or height - if(is_valid_pixel_index(x_src, y_src, width, height, border_size)) - { - out[element_idx] = tensor_elem_at(in, id, border_mode, constant_border_value); - } - break; - } - case InterpolationPolicy::BILINEAR: - { - id.set(0, std::floor(x_src)); - id.set(1, std::floor(y_src)); - if(is_valid_pixel_index(x_src, y_src, width, height, border_size)) - { - out[element_idx] = bilinear_policy(in, id, x_src, y_src, border_mode, constant_border_value); - } - else - { - if(border_mode == BorderMode::CONSTANT) - { - out[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, clamp(static_cast(x_src), 0, width - 1)); - id.set(1, clamp(static_cast(y_src), 0, height - 1)); - out[element_idx] = in[coord2index(in.shape(), id)]; - } - } - break; - } - case InterpolationPolicy::AREA: - { - int x_from = std::floor(idx * wr - 0.5f - x_src); - int y_from = std::floor(idy * hr - 0.5f - y_src); - int x_to = std::ceil((idx + 1) * wr - 0.5f - x_src); - int y_to = std::ceil((idy + 1) * hr - 0.5f - y_src); - const int xi = std::floor(x_src); - const int yi = std::floor(y_src); - - // Clamp position to borders - x_src = std::max(-static_cast(border_size), std::min(x_src, static_cast(width - 1 + border_size))); - y_src = std::max(-static_cast(border_size), std::min(y_src, static_cast(height - 1 + border_size))); - - // Clamp bounding box offsets to borders - x_from = ((x_src + x_from) < -border_size) ? -border_size : x_from; - y_from = ((y_src + y_from) < -border_size) ? -border_size : y_from; - x_to = ((x_src + x_to) >= (width + border_size)) ? (width - 1 + border_size) : x_to; - y_to = ((y_src + y_to) >= (height + border_size)) ? (height - 1 + border_size) : y_to; - ARM_COMPUTE_ERROR_ON((x_to - x_from + 1) == 0 || (y_to - y_from + 1) == 0); - - float sum = 0; - for(int j = yi + y_from, je = yi + y_to; j <= je; ++j) - { - for(int i = xi + x_from, ie = xi + x_to; i <= ie; ++i) - { - id.set(0, static_cast(i)); - id.set(1, static_cast(j)); - sum += tensor_elem_at(in, id, border_mode, constant_border_value); - } - } - out[element_idx] = sum / ((x_to - x_from + 1) * (y_to - y_from + 1)); - - break; - } - default: - ARM_COMPUTE_ERROR("Unsupported interpolation mode"); - } - } - - return out; -} - -template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale); -template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, int16_t constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale); -template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, half constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale); -template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, float constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Scale.h b/tests/validation/CPP/Scale.h deleted file mode 100644 index 566e30af10..0000000000 --- a/tests/validation/CPP/Scale.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_SCALE_H__ -#define __ARM_COMPUTE_TEST_SCALE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor scale(const SimpleTensor &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value = 0, - SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool ceil_policy_scale = false); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_SCALE_H__ */ diff --git a/tests/validation/CPP/Scharr.cpp b/tests/validation/CPP/Scharr.cpp deleted file mode 100644 index 98e4d62dba..0000000000 --- a/tests/validation/CPP/Scharr.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2017 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 "Scharr.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array scharr_3_x{ { -3, 0, 3, -10, 0, 10, -3, 0, 3 } }; -const std::array scharr_3_y{ { -3, -10, -3, 0, 0, 0, 3, 10, 3 } }; - -const std::map> masks -{ - { 3, { scharr_3_x.data(), scharr_3_y.data() } } -}; - -template -struct data_type; - -template <> -struct data_type -{ - const static DataType value = DataType::S16; -}; -} // namespace - -template -std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - const auto shape_size = static_cast(filter_size); - - SimpleTensor dst_x(src.shape(), data_type::value, src.num_channels()); - SimpleTensor dst_y(src.shape(), data_type::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - for(int i = 0; i < src.num_elements(); ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Scharr.h b/tests/validation/CPP/Scharr.h deleted file mode 100644 index 8f383811cf..0000000000 --- a/tests/validation/CPP/Scharr.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_SCHARR_H__ -#define __ARM_COMPUTE_TEST_SCHARR_H__ - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_SCHARR_H__ */ diff --git a/tests/validation/CPP/Sobel.cpp b/tests/validation/CPP/Sobel.cpp deleted file mode 100644 index ff0e11d3a8..0000000000 --- a/tests/validation/CPP/Sobel.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2017 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 "Sobel.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array sobel_3_x{ { -1, 0, 1, -2, 0, 2, -1, 0, 1 } }; -const std::array sobel_3_y{ { -1, -2, -1, 0, 0, 0, 1, 2, 1 } }; - -const std::array sobel_5_x{ { - -1, -2, 0, 2, 1, - -4, -8, 0, 8, 4, - -6, -12, 0, 12, 6, - -4, -8, 0, 8, 4, - -1, -2, 0, 2, 1 - } }; - -const std::array sobel_5_y{ { - -1, -4, -6, -4, -1, - -2, -8, -12, -8, -2, - 0, 0, 0, 0, 0, - 2, 8, 12, 8, 2, - 1, 4, 6, 4, 1 - } }; - -const std::array sobel_7_x{ { - -1, -4, -5, 0, 5, 4, 1, - -6, -24, -30, 0, 30, 24, 6, - -15, -60, -75, 0, 75, 60, 15, - -20, -80, -100, 0, 100, 80, 20, - -15, -60, -75, 0, 75, 60, 15, - -6, -24, -30, 0, 30, 24, 6, - -1, -4, -5, 0, 5, 4, 1 - } }; - -const std::array sobel_7_y{ { - -1, -6, -15, -20, -15, -6, -1, - -4, -24, -60, -80, -60, -24, -4, - -5, -30, -75, -100, -75, -30, -5, - 0, 0, 0, 0, 0, 0, 0, - 5, 30, 75, 100, 75, 30, 5, - 4, 24, 60, 80, 60, 24, 4, - 1, 6, 15, 20, 15, 6, 1 - } }; - -const std::map> masks -{ - { 3, { sobel_3_x.data(), sobel_3_y.data() } }, - { 5, { sobel_5_x.data(), sobel_5_y.data() } }, - { 7, { sobel_7_x.data(), sobel_7_y.data() } }, -}; - -template -struct data_type; - -template <> -struct data_type -{ - const static DataType value = DataType::S16; -}; - -template <> -struct data_type -{ - const static DataType value = DataType::S32; -}; -} // namespace - -template -std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - SimpleTensor dst_x(src.shape(), data_type::value, src.num_channels()); - SimpleTensor dst_y(src.shape(), data_type::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - for(int i = 0; i < src.num_elements(); ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -template std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Sobel.h b/tests/validation/CPP/Sobel.h deleted file mode 100644 index 9099f1a932..0000000000 --- a/tests/validation/CPP/Sobel.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017 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_SOBEL_H__ -#define __ARM_COMPUTE_TEST_SOBEL_H__ - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_SOBEL_H__ */ diff --git a/tests/validation/CPP/SoftmaxLayer.cpp b/tests/validation/CPP/SoftmaxLayer.cpp deleted file mode 100644 index 8e8cc1bd25..0000000000 --- a/tests/validation/CPP/SoftmaxLayer.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2017 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 "SoftmaxLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type> -SimpleTensor softmax_layer(const SimpleTensor &src) -{ - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const int cols = src.shape()[0]; - const int upper_dims = src.num_elements() / cols; - - for(int r = 0; r < upper_dims; ++r) - { - const T *src_row_ptr = src.data() + r * cols; - T *dst_row_ptr = dst.data() + r * cols; - - // Find max - const T max = *std::max_element(src_row_ptr, src_row_ptr + cols); - - // Regularize - T sum(0.f); - std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&sum, max](T val) - { - const T res(std::exp(val - max)); - sum += res; - return res; - }); - - // Normalize - std::transform(dst_row_ptr, dst_row_ptr + cols, dst_row_ptr, [sum](T val) - { - return val / sum; - }); - } - - return dst; -} - -template ::value, int>::type> -SimpleTensor softmax_layer(const SimpleTensor &src) -{ - using namespace fixed_point_arithmetic; - - // Create reference - SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; - - // Compute reference - const int cols = src.shape()[0]; - const int upper_dims = src.num_elements() / cols; - - for(int r = 0; r < upper_dims; ++r) - { - const T *src_row_ptr = src.data() + r * cols; - T *dst_row_ptr = dst.data() + r * cols; - - // Find max - const fixed_point max(*std::max_element(src_row_ptr, src_row_ptr + cols), src.fixed_point_position(), true); - - // Regularize - using promoted_type = fixed_point_arithmetic::traits::promote_t; - fixed_point sum(0, src.fixed_point_position(), true); - std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&](T val) - { - const fixed_point res = exp(fixed_point(val, src.fixed_point_position(), true) - max); - sum = add(sum, fixed_point(res.raw(), src.fixed_point_position(), true)); - return res.raw(); - }); - - // Normalize - fixed_point saturated_sum(sum); - std::transform(dst_row_ptr, dst_row_ptr + cols, dst_row_ptr, [&](T val) - { - return div(fixed_point(val, src.fixed_point_position(), true), saturated_sum).raw(); - }); - } - - return dst; -} - -template <> -SimpleTensor softmax_layer(const SimpleTensor &src) -{ - // Note: Output quantization info should always have scale = 1/256 and offset = 0 - const QuantizationInfo output_quantization_info = QuantizationInfo(1.f / 256, 0); - - SimpleTensor src_tmp = convert_from_asymmetric(src); - SimpleTensor dst_tmp = softmax_layer(src_tmp); - SimpleTensor dst = convert_to_asymmetric(dst_tmp, output_quantization_info); - return dst; -} - -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/SoftmaxLayer.h b/tests/validation/CPP/SoftmaxLayer.h deleted file mode 100644 index ab79bc4850..0000000000 --- a/tests/validation/CPP/SoftmaxLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 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_SOFTMAX_LAYER_H__ -#define __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template ::value, int>::type = 0> -SimpleTensor softmax_layer(const SimpleTensor &src); - -template ::value, int>::type = 0> -SimpleTensor softmax_layer(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ */ diff --git a/tests/validation/CPP/TableLookup.cpp b/tests/validation/CPP/TableLookup.cpp deleted file mode 100644 index 7f105d99ca..0000000000 --- a/tests/validation/CPP/TableLookup.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017 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 "TableLookup.h" - -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut) -{ - SimpleTensor result(src.shape(), src.data_type()); - - for(int i = 0; i < src.num_elements(); ++i) - { - result[i] = rawlut.at(src[i]); - } - - return result; -} - -template SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); -template SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/TableLookup.h b/tests/validation/CPP/TableLookup.h deleted file mode 100644 index 3fdecac660..0000000000 --- a/tests/validation/CPP/TableLookup.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 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_TABLE_LOOKUP_H__ -#define __ARM_COMPUTE_TEST_TABLE_LOOKUP_H__ - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_TABLE_LOOKUP_H__ */ diff --git a/tests/validation/CPP/Threshold.cpp b/tests/validation/CPP/Threshold.cpp deleted file mode 100644 index d0ef31df04..0000000000 --- a/tests/validation/CPP/Threshold.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS src THE - * SOFTWARE. - */ -#include "Threshold.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor threshold(const SimpleTensor &src, T threshold, T false_value, T true_value, ThresholdType type, T upper) -{ - SimpleTensor dst(src.shape(), src.data_type()); - - switch(type) - { - case ThresholdType::BINARY: - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = ((src[i] > threshold) ? true_value : false_value); - } - break; - case ThresholdType::RANGE: - for(int i = 0; i < src.num_elements(); ++i) - { - if(src[i] > upper) - { - dst[i] = false_value; - } - else if(src[i] < threshold) - { - dst[i] = false_value; - } - else - { - dst[i] = true_value; - } - } - break; - default: - ARM_COMPUTE_ERROR("Thresholding type not recognised"); - break; - } - - return dst; -} - -template SimpleTensor threshold(const SimpleTensor &src, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Threshold.h b/tests/validation/CPP/Threshold.h deleted file mode 100644 index fbe2dba19b..0000000000 --- a/tests/validation/CPP/Threshold.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_THRESHOLD_H__ -#define __ARM_COMPUTE_TEST_THRESHOLD_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor threshold(const SimpleTensor &src, T threshold, T false_value, T true_value, ThresholdType type, T upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_THRESHOLD_H__ */ diff --git a/tests/validation/CPP/Transpose.cpp b/tests/validation/CPP/Transpose.cpp deleted file mode 100644 index 9f2e62e1aa..0000000000 --- a/tests/validation/CPP/Transpose.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017 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 "Transpose.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/FixedPoint.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor transpose(const SimpleTensor &src) -{ - // Make rows the columns of the original shape - TensorShape dst_shape{ src.shape().y(), src.shape().x() }; - - // Create reference - SimpleTensor dst{ dst_shape, src.data_type() }; - - // Compute reference - for(int i = 0; i < src.num_elements(); ++i) - { - const Coordinates coord = index2coord(src.shape(), i); - const Coordinates dst_coord{ coord.y(), coord.x() }; - const size_t dst_index = coord2index(dst.shape(), dst_coord); - - dst[dst_index] = src[i]; - } - - return dst; -} - -template SimpleTensor transpose(const SimpleTensor &src); -template SimpleTensor transpose(const SimpleTensor &src); -template SimpleTensor transpose(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Transpose.h b/tests/validation/CPP/Transpose.h deleted file mode 100644 index 3f42f41253..0000000000 --- a/tests/validation/CPP/Transpose.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_TRANSPOSE_H__ -#define __ARM_COMPUTE_TEST_TRANSPOSE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor transpose(const SimpleTensor &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_TRANSPOSE_H__ */ diff --git a/tests/validation/CPP/Utils.cpp b/tests/validation/CPP/Utils.cpp deleted file mode 100644 index d163e8436f..0000000000 --- a/tests/validation/CPP/Utils.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2017 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 "Utils.h" - -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -// Return the bilinear value at a specified coordinate with different border modes -template -T bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value) -{ - const int idx = std::floor(xn); - const int idy = std::floor(yn); - - const float dx = xn - idx; - const float dy = yn - idy; - const float dx_1 = 1.0f - dx; - const float dy_1 = 1.0f - dy; - - const T border_value = constant_border_value; - - id.set(0, idx); - id.set(1, idy); - const float tl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, idx + 1); - id.set(1, idy); - const float tr = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, idx); - id.set(1, idy + 1); - const float bl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, idx + 1); - id.set(1, idy + 1); - const float br = tensor_elem_at(in, id, border_mode, border_value); - - return static_cast(tl * (dx_1 * dy_1) + tr * (dx * dy_1) + bl * (dx_1 * dy) + br * (dx * dy)); -} - -template uint8_t bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, uint8_t constant_border_value); -template int16_t bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, int16_t constant_border_value); -template half bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, half constant_border_value); -template float bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, float constant_border_value); - -RawTensor transpose(const RawTensor &src, int chunk_width) -{ - // Create reference - TensorShape dst_shape(src.shape()); - dst_shape.set(0, src.shape().y() * chunk_width); - dst_shape.set(1, std::ceil(src.shape().x() / static_cast(chunk_width))); - - RawTensor dst{ dst_shape, src.data_type() }; - - // Compute reference - uint8_t *out_ptr = dst.data(); - - for(int i = 0; i < dst.num_elements(); i += chunk_width) - { - Coordinates coord = index2coord(dst.shape(), i); - size_t coord_x = coord.x(); - coord.set(0, coord.y() * chunk_width); - coord.set(1, coord_x / chunk_width); - - const int num_elements = std::min(chunk_width, src.shape().x() - coord.x()); - - std::copy_n(static_cast(src(coord)), num_elements * src.element_size(), out_ptr); - - out_ptr += chunk_width * dst.element_size(); - } - - return dst; -} - -bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) -{ - if(border_mode != BorderMode::UNDEFINED) - { - return true; - } - if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) - { - return true; - } - return false; -} -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/Utils.h b/tests/validation/CPP/Utils.h deleted file mode 100644 index 2aa77c6ff7..0000000000 --- a/tests/validation/CPP/Utils.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2017 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_VALIDATION_UTILS_H__ -#define __ARM_COMPUTE_TEST_VALIDATION_UTILS_H__ - -#include "arm_compute/core/Types.h" -#include "tests/Globals.h" -#include "tests/ILutAccessor.h" -#include "tests/Types.h" - -#include -#include -#include -#include -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -/** Checks if a pixel has valid coordinates - * - * @param x X coordinate - * @param y Y coordinate - * @param width Width of the image - * @param height Height of the image - * @param border_size Border size - * - * @return True if pixel is valid else false - */ -inline bool is_valid_pixel_index(int x, int y, int width, int height, int border_size) -{ - return ((x >= -border_size) && (y >= -border_size) && (x < (width + border_size)) && (y < height + border_size)); -} - -// Return a tensor element at a specified coordinate with different border modes -template -T tensor_elem_at(const SimpleTensor &src, Coordinates coord, BorderMode border_mode, T constant_border_value) -{ - const int x = coord.x(); - const int y = coord.y(); - const int width = src.shape().x(); - const int height = src.shape().y(); - - // If coordinates beyond range of tensor's width or height - if(x < 0 || y < 0 || x >= width || y >= height) - { - if(border_mode == BorderMode::REPLICATE) - { - coord.set(0, std::max(0, std::min(x, width - 1))); - coord.set(1, std::max(0, std::min(y, height - 1))); - } - else - { - return constant_border_value; - } - } - - return src[coord2index(src.shape(), coord)]; -} - -template -T bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value); - -/* Apply 2D spatial filter on a single element of @p in at coordinates @p coord - * - * - filter sizes have to be odd number - * - Row major order of filter assumed - * - TO_ZERO rounding policy assumed - * - SATURATE convert policy assumed - */ -template -void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor &src, SimpleTensor &dst, const TensorShape &filter_shape, const V *filter_itr, double scale, BorderMode border_mode, - T constant_border_value = T(0)) -{ - double val = 0.; - const int x = coord.x(); - const int y = coord.y(); - for(int j = y - static_cast(filter_shape[1] / 2); j <= y + static_cast(filter_shape[1] / 2); ++j) - { - for(int i = x - static_cast(filter_shape[0] / 2); i <= x + static_cast(filter_shape[0] / 2); ++i) - { - coord.set(0, i); - coord.set(1, j); - val += static_cast(*filter_itr) * tensor_elem_at(src, coord, border_mode, constant_border_value); - ++filter_itr; - } - } - coord.set(0, x); - coord.set(1, y); - dst[coord2index(src.shape(), coord)] = saturate_cast(support::cpp11::trunc(val * scale)); -} - -RawTensor transpose(const RawTensor &src, int chunk_width = 1); - -/** Fill matrix random. - * - * @param[in,out] matrix Matrix - */ -template -inline void fill_warp_matrix(std::array &matrix) -{ - std::mt19937 gen(library.get()->seed()); - std::uniform_real_distribution dist(-1, 1); - for(auto &x : matrix) - { - x = dist(gen); - } - if(SIZE == 9) - { - // This is only used in Warp Perspective, we set M[3][3] = 1 so that Z0 is not 0 and we avoid division by 0. - matrix[8] = 1.f; - } -} - -bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode); -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_VALIDATION_UTILS_H__ */ diff --git a/tests/validation/CPP/UtilsQuantizedAsymm.h b/tests/validation/CPP/UtilsQuantizedAsymm.h deleted file mode 100644 index b7b69d588a..0000000000 --- a/tests/validation/CPP/UtilsQuantizedAsymm.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 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_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ -#define __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ - -#include - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -/** Rounded to nearest division by a power-of-two. */ -inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) -{ - const int32_t mask = (1 << exponent) - 1; - const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0); - return (x >> exponent) + ((x & mask) > threshold ? 1 : 0); -} - -/** Multiplication of two integers. The same as ARMv7 NEON VQRDMULH instruction. */ -inline int32_t asymm_int_mult(int32_t a, int32_t b) -{ - bool overflow = a == b && a == std::numeric_limits::min(); - int64_t a_64(a); - int64_t b_64(b); - int64_t ab_64 = a_64 * b_64; - int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); - int32_t ab_x2_high32 = static_cast((ab_64 + nudge) / (1ll << 31)); - return overflow ? std::numeric_limits::max() : ab_x2_high32; -} -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ */ diff --git a/tests/validation/CPP/WarpAffine.cpp b/tests/validation/CPP/WarpAffine.cpp deleted file mode 100644 index 7b903b7661..0000000000 --- a/tests/validation/CPP/WarpAffine.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2017 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 "WarpAffine.h" - -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) -{ - if(border_mode != BorderMode::UNDEFINED) - { - return true; - } - if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) - { - return true; - } - return false; -} - -template -SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M01 = matrix[0 + 1 * 2]; - const float M11 = matrix[1 + 1 * 2]; - const float M02 = matrix[0 + 2 * 2]; - const float M12 = matrix[1 + 2 * 2]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - int idx = id.x(); - int idy = id.y(); - - float x0 = M00 * idx + M01 * idy + M02; - float y0 = M10 * idx + M11 * idy + M12; - - id.set(0, static_cast(std::floor(x0))); - id.set(1, static_cast(std::floor(y0))); - if((0 <= y0) && (y0 < height) && (0 <= x0) && (x0 < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(x0, y0, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value) : - valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast(x0), width - 1))); - id.set(1, std::max(0, std::min(static_cast(y0), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - } - } - - return dst; -} - -template SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute \ No newline at end of file diff --git a/tests/validation/CPP/WarpAffine.h b/tests/validation/CPP/WarpAffine.h deleted file mode 100644 index 973b1b2e29..0000000000 --- a/tests/validation/CPP/WarpAffine.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_WARP_AFFINE_H__ -#define __ARM_COMPUTE_TEST_WARP_AFFINE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_WARP_AFFINE_H__ */ diff --git a/tests/validation/CPP/WarpPerspective.cpp b/tests/validation/CPP/WarpPerspective.cpp deleted file mode 100644 index 7a50253d69..0000000000 --- a/tests/validation/CPP/WarpPerspective.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2017 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/Helpers.h" - -#include "Utils.h" -#include "WarpPerspective.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - // z0 = M20 * x + M21 * y + M22 - // xn = x0 / z0 - // yn = y0 / z0 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M20 = matrix[2]; - const float M01 = matrix[0 + 1 * 3]; - const float M11 = matrix[1 + 1 * 3]; - const float M21 = matrix[2 + 1 * 3]; - const float M02 = matrix[0 + 2 * 3]; - const float M12 = matrix[1 + 2 * 3]; - const float M22 = matrix[2 + 2 * 3]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - const int idx = id.x(); - const int idy = id.y(); - const float z0 = M20 * idx + M21 * idy + M22; - - const float x0 = (M00 * idx + M01 * idy + M02); - const float y0 = (M10 * idx + M11 * idy + M12); - - const float xn = x0 / z0; - const float yn = y0 / z0; - id.set(0, static_cast(std::floor(xn))); - id.set(1, static_cast(std::floor(yn))); - if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(xn, yn, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value) : valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast(xn), width - 1))); - id.set(1, std::max(0, std::min(static_cast(yn), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - } - } - return dst; -} - -template SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/CPP/WarpPerspective.h b/tests/validation/CPP/WarpPerspective.h deleted file mode 100644 index 2367f4d6dc..0000000000 --- a/tests/validation/CPP/WarpPerspective.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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_WARP_PERSPECTIVE_H__ -#define __ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H__ - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template -SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H__ */ diff --git a/tests/validation/NEON/GaussianPyramid.cpp b/tests/validation/NEON/GaussianPyramid.cpp index fb4944f9c3..a9130cfcf2 100644 --- a/tests/validation/NEON/GaussianPyramid.cpp +++ b/tests/validation/NEON/GaussianPyramid.cpp @@ -32,9 +32,9 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Validation.h" #include "tests/validation/fixtures/GaussianPyramidHalfFixture.h" +#include "tests/validation/reference/Utils.h" namespace arm_compute { diff --git a/tests/validation/NEON/WarpAffine.cpp b/tests/validation/NEON/WarpAffine.cpp index 678549d21e..8c83507e95 100644 --- a/tests/validation/NEON/WarpAffine.cpp +++ b/tests/validation/NEON/WarpAffine.cpp @@ -34,9 +34,9 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Validation.h" #include "tests/validation/fixtures/WarpAffineFixture.h" +#include "tests/validation/reference/Utils.h" namespace arm_compute { diff --git a/tests/validation/fixtures/AbsoluteDifferenceFixture.h b/tests/validation/fixtures/AbsoluteDifferenceFixture.h index 54e202d087..b725304a4d 100644 --- a/tests/validation/fixtures/AbsoluteDifferenceFixture.h +++ b/tests/validation/fixtures/AbsoluteDifferenceFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/AbsoluteDifference.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/AbsoluteDifference.h" namespace arm_compute { diff --git a/tests/validation/fixtures/AccumulateFixture.h b/tests/validation/fixtures/AccumulateFixture.h index 3d8ca2dafc..091000175c 100644 --- a/tests/validation/fixtures/AccumulateFixture.h +++ b/tests/validation/fixtures/AccumulateFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Accumulate.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/Accumulate.h" namespace arm_compute { diff --git a/tests/validation/fixtures/ActivationLayerFixture.h b/tests/validation/fixtures/ActivationLayerFixture.h index 384e63bf49..75e625f715 100644 --- a/tests/validation/fixtures/ActivationLayerFixture.h +++ b/tests/validation/fixtures/ActivationLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ActivationLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ActivationLayer.h" #include diff --git a/tests/validation/fixtures/ArithmeticAdditionFixture.h b/tests/validation/fixtures/ArithmeticAdditionFixture.h index 02c3ca9716..c3a51b97d1 100644 --- a/tests/validation/fixtures/ArithmeticAdditionFixture.h +++ b/tests/validation/fixtures/ArithmeticAdditionFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ArithmeticAddition.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ArithmeticAddition.h" namespace arm_compute { diff --git a/tests/validation/fixtures/ArithmeticSubtractionFixture.h b/tests/validation/fixtures/ArithmeticSubtractionFixture.h index 9e65faef00..ba0dd14414 100644 --- a/tests/validation/fixtures/ArithmeticSubtractionFixture.h +++ b/tests/validation/fixtures/ArithmeticSubtractionFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ArithmeticSubtraction.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ArithmeticSubtraction.h" namespace arm_compute { diff --git a/tests/validation/fixtures/BatchNormalizationLayerFixture.h b/tests/validation/fixtures/BatchNormalizationLayerFixture.h index f4772a8dd9..298c9ca411 100644 --- a/tests/validation/fixtures/BatchNormalizationLayerFixture.h +++ b/tests/validation/fixtures/BatchNormalizationLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/BatchNormalizationLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/BatchNormalizationLayer.h" namespace arm_compute { diff --git a/tests/validation/fixtures/BitwiseAndFixture.h b/tests/validation/fixtures/BitwiseAndFixture.h index 0dfff868ab..c1247de6c4 100644 --- a/tests/validation/fixtures/BitwiseAndFixture.h +++ b/tests/validation/fixtures/BitwiseAndFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/BitwiseAnd.h" +#include "tests/validation/reference/BitwiseAnd.h" namespace arm_compute { diff --git a/tests/validation/fixtures/BitwiseNotFixture.h b/tests/validation/fixtures/BitwiseNotFixture.h index e5bf69992e..f90d0895aa 100644 --- a/tests/validation/fixtures/BitwiseNotFixture.h +++ b/tests/validation/fixtures/BitwiseNotFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/BitwiseNot.h" +#include "tests/validation/reference/BitwiseNot.h" namespace arm_compute { diff --git a/tests/validation/fixtures/BitwiseOrFixture.h b/tests/validation/fixtures/BitwiseOrFixture.h index d61e767bf3..d6ec5b8065 100644 --- a/tests/validation/fixtures/BitwiseOrFixture.h +++ b/tests/validation/fixtures/BitwiseOrFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/BitwiseOr.h" +#include "tests/validation/reference/BitwiseOr.h" namespace arm_compute { diff --git a/tests/validation/fixtures/BitwiseXorFixture.h b/tests/validation/fixtures/BitwiseXorFixture.h index 16fa8c0422..8da2181fac 100644 --- a/tests/validation/fixtures/BitwiseXorFixture.h +++ b/tests/validation/fixtures/BitwiseXorFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/BitwiseXor.h" +#include "tests/validation/reference/BitwiseXor.h" namespace arm_compute { diff --git a/tests/validation/fixtures/Box3x3Fixture.h b/tests/validation/fixtures/Box3x3Fixture.h index 1aa958a11b..e851b3418e 100644 --- a/tests/validation/fixtures/Box3x3Fixture.h +++ b/tests/validation/fixtures/Box3x3Fixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Box3x3.h" +#include "tests/validation/reference/Box3x3.h" #include diff --git a/tests/validation/fixtures/ConvolutionLayerFixture.h b/tests/validation/fixtures/ConvolutionLayerFixture.h index fe206997b8..859780812a 100644 --- a/tests/validation/fixtures/ConvolutionLayerFixture.h +++ b/tests/validation/fixtures/ConvolutionLayerFixture.h @@ -32,9 +32,9 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ConvolutionLayer.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ConvolutionLayer.h" +#include "tests/validation/reference/Utils.h" #include diff --git a/tests/validation/fixtures/DeconvolutionLayerFixture.h b/tests/validation/fixtures/DeconvolutionLayerFixture.h index 8dff97d83f..e98f5e93c0 100644 --- a/tests/validation/fixtures/DeconvolutionLayerFixture.h +++ b/tests/validation/fixtures/DeconvolutionLayerFixture.h @@ -28,8 +28,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DeconvolutionLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/DeconvolutionLayer.h" #include diff --git a/tests/validation/fixtures/DepthConcatenateLayerFixture.h b/tests/validation/fixtures/DepthConcatenateLayerFixture.h index 103c73e4ea..e7fe6340f7 100644 --- a/tests/validation/fixtures/DepthConcatenateLayerFixture.h +++ b/tests/validation/fixtures/DepthConcatenateLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DepthConcatenateLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/DepthConcatenateLayer.h" #include diff --git a/tests/validation/fixtures/DepthConvertLayerFixture.h b/tests/validation/fixtures/DepthConvertLayerFixture.h index c2fdc75bb4..4b4e959273 100644 --- a/tests/validation/fixtures/DepthConvertLayerFixture.h +++ b/tests/validation/fixtures/DepthConvertLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DepthConvertLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/DepthConvertLayer.h" namespace arm_compute { diff --git a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h index 0af3fdf6c4..4426215114 100644 --- a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DepthwiseConvolutionLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/DepthwiseConvolutionLayer.h" #include diff --git a/tests/validation/fixtures/DepthwiseSeparableConvolutionLayerFixture.h b/tests/validation/fixtures/DepthwiseSeparableConvolutionLayerFixture.h index 9b9c0c5af7..8bce60caf2 100644 --- a/tests/validation/fixtures/DepthwiseSeparableConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DepthwiseSeparableConvolutionLayerFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DepthwiseSeparableConvolutionLayer.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/DepthwiseSeparableConvolutionLayer.h" #include diff --git a/tests/validation/fixtures/DequantizationLayerFixture.h b/tests/validation/fixtures/DequantizationLayerFixture.h index 28d43cf754..5855820d86 100644 --- a/tests/validation/fixtures/DequantizationLayerFixture.h +++ b/tests/validation/fixtures/DequantizationLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/DequantizationLayer.h" +#include "tests/validation/reference/DequantizationLayer.h" #include diff --git a/tests/validation/fixtures/DilateFixture.h b/tests/validation/fixtures/DilateFixture.h index 7b56cf6c90..aa531a10fe 100644 --- a/tests/validation/fixtures/DilateFixture.h +++ b/tests/validation/fixtures/DilateFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Dilate.h" +#include "tests/validation/reference/Dilate.h" #include diff --git a/tests/validation/fixtures/DirectConvolutionLayerFixture.h b/tests/validation/fixtures/DirectConvolutionLayerFixture.h index 4916c3335b..d63a5bcdba 100644 --- a/tests/validation/fixtures/DirectConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DirectConvolutionLayerFixture.h @@ -28,9 +28,9 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ConvolutionLayer.h" #include "tests/validation/Helpers.h" #include "tests/validation/fixtures/ConvolutionLayerFixture.h" +#include "tests/validation/reference/ConvolutionLayer.h" #include diff --git a/tests/validation/fixtures/ErodeFixture.h b/tests/validation/fixtures/ErodeFixture.h index 6ba5fc1e78..d37cac0298 100644 --- a/tests/validation/fixtures/ErodeFixture.h +++ b/tests/validation/fixtures/ErodeFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Erode.h" +#include "tests/validation/reference/Erode.h" #include diff --git a/tests/validation/fixtures/FixedPointFixture.h b/tests/validation/fixtures/FixedPointFixture.h index 2980e2f324..3f3bb6e0b7 100644 --- a/tests/validation/fixtures/FixedPointFixture.h +++ b/tests/validation/fixtures/FixedPointFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/FixedPoint.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/FixedPoint.h" namespace arm_compute { diff --git a/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h b/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h index d090d8583d..73386dfc97 100644 --- a/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h +++ b/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/FixedPointPixelWiseMultiplication.h" +#include "tests/validation/reference/FixedPointPixelWiseMultiplication.h" namespace arm_compute { diff --git a/tests/validation/fixtures/FlattenLayerFixture.h b/tests/validation/fixtures/FlattenLayerFixture.h index faf53c70a3..436138b8b4 100644 --- a/tests/validation/fixtures/FlattenLayerFixture.h +++ b/tests/validation/fixtures/FlattenLayerFixture.h @@ -33,7 +33,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/FlattenLayer.h" +#include "tests/validation/reference/FlattenLayer.h" #include diff --git a/tests/validation/fixtures/FloorFixture.h b/tests/validation/fixtures/FloorFixture.h index 3f948412af..246105e365 100644 --- a/tests/validation/fixtures/FloorFixture.h +++ b/tests/validation/fixtures/FloorFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Floor.h" +#include "tests/validation/reference/Floor.h" namespace arm_compute { diff --git a/tests/validation/fixtures/FullyConnectedLayerFixture.h b/tests/validation/fixtures/FullyConnectedLayerFixture.h index dba20bb375..f23fc207a8 100644 --- a/tests/validation/fixtures/FullyConnectedLayerFixture.h +++ b/tests/validation/fixtures/FullyConnectedLayerFixture.h @@ -33,9 +33,9 @@ #include "tests/RawTensor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/FullyConnectedLayer.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/FullyConnectedLayer.h" +#include "tests/validation/reference/Utils.h" #include diff --git a/tests/validation/fixtures/GEMMFixture.h b/tests/validation/fixtures/GEMMFixture.h index 923a29c7d0..e807ad8c06 100644 --- a/tests/validation/fixtures/GEMMFixture.h +++ b/tests/validation/fixtures/GEMMFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GEMM.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/GEMM.h" #include diff --git a/tests/validation/fixtures/GEMMInterleave4x4Fixture.h b/tests/validation/fixtures/GEMMInterleave4x4Fixture.h index b5e3eb6ee0..1f0a7429f1 100644 --- a/tests/validation/fixtures/GEMMInterleave4x4Fixture.h +++ b/tests/validation/fixtures/GEMMInterleave4x4Fixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GEMMInterleave4x4.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/GEMMInterleave4x4.h" #include diff --git a/tests/validation/fixtures/GEMMInterleaveBlockedFixture.h b/tests/validation/fixtures/GEMMInterleaveBlockedFixture.h index 89c188f6a6..488324dcc8 100644 --- a/tests/validation/fixtures/GEMMInterleaveBlockedFixture.h +++ b/tests/validation/fixtures/GEMMInterleaveBlockedFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GEMMInterleaveBlocked.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/GEMMInterleaveBlocked.h" #include diff --git a/tests/validation/fixtures/GEMMLowpAssemblyFixture.h b/tests/validation/fixtures/GEMMLowpAssemblyFixture.h index 38e08f7992..ff33c9db39 100644 --- a/tests/validation/fixtures/GEMMLowpAssemblyFixture.h +++ b/tests/validation/fixtures/GEMMLowpAssemblyFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GEMMLowp.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/GEMMLowp.h" #include diff --git a/tests/validation/fixtures/GEMMLowpFixture.h b/tests/validation/fixtures/GEMMLowpFixture.h index d3e2aacbe1..c504e2e10d 100644 --- a/tests/validation/fixtures/GEMMLowpFixture.h +++ b/tests/validation/fixtures/GEMMLowpFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GEMMLowp.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/GEMMLowp.h" #include diff --git a/tests/validation/fixtures/Gaussian3x3Fixture.h b/tests/validation/fixtures/Gaussian3x3Fixture.h index 72f082e64c..396e63e73f 100644 --- a/tests/validation/fixtures/Gaussian3x3Fixture.h +++ b/tests/validation/fixtures/Gaussian3x3Fixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Gaussian3x3.h" +#include "tests/validation/reference/Gaussian3x3.h" #include diff --git a/tests/validation/fixtures/Gaussian5x5Fixture.h b/tests/validation/fixtures/Gaussian5x5Fixture.h index 9fdb0d2422..31d7acf0f1 100644 --- a/tests/validation/fixtures/Gaussian5x5Fixture.h +++ b/tests/validation/fixtures/Gaussian5x5Fixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Gaussian5x5.h" +#include "tests/validation/reference/Gaussian5x5.h" #include diff --git a/tests/validation/fixtures/GaussianPyramidHalfFixture.h b/tests/validation/fixtures/GaussianPyramidHalfFixture.h index c3e3efb6e6..ef7657a93c 100644 --- a/tests/validation/fixtures/GaussianPyramidHalfFixture.h +++ b/tests/validation/fixtures/GaussianPyramidHalfFixture.h @@ -33,7 +33,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/GaussianPyramidHalf.h" +#include "tests/validation/reference/GaussianPyramidHalf.h" namespace arm_compute { diff --git a/tests/validation/fixtures/HarrisCornersFixture.h b/tests/validation/fixtures/HarrisCornersFixture.h index 50677f6bf3..6395e3b6d8 100644 --- a/tests/validation/fixtures/HarrisCornersFixture.h +++ b/tests/validation/fixtures/HarrisCornersFixture.h @@ -30,8 +30,8 @@ #include "tests/Globals.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/HarrisCornerDetector.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/HarrisCornerDetector.h" namespace arm_compute { diff --git a/tests/validation/fixtures/HistogramFixture.h b/tests/validation/fixtures/HistogramFixture.h index 943b2cdde3..7349bdfae2 100644 --- a/tests/validation/fixtures/HistogramFixture.h +++ b/tests/validation/fixtures/HistogramFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Histogram.h" +#include "tests/validation/reference/Histogram.h" #include "utils/Utils.h" #include diff --git a/tests/validation/fixtures/IntegralImageFixture.h b/tests/validation/fixtures/IntegralImageFixture.h index 2f0ec51642..8d2149e1fd 100644 --- a/tests/validation/fixtures/IntegralImageFixture.h +++ b/tests/validation/fixtures/IntegralImageFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/IntegralImage.h" +#include "tests/validation/reference/IntegralImage.h" namespace arm_compute { diff --git a/tests/validation/fixtures/L2NormalizeLayerFixture.h b/tests/validation/fixtures/L2NormalizeLayerFixture.h index 7bb95883f7..6f11dcb658 100644 --- a/tests/validation/fixtures/L2NormalizeLayerFixture.h +++ b/tests/validation/fixtures/L2NormalizeLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/L2NormalizeLayer.h" +#include "tests/validation/reference/L2NormalizeLayer.h" namespace arm_compute { diff --git a/tests/validation/fixtures/MagnitudeFixture.h b/tests/validation/fixtures/MagnitudeFixture.h index dcd3da8dfe..1c529070a8 100644 --- a/tests/validation/fixtures/MagnitudeFixture.h +++ b/tests/validation/fixtures/MagnitudeFixture.h @@ -30,7 +30,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Magnitude.h" +#include "tests/validation/reference/Magnitude.h" namespace arm_compute { diff --git a/tests/validation/fixtures/MeanStdDevFixture.h b/tests/validation/fixtures/MeanStdDevFixture.h index 37f538b216..17dfe78dbd 100644 --- a/tests/validation/fixtures/MeanStdDevFixture.h +++ b/tests/validation/fixtures/MeanStdDevFixture.h @@ -27,7 +27,7 @@ #include "tests/Globals.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/MeanStdDev.h" +#include "tests/validation/reference/MeanStdDev.h" namespace arm_compute { diff --git a/tests/validation/fixtures/Median3x3Fixture.h b/tests/validation/fixtures/Median3x3Fixture.h index b45e93585a..094635804b 100644 --- a/tests/validation/fixtures/Median3x3Fixture.h +++ b/tests/validation/fixtures/Median3x3Fixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Median3x3.h" +#include "tests/validation/reference/Median3x3.h" #include diff --git a/tests/validation/fixtures/MinMaxLocationFixture.h b/tests/validation/fixtures/MinMaxLocationFixture.h index bf076ef0ab..120a5c49c4 100644 --- a/tests/validation/fixtures/MinMaxLocationFixture.h +++ b/tests/validation/fixtures/MinMaxLocationFixture.h @@ -31,7 +31,7 @@ #include "tests/Types.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/MinMaxLocation.h" +#include "tests/validation/reference/MinMaxLocation.h" namespace arm_compute { diff --git a/tests/validation/fixtures/NonLinearFilterFixture.h b/tests/validation/fixtures/NonLinearFilterFixture.h index 2f22873488..78ba0eaf86 100644 --- a/tests/validation/fixtures/NonLinearFilterFixture.h +++ b/tests/validation/fixtures/NonLinearFilterFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/NonLinearFilter.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/NonLinearFilter.h" namespace arm_compute { diff --git a/tests/validation/fixtures/NormalizationLayerFixture.h b/tests/validation/fixtures/NormalizationLayerFixture.h index 67881d0347..e7d83c7735 100644 --- a/tests/validation/fixtures/NormalizationLayerFixture.h +++ b/tests/validation/fixtures/NormalizationLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/NormalizationLayer.h" +#include "tests/validation/reference/NormalizationLayer.h" #include diff --git a/tests/validation/fixtures/PhaseFixture.h b/tests/validation/fixtures/PhaseFixture.h index 693a61ed1a..09badcfd2a 100644 --- a/tests/validation/fixtures/PhaseFixture.h +++ b/tests/validation/fixtures/PhaseFixture.h @@ -30,7 +30,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Phase.h" +#include "tests/validation/reference/Phase.h" namespace arm_compute { diff --git a/tests/validation/fixtures/PixelWiseMultiplicationFixture.h b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h index 351349e64e..7428fb5cb7 100644 --- a/tests/validation/fixtures/PixelWiseMultiplicationFixture.h +++ b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/PixelWiseMultiplication.h" +#include "tests/validation/reference/PixelWiseMultiplication.h" namespace arm_compute { diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index 14192517fc..890eef2d4b 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/PoolingLayer.h" +#include "tests/validation/reference/PoolingLayer.h" #include diff --git a/tests/validation/fixtures/QuantizationLayerFixture.h b/tests/validation/fixtures/QuantizationLayerFixture.h index 83ee0495f3..6ce673a6f0 100644 --- a/tests/validation/fixtures/QuantizationLayerFixture.h +++ b/tests/validation/fixtures/QuantizationLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/QuantizationLayer.h" +#include "tests/validation/reference/QuantizationLayer.h" #include diff --git a/tests/validation/fixtures/ReductionOperationFixture.h b/tests/validation/fixtures/ReductionOperationFixture.h index 7c871aed3b..6fa5f0c44f 100644 --- a/tests/validation/fixtures/ReductionOperationFixture.h +++ b/tests/validation/fixtures/ReductionOperationFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ReductionOperation.h" +#include "tests/validation/reference/ReductionOperation.h" namespace arm_compute { diff --git a/tests/validation/fixtures/RemapFixture.h b/tests/validation/fixtures/RemapFixture.h index 1cff1294ba..846ebf44a2 100644 --- a/tests/validation/fixtures/RemapFixture.h +++ b/tests/validation/fixtures/RemapFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Remap.h" +#include "tests/validation/reference/Remap.h" #include diff --git a/tests/validation/fixtures/ReshapeLayerFixture.h b/tests/validation/fixtures/ReshapeLayerFixture.h index 435717cfbd..2bd514830f 100644 --- a/tests/validation/fixtures/ReshapeLayerFixture.h +++ b/tests/validation/fixtures/ReshapeLayerFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ReshapeLayer.h" +#include "tests/validation/reference/ReshapeLayer.h" namespace arm_compute { diff --git a/tests/validation/fixtures/ScaleFixture.h b/tests/validation/fixtures/ScaleFixture.h index 894260a02f..fe24f5bac5 100644 --- a/tests/validation/fixtures/ScaleFixture.h +++ b/tests/validation/fixtures/ScaleFixture.h @@ -31,7 +31,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Scale.h" +#include "tests/validation/reference/Scale.h" namespace arm_compute { diff --git a/tests/validation/fixtures/ScharrFixture.h b/tests/validation/fixtures/ScharrFixture.h index f432f85032..36b8e98fb8 100644 --- a/tests/validation/fixtures/ScharrFixture.h +++ b/tests/validation/fixtures/ScharrFixture.h @@ -29,7 +29,7 @@ #include "tests/Types.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Scharr.h" +#include "tests/validation/reference/Scharr.h" #include diff --git a/tests/validation/fixtures/SobelFixture.h b/tests/validation/fixtures/SobelFixture.h index f8041b9829..f075a69c40 100644 --- a/tests/validation/fixtures/SobelFixture.h +++ b/tests/validation/fixtures/SobelFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Sobel.h" +#include "tests/validation/reference/Sobel.h" #include diff --git a/tests/validation/fixtures/SoftmaxLayerFixture.h b/tests/validation/fixtures/SoftmaxLayerFixture.h index 9836502cd2..3ffbc6aac7 100644 --- a/tests/validation/fixtures/SoftmaxLayerFixture.h +++ b/tests/validation/fixtures/SoftmaxLayerFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/SoftmaxLayer.h" +#include "tests/validation/reference/SoftmaxLayer.h" #include diff --git a/tests/validation/fixtures/TableLookupFixture.h b/tests/validation/fixtures/TableLookupFixture.h index 49e0f413ce..6886c7eca4 100644 --- a/tests/validation/fixtures/TableLookupFixture.h +++ b/tests/validation/fixtures/TableLookupFixture.h @@ -32,8 +32,8 @@ #include "tests/RawLutAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/TableLookup.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/TableLookup.h" namespace arm_compute { diff --git a/tests/validation/fixtures/ThresholdFixture.h b/tests/validation/fixtures/ThresholdFixture.h index 0ea43a5cb3..9a92175728 100644 --- a/tests/validation/fixtures/ThresholdFixture.h +++ b/tests/validation/fixtures/ThresholdFixture.h @@ -29,7 +29,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Threshold.h" +#include "tests/validation/reference/Threshold.h" namespace arm_compute { diff --git a/tests/validation/fixtures/TransposeFixture.h b/tests/validation/fixtures/TransposeFixture.h index 7a9516a282..c798162a71 100644 --- a/tests/validation/fixtures/TransposeFixture.h +++ b/tests/validation/fixtures/TransposeFixture.h @@ -32,7 +32,7 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Transpose.h" +#include "tests/validation/reference/Transpose.h" namespace arm_compute { diff --git a/tests/validation/fixtures/WarpAffineFixture.h b/tests/validation/fixtures/WarpAffineFixture.h index fef1f6b626..c027072a13 100644 --- a/tests/validation/fixtures/WarpAffineFixture.h +++ b/tests/validation/fixtures/WarpAffineFixture.h @@ -33,8 +33,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Utils.h" -#include "tests/validation/CPP/WarpAffine.h" +#include "tests/validation/reference/Utils.h" +#include "tests/validation/reference/WarpAffine.h" namespace arm_compute { diff --git a/tests/validation/fixtures/WarpPerspectiveFixture.h b/tests/validation/fixtures/WarpPerspectiveFixture.h index 1a6d6c035e..c804fa6da7 100644 --- a/tests/validation/fixtures/WarpPerspectiveFixture.h +++ b/tests/validation/fixtures/WarpPerspectiveFixture.h @@ -31,8 +31,8 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/Utils.h" -#include "tests/validation/CPP/WarpPerspective.h" +#include "tests/validation/reference/Utils.h" +#include "tests/validation/reference/WarpPerspective.h" #include diff --git a/tests/validation/fixtures/WinogradLayerFixture.h b/tests/validation/fixtures/WinogradLayerFixture.h index a5d6fc966d..7aa26c7143 100644 --- a/tests/validation/fixtures/WinogradLayerFixture.h +++ b/tests/validation/fixtures/WinogradLayerFixture.h @@ -32,9 +32,9 @@ #include "tests/IAccessor.h" #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" -#include "tests/validation/CPP/ConvolutionLayer.h" -#include "tests/validation/CPP/Utils.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ConvolutionLayer.h" +#include "tests/validation/reference/Utils.h" #include diff --git a/tests/validation/reference/AbsoluteDifference.cpp b/tests/validation/reference/AbsoluteDifference.cpp new file mode 100644 index 0000000000..f518e67324 --- /dev/null +++ b/tests/validation/reference/AbsoluteDifference.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 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 "AbsoluteDifference.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type) +{ + SimpleTensor result(src1.shape(), dst_data_type); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src1.num_elements(); ++i) + { + intermediate_type val = std::abs(static_cast(src1[i]) - static_cast(src2[i])); + result[i] = saturate_cast(val); + } + + return result; +} + +template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); +template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); +template SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/AbsoluteDifference.h b/tests/validation/reference/AbsoluteDifference.h new file mode 100644 index 0000000000..b14da157df --- /dev/null +++ b/tests/validation/reference/AbsoluteDifference.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_ABSOLUTE_DIFFERENCE_H__ +#define __ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor absolute_difference(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_H__ */ diff --git a/tests/validation/reference/Accumulate.cpp b/tests/validation/reference/Accumulate.cpp new file mode 100644 index 0000000000..29a2007bbd --- /dev/null +++ b/tests/validation/reference/Accumulate.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017 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 "Accumulate.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type) +{ + SimpleTensor dst{ src.shape(), output_data_type }; + + library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src.num_elements(); ++i) + { + intermediate_type val = static_cast(src[i]) + static_cast(dst[i]); + dst[i] = saturate_cast(val); + } + + return dst; +} + +template +SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type) +{ + ARM_COMPUTE_ERROR_ON_MSG(alpha < 0.f || alpha > 1.f, "Weight (alpha) specified in accumulate_weighted must be within the range [0, 1]"); + + SimpleTensor dst{ src.shape(), output_data_type }; + + library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src.num_elements(); ++i) + { + double val = (1. - static_cast(alpha)) * static_cast(dst[i]) + static_cast(alpha) * static_cast(src[i]); + dst[i] = static_cast(val); + } + + return dst; +} + +template +SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type) +{ + ARM_COMPUTE_ERROR_ON_MSG(shift > 15, "Shift in accumulate_squared must be within the range [0, 15]"); + + SimpleTensor dst{ src.shape(), output_data_type }; + + library->fill_tensor_uniform(dst, 1, static_cast(0), static_cast(std::numeric_limits::max())); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + intermediate_type denom = 1 << shift; + + for(int i = 0; i < src.num_elements(); ++i) + { + intermediate_type val = static_cast(dst[i]) + (static_cast(src[i]) * static_cast(src[i]) / denom); + dst[i] = saturate_cast(val); + } + + return dst; +} + +template SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type); +template SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type); +template SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Accumulate.h b/tests/validation/reference/Accumulate.h new file mode 100644 index 0000000000..faa570bd05 --- /dev/null +++ b/tests/validation/reference/Accumulate.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 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_ACCUMULATE_H__ +#define __ARM_COMPUTE_TEST_ACCUMULATE_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor accumulate(const SimpleTensor &src, DataType output_data_type); + +template +SimpleTensor accumulate_weighted(const SimpleTensor &src, float alpha, DataType output_data_type); + +template +SimpleTensor accumulate_squared(const SimpleTensor &src, uint32_t shift, DataType output_data_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ACCUMULATE_H__ */ diff --git a/tests/validation/reference/ActivationLayer.cpp b/tests/validation/reference/ActivationLayer.cpp new file mode 100644 index 0000000000..2243e6ff59 --- /dev/null +++ b/tests/validation/reference/ActivationLayer.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2017 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 "ActivationLayer.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info) +{ + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const T a(info.a()); + const T b(info.b()); + + for(int i = 0; i < src.num_elements(); ++i) + { + T x = src[i]; + + switch(info.activation()) + { + case ActivationLayerInfo::ActivationFunction::ABS: + dst[i] = std::abs(x); + break; + case ActivationLayerInfo::ActivationFunction::LINEAR: + dst[i] = a * x + b; + break; + case ActivationLayerInfo::ActivationFunction::LOGISTIC: + dst[i] = static_cast(1) / (static_cast(1) + std::exp(-x)); + break; + case ActivationLayerInfo::ActivationFunction::RELU: + dst[i] = std::max(static_cast(0), x); + break; + case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: + dst[i] = std::min(a, std::max(static_cast(0), x)); + break; + case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: + dst[i] = std::min(a, std::max(b, x)); + break; + case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: + dst[i] = (x > 0) ? x : a * x; + break; + case ActivationLayerInfo::ActivationFunction::SOFT_RELU: + dst[i] = std::log(static_cast(1) + std::exp(x)); + break; + case ActivationLayerInfo::ActivationFunction::SQRT: + dst[i] = std::sqrt(x); + break; + case ActivationLayerInfo::ActivationFunction::SQUARE: + dst[i] = x * x; + break; + case ActivationLayerInfo::ActivationFunction::TANH: + dst[i] = a * std::tanh(b * x); + break; + default: + ARM_COMPUTE_ERROR("Unsupported activation function"); + } + } + + return dst; +} + +template ::value, int>::type> +SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info) +{ + using namespace fixed_point_arithmetic; + + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const int fixed_point_position = src.fixed_point_position(); + const fixed_point a(info.a(), fixed_point_position); + const fixed_point b(info.b(), fixed_point_position); + const fixed_point const_0(0, fixed_point_position); + const fixed_point const_1(1, fixed_point_position); + + for(int i = 0; i < src.num_elements(); ++i) + { + fixed_point x(src[i], fixed_point_position, true); + + switch(info.activation()) + { + case ActivationLayerInfo::ActivationFunction::ABS: + dst[i] = abs(x).raw(); + break; + case ActivationLayerInfo::ActivationFunction::LINEAR: + dst[i] = add(b, mul(a, x)).raw(); + break; + case ActivationLayerInfo::ActivationFunction::LOGISTIC: + dst[i] = (const_1 / (const_1 + exp(-x))).raw(); + break; + case ActivationLayerInfo::ActivationFunction::RELU: + dst[i] = max(const_0, x).raw(); + break; + case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: + dst[i] = min(a, max(const_0, x)).raw(); + break; + case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: + dst[i] = min(a, max(b, x)).raw(); + break; + case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: + dst[i] = (x > const_0) ? x.raw() : mul(a, x).raw(); + break; + case ActivationLayerInfo::ActivationFunction::SOFT_RELU: + dst[i] = log(const_1 + exp(x)).raw(); + break; + case ActivationLayerInfo::ActivationFunction::SQRT: + dst[i] = (const_1 / inv_sqrt(x)).raw(); + break; + case ActivationLayerInfo::ActivationFunction::SQUARE: + dst[i] = mul(x, x).raw(); + break; + case ActivationLayerInfo::ActivationFunction::TANH: + dst[i] = mul(a, tanh(mul(b, x))).raw(); + break; + default: + ARM_COMPUTE_ERROR("Unsupported activation function"); + } + } + + return dst; +} + +template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); +template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); +template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); +template SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ActivationLayer.h b/tests/validation/reference/ActivationLayer.h new file mode 100644 index 0000000000..09f602ffa1 --- /dev/null +++ b/tests/validation/reference/ActivationLayer.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_ACTIVATION_LAYER_H__ +#define __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); + +template ::value, int>::type = 0> +SimpleTensor activation_layer(const SimpleTensor &src, ActivationLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ */ diff --git a/tests/validation/reference/ArithmeticAddition.cpp b/tests/validation/reference/ArithmeticAddition.cpp new file mode 100644 index 0000000000..82dd1437cd --- /dev/null +++ b/tests/validation/reference/ArithmeticAddition.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017 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 "ArithmeticAddition.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy) +{ + SimpleTensor result(src1.shape(), dst_data_type); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src1.num_elements(); ++i) + { + intermediate_type val = static_cast(src1[i]) + static_cast(src2[i]); + result[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); + } + + return result; +} + +template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, + ConvertPolicy convert_policy); +template SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ArithmeticAddition.h b/tests/validation/reference/ArithmeticAddition.h new file mode 100644 index 0000000000..5902a6f529 --- /dev/null +++ b/tests/validation/reference/ArithmeticAddition.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_ARITHMETIC_ADDITION_H__ +#define __ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor arithmetic_addition(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_H__ */ diff --git a/tests/validation/reference/ArithmeticSubtraction.cpp b/tests/validation/reference/ArithmeticSubtraction.cpp new file mode 100644 index 0000000000..bed2d37090 --- /dev/null +++ b/tests/validation/reference/ArithmeticSubtraction.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017 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 "ArithmeticSubtraction.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy) +{ + SimpleTensor result(src1.shape(), dst_data_type); + + using intermediate_type = typename common_promoted_signed_type= sizeof(T2), T1, T2>::type >::intermediate_type; + + for(int i = 0; i < src1.num_elements(); ++i) + { + intermediate_type val = static_cast(src1[i]) - static_cast(src2[i]); + result[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); + } + + return result; +} + +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +template SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ArithmeticSubtraction.h b/tests/validation/reference/ArithmeticSubtraction.h new file mode 100644 index 0000000000..9308314bda --- /dev/null +++ b/tests/validation/reference/ArithmeticSubtraction.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_ARITHMETIC_SUBTRACTION_H__ +#define __ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor arithmetic_subtraction(const SimpleTensor &src1, const SimpleTensor &src2, DataType dst_data_type, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_H__ */ diff --git a/tests/validation/reference/BatchNormalizationLayer.cpp b/tests/validation/reference/BatchNormalizationLayer.cpp new file mode 100644 index 0000000000..e4446d1694 --- /dev/null +++ b/tests/validation/reference/BatchNormalizationLayer.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2017 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 "BatchNormalizationLayer.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +// Batch Normalization Layer for fixed point type +template ::value, int>::type *> +SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, + int fixed_point_position) +{ + SimpleTensor result(src.shape(), src.data_type()); + + const auto cols = static_cast(src.shape()[0]); + const auto rows = static_cast(src.shape()[1]); + const auto depth = static_cast(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < depth; ++i) + { + for(int k = 0; k < rows; ++k) + { + for(int l = 0; l < cols; ++l) + { + const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; + + fixed_point_arithmetic::fixed_point src_qs(src[pos], fixed_point_position, true); + fixed_point_arithmetic::fixed_point var_qs(var[i], fixed_point_position, true); + fixed_point_arithmetic::fixed_point mean_qs(mean[i], fixed_point_position, true); + fixed_point_arithmetic::fixed_point beta_qs(beta[i], fixed_point_position, true); + fixed_point_arithmetic::fixed_point gamma_qs(gamma[i], fixed_point_position, true); + fixed_point_arithmetic::fixed_point epsilon_qs(epsilon, fixed_point_position); + + auto denominator = fixed_point_arithmetic::inv_sqrt(var_qs + epsilon_qs); + auto numerator = src_qs - mean_qs; + auto x_bar = numerator * denominator; + x_bar = beta_qs + x_bar * gamma_qs; + result[pos] = x_bar.raw(); + } + } + } + } + + return result; +} + +// Batch Normalization Layer for floating point type +template ::value, int>::type *> +SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, + int fixed_point_position) +{ + ARM_COMPUTE_UNUSED(fixed_point_position); + + SimpleTensor result(src.shape(), src.data_type()); + + const auto cols = static_cast(src.shape()[0]); + const auto rows = static_cast(src.shape()[1]); + const auto depth = static_cast(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < depth; ++i) + { + for(int k = 0; k < rows; ++k) + { + for(int l = 0; l < cols; ++l) + { + const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; + const float denominator = sqrt(var[i] + epsilon); + const float numerator = src[pos] - mean[i]; + const float x_bar = numerator / denominator; + result[pos] = beta[i] + x_bar * gamma[i]; + } + } + } + } + return result; +} +template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, + const SimpleTensor &gamma, float epsilon, int fixed_point_position); +template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, + const SimpleTensor &gamma, float epsilon, int fixed_point_position); +template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, + const SimpleTensor &gamma, float epsilon, int fixed_point_position); +template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, + const SimpleTensor &beta, + const SimpleTensor &gamma, float epsilon, int fixed_point_position); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/BatchNormalizationLayer.h b/tests/validation/reference/BatchNormalizationLayer.h new file mode 100644 index 0000000000..1a554adf7e --- /dev/null +++ b/tests/validation/reference/BatchNormalizationLayer.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 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_BATCH_NORMALIZATION_LAYER_H__ +#define __ARM_COMPUTE_TEST_BATCH_NORMALIZATION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type * = nullptr> +SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, + int fixed_point_position); + +template ::value, int>::type * = nullptr> +SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, + int fixed_point_position); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BATCH_NORMALIZATION_LAYER_H__ */ diff --git a/tests/validation/reference/BitwiseAnd.cpp b/tests/validation/reference/BitwiseAnd.cpp new file mode 100644 index 0000000000..6fc46b402b --- /dev/null +++ b/tests/validation/reference/BitwiseAnd.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 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 "BitwiseAnd.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2) +{ + SimpleTensor dst(src1.shape(), src1.data_type()); + + for(int i = 0; i < src1.num_elements(); ++i) + { + dst[i] = src1[i] & src2[i]; + } + + return dst; +} + +template SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/BitwiseAnd.h b/tests/validation/reference/BitwiseAnd.h new file mode 100644 index 0000000000..eba2fd695f --- /dev/null +++ b/tests/validation/reference/BitwiseAnd.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_BITWISE_AND_H__ +#define __ARM_COMPUTE_TEST_BITWISE_AND_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_and(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BITWISE_AND_H__ */ diff --git a/tests/validation/reference/BitwiseNot.cpp b/tests/validation/reference/BitwiseNot.cpp new file mode 100644 index 0000000000..5a6a13b56c --- /dev/null +++ b/tests/validation/reference/BitwiseNot.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 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 "BitwiseNot.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_not(const SimpleTensor &src) +{ + SimpleTensor dst(src.shape(), src.data_type()); + + for(int i = 0; i < src.num_elements(); ++i) + { + dst[i] = ~src[i]; + } + + return dst; +} + +template SimpleTensor bitwise_not(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/BitwiseNot.h b/tests/validation/reference/BitwiseNot.h new file mode 100644 index 0000000000..b4206f9388 --- /dev/null +++ b/tests/validation/reference/BitwiseNot.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_BITWISE_NOT_H__ +#define __ARM_COMPUTE_TEST_BITWISE_NOT_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_not(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BITWISE_NOT_H__ */ diff --git a/tests/validation/reference/BitwiseOr.cpp b/tests/validation/reference/BitwiseOr.cpp new file mode 100644 index 0000000000..fc258d54f1 --- /dev/null +++ b/tests/validation/reference/BitwiseOr.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 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 "BitwiseOr.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2) +{ + SimpleTensor dst(src1.shape(), src1.data_type()); + + for(int i = 0; i < src1.num_elements(); ++i) + { + dst[i] = src1[i] | src2[i]; + } + + return dst; +} + +template SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/BitwiseOr.h b/tests/validation/reference/BitwiseOr.h new file mode 100644 index 0000000000..39158cb411 --- /dev/null +++ b/tests/validation/reference/BitwiseOr.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_BITWISE_OR_H__ +#define __ARM_COMPUTE_TEST_BITWISE_OR_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_or(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BITWISE_OR_H__ */ diff --git a/tests/validation/reference/BitwiseXor.cpp b/tests/validation/reference/BitwiseXor.cpp new file mode 100644 index 0000000000..b8d275d8b5 --- /dev/null +++ b/tests/validation/reference/BitwiseXor.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 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 "BitwiseXor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2) +{ + SimpleTensor dst(src1.shape(), src1.data_type()); + + for(int i = 0; i < src1.num_elements(); ++i) + { + dst[i] = src1[i] ^ src2[i]; + } + + return dst; +} + +template SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/BitwiseXor.h b/tests/validation/reference/BitwiseXor.h new file mode 100644 index 0000000000..3e7721e843 --- /dev/null +++ b/tests/validation/reference/BitwiseXor.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_BITWISE_XOR_H__ +#define __ARM_COMPUTE_TEST_BITWISE_XOR_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor bitwise_xor(const SimpleTensor &src1, const SimpleTensor &src2); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BITWISE_XOR_H__ */ diff --git a/tests/validation/reference/Box3x3.cpp b/tests/validation/reference/Box3x3.cpp new file mode 100644 index 0000000000..8d304a8236 --- /dev/null +++ b/tests/validation/reference/Box3x3.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Box3x3.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + const std::array filter{ { 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; + const float scale = 1.f / static_cast(filter.size()); + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + const Coordinates id = index2coord(src.shape(), element_idx); + apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); + } + return dst; +} + +template SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Box3x3.h b/tests/validation/reference/Box3x3.h new file mode 100644 index 0000000000..80ac451b93 --- /dev/null +++ b/tests/validation/reference/Box3x3.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_BOX3X3_H__ +#define __ARM_COMPUTE_TEST_BOX3X3_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor box3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BOX3X3_H__ */ diff --git a/tests/validation/reference/ConvolutionLayer.cpp b/tests/validation/reference/ConvolutionLayer.cpp new file mode 100644 index 0000000000..10664119fb --- /dev/null +++ b/tests/validation/reference/ConvolutionLayer.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2017 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 "ConvolutionLayer.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/Utils.h" +#include "tests/validation/reference/UtilsQuantizedAsymm.h" + +#include "tests/framework/Asserts.h" + +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +inline bool is_valid_pixel(int i, int min, int max) +{ + return (i >= min && i < max); +} + +// 3D convolution for floating point type +template < typename T, typename TB, typename std::enable_if < is_floating_point::value &&is_floating_point::value, int >::type = 0 > +void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, + int i_offset, int w_offset, int b_offset, int o_offset, + int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) +{ + const T *in_ptr = in.data() + i_offset; + const T *w_ptr = weights.data() + w_offset; + const TB *b_ptr = bias.data() + b_offset; + T *out_ptr = out.data() + o_offset; + + const int half_width_weights = width_weights / 2; + const int half_height_weights = height_weights / 2; + + // Reset accumulator + T acc(0); + + // Compute a 2D convolution for each IFM and accumulate the result + for(int ifm = 0; ifm < depth_in; ++ifm) + { + // Compute the offset for the input slice + const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; + + // Compute 2D convolution + for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) + { + for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) + { + // Check if the pixel is out-of-bound + if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) + { + const int idx = xk + half_width_weights; + const int idy = yk + half_height_weights; + + const T i_value = in_ptr[offset_slice_in + xk + yk * width_in]; + const T w_value = w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights]; + + acc += i_value * w_value; + } + } + } + } + + // Accumulate the bias and store the result + *out_ptr = acc + (*b_ptr); +} + +// 3D convolution for fixed point type +template < typename T, typename TB, typename std::enable_if < std::is_integral::value &&std::is_integral::value, int >::type = 0 > +void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, + int i_offset, int w_offset, int b_offset, int o_offset, + int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) +{ + const T *in_ptr = in.data() + i_offset; + const T *w_ptr = weights.data() + w_offset; + const T *b_ptr = bias.data() + b_offset; + T *out_ptr = out.data() + o_offset; + int fixed_point_position = in.fixed_point_position(); + + const int half_width_weights = width_weights / 2; + const int half_height_weights = height_weights / 2; + + using namespace fixed_point_arithmetic; + using promoted_type = fixed_point_arithmetic::traits::promote_t; + + // Reset accumulator + fixed_point acc(0, fixed_point_position); + + // Compute a 2D convolution for each IFM and accumulate the result + for(int ifm = 0; ifm < depth_in; ++ifm) + { + // Compute the offset for the input slice + const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; + + // Compute 2D convolution + for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) + { + for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) + { + // Check if the pixel is out-of-bound + if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) + { + const int idx = xk + half_width_weights; + const int idy = yk + half_height_weights; + + const fixed_point i_value(in_ptr[offset_slice_in + xk + yk * width_in], fixed_point_position, true); + const fixed_point w_value(w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights], fixed_point_position, true); + const fixed_point iw = i_value * w_value; + acc = iw + acc; + } + } + } + } + + // Get the bias + const fixed_point b(*b_ptr, fixed_point_position, true); + + // Accumulate the bias and covert back + acc = acc + b; + fixed_point res(acc); + *out_ptr = res.raw(); +} + +// 3D convolution for QASYMM8 type +template <> +void convolution3d(const SimpleTensor &in, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &out, + int i_offset, int w_offset, int b_offset, int o_offset, + int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights) +{ + const uint8_t *in_ptr = in.data() + i_offset; + const uint8_t *w_ptr = weights.data() + w_offset; + const int32_t *b_ptr = bias.data() + b_offset; + uint8_t *out_ptr = out.data() + o_offset; + + const int input_offset = -in.quantization_info().offset; + const float input_scale = in.quantization_info().scale; + const int weights_offset = -weights.quantization_info().offset; + const float weights_scale = weights.quantization_info().scale; + const int output_offset = out.quantization_info().offset; + const float output_scale = out.quantization_info().scale; + + int output_multiplier = 0; + int output_shift = 0; + const float multiplier = input_scale * weights_scale / output_scale; + arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + + const int half_width_weights = width_weights / 2; + const int half_height_weights = height_weights / 2; + + // Reset accumulator + int32_t acc(0); + + // Compute a 2D convolution for each IFM and accumulate the result + for(int ifm = 0; ifm < depth_in; ++ifm) + { + // Compute the offset for the input slice + const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in; + + // Compute 2D convolution + for(int yk = -half_height_weights; yk <= half_height_weights; ++yk) + { + for(int xk = -half_width_weights; xk <= half_width_weights; ++xk) + { + // Check if the pixel is out-of-bound + if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in)) + { + const int idx = xk + half_width_weights; + const int idy = yk + half_height_weights; + + const uint8_t i_value = in_ptr[offset_slice_in + xk + yk * width_in]; + const uint8_t w_value = w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights]; + + acc += (i_value + input_offset) * (w_value + weights_offset); + } + } + } + } + + // Accumulate the bias + acc += (*b_ptr); + + acc = asymm_rounding_divide_by_pow2(asymm_int_mult(acc, output_multiplier), output_shift); + acc += output_offset; + acc = clamp(acc, 0, 255); + + // Store the result + *out_ptr = acc; +} +} // namespace + +template +SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info) +{ + // Create reference + SimpleTensor dst{ output_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; + + // Compute reference + const int width_in = src.shape().x(); + const int height_in = src.shape().y(); + const int depth_in = src.shape().z(); + const int width_out = dst.shape().x(); + const int height_out = dst.shape().y(); + const int depth_out = dst.shape().z(); + const int width_weights = weights.shape().x(); + const int height_weights = weights.shape().y(); + const int depth_weights = weights.shape().z(); + const int pad_left = std::min(static_cast(info.pad_left()), width_weights / 2); + const int pad_top = std::min(static_cast(info.pad_top()), height_weights / 2); + const int pad_right = std::min(static_cast(info.pad_right()), width_weights / 2); + const int pad_bottom = std::min(static_cast(info.pad_bottom()), height_weights / 2); + + const int start_xi = width_weights / 2 - pad_left; + const int start_yi = height_weights / 2 - pad_top; + const int end_xi = width_in + pad_left - width_weights / 2 + pad_right - width_weights / 2; + const int end_yi = height_in + pad_top - height_weights / 2 + pad_bottom - height_weights / 2; + const int stride_xi = info.stride().first; + const int stride_yi = info.stride().second; + const int num_batches = src.shape().total_size() / (width_in * height_in * depth_in); + + for(int r = 0; r < num_batches; ++r) + { + for(int yi = start_yi; yi < start_yi + end_yi; yi += stride_yi) + { + for(int xi = start_xi; xi < start_xi + end_xi; xi += stride_xi) + { + for(int ofm = 0; ofm < depth_out; ++ofm) + { + // Compute input and output offsets + const int offset_in = r * width_in * height_in * depth_in; + const int xo = (xi - start_xi) / stride_xi; + const int yo = (yi - start_yi) / stride_yi; + const int offset_out = xo + yo * width_out + ofm * width_out * height_out + r * width_out * height_out * depth_out; + + ARM_COMPUTE_ASSERT(xo < width_out); + ARM_COMPUTE_ASSERT(yo < height_out); + + // Compute 3D convolution + convolution3d(src, weights, bias, dst, + offset_in, ofm * width_weights * height_weights * depth_weights, ofm, offset_out, + xi, yi, + width_in, height_in, depth_in, + width_weights, height_weights); + } + } + } + } + + return dst; +} + +template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info); +template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info); +template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info); +template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info); +template SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ConvolutionLayer.h b/tests/validation/reference/ConvolutionLayer.h new file mode 100644 index 0000000000..57455ba401 --- /dev/null +++ b/tests/validation/reference/ConvolutionLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_CONVOLUTION_LAYER_H__ +#define __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor convolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/reference/DeconvolutionLayer.cpp b/tests/validation/reference/DeconvolutionLayer.cpp new file mode 100644 index 0000000000..82c2188ade --- /dev/null +++ b/tests/validation/reference/DeconvolutionLayer.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017 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 "ConvolutionLayer.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info, const std::pair &a) +{ + // Create reference + TensorShape scaled_shape = src.shape(); + scaled_shape.set(0, output_shape.x()); + scaled_shape.set(1, output_shape.y()); + SimpleTensor scaled{ scaled_shape, src.data_type(), 1, src.fixed_point_position() }; + + const int width_in = src.shape().x(); + const int height_in = src.shape().y(); + const int width_scaled = scaled.shape().x(); + const int height_scaled = scaled.shape().y(); + const int num_2d_slices = src.shape().total_size() / (width_in * height_in); + const float width_ratio = static_cast(width_in) / static_cast(width_scaled); + const float height_ratio = static_cast(height_in) / static_cast(height_scaled); + const int ax = a.first; // The number of zeros added to right edge of the input. + const int ay = a.second; // The number of zeros added to bottom edge of the input. + const unsigned int kernel_size = weights.shape().x(); + ARM_COMPUTE_ERROR_ON(info.pad().first > (kernel_size - 1)); + const int transposed_convolution_padx = kernel_size - info.pad().first - 1; + const int transposed_convolution_pady = kernel_size - info.pad().second - 1; + const int stridex = info.stride().first; + const int stridey = info.stride().second; + for(int j = 0; j < scaled.num_elements(); ++j) + { + scaled[j] = T(0); + } + + for(int slice = 0; slice < num_2d_slices; ++slice) + { + const int offset_slice_in = slice * width_in * height_in; + const int offset_slice_out = slice * width_scaled * height_scaled; + for(int yi = ay; yi < height_scaled; yi += stridey) + { + for(int xi = transposed_convolution_padx; xi < width_scaled; xi += stridex) + { + const float x_src = (xi + 0.5f) * width_ratio - 0.5f; + const float y_src = (yi + 0.5f) * height_ratio - 0.5f; + T *out = scaled.data() + offset_slice_out + xi + yi * width_scaled; + const bool in_bounds = x_src > -1 && y_src > -1 && x_src < width_in && y_src < height_in; + const bool in_axy = xi < transposed_convolution_padx || xi >= (width_scaled - ax) // this is checking if the x coordinate is in the padded left/right area + || yi < ay || yi >= (height_scaled - transposed_convolution_pady); // like above but top and bottom padding in the upscaled XY plane + if(!in_axy) + { + if(in_bounds) + { + const int in_scaled_x = (x_src < 0.f) ? static_cast(x_src - 0.5f) : static_cast(x_src + 0.5f); + const int in_scaled_y = (y_src < 0.f) ? static_cast(y_src - 0.5f) : static_cast(y_src + 0.5f); + const T *in = src.data() + offset_slice_in + in_scaled_x + in_scaled_y * width_in; + *out = *in; + } + else + { + *out = T(0); + } + } + } + } + } + const PadStrideInfo conv_info(1, 1, 1, 1, DimensionRoundingType::CEIL); + return convolution_layer(scaled, weights, bias, output_shape, conv_info); +} + +template SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, + const PadStrideInfo &info, const std::pair &a); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DeconvolutionLayer.h b/tests/validation/reference/DeconvolutionLayer.h new file mode 100644 index 0000000000..8222e32027 --- /dev/null +++ b/tests/validation/reference/DeconvolutionLayer.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 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_DECONVOLUTION_LAYER_H__ +#define __ARM_COMPUTE_TEST_DECONVOLUTION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +/** Deconvolution reference implementation. + * + * src Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F32. + * weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input. + * bias Optional, ignored if NULL. The biases have one dimension. Data type supported: Same as @p input. + * output_shape Output tensor shape. The output has the same number of dimensions as the @p input. + * info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. + * a The number of zeros added to right edge of the input. + * + */ +template +SimpleTensor deconvolution_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &output_shape, const PadStrideInfo &info, + const std::pair &a); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DECONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/reference/DepthConcatenateLayer.cpp b/tests/validation/reference/DepthConcatenateLayer.cpp new file mode 100644 index 0000000000..9a7248493d --- /dev/null +++ b/tests/validation/reference/DepthConcatenateLayer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017 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 "DepthConcatenateLayer.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthconcatenate_layer(const std::vector> &srcs) +{ + // Create reference + std::vector shapes; + + for(const auto &src : srcs) + { + shapes.emplace_back(src.shape()); + } + + DataType dst_type = srcs.empty() ? DataType::UNKNOWN : srcs[0].data_type(); + TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); + SimpleTensor dst(dst_shape, dst_type); + + // Compute reference + int depth_offset = 0; + const int width_out = dst.shape().x(); + const int height_out = dst.shape().y(); + const int depth_out = dst.shape().z(); + const int out_stride_z = width_out * height_out; + const int batches = dst.shape().total_size_upper(3); + + // Set output tensor to 0 + std::fill_n(dst.data(), dst.num_elements(), 0); + + for(const auto &src : srcs) + { + ARM_COMPUTE_ERROR_ON(depth_offset >= depth_out); + ARM_COMPUTE_ERROR_ON(batches != static_cast(src.shape().total_size_upper(3))); + + const int width = src.shape().x(); + const int height = src.shape().y(); + const int depth = src.shape().z(); + const int x_diff = (width_out - width) / 2; + const int y_diff = (height_out - height) / 2; + + const T *src_ptr = src.data(); + + for(int b = 0; b < batches; ++b) + { + const size_t offset_to_first_element = b * out_stride_z * depth_out + depth_offset * out_stride_z + y_diff * width_out + x_diff; + + for(int d = 0; d < depth; ++d) + { + for(int r = 0; r < height; ++r) + { + std::copy(src_ptr, src_ptr + width, dst.data() + offset_to_first_element + d * out_stride_z + r * width_out); + src_ptr += width; + } + } + } + + depth_offset += depth; + } + + return dst; +} + +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DepthConcatenateLayer.h b/tests/validation/reference/DepthConcatenateLayer.h new file mode 100644 index 0000000000..3c486a8015 --- /dev/null +++ b/tests/validation/reference/DepthConcatenateLayer.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 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_DEPTHCONCATENATE_LAYER_H__ +#define __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ + +#include "tests/SimpleTensor.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ */ diff --git a/tests/validation/reference/DepthConvertLayer.cpp b/tests/validation/reference/DepthConvertLayer.cpp new file mode 100644 index 0000000000..dd095b8912 --- /dev/null +++ b/tests/validation/reference/DepthConvertLayer.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2017 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 "DepthConvertLayer.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_floating_point::value, int >::type > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) +{ + ARM_COMPUTE_UNUSED(policy); + ARM_COMPUTE_UNUSED(shift); + + using namespace fixed_point_arithmetic; + SimpleTensor result(src.shape(), dt_out); + + const int fixed_point_position = src.fixed_point_position(); + + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = static_cast(fixed_point(src[i], fixed_point_position, true)); + } + + return result; +} + +template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&std::is_integral::value, int >::type > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) +{ + ARM_COMPUTE_UNUSED(policy); + ARM_COMPUTE_UNUSED(shift); + + using namespace fixed_point_arithmetic; + SimpleTensor result(src.shape(), dt_out, 1, src.fixed_point_position()); + + const int fixed_point_position = result.fixed_point_position(); + + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point(src[i], fixed_point_position).raw(); + } + + return result; +} + +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&!std::is_same::value, int >::type > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) +{ + SimpleTensor result(src.shape(), dt_out); + + // Up-casting + if(src.data_type() <= dt_out) + { + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = src[i] << shift; + } + } + // Down-casting + else + { + for(int i = 0; i < src.num_elements(); ++i) + { + T1 val = src[i] >> shift; + result[i] = (policy == ConvertPolicy::SATURATE) ? saturate_cast(val) : static_cast(val); + } + } + return result; +} + +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&std::is_same::value, int >::type > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) +{ + ARM_COMPUTE_UNUSED(policy); + + using namespace fixed_point_arithmetic; + + SimpleTensor result(src.shape(), dt_out); + + bool is_in_place = (&src == &result); + + const int fixed_point_position_in = src.fixed_point_position(); + const int fixed_point_position_out = (is_in_place) ? static_cast(shift) : result.fixed_point_position(); + + if(!is_in_place || (fixed_point_position_in != fixed_point_position_out)) + { + for(int i = 0; i < src.num_elements(); ++i) + { + auto x = fixed_point(src[i], fixed_point_position_in, true); + x.resacle(fixed_point_position_out); + result[i] = x.raw(); + } + } + + return result; +} + +template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&is_floating_point::value, int >::type > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift) +{ + ARM_COMPUTE_UNUSED(policy); + ARM_COMPUTE_UNUSED(shift); + + SimpleTensor result(src.shape(), dt_out); + + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = static_cast(src[i]); + } +} + +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DepthConvertLayer.h b/tests/validation/reference/DepthConvertLayer.h new file mode 100644 index 0000000000..1446bfda5b --- /dev/null +++ b/tests/validation/reference/DepthConvertLayer.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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_DEPTH_CONVERT_H__ +#define __ARM_COMPUTE_TEST_DEPTH_CONVERT_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_floating_point::value, int >::type = 0 > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); + +template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&std::is_integral::value, int >::type = 0 > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); + +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&!std::is_same::value, int >::type = 0 > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); + +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&std::is_same::value, int >::type = 0 > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); + +template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&is_floating_point::value, int >::type = 0 > +SimpleTensor depth_convert(const SimpleTensor &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEPTH_CONVERT_H__ */ diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp new file mode 100644 index 0000000000..0e88d3dbd3 --- /dev/null +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2017 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 "DepthwiseConvolutionLayer.h" + +#include "ConvolutionLayer.h" +#include "Utils.h" + +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/Utils.h" +#include "tests/validation/reference/UtilsQuantizedAsymm.h" + +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +/** Perform a depthwise convolution + * + * - Three dimensions tensors + * - Third dimention is number of channels + * - Depths of input tensor and filter are equals + * - Padding, stride and output shape "match" + * + */ +template +SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info) +{ + // Create reference + SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const int filter_width = weights.shape().x(); + const int filter_height = weights.shape().y(); + const int filter_plane = filter_width * filter_height; + const int input_width = src.shape().x(); + const int input_height = src.shape().y(); + const int input_depth = src.shape().z(); + const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); + + const int filter_half_width = filter_width / 2; + const int filter_half_height = filter_height / 2; + + const int pad_left = std::min(static_cast(conv_info.pad_left()), filter_half_width); + const int pad_top = std::min(static_cast(conv_info.pad_top()), filter_half_height); + const int pad_right = std::min(static_cast(conv_info.pad_right()), filter_half_width); + const int pad_bottom = std::min(static_cast(conv_info.pad_bottom()), filter_half_height); + + const int minimum_x = -pad_left + filter_half_width; + const int minimum_y = -pad_top + filter_half_height; + const int maximum_x = input_width + pad_left - filter_half_width + pad_right - filter_half_width; + const int maximum_y = input_height + pad_top - filter_half_height + pad_bottom - filter_half_height; + + int out_pos = 0; + for(int r = 0; r < num_batches; ++r) + { + for(int z = 0; z < input_depth; ++z) + { + for(int y = minimum_y; y < minimum_y + maximum_y; y += conv_info.stride().second) + { + for(int x = minimum_x; x < minimum_x + maximum_x; x += conv_info.stride().first) + { + Coordinates coords(static_cast(x), static_cast(y), static_cast(z), static_cast(r)); + size_t filter_offset = filter_plane * z; + + T val = 0; + for(int j = y - filter_half_height; j <= static_cast(y + filter_half_height); ++j) + { + for(int i = x - filter_half_width; i <= static_cast(x + filter_half_width); ++i) + { + coords.set(0, i); + coords.set(1, j); + val += *(weights.data() + filter_offset) * tensor_elem_at(src, coords, BorderMode::CONSTANT, 0.f); + ++filter_offset; + } + } + coords.set(0, x); + coords.set(1, y); + dst[out_pos++] = saturate_cast(val + *static_cast(biases(Coordinates(z)))); + } + } + } + } + + return dst; +} + +template <> +SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, + const PadStrideInfo &conv_info) +{ + // Create reference + SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; + + const int input_offset = -src.quantization_info().offset; + const float input_scale = src.quantization_info().scale; + const int weights_offset = -weights.quantization_info().offset; + const float weights_scale = weights.quantization_info().scale; + const int output_offset = dst.quantization_info().offset; + const float output_scale = dst.quantization_info().scale; + + int output_multiplier; + int output_shift; + const float multiplier = input_scale * weights_scale / output_scale; + arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + + // Compute reference + const int filter_width = weights.shape().x(); + const int filter_height = weights.shape().y(); + const int filter_plane = filter_width * filter_height; + const int input_width = src.shape().x(); + const int input_height = src.shape().y(); + const int input_depth = src.shape().z(); + const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); + + const int filter_half_size = filter_width / 2; + const int pad_x = std::min(filter_half_size, static_cast(conv_info.pad().first)); + const int pad_y = std::min(filter_half_size, static_cast(conv_info.pad().second)); + const int minimum_x = -pad_x + filter_half_size; + const int minimum_y = -pad_y + filter_half_size; + + int out_pos = 0; + for(int r = 0; r < num_batches; ++r) + { + for(int z = 0; z < input_depth; ++z) + { + int32_t bias_val = *static_cast(biases(Coordinates(z))); + for(int y = minimum_y; y < input_height + pad_y - filter_half_size; y += conv_info.stride().second) + { + for(int x = minimum_x; x < input_width + pad_x - filter_half_size; x += conv_info.stride().first) + { + Coordinates coords(x, y, z); + int filter_offset = filter_plane * z; + + uint32_t val = 0; + for(int j = y - filter_half_size; j <= (y + filter_half_size); ++j) + { + for(int i = x - filter_half_size; i <= (x + filter_half_size); ++i) + { + coords.set(0, i); + coords.set(1, j); + auto in_val = tensor_elem_at(src, coords, BorderMode::CONSTANT, 0); + uint8_t w_val = *(weights.data() + filter_offset); + val += (in_val + input_offset) * (w_val + weights_offset); + ++filter_offset; + } + } + val += bias_val; + val = asymm_rounding_divide_by_pow2(asymm_int_mult(val, output_multiplier), output_shift); + val += output_offset; + val = std::max(val, 0); + val = std::min(val, 255); + + // Store the result + dst[out_pos++] = val; + } + } + } + } + + return dst; +} + +template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, + const PadStrideInfo &conv_info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.h b/tests/validation/reference/DepthwiseConvolutionLayer.h new file mode 100644 index 0000000000..df743a5b8e --- /dev/null +++ b/tests/validation/reference/DepthwiseConvolutionLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_DEPTHWISE_CONVOLUTION_H__ +#define __ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/reference/DepthwiseSeparableConvolutionLayer.cpp b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.cpp new file mode 100644 index 0000000000..ca6c168114 --- /dev/null +++ b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017 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 "DepthwiseConvolutionLayer.h" + +#include "DepthwiseSeparableConvolutionLayer.h" + +#include "ConvolutionLayer.h" +#include "Utils.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +// Depthwise separable convolution layer +template +SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &src, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, + const TensorShape &depthwise_out_shape, + const SimpleTensor &pointwise_weights, + const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, const PadStrideInfo &depthwise_conv_info, const PadStrideInfo &pointwise_conv_info) +{ + // Compute reference + SimpleTensor depthwise_out = depthwise_convolution(src, depthwise_weights, depthwise_biases, depthwise_out_shape, depthwise_conv_info); + SimpleTensor dst = convolution_layer(depthwise_out, pointwise_weights, pointwise_biases, dst_shape, pointwise_conv_info); + + return dst; +} + +template SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &in, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, + const TensorShape &depthwise_out_shape, + const SimpleTensor &pointwise_weights, const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, const PadStrideInfo &depthwise_conv_info, + const PadStrideInfo &pointwise_conv_info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h new file mode 100644 index 0000000000..0fcce2c964 --- /dev/null +++ b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ +#define __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthwise_separable_convolution_layer(const SimpleTensor &src, const SimpleTensor &depthwise_weights, const SimpleTensor &depthwise_biases, + const TensorShape &depthwise_out_shape, + const SimpleTensor &pointwise_weights, const SimpleTensor &pointwise_biases, const TensorShape &dst_shape, + const PadStrideInfo &depthwise_conv_info, const PadStrideInfo &pointwise_conv_info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEPTHWISE_SEPARABLE_CONVOLUTION_LAYER_H__ */ diff --git a/tests/validation/reference/DequantizationLayer.cpp b/tests/validation/reference/DequantizationLayer.cpp new file mode 100644 index 0000000000..33096a1d81 --- /dev/null +++ b/tests/validation/reference/DequantizationLayer.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 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 "DequantizationLayer.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max) +{ + // Create reference + SimpleTensor dst{ src.shape(), DataType::F32 }; + + // Compute reference + const int width = src.shape().x(); + const int height = src.shape().y(); + const int depth = src.shape().z(); + const int stride_w = width * height * depth; + const int num_batches = min_max.shape().total_size_upper(1); + + for(int k = 0; k < num_batches; ++k) + { + const float min = min_max[k * 2 + 0]; + const float max = min_max[k * 2 + 1]; + const float range = max - min; + const float scaling = range / 255.0f; + + for(int i = 0; i < stride_w; ++i) + { + dst[i + k * stride_w] = (static_cast(src[i + k * stride_w]) * scaling) + min; + } + } + + return dst; +} + +template SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/DequantizationLayer.h b/tests/validation/reference/DequantizationLayer.h new file mode 100644 index 0000000000..1a8adcf9d8 --- /dev/null +++ b/tests/validation/reference/DequantizationLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_DEQUANTIZATION_LAYER_H__ +#define __ARM_COMPUTE_TEST_DEQUANTIZATION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor dequantization_layer(const SimpleTensor &src, const SimpleTensor &min_max); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEQUANTIZATION_LAYER_H__ */ diff --git a/tests/validation/reference/Dilate.cpp b/tests/validation/reference/Dilate.cpp new file mode 100644 index 0000000000..0683a0a9a1 --- /dev/null +++ b/tests/validation/reference/Dilate.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017 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 "Dilate.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + /* + -1 x +1 + -1 [tl][tc][tr] -1 + y [ml][xy][mr] y + +1 [bl][bc][br] +1 + -1 x +1 + dilate: + dst(x, y) = max[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = max({tl, tc, tr, ml, xy, mr, bl, bc, br}) + */ + SimpleTensor dst(src.shape(), src.data_type()); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + const int x = coord.x(); + const int y = coord.y(); + + std::array neighbours = { { 0 } }; + for(int row = y - 1, j = 0; row <= y + 1; ++row) + { + for(int col = x - 1; col <= x + 1; ++col, ++j) + { + coord.set(0, col); + coord.set(1, row); + neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); + } + } + + dst[i] = *std::max_element(neighbours.cbegin(), neighbours.cend()); + } + + return dst; +} + +template SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Dilate.h b/tests/validation/reference/Dilate.h new file mode 100644 index 0000000000..6586cbf841 --- /dev/null +++ b/tests/validation/reference/Dilate.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_DILATE_H__ +#define __ARM_COMPUTE_TEST_DILATE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor dilate(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DILATE_H__ */ diff --git a/tests/validation/reference/Erode.cpp b/tests/validation/reference/Erode.cpp new file mode 100644 index 0000000000..5e8b36f47b --- /dev/null +++ b/tests/validation/reference/Erode.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017 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 "Erode.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + /* + -1 x +1 + -1 [tl][tc][tr] -1 + y [ml][xy][mr] y + +1 [bl][bc][br] +1 + -1 x +1 + erode: + dst(x, y) = min[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = min({tl, tc, tr, ml, xy, mr, bl, bc, br}) + */ + SimpleTensor dst(src.shape(), src.data_type()); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + const int x = coord.x(); + const int y = coord.y(); + + std::array neighbours = { { 0 } }; + for(int row = y - 1, j = 0; row <= y + 1; ++row) + { + for(int col = x - 1; col <= x + 1; ++col, ++j) + { + coord.set(0, col); + coord.set(1, row); + neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); + } + } + + dst[i] = *std::min_element(neighbours.cbegin(), neighbours.cend()); + } + + return dst; +} + +template SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Erode.h b/tests/validation/reference/Erode.h new file mode 100644 index 0000000000..5e27513471 --- /dev/null +++ b/tests/validation/reference/Erode.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_ERODE_H__ +#define __ARM_COMPUTE_TEST_ERODE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor erode(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ERODE_H__ */ diff --git a/tests/validation/reference/FixedPoint.cpp b/tests/validation/reference/FixedPoint.cpp new file mode 100644 index 0000000000..a016093ed6 --- /dev/null +++ b/tests/validation/reference/FixedPoint.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 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 "FixedPoint.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op) +{ + SimpleTensor result(src.shape(), src.data_type()); + + const int p = src.fixed_point_position(); + switch(op) + { + case FixedPointOp::EXP: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::exp(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); + } + break; + case FixedPointOp::LOG: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::log(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); + } + break; + case FixedPointOp::INV_SQRT: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::inv_sqrt(fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); + } + break; + case FixedPointOp::RECIPROCAL: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::div(fixed_point_arithmetic::fixed_point(1, p), fixed_point_arithmetic::fixed_point(src[i], p, true)).raw(); + } + break; + default: + ARM_COMPUTE_ERROR("Fixed point operation not supported"); + break; + } + + return result; +} + +template SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); +template SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/FixedPoint.h b/tests/validation/reference/FixedPoint.h new file mode 100644 index 0000000000..f0117f9dd0 --- /dev/null +++ b/tests/validation/reference/FixedPoint.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_FIXED_POINT_OPERATION_H__ +#define __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_operation(const SimpleTensor &src, FixedPointOp op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ */ diff --git a/tests/validation/reference/FixedPointPixelWiseMultiplication.cpp b/tests/validation/reference/FixedPointPixelWiseMultiplication.cpp new file mode 100644 index 0000000000..636919b1ff --- /dev/null +++ b/tests/validation/reference/FixedPointPixelWiseMultiplication.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017 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, + * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "FixedPointPixelWiseMultiplication.h" + +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy) +{ + using namespace fixed_point_arithmetic; + + SimpleTensor dst(src2.shape(), src2.data_type(), 1, src2.fixed_point_position()); + + const int fixed_point_position = src1.fixed_point_position(); + + ARM_COMPUTE_ERROR_ON_MSG(src1.data_type() != src2.data_type() || src1.data_type() != dst.data_type(), + "Tensors must all have the same DataType"); + ARM_COMPUTE_ERROR_ON_MSG(fixed_point_position != src2.fixed_point_position() || fixed_point_position != dst.fixed_point_position(), + "Fixed-point position must be the same for both inputs and outputs"); + + // Validate fixed_point_position + ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS8) && (fixed_point_position == 0 || fixed_point_position > 7)); + ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS16) && (fixed_point_position == 0 || fixed_point_position > 15)); + + const fixed_point fp_scale(scale, fixed_point_position); + const bool is_sat = convert_policy == ConvertPolicy::SATURATE; + + for(int i = 0; i < src1.num_elements(); ++i) + { + const fixed_point val1(src1[i], fixed_point_position, true); + fixed_point res(src2[i], fixed_point_position, true); + if(is_sat) + { + res = mul(mul(res, val1), fp_scale); + } + else + { + res = mul(mul(res, val1), fp_scale); + } + dst[i] = res.raw(); + } + + return dst; +} + +// *INDENT-OFF* +// clang-format off +template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +// *INDENT-ON* +// clang-format on + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/FixedPointPixelWiseMultiplication.h b/tests/validation/reference/FixedPointPixelWiseMultiplication.h new file mode 100644 index 0000000000..124a33c9da --- /dev/null +++ b/tests/validation/reference/FixedPointPixelWiseMultiplication.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ +#define __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/reference/FlattenLayer.cpp b/tests/validation/reference/FlattenLayer.cpp new file mode 100644 index 0000000000..611701d8cf --- /dev/null +++ b/tests/validation/reference/FlattenLayer.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 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 "FlattenLayer.h" + +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor flatten_layer(const SimpleTensor &src) +{ + TensorShape shape_flatten(src.shape()); + shape_flatten.set(0, src.shape()[0] * src.shape()[1] * src.shape()[2]); + shape_flatten.remove_dimension(1); + shape_flatten.remove_dimension(1); + SimpleTensor dst(shape_flatten, src.data_type(), 1, src.fixed_point_position()); + + // Note: Since the reference implementation does not use padding bytes, we can copy directly the content of the source tensor + std::copy(src.data(), src.data() + src.num_elements(), dst.data()); + + return dst; +} + +template SimpleTensor flatten_layer(const SimpleTensor &src); +template SimpleTensor flatten_layer(const SimpleTensor &src); +template SimpleTensor flatten_layer(const SimpleTensor &src); +template SimpleTensor flatten_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/FlattenLayer.h b/tests/validation/reference/FlattenLayer.h new file mode 100644 index 0000000000..b1286fe2bd --- /dev/null +++ b/tests/validation/reference/FlattenLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_FLATTEN_LAYER_H__ +#define __ARM_COMPUTE_TEST_FLATTEN_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor flatten_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FLATTEN_LAYER_H__ */ diff --git a/tests/validation/reference/Floor.cpp b/tests/validation/reference/Floor.cpp new file mode 100644 index 0000000000..1c739448b7 --- /dev/null +++ b/tests/validation/reference/Floor.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 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 "Floor.h" + +#include "tests/validation/Helpers.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor floor_layer(const SimpleTensor &src) +{ + // Create reference + SimpleTensor dst{ src.shape(), src.data_type() }; + + // Compute reference + for(int i = 0; i < src.num_elements(); ++i) + { + dst[i] = std::floor(src[i]); + } + + return dst; +} + +template SimpleTensor floor_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Floor.h b/tests/validation/reference/Floor.h new file mode 100644 index 0000000000..d95ee303fc --- /dev/null +++ b/tests/validation/reference/Floor.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_FLOOR_H__ +#define __ARM_COMPUTE_TEST_FLOOR_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor floor_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FLOOR_H__ */ diff --git a/tests/validation/reference/FullyConnectedLayer.cpp b/tests/validation/reference/FullyConnectedLayer.cpp new file mode 100644 index 0000000000..c24881e2b4 --- /dev/null +++ b/tests/validation/reference/FullyConnectedLayer.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2017 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 "FullyConnectedLayer.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/reference/UtilsQuantizedAsymm.h" + +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +// Vector matrix multiply for floating point +template < typename T, typename TB, typename std::enable_if < is_floating_point::value &&is_floating_point::value, int >::type = 0 > +void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, int cols_weights, + int rows_weights, uint8_t fixed_point_position) +{ + ARM_COMPUTE_UNUSED(fixed_point_position); + + const T *src_ptr = src.data() + offset_src; + const T *weights_ptr = weights.data(); + const TB *bias_ptr = bias.data(); + T *dst_ptr = dst.data() + offset_dst; + + for(int y = 0; y < rows_weights; ++y) + { + dst_ptr[y] = std::inner_product(src_ptr, src_ptr + cols_weights, weights_ptr, static_cast(0)) + bias_ptr[y]; + weights_ptr += cols_weights; + } +} + +// Vector matrix multiply for fixed point type +template < typename T, typename TB, typename std::enable_if < std::is_integral::value &&std::is_integral::value, int >::type = 0 > +void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, int cols_weights, + int rows_weights, uint8_t fixed_point_position) +{ + const T *src_ptr = src.data() + offset_src; + const T *weights_ptr = weights.data(); + const TB *bias_ptr = bias.data(); + T *dst_ptr = dst.data() + offset_dst; + + using namespace fixed_point_arithmetic; + using promoted_type = fixed_point_arithmetic::traits::promote_t; + + for(int y = 0; y < rows_weights; ++y) + { + // Reset accumulator + fixed_point acc(0, fixed_point_position); + + for(int x = 0; x < cols_weights; ++x) + { + const fixed_point i_value(src_ptr[x], fixed_point_position, true); + const fixed_point w_value(weights_ptr[x], fixed_point_position, true); + acc = acc + i_value * w_value; + } + + // Get the bias + const fixed_point b(bias_ptr[y], fixed_point_position, true); + + // Convert back and accumulate the bias + fixed_point res(acc); + res = res + b; + + // Store the result + dst_ptr[y] = res.raw(); + + weights_ptr += cols_weights; + } +} + +// Vector matrix multiply for quantized type +template <> +void vector_matrix_multiply(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, SimpleTensor &dst, int offset_src, int offset_dst, + int cols_weights, int rows_weights, uint8_t fixed_point_position) +{ + ARM_COMPUTE_UNUSED(fixed_point_position); + + const uint8_t *src_ptr = src.data() + offset_src; + const uint8_t *weights_ptr = weights.data(); + const int32_t *bias_ptr = bias.data(); + uint8_t *dst_ptr = dst.data() + offset_dst; + + const int input_offset = -src.quantization_info().offset; + const float input_scale = src.quantization_info().scale; + const int weights_offset = -weights.quantization_info().offset; + const float weights_scale = weights.quantization_info().scale; + const int output_offset = dst.quantization_info().offset; + const float output_scale = dst.quantization_info().scale; + + int output_multiplier = 0; + int output_shift = 0; + const float multiplier = input_scale * weights_scale / output_scale; + arm_compute::quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); + + for(int y = 0; y < rows_weights; ++y) + { + // Reset accumulator + int32_t acc = 0; + + for(int x = 0; x < cols_weights; ++x) + { + acc += (src_ptr[x] + input_offset) * (weights_ptr[x] + weights_offset); + } + + // Accumulate the bias + acc += bias_ptr[y]; + + acc = asymm_rounding_divide_by_pow2(asymm_int_mult(acc, output_multiplier), output_shift); + acc += output_offset; + acc = clamp(acc, 0, 255); + + // Store the result + dst_ptr[y] = static_cast(acc); + + weights_ptr += cols_weights; + } +} +} // namespace + +template +SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape) +{ + // Create reference + SimpleTensor dst{ TensorShape{ dst_shape }, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; + + // Sanity checks + const int num_batch_dimensions = std::max(0, static_cast(dst_shape.num_dimensions()) - 1); + const int num_input_dimensions = src.shape().num_dimensions() - num_batch_dimensions; + const unsigned int linear_input_size = src.shape().total_size_lower(num_input_dimensions); + + ARM_COMPUTE_UNUSED(num_batch_dimensions); + ARM_COMPUTE_UNUSED(num_input_dimensions); + ARM_COMPUTE_UNUSED(linear_input_size); + ARM_COMPUTE_ERROR_ON(weights.shape().x() != linear_input_size); + ARM_COMPUTE_ERROR_ON(weights.shape().y() != bias.shape().x()); + ARM_COMPUTE_ERROR_ON(weights.shape().y() != dst.shape().x()); + + // Compute reference + const int cols_weights = weights.shape().x(); + const int rows_weights = weights.shape().y(); + const int num_batches = dst_shape.total_size_upper(1); + + for(int k = 0; k < num_batches; ++k) + { + const int offset_in = k * cols_weights; + const int offset_out = k * rows_weights; + + vector_matrix_multiply(src, + weights, + bias, + dst, + offset_in, + offset_out, + cols_weights, + rows_weights, + src.fixed_point_position()); + } + + return dst; +} + +template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +template SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/FullyConnectedLayer.h b/tests/validation/reference/FullyConnectedLayer.h new file mode 100644 index 0000000000..1dfb496924 --- /dev/null +++ b/tests/validation/reference/FullyConnectedLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_FULLY_CONNECTED_LAYER_H__ +#define __ARM_COMPUTE_TEST_FULLY_CONNECTED_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fully_connected_layer(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &bias, const TensorShape &dst_shape); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FULLY_CONNECTED_LAYER_H__ */ diff --git a/tests/validation/reference/GEMM.cpp b/tests/validation/reference/GEMM.cpp new file mode 100644 index 0000000000..77d025ec8e --- /dev/null +++ b/tests/validation/reference/GEMM.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017 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 "GEMM.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta) +{ + // Create reference + SimpleTensor dst{ c.shape(), c.data_type(), 1, c.fixed_point_position() }; + + // Compute reference + const int M = dst.shape().y(); + const int N = dst.shape().x(); + const int K = a.shape().x(); + + for(int row = 0; row < M; ++row) + { + for(int col = 0; col < N; ++col) + { + T acc(0); + + for(int k = 0; k < K; ++k) + { + acc += a[row * K + k] * b[k * N + col]; + } + + // Finalize the result: alpha * A * B + beta * C + dst[col + row * N] = alpha * acc + beta * c[col + row * N]; + } + } + + return dst; +} + +template ::value, int>::type> +SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta) +{ + using namespace fixed_point_arithmetic; + + // Create reference + SimpleTensor dst{ c.shape(), c.data_type(), 1, c.fixed_point_position() }; + + // Compute reference + using promoted_type = fixed_point_arithmetic::traits::promote_t; + + const int M = dst.shape().y(); + const int N = dst.shape().x(); + const int K = a.shape().x(); + const int fixed_point_position = a.fixed_point_position(); + + const fixed_point alpha_q(alpha, fixed_point_position); + const fixed_point beta_q(beta, fixed_point_position); + + for(int row = 0; row < M; ++row) + { + for(int col = 0; col < N; ++col) + { + fixed_point acc_q(0, fixed_point_position); + + for(int k = 0; k < K; ++k) + { + const fixed_point a0_q(a[row * K + k], fixed_point_position, true); + const fixed_point b0_q(b[k * N + col], fixed_point_position, true); + + acc_q = acc_q + (a0_q * b0_q); + } + + // Finalize the result: alpha * A * B + beta * C + const fixed_point c0_q(c[col + row * N], fixed_point_position, true); + + fixed_point res_q(acc_q); + res_q = alpha_q * res_q; + res_q = res_q + (beta_q * c0_q); + + // Store the result + dst[col + row * N] = res_q.raw(); + } + } + + return dst; +} + +template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); +template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); +template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); +template SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/GEMM.h b/tests/validation/reference/GEMM.h new file mode 100644 index 0000000000..cda792bf8b --- /dev/null +++ b/tests/validation/reference/GEMM.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_GEMM_H__ +#define __ARM_COMPUTE_TEST_GEMM_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); + +template ::value, int>::type = 0> +SimpleTensor gemm(const SimpleTensor &a, const SimpleTensor &b, const SimpleTensor &c, float alpha, float beta); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GEMM_H__ */ diff --git a/tests/validation/reference/GEMMInterleave4x4.h b/tests/validation/reference/GEMMInterleave4x4.h new file mode 100644 index 0000000000..e6b09afb9a --- /dev/null +++ b/tests/validation/reference/GEMMInterleave4x4.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 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 "GEMM.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gemm_interleave_4x4(const SimpleTensor &in, SimpleTensor &out) +{ + const T *mtx_in = reinterpret_cast(in.data()); + T *mtx_ref = reinterpret_cast(out.data()); + const int32_t in_rows = in.shape().y(); + const int32_t in_cols = in.shape().x(); + const int32_t out_stride = out.shape().x(); + int32_t y = 0; + for(; y <= (in_rows - 4); y += 4) + { + const T *in_ptr = &mtx_in[y * in_cols]; + + for(int32_t x = 0; x < in_cols; x++) + { + const T tmp[4] = { in_ptr[x + 0 * in_cols], + in_ptr[x + 1 * in_cols], + in_ptr[x + 2 * in_cols], + in_ptr[x + 3 * in_cols] + }; + + T *dst = &mtx_ref[static_cast(x * 4.f) + static_cast(std::ceil(y / 4.f)) * out_stride]; + memcpy(dst, tmp, sizeof(T) * 4); + } + } + + // Leftover along the Y direction + const int32_t leftover_y = in_rows - y; + + if(leftover_y != 0) + { + const T *in_ptr = &mtx_in[y * in_cols]; + + for(int32_t x = 0; x < in_cols; x++) + { + T tmp[4] = { 0, 0, 0, 0 }; + + for(int32_t k = 0; k < leftover_y; k++) + { + tmp[k] = in_ptr[k * in_cols + x]; + } + T *dst = &mtx_ref[static_cast(x * 4.f) + static_cast(std::ceil(y / 4.f)) * out_stride]; + memcpy(dst, tmp, sizeof(T) * 4); + } + } + + return out; +} + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/GEMMInterleaveBlocked.h b/tests/validation/reference/GEMMInterleaveBlocked.h new file mode 100644 index 0000000000..ff5a0d647c --- /dev/null +++ b/tests/validation/reference/GEMMInterleaveBlocked.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017 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 "GEMM.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +T safe_read(const SimpleTensor &t, int y, int x) +{ + const int stride = t.shape().x(); + const int M = t.shape().y(); + const int N = t.shape().x(); + if((y < M) && (x < N)) + { + return t[y * stride + x]; + } + return 0; +} + +template +SimpleTensor gemm_interleave_blocked(const SimpleTensor &in, SimpleTensor &out, int int_by, int block, bool transposed) +{ + const int M = out.shape().y(); + const int N = out.shape().x(); + for(int y = 0; y < M; y++) + { + T *out_ptr = &out[y * N]; + for(int x = 0; x < (N / int_by); x += block) + { + for(int z = 0; z < int_by; z++) + { + for(int a = 0; (out_ptr <= &out[y * N + (N - 1)]) && a < block; a++) + { + if(!transposed) + *out_ptr++ = safe_read(in, (y * int_by) + z, x + a); + else + { + const T value = safe_read(in, x + a, (y * int_by) + z); + *out_ptr++ = value; + } + } + } + } + } + return out; +} + +template SimpleTensor gemm_interleave_blocked(const SimpleTensor &in, SimpleTensor &out, int int_by, int block, bool transposed); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/GEMMLowp.cpp b/tests/validation/reference/GEMMLowp.cpp new file mode 100644 index 0000000000..8e41aef46a --- /dev/null +++ b/tests/validation/reference/GEMMLowp.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2017 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 "GEMMLowp.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/reference/UtilsQuantizedAsymm.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +template +void quantize_down_int32_to_uint8_scale(const SimpleTensor *in, const SimpleTensor *bias, SimpleTensor *dst, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, + int32_t min, int32_t max) +{ + const int cols_in = in->shape().x(); + + for(int i = 0; i < in->num_elements(); ++i) + { + int32_t result = ((*in)[i] + result_offset); + + if(bias != nullptr) + { + result += (*bias)[i % cols_in]; + } + + result *= result_mult_int; + + result >>= result_shift; + + // Bounded ReLu + if(min != max) + { + result = std::max(min, std::min(max, result)); + } + + (*dst)[i] = static_cast(std::max(0, std::min(255, result))); + } +} + +template +void quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor *in, const SimpleTensor *bias, SimpleTensor *dst, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min, int32_t max) +{ + const int cols_in = in->shape().x(); + + for(int i = 0; i < in->num_elements(); ++i) + { + int32_t result = (*in)[i]; + + if(bias != nullptr) + { + result += (*bias)[i % cols_in]; + } + + // Fixed point multiplication + result = asymm_rounding_divide_by_pow2(asymm_int_mult(result, result_fixedpoint_multiplier), result_shift); + result += result_offset_after_shift; + + // Bounded ReLu + if(min != max) + { + result = std::max(min, std::min(max, result)); + } + + (*dst)[i] = static_cast(std::max(0, std::min(255, result))); + } +} +} // namespace + +template +SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset) +{ + static_assert(std::is_same::type, int32_t>::value, "Only int32_t is allowed for the output"); + + TensorShape shape(b.shape()[0], a.shape()[1]); + DataType dt = std::is_same::value ? DataType::S32 : DataType::U32; + SimpleTensor c(shape, dt); + + const int K = a.shape().x(); + const int b_width = b.shape().x(); + const int rows = c.shape().y(); //M + const int cols = c.shape().x(); //N + + std::vector acc; + acc.resize(cols); + + for(int i = 0; i < rows; ++i) + { + for(int j = 0; j < cols; ++j) + { + acc[j] = 0; + } + for(int k = 0; k < K; ++k) + { + const T_out tmp_a = a_offset + static_cast(a[k + i * K]); + for(int j = 0; j < b_width; ++j) + { + const T_out tmp_b = b_offset + static_cast(b[j + k * b_width]); + const T_out mult_as_int = tmp_a * tmp_b; + acc[j] += mult_as_int; + } + } + for(int j = 0; j < cols; ++j) + { + c[j + i * cols] = acc[j]; + } + } + + return c; +} + +// used to validate assembly kernels which don't know anything about offsets +template +SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b) +{ + return gemmlowp_matrix_multiply_core(a, b, 0, 0); +} + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min, int32_t max) +{ + SimpleTensor dst(in.shape(), DataType::QASYMM8); + + quantize_down_int32_to_uint8_scale(&in, nullptr, &dst, result_offset, result_mult_int, result_shift, min, max); + + return dst; +} + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, + int32_t min, int32_t max) +{ + SimpleTensor dst(in.shape(), DataType::QASYMM8); + + quantize_down_int32_to_uint8_scale(&in, &bias, &dst, result_offset, result_mult_int, result_shift, min, max); + + return dst; +} + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min, + int32_t max) +{ + SimpleTensor dst(in.shape(), DataType::QASYMM8); + + quantize_down_int32_to_uint8_scale_by_fixedpoint(&in, nullptr, &dst, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); + + return dst; +} + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min, int32_t max) +{ + SimpleTensor dst(in.shape(), DataType::QASYMM8); + + quantize_down_int32_to_uint8_scale_by_fixedpoint(&in, &bias, &dst, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); + + return dst; +} + +template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &a, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min, int32_t max); +template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &a, const SimpleTensor &b, int32_t result_fixedpoint_multiplier, + int32_t result_shift, int32_t result_offset_after_shift, int32_t min, int32_t max); +template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &a, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min, + int32_t max); +template SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &a, const SimpleTensor &b, int32_t result_offset, int32_t result_mult_int, + int32_t result_shift, int32_t min, int32_t max); +template SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); +template SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); +template SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); +template SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/GEMMLowp.h b/tests/validation/reference/GEMMLowp.h new file mode 100644 index 0000000000..a3d0bebe3f --- /dev/null +++ b/tests/validation/reference/GEMMLowp.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017 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_GEMMLOWP_H__ +#define __ARM_COMPUTE_TEST_GEMMLOWP_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, int32_t min = 0, int32_t max = 0); +template +SimpleTensor gemmlowp_matrix_multiply_core(const SimpleTensor &a, const SimpleTensor &b, int32_t a_offset, int32_t b_offset); + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, int32_t result_offset, int32_t result_mult_int, int32_t result_shift); + +template +SimpleTensor gemmlowp(const SimpleTensor &a, const SimpleTensor &b); + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_offset, int32_t result_mult_int, int32_t result_shift, + int32_t min = 0, int32_t max = 0); + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, + int32_t min = 0, int32_t max = 0); + +template +SimpleTensor gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(const SimpleTensor &in, const SimpleTensor &bias, int32_t result_fixedpoint_multiplier, int32_t result_shift, + int32_t result_offset_after_shift, int32_t min = 0, int32_t max = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GEMMLOWP_H__ */ diff --git a/tests/validation/reference/Gaussian3x3.cpp b/tests/validation/reference/Gaussian3x3.cpp new file mode 100644 index 0000000000..c71eade5c1 --- /dev/null +++ b/tests/validation/reference/Gaussian3x3.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Gaussian3x3.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + const std::array filter{ { 1, 2, 1, 2, 4, 2, 1, 2, 1 } }; + const float scale = 1.f / 16.f; + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + const Coordinates id = index2coord(src.shape(), element_idx); + apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); + } + return dst; +} + +template SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian3x3.h b/tests/validation/reference/Gaussian3x3.h new file mode 100644 index 0000000000..85a7acdbfc --- /dev/null +++ b/tests/validation/reference/Gaussian3x3.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_GAUSSIAN3X3_H__ +#define __ARM_COMPUTE_TEST_GAUSSIAN3X3_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gaussian3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GAUSSIAN3X3_H__ */ diff --git a/tests/validation/reference/Gaussian5x5.cpp b/tests/validation/reference/Gaussian5x5.cpp new file mode 100644 index 0000000000..55bb287fbe --- /dev/null +++ b/tests/validation/reference/Gaussian5x5.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Gaussian5x5.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + const std::array filter{ { + 1, 4, 6, 4, 1, + 4, 16, 24, 16, 4, + 6, 24, 36, 24, 6, + 4, 16, 24, 16, 4, + 1, 4, 6, 4, 1 + } }; + const float scale = 1.f / 256.f; + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + const Coordinates id = index2coord(src.shape(), element_idx); + apply_2d_spatial_filter(id, src, dst, TensorShape(5U, 5U), filter.data(), scale, border_mode, constant_border_value); + } + return dst; +} + +template SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian5x5.h b/tests/validation/reference/Gaussian5x5.h new file mode 100644 index 0000000000..df981c70b0 --- /dev/null +++ b/tests/validation/reference/Gaussian5x5.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_GAUSSIAN5X5_H__ +#define __ARM_COMPUTE_TEST_GAUSSIAN5X5_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor gaussian5x5(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GAUSSIAN5X5_H__ */ diff --git a/tests/validation/reference/GaussianPyramidHalf.cpp b/tests/validation/reference/GaussianPyramidHalf.cpp new file mode 100644 index 0000000000..0a68dedaee --- /dev/null +++ b/tests/validation/reference/GaussianPyramidHalf.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 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 "GaussianPyramidHalf.h" + +#include "arm_compute/core/Helpers.h" + +#include "Gaussian5x5.h" +#include "Scale.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels) +{ + std::vector> dst; + + // Level0 is equal to src + dst.push_back(src); + + for(size_t i = 1; i < num_levels; ++i) + { + // Gaussian Filter + const SimpleTensor out_gaus5x5 = reference::gaussian5x5(dst[i - 1], border_mode, constant_border_value); + + // Scale down by 2 with nearest interpolation + const SimpleTensor out = reference::scale(out_gaus5x5, SCALE_PYRAMID_HALF, SCALE_PYRAMID_HALF, InterpolationPolicy::NEAREST_NEIGHBOR, border_mode, constant_border_value, SamplingPolicy::CENTER, + true); + + dst.push_back(out); + } + + return dst; +} + +template std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/GaussianPyramidHalf.h b/tests/validation/reference/GaussianPyramidHalf.h new file mode 100644 index 0000000000..abd29e1700 --- /dev/null +++ b/tests/validation/reference/GaussianPyramidHalf.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_GAUSSIAN_PYRAMID_HALF_H__ +#define __ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::vector> gaussian_pyramid_half(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H__ */ \ No newline at end of file diff --git a/tests/validation/reference/HarrisCornerDetector.cpp b/tests/validation/reference/HarrisCornerDetector.cpp new file mode 100644 index 0000000000..12afd95efa --- /dev/null +++ b/tests/validation/reference/HarrisCornerDetector.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2017 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 "HarrisCornerDetector.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/NonMaximaSuppression.h" +#include "tests/validation/reference/Sobel.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +template +std::tuple, SimpleTensor, float> compute_sobel(const SimpleTensor &src, int gradient_size, int block_size, BorderMode border_mode, uint8_t constant_border_value) +{ + SimpleTensor grad_x; + SimpleTensor grad_y; + float norm_factor = 0.f; + + std::tie(grad_x, grad_y) = sobel(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); + + switch(gradient_size) + { + case 3: + norm_factor = 1.f / (4 * 255 * block_size); + break; + case 5: + norm_factor = 1.f / (16 * 255 * block_size); + break; + case 7: + norm_factor = 1.f / (64 * 255 * block_size); + break; + default: + ARM_COMPUTE_ERROR("Gradient size not supported."); + } + + return std::make_tuple(grad_x, grad_y, norm_factor); +} + +template +std::vector harris_corner_detector_impl(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, + U constant_border_value) +{ + ARM_COMPUTE_ERROR_ON(block_size != 3 && block_size != 5 && block_size != 7); + + SimpleTensor grad_x; + SimpleTensor grad_y; + float norm_factor = 0.f; + + // Sobel + std::tie(grad_x, grad_y, norm_factor) = compute_sobel(src, gradient_size, block_size, border_mode, constant_border_value); + + SimpleTensor scores(src.shape(), DataType::F32); + ValidRegion scores_region = shape_to_valid_region(scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2)); + + // Calculate scores + for(int i = 0; i < scores.num_elements(); ++i) + { + Coordinates src_coord = index2coord(src.shape(), i); + Coordinates block_top_left{ src_coord.x() - block_size / 2, src_coord.y() - block_size / 2 }; + Coordinates block_bottom_right{ src_coord.x() + block_size / 2, src_coord.y() + block_size / 2 }; + + if(!is_in_valid_region(scores_region, src_coord)) + { + scores[i] = 0.f; + continue; + } + + float Gx2 = 0.f; + float Gy2 = 0.f; + float Gxy = 0.f; + + // Calculate Gx^2, Gy^2 and Gxy within the given window + for(int y = src_coord.y() - block_size / 2; y <= src_coord.y() + block_size / 2; ++y) + { + for(int x = src_coord.x() - block_size / 2; x <= src_coord.x() + block_size / 2; ++x) + { + Coordinates block_coord(x, y); + + const float norm_x = tensor_elem_at(grad_x, block_coord, border_mode, static_cast(constant_border_value)) * norm_factor; + const float norm_y = tensor_elem_at(grad_y, block_coord, border_mode, static_cast(constant_border_value)) * norm_factor; + + Gx2 += std::pow(norm_x, 2); + Gy2 += std::pow(norm_y, 2); + Gxy += norm_x * norm_y; + } + } + + const float trace2 = std::pow(Gx2 + Gy2, 2); + const float det = Gx2 * Gy2 - std::pow(Gxy, 2); + const float response = det - sensitivity * trace2; + + if(response > threshold) + { + scores[i] = response; + } + else + { + scores[i] = 0.f; + } + } + + // Suppress non-maxima candidates + SimpleTensor suppressed_scores = non_maxima_suppression(scores, border_mode != BorderMode::UNDEFINED ? BorderMode::CONSTANT : BorderMode::UNDEFINED, 0.f); + ValidRegion suppressed_scores_region = shape_to_valid_region(suppressed_scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2 + 1)); + + // Create vector of candidate corners + std::vector corner_candidates; + + for(int i = 0; i < suppressed_scores.num_elements(); ++i) + { + Coordinates coord = index2coord(suppressed_scores.shape(), i); + + if(is_in_valid_region(suppressed_scores_region, coord) && suppressed_scores[i] > 0.f) + { + KeyPoint corner; + corner.x = coord.x(); + corner.y = coord.y(); + corner.tracking_status = 1; + corner.strength = suppressed_scores[i]; + corner.scale = 0.f; + corner.orientation = 0.f; + corner.error = 0.f; + + corner_candidates.emplace_back(corner); + } + } + + // Sort descending by strength + std::sort(corner_candidates.begin(), corner_candidates.end(), [](const KeyPoint & a, const KeyPoint & b) + { + return a.strength > b.strength; + }); + + std::vector corners; + corners.reserve(corner_candidates.size()); + + // Only add corner if there is no stronger within min_dist + for(const KeyPoint &point : corner_candidates) + { + const auto strongest = std::find_if(corners.begin(), corners.end(), [&](const KeyPoint & other) + { + return std::sqrt((std::pow(point.x - other.x, 2) + std::pow(point.y - other.y, 2))) < min_dist; + }); + + if(strongest == corners.end()) + { + corners.emplace_back(point); + } + } + + corners.shrink_to_fit(); + + return corners; +} +} // namespace + +template +std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, + T constant_border_value) +{ + if(gradient_size < 7) + { + return harris_corner_detector_impl(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); + } + else + { + return harris_corner_detector_impl(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); + } +} + +template std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, + uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/HarrisCornerDetector.h b/tests/validation/reference/HarrisCornerDetector.h new file mode 100644 index 0000000000..042e8570c2 --- /dev/null +++ b/tests/validation/reference/HarrisCornerDetector.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_HARRIS_CORNER_DETECTOR_H__ +#define __ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H__ + +#include "arm_compute/core/Types.h" +#include "tests/SimpleTensor.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::vector harris_corner_detector(const SimpleTensor &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, + T constant_border_value = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H__ */ diff --git a/tests/validation/reference/Histogram.cpp b/tests/validation/reference/Histogram.cpp new file mode 100644 index 0000000000..594c4fb81f --- /dev/null +++ b/tests/validation/reference/Histogram.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017 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 "Histogram.h" + +#include "Utils.h" +#include "arm_compute/core/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range) +{ + SimpleTensor dst(TensorShape(num_bins), DataType::U32); + + // Clear the distribution + for(size_t element_idx = 0; element_idx < num_bins; ++element_idx) + { + dst[element_idx] = 0; + } + + // Create the histogram + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + if((offset <= src[element_idx]) && (src[element_idx] < (offset + range))) + { + const int index = (src[element_idx] - offset) * num_bins / range; + dst[index]++; + } + } + + return dst; +} + +template SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Histogram.h b/tests/validation/reference/Histogram.h new file mode 100644 index 0000000000..7ec16693aa --- /dev/null +++ b/tests/validation/reference/Histogram.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_HISTOGRAM_H__ +#define __ARM_COMPUTE_TEST_HISTOGRAM_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor histogram(const SimpleTensor &src, size_t num_bins, int32_t offset, uint32_t range); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_HISTOGRAM_H__ */ diff --git a/tests/validation/reference/IntegralImage.cpp b/tests/validation/reference/IntegralImage.cpp new file mode 100644 index 0000000000..8d07e995b5 --- /dev/null +++ b/tests/validation/reference/IntegralImage.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017 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 "IntegralImage.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor integral_image(const SimpleTensor &src) +{ + SimpleTensor dst(src.shape(), DataType::U32); + + // Length of dimensions + const size_t width = src.shape().x(); + const size_t height = src.shape().y(); + const size_t depth = src.shape().total_size_upper(2); + + const size_t image_size = width * height; + + for(size_t z = 0; z < depth; ++z) + { + size_t current_image = z * image_size; + + //First element of each image + dst[current_image] = src[current_image]; + + // First row of each image (add only pixel on the left) + for(size_t x = 1; x < width; ++x) + { + dst[current_image + x] = static_cast(src[current_image + x]) + dst[current_image + x - 1]; + } + + // Subsequent rows + for(size_t y = 1; y < height; ++y) + { + size_t current_row = current_image + (width * y); + + // First element of each row (add only pixel up) + dst[current_row] = static_cast(src[current_row]) + dst[current_row - width]; + + // Following row elements + for(size_t x = 1; x < width; ++x) + { + size_t current_pixel = current_row + x; + + // out = in + up(out) + left(out) - up_left(out) + dst[current_pixel] = static_cast(src[current_pixel]) + dst[current_pixel - 1] + + dst[current_pixel - width] - dst[current_pixel - width - 1]; + } + } + } + + return dst; +} + +template SimpleTensor integral_image(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/IntegralImage.h b/tests/validation/reference/IntegralImage.h new file mode 100644 index 0000000000..c766aae89e --- /dev/null +++ b/tests/validation/reference/IntegralImage.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_INTEGRAL_IMAGE_H__ +#define __ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor integral_image(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H__ */ diff --git a/tests/validation/reference/L2NormalizeLayer.cpp b/tests/validation/reference/L2NormalizeLayer.cpp new file mode 100644 index 0000000000..99f4e8a6e6 --- /dev/null +++ b/tests/validation/reference/L2NormalizeLayer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 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 "L2NormalizeLayer.h" +#include "ReductionOperation.h" + +#include "tests/validation/Helpers.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +TensorShape get_output_shape(TensorShape shape, unsigned int axis) +{ + TensorShape output_shape(shape); + output_shape.set(axis, 1); + return output_shape; +} +} // namespace + +template +SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon) +{ + // Create reference + SimpleTensor dst{ src.shape(), src.data_type() }; + + // Reduce across given axis + SimpleTensor sum = reduction_operation(src, get_output_shape(src.shape(), axis), axis, ReductionOperation::SUM_SQUARE); + + // Compute reference + const int elems = src.shape()[axis]; + const int upper_dims = src.shape().total_size_upper(axis + 1); + + for(int du = 0; du < upper_dims; ++du) + { + if(axis == 0) + { + const T *src_row_ptr = src.data() + du * elems; + T *dst_row_ptr = dst.data() + du * elems; + const T normalization_value = std::sqrt(std::max(sum[du], epsilon)); + std::transform(src_row_ptr, src_row_ptr + elems, dst_row_ptr, [normalization_value](T val) + { + return val / normalization_value; + }); + } + else + { + ARM_COMPUTE_ERROR("Unsupported normalization axis"); + } + } + + return dst; +} + +template SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/L2NormalizeLayer.h b/tests/validation/reference/L2NormalizeLayer.h new file mode 100644 index 0000000000..1db3ae6174 --- /dev/null +++ b/tests/validation/reference/L2NormalizeLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_L2NORMALIZE_H__ +#define __ARM_COMPUTE_TEST_L2NORMALIZE_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor l2_normalize(const SimpleTensor &src, unsigned int axis, float epsilon); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_L2NORMALIZE_H__ */ diff --git a/tests/validation/reference/Magnitude.cpp b/tests/validation/reference/Magnitude.cpp new file mode 100644 index 0000000000..f0002bfb33 --- /dev/null +++ b/tests/validation/reference/Magnitude.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 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 "Magnitude.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type) +{ + SimpleTensor mag(gx.shape(), gx.data_type()); + + using intermediate_type = typename common_promoted_unsigned_type::intermediate_type; + + for(int i = 0; i < gx.num_elements(); ++i) + { + double val = 0.f; + + if(magnitude_type == MagnitudeType::L1NORM) + { + val = static_cast(std::abs(gx[i])) + static_cast(std::abs(gy[i])); + } + else // MagnitudeType::L2NORM + { + // Note: kernel saturates to uint32_t instead of intermediate_type for S32 format + auto sum = static_cast(gx[i] * gx[i]) + static_cast(gy[i] * gy[i]); + val = std::sqrt(sum) + 0.5f; + } + + mag[i] = saturate_cast(val); + } + + return mag; +} + +template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); +template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); +template SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Magnitude.h b/tests/validation/reference/Magnitude.h new file mode 100644 index 0000000000..75620712e3 --- /dev/null +++ b/tests/validation/reference/Magnitude.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_MAGNITUDE_H__ +#define __ARM_COMPUTE_TEST_MAGNITUDE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor magnitude(const SimpleTensor &gx, const SimpleTensor &gy, MagnitudeType magnitude_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_MAGNITUDE_H__ */ diff --git a/tests/validation/reference/MeanStdDev.cpp b/tests/validation/reference/MeanStdDev.cpp new file mode 100644 index 0000000000..4a39b13d56 --- /dev/null +++ b/tests/validation/reference/MeanStdDev.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 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 "MeanStdDev.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::pair mean_and_standard_deviation(const SimpleTensor &in) +{ + const int num_elements = in.num_elements(); + + // Calculate mean + float mean = std::accumulate(in.data(), in.data() + num_elements, 0.f) / num_elements; + + // Calculate standard deviation + float std_dev = std::accumulate(in.data(), in.data() + num_elements, 0.f, [&mean](float a, float b) + { + return a + (mean - b) * (mean - b); + }); + + std_dev = std::sqrt(std_dev / num_elements); + + return std::make_pair(mean, std_dev); +} + +template std::pair mean_and_standard_deviation(const SimpleTensor &in); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/MeanStdDev.h b/tests/validation/reference/MeanStdDev.h new file mode 100644 index 0000000000..6b89ae0656 --- /dev/null +++ b/tests/validation/reference/MeanStdDev.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_STD_MEAN_DEV_H__ +#define __ARM_COMPUTE_TEST_STD_MEAN_DEV_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::pair mean_and_standard_deviation(const SimpleTensor &in); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_STD_MEAN_DEV_H__ */ diff --git a/tests/validation/reference/Median3x3.cpp b/tests/validation/reference/Median3x3.cpp new file mode 100644 index 0000000000..91a787a0a3 --- /dev/null +++ b/tests/validation/reference/Median3x3.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Median3x3.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +constexpr unsigned int filter_size = 3; /* Size of the kernel/filter in number of elements. */ +constexpr BorderSize border_size(filter_size / 2); /* Border size of the kernel/filter around its central element. */ +} // namespace + +template +SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + const int size_tot_filter = filter_size * filter_size; + + for(int src_idx = 0; src_idx < src.num_elements(); ++src_idx) + { + std::array filter_elems = { { 0 } }; + Coordinates id = index2coord(src.shape(), src_idx); + const int x = id.x(); + const int y = id.y(); + + for(int j = y - static_cast(border_size.top), index = 0; j <= y + static_cast(border_size.bottom); ++j) + { + for(int i = x - static_cast(border_size.left); i <= x + static_cast(border_size.right); ++i, ++index) + { + id.set(0, i); + id.set(1, j); + filter_elems[index] = tensor_elem_at(src, id, border_mode, constant_border_value); + } + } + std::sort(filter_elems.begin(), filter_elems.end()); + dst[src_idx] = filter_elems[size_tot_filter / 2]; + } + + return dst; +} + +template SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Median3x3.h b/tests/validation/reference/Median3x3.h new file mode 100644 index 0000000000..8345daa5e0 --- /dev/null +++ b/tests/validation/reference/Median3x3.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_MEDIAN3X3_H__ +#define __ARM_COMPUTE_TEST_MEDIAN3X3_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor median3x3(const SimpleTensor &src, BorderMode border_mode, T constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_MEDIAN3X3_H__ */ diff --git a/tests/validation/reference/MinMaxLocation.cpp b/tests/validation/reference/MinMaxLocation.cpp new file mode 100644 index 0000000000..427adebc61 --- /dev/null +++ b/tests/validation/reference/MinMaxLocation.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "MinMaxLocation.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +void compute_min_max(const SimpleTensor &src, T &min, T &max) +{ + // Set min and max to first pixel + min = src[0]; + max = src[0]; + + ARM_COMPUTE_ERROR_ON(src.num_elements() == 0); + + // Look for min and max values + for(int i = 1; i < src.num_elements(); ++i) + { + if(src[i] < min) + { + min = src[i]; + } + if(src[i] > max) + { + max = src[i]; + } + } +} + +template +MinMaxLocationValues min_max_location(const SimpleTensor &src) +{ + MinMaxLocationValues dst; + + const size_t width = src.shape().x(); + + compute_min_max(src, dst.min, dst.max); + + Coordinates2D coord{ 0, 0 }; + + for(int i = 0; i < src.num_elements(); ++i) + { + coord.x = static_cast(i % width); + coord.y = static_cast(i / width); + + if(src[i] == dst.min) + { + dst.min_loc.push_back(coord); + } + if(src[i] == dst.max) + { + dst.max_loc.push_back(coord); + } + } + + return dst; +} + +template MinMaxLocationValues min_max_location(const SimpleTensor &src); +template MinMaxLocationValues min_max_location(const SimpleTensor &src); +template MinMaxLocationValues min_max_location(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/MinMaxLocation.h b/tests/validation/reference/MinMaxLocation.h new file mode 100644 index 0000000000..ebaf90b131 --- /dev/null +++ b/tests/validation/reference/MinMaxLocation.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_MIN_MAX_LOCATION_H__ +#define __ARM_COMPUTE_TEST_MIN_MAX_LOCATION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +MinMaxLocationValues min_max_location(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_MIN_MAX_LOCATION_H__ */ diff --git a/tests/validation/reference/NonLinearFilter.cpp b/tests/validation/reference/NonLinearFilter.cpp new file mode 100644 index 0000000000..8669c9c776 --- /dev/null +++ b/tests/validation/reference/NonLinearFilter.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "NonLinearFilter.h" +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, + uint8_t constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + + ARM_COMPUTE_ERROR_ON(pattern == MatrixPattern::OTHER && mask == nullptr); + ARM_COMPUTE_UNUSED(pattern); + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + const int sq_mask_size = mask_size * mask_size; + const int half_mask_size = mask_size / 2; + std::vector vals(sq_mask_size); + intermediate_type current_value = 0; + + const ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(half_mask_size)); + + for(int element_idx = 0, count = 0, index = 0; element_idx < src.num_elements(); ++element_idx, count = 0, index = 0) + { + Coordinates id = index2coord(src.shape(), element_idx); + if(is_in_valid_region(valid_region, id)) + { + int idx = id.x(); + int idy = id.y(); + for(int y = idy - half_mask_size; y <= idy + half_mask_size; ++y) + { + for(int x = idx - half_mask_size; x <= idx + half_mask_size; ++x, ++index) + { + id.set(0, x); + id.set(1, y); + current_value = tensor_elem_at(src, id, border_mode, constant_border_value); + + if(mask[index] == 255) + { + vals[count] = static_cast(current_value); + ++count; + } + } + } + std::sort(vals.begin(), vals.begin() + count); + + ARM_COMPUTE_ERROR_ON(count == 0); + + switch(function) + { + case NonLinearFilterFunction::MIN: + dst[element_idx] = saturate_cast(vals[0]); + break; + case NonLinearFilterFunction::MAX: + dst[element_idx] = saturate_cast(vals[count - 1]); + break; + case NonLinearFilterFunction::MEDIAN: + dst[element_idx] = saturate_cast(vals[count / 2]); + break; + default: + ARM_COMPUTE_ERROR("Unsupported NonLinearFilter function."); + } + } + } + + return dst; +} + +template SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, + BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NonLinearFilter.h b/tests/validation/reference/NonLinearFilter.h new file mode 100644 index 0000000000..1df47c85be --- /dev/null +++ b/tests/validation/reference/NonLinearFilter.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_BITWISE_NOT_H__ +#define __ARM_COMPUTE_TEST_BITWISE_NOT_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor non_linear_filter(const SimpleTensor &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, + uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_BITWISE_NOT_H__ */ diff --git a/tests/validation/reference/NonMaximaSuppression.cpp b/tests/validation/reference/NonMaximaSuppression.cpp new file mode 100644 index 0000000000..eab5cecfc8 --- /dev/null +++ b/tests/validation/reference/NonMaximaSuppression.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017 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 "NonMaximaSuppression.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, T constant_border_value) +{ + constexpr int block_size = 3; + SimpleTensor dst(src.shape(), src.data_type(), src.num_channels()); + ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(block_size / 2)); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + int x = coord.x(); + int y = coord.y(); + + if(!is_in_valid_region(valid_region, coord)) + { + continue; + } + + if(src[i] >= tensor_elem_at(src, Coordinates(x - 1, y - 1), border_mode, constant_border_value) && src[i] >= tensor_elem_at(src, Coordinates(x, y - 1), border_mode, constant_border_value) + && src[i] >= tensor_elem_at(src, Coordinates(x + 1, y - 1), border_mode, constant_border_value) && src[i] >= tensor_elem_at(src, Coordinates(x - 1, y), border_mode, constant_border_value) + && src[i] > tensor_elem_at(src, Coordinates(x + 1, y), border_mode, constant_border_value) && src[i] > tensor_elem_at(src, Coordinates(x - 1, y + 1), border_mode, constant_border_value) + && src[i] > tensor_elem_at(src, Coordinates(x, y + 1), border_mode, constant_border_value) && src[i] > tensor_elem_at(src, Coordinates(x + 1, y + 1), border_mode, constant_border_value)) + { + dst[i] = src[i]; + } + else + { + dst[i] = T(0); + } + } + + return dst; +} + +template SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, float constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NonMaximaSuppression.h b/tests/validation/reference/NonMaximaSuppression.h new file mode 100644 index 0000000000..2086abfe83 --- /dev/null +++ b/tests/validation/reference/NonMaximaSuppression.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_NON_MAXIMA_SUPPRESSION_H__ +#define __ARM_COMPUTE_TEST_NON_MAXIMA_SUPPRESSION_H__ + +#include "arm_compute/core/Types.h" +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor non_maxima_suppression(const SimpleTensor &src, BorderMode border_mode, T constant_border_value = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_NON_MAXIMA_SUPPRESSION_H__ */ diff --git a/tests/validation/reference/NormalizationLayer.cpp b/tests/validation/reference/NormalizationLayer.cpp new file mode 100644 index 0000000000..226af96fe3 --- /dev/null +++ b/tests/validation/reference/NormalizationLayer.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2017 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 "NormalizationLayer.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info) +{ + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const uint32_t norm_size = info.norm_size(); + NormType type = info.type(); + float beta = info.beta(); + uint32_t kappa = info.kappa(); + + const int cols = src.shape()[0]; + const int rows = src.shape()[1]; + const int depth = src.shape()[2]; + int upper_dims = src.shape().total_size() / (cols * rows); + + float coeff = info.scale_coeff(); + int radius_cols = norm_size / 2; + + // IN_MAP_1D and CROSS_MAP normalize over a single axis only + int radius_rows = (NormType::IN_MAP_2D == type) ? norm_size / 2 : 0; + + if(type == NormType::CROSS_MAP) + { + // Remove also depth from upper dimensions since it is the dimension we + // want to use for normalization + upper_dims /= depth; + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < rows; ++i) + { + for(int k = 0; k < cols; ++k) + { + for(int l = 0; l < depth; ++l) + { + float accumulated_scale = 0.f; + + for(int j = -radius_cols; j <= radius_cols; ++j) + { + const int z = l + j; + + if(z >= 0 && z < depth) + { + const T value = src[k + i * cols + z * rows * cols + r * cols * rows * depth]; + accumulated_scale += value * value; + } + } + + dst[k + i * cols + l * rows * cols + r * cols * rows * depth] = kappa + accumulated_scale * coeff; + } + } + } + } + } + else + { + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < rows; ++i) + { + for(int k = 0; k < cols; ++k) + { + float accumulated_scale = 0.f; + + for(int j = -radius_rows; j <= radius_rows; ++j) + { + const int y = i + j; + for(int l = -radius_cols; l <= radius_cols; ++l) + { + const int x = k + l; + + if((x >= 0 && y >= 0) && (x < cols && y < rows)) + { + const T value = src[x + y * cols + r * cols * rows]; + accumulated_scale += value * value; + } + } + } + + dst[k + i * cols + r * cols * rows] = kappa + accumulated_scale * coeff; + } + } + } + } + + if(beta == 1.f) + { + for(int i = 0; i < dst.num_elements(); ++i) + { + dst[i] = src[i] / dst[i]; + } + } + else if(beta == 0.5f) + { + for(int i = 0; i < dst.num_elements(); ++i) + { + dst[i] = src[i] / std::sqrt(dst[i]); + } + } + else + { + for(int i = 0; i < dst.num_elements(); ++i) + { + dst[i] = src[i] * std::exp(std::log(dst[i]) * -beta); + } + } + + return dst; +} + +template ::value, int>::type> +SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info) +{ + using namespace fixed_point_arithmetic; + + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const int fixed_point_position = src.fixed_point_position(); + + const uint32_t norm_size = info.norm_size(); + NormType type = info.type(); + fixed_point beta(info.beta(), fixed_point_position); + fixed_point kappa(info.kappa(), fixed_point_position); + + const int cols = src.shape()[0]; + const int rows = src.shape()[1]; + const int depth = src.shape()[2]; + int upper_dims = src.shape().total_size() / (cols * rows); + + fixed_point coeff(info.scale_coeff(), fixed_point_position); + int radius_cols = norm_size / 2; + + // IN_MAP_1D and CROSS_MAP normalize over a single axis only + int radius_rows = (NormType::IN_MAP_2D == type) ? norm_size / 2 : 0; + + if(type == NormType::CROSS_MAP) + { + // Remove also depth from upper dimensions since it is the dimension we + // want to use for normalization + upper_dims /= depth; + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < rows; ++i) + { + for(int k = 0; k < cols; ++k) + { + for(int l = 0; l < depth; ++l) + { + fixed_point accumulated_scale(0.f, fixed_point_position); + + for(int j = -radius_cols; j <= radius_cols; ++j) + { + const int z = l + j; + + if(z >= 0 && z < depth) + { + const T value = src[k + i * cols + z * rows * cols + r * cols * rows * depth]; + const fixed_point fp_value(value, fixed_point_position, true); + accumulated_scale = add(accumulated_scale, mul(fp_value, fp_value)); + } + } + + accumulated_scale = add(kappa, mul(accumulated_scale, coeff)); + dst[k + i * cols + l * rows * cols + r * cols * rows * depth] = accumulated_scale.raw(); + } + } + } + } + } + else + { + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < rows; ++i) + { + for(int k = 0; k < cols; ++k) + { + fixed_point accumulated_scale(0.f, fixed_point_position); + + for(int j = -radius_rows; j <= radius_rows; ++j) + { + const int y = i + j; + + for(int l = -radius_cols; l <= radius_cols; ++l) + { + const int x = k + l; + + if((x >= 0 && y >= 0) && (x < cols && y < rows)) + { + const T value = src[x + y * cols + r * cols * rows]; + const fixed_point fp_value(value, fixed_point_position, true); + accumulated_scale = add(accumulated_scale, mul(fp_value, fp_value)); + } + } + } + + accumulated_scale = add(kappa, mul(accumulated_scale, coeff)); + dst[k + i * cols + r * cols * rows] = accumulated_scale.raw(); + } + } + } + } + + if(info.beta() == 1.f) + { + for(int i = 0; i < dst.num_elements(); ++i) + { + fixed_point res = div(fixed_point(src[i], fixed_point_position, true), fixed_point(dst[i], fixed_point_position, true)); + dst[i] = res.raw(); + } + } + else + { + const fixed_point beta(info.beta(), fixed_point_position); + + for(int i = 0; i < dst.num_elements(); ++i) + { + fixed_point res = pow(fixed_point(dst[i], fixed_point_position, true), beta); + res = div(fixed_point(src[i], fixed_point_position, true), res); + dst[i] = res.raw(); + } + } + + return dst; +} + +template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); +template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); +template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); +template SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NormalizationLayer.h b/tests/validation/reference/NormalizationLayer.h new file mode 100644 index 0000000000..3f624ff30a --- /dev/null +++ b/tests/validation/reference/NormalizationLayer.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_NORMALIZATION_LAYER_H__ +#define __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); + +template ::value, int>::type = 0> +SimpleTensor normalization_layer(const SimpleTensor &src, NormalizationLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ */ diff --git a/tests/validation/reference/Phase.cpp b/tests/validation/reference/Phase.cpp new file mode 100644 index 0000000000..7827cd2989 --- /dev/null +++ b/tests/validation/reference/Phase.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 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 "Phase.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type) +{ + const float PI = std::atan(1) * 4; + SimpleTensor phase(gx.shape(), DataType::U8); + + if(phase_type == PhaseType::UNSIGNED) // unsigned: map to [0-255) + { + for(int i = 0; i < gx.num_elements(); ++i) + { + float angle_deg = (std::atan2(float(gy[i]), float(gx[i])) / PI) * 180.0f; + phase[i] = (angle_deg < 0.0f) ? 180.f + angle_deg : angle_deg; + } + } + else // signed: map to [0-180) degrees + { + for(int i = 0; i < gx.num_elements(); ++i) + { + float angle_pi = std::atan2(gy[i], gx[i]) / PI; + angle_pi = (angle_pi < 0.0f) ? 2 + angle_pi : angle_pi; + phase[i] = lround(angle_pi * 128) & 0xFFu; + } + } + + return phase; +} + +template SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); +template SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Phase.h b/tests/validation/reference/Phase.h new file mode 100644 index 0000000000..d322d53e02 --- /dev/null +++ b/tests/validation/reference/Phase.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_PHASE_H__ +#define __ARM_COMPUTE_TEST_PHASE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor phase(const SimpleTensor &gx, const SimpleTensor &gy, PhaseType phase_type); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_PHASE_H__ */ diff --git a/tests/validation/reference/PixelWiseMultiplication.cpp b/tests/validation/reference/PixelWiseMultiplication.cpp new file mode 100644 index 0000000000..b3647fc9ce --- /dev/null +++ b/tests/validation/reference/PixelWiseMultiplication.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017 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, + * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "PixelWiseMultiplication.h" + +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +struct is_floating_point + : std::integral_constant < bool, + std::is_same::type>::value || std::is_same::type>::value + || std::is_same::type>::value || std::is_same::type>::value > +{ +}; + +template +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) +{ + SimpleTensor dst(src2.shape(), src2.data_type()); + + if(scale < 0) + { + ARM_COMPUTE_ERROR("Scale of pixel-wise multiplication must be non-negative"); + } + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src1.num_elements(); ++i) + { + double val = static_cast(src1[i]) * static_cast(src2[i]) * static_cast(scale); + if(is_floating_point::value) + { + dst[i] = val; + } + else + { + double rounded_val = 0; + switch(rounding_policy) + { + case(RoundingPolicy::TO_ZERO): + rounded_val = support::cpp11::trunc(val); + break; + case(RoundingPolicy::TO_NEAREST_UP): + rounded_val = round_half_up(val); + break; + case(RoundingPolicy::TO_NEAREST_EVEN): + rounded_val = round_half_even(val); + break; + default: + ARM_COMPUTE_ERROR("Unsupported rounding policy"); + } + + dst[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(rounded_val) : static_cast(rounded_val); + } + } + + return dst; +} + +// *INDENT-OFF* +// clang-format off +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +// clang-format on +// *INDENT-ON* +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/PixelWiseMultiplication.h b/tests/validation/reference/PixelWiseMultiplication.h new file mode 100644 index 0000000000..1dce154719 --- /dev/null +++ b/tests/validation/reference/PixelWiseMultiplication.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_PIXEL_WISE_MULTIPLICATION_H__ +#define __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp new file mode 100644 index 0000000000..1a7dd4cbb7 --- /dev/null +++ b/tests/validation/reference/PoolingLayer.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2017 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 "PoolingLayer.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +TensorShape calculate_output_shape(TensorShape shape, PoolingLayerInfo info) +{ + TensorShape dst_shape = shape; + const int pool_size = info.is_global_pooling() ? shape.x() : info.pool_size(); + const std::pair scaled_dims = arm_compute::scaled_dimensions(shape.x(), + shape.y(), + pool_size, + pool_size, + info.pad_stride_info()); + dst_shape.set(0, scaled_dims.first); + dst_shape.set(1, scaled_dims.second); + + return dst_shape; +} +} // namespace + +template ::value, int>::type> +SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) +{ + ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); + + const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); + PoolingType type = info.pool_type(); + int pool_stride_x = info.pad_stride_info().stride().first; + int pool_stride_y = info.pad_stride_info().stride().second; + int pad_x = info.pad_stride_info().pad().first; + int pad_y = info.pad_stride_info().pad().second; + bool exclude_padding = info.exclude_padding(); + + const auto w_src = static_cast(src.shape()[0]); + const auto h_src = static_cast(src.shape()[1]); + const int upper_dims = src.shape().total_size() / (w_src * h_src); + + // Create reference + SimpleTensor dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; + + const auto w_dst = static_cast(dst.shape()[0]); + const auto h_dst = static_cast(dst.shape()[1]); + + if(type == PoolingType::MAX) + { + for(int r = 0; r < upper_dims; ++r) + { + for(int h = 0; h < h_dst; ++h) + { + for(int w = 0; w < w_dst; ++w) + { + int wstart = w * pool_stride_x - pad_x; + int hstart = h * pool_stride_y - pad_y; + int wend = std::min(wstart + pool_size, w_src); + int hend = std::min(hstart + pool_size, h_src); + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + + T max_val = std::numeric_limits::lowest(); + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const T val = src[r * h_src * w_src + y * w_src + x]; + if(val > max_val) + { + max_val = val; + } + } + } + + dst[r * h_dst * w_dst + h * w_dst + w] = max_val; + } + } + } + } + else // Average or l2 pooling + { + for(int r = 0; r < upper_dims; ++r) + { + for(int h = 0; h < h_dst; ++h) + { + for(int w = 0; w < w_dst; ++w) + { + T avg_val(0); + int wstart = w * pool_stride_x - pad_x; + int hstart = h * pool_stride_y - pad_y; + int wend = std::min(wstart + pool_size, w_src + pad_x); + int hend = std::min(hstart + pool_size, h_src + pad_y); + int pool = (hend - hstart) * (wend - wstart); + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + wend = std::min(wend, w_src); + hend = std::min(hend, h_src); + // Exclude padding pixels from the average + if(exclude_padding) + { + pool = (hend - hstart) * (wend - wstart); + } + + if(type == PoolingType::AVG) + { + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + avg_val += src[r * h_src * w_src + y * w_src + x]; + } + } + dst[r * h_dst * w_dst + h * w_dst + w] = avg_val / pool; + } + else + { + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const T val = src[r * h_src * w_src + y * w_src + x]; + avg_val += val * val; + } + } + dst[r * h_dst * w_dst + h * w_dst + w] = std::sqrt(avg_val / pool); + } + } + } + } + } + + return dst; +} + +template ::value, int>::type> +SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) +{ + ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); + + const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); + PoolingType type = info.pool_type(); + int pool_stride_x = info.pad_stride_info().stride().first; + int pool_stride_y = info.pad_stride_info().stride().second; + int pad_x = info.pad_stride_info().pad().first; + int pad_y = info.pad_stride_info().pad().second; + bool exclude_padding = info.exclude_padding(); + + const auto w_src = static_cast(src.shape()[0]); + const auto h_src = static_cast(src.shape()[1]); + const int upper_dims = src.shape().total_size() / (w_src * h_src); + + // Create reference + SimpleTensor dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; + + const auto w_dst = static_cast(dst.shape()[0]); + const auto h_dst = static_cast(dst.shape()[1]); + + if(type == PoolingType::MAX) + { + for(int r = 0; r < upper_dims; ++r) + { + for(int h = 0; h < h_dst; ++h) + { + for(int w = 0; w < w_dst; ++w) + { + int wstart = w * pool_stride_x - pad_x; + int hstart = h * pool_stride_y - pad_y; + int wend = std::min(wstart + pool_size, w_src); + int hend = std::min(hstart + pool_size, h_src); + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + + T max_val = std::numeric_limits::lowest(); + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const T val = src[r * h_src * w_src + y * w_src + x]; + if(val > max_val) + { + max_val = val; + } + } + } + + dst[r * h_dst * w_dst + h * w_dst + w] = max_val; + } + } + } + } + else // Average or l2 pooling + { + for(int r = 0; r < upper_dims; ++r) + { + for(int h = 0; h < h_dst; ++h) + { + for(int w = 0; w < w_dst; ++w) + { + int wstart = w * pool_stride_x - pad_x; + int hstart = h * pool_stride_y - pad_y; + int wend = std::min(wstart + pool_size, w_src + pad_x); + int hend = std::min(hstart + pool_size, h_src + pad_y); + int pool = (hend - hstart) * (wend - wstart); + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + wend = std::min(wend, w_src); + hend = std::min(hend, h_src); + // Exclude padding pixels from the average + if(exclude_padding) + { + pool = (hend - hstart) * (wend - wstart); + } + + using namespace fixed_point_arithmetic; + + const int fixed_point_position = src.fixed_point_position(); + const fixed_point const_1(1, fixed_point_position); + const fixed_point invpool_fp(1.f / static_cast(pool), fixed_point_position); + fixed_point avg_val(0, fixed_point_position, true); + + if(type == PoolingType::AVG) + { + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const fixed_point in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); + avg_val = add(avg_val, in_fp); + } + } + dst[r * h_dst * w_dst + h * w_dst + w] = mul(avg_val, invpool_fp).raw(); + } + else + { + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const fixed_point in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); + avg_val = add(avg_val, mul(in_fp, in_fp)); + } + } + auto res = div(const_1, (inv_sqrt(mul(avg_val, invpool_fp)))); + dst[r * h_dst * w_dst + h * w_dst + w] = res.raw(); + } + } + } + } + } + + return dst; +} + +template <> +SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) +{ + SimpleTensor src_tmp = convert_from_asymmetric(src); + SimpleTensor dst_tmp = pooling_layer(src_tmp, info); + SimpleTensor dst = convert_to_asymmetric(dst_tmp, src.quantization_info()); + return dst; +} + +template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); +template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); +template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); +template SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/PoolingLayer.h b/tests/validation/reference/PoolingLayer.h new file mode 100644 index 0000000000..334054a0eb --- /dev/null +++ b/tests/validation/reference/PoolingLayer.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_POOLING_LAYER_H__ +#define __ARM_COMPUTE_TEST_POOLING_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); + +template ::value, int>::type = 0> +SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_POOLING_LAYER_H__ */ diff --git a/tests/validation/reference/QuantizationLayer.cpp b/tests/validation/reference/QuantizationLayer.cpp new file mode 100644 index 0000000000..d7ce490209 --- /dev/null +++ b/tests/validation/reference/QuantizationLayer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017 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 "QuantizationLayer.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor quantization_layer(const SimpleTensor &src) +{ + // Create reference + SimpleTensor dst{ src.shape(), DataType::U8 }; + + const int width = src.shape().x(); + const int height = src.shape().y(); + const int depth = src.shape().z(); + const int stride_w = width * height * depth; + const int num_batches = src.shape().total_size_upper(3); + + for(int k = 0; k < num_batches; ++k) + { + // Compute min and max of the 3D tensor + float min = src[k * stride_w]; + float max = src[k * stride_w]; + + // Look for min and max values + for(int i = 1; i < stride_w; ++i) + { + float val = src[i + k * stride_w]; + min = std::min(min, val); + max = std::max(max, val); + } + + // Saturate the result in case min = max + if(min == max) + { + min = 0.0f; + max = 1.0f; + } + + const float range = max - min; + + for(int i = 0; i < stride_w; ++i) + { + // map values to range [0.0, 1.0] + float val = src[i + k * stride_w]; + const float normalized = (val - min) / range; + dst[i + k * stride_w] = static_cast(std::min(255.0f, normalized * 256.0f)); + } + } + + return dst; +} + +template SimpleTensor quantization_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/QuantizationLayer.h b/tests/validation/reference/QuantizationLayer.h new file mode 100644 index 0000000000..7c5572ccf8 --- /dev/null +++ b/tests/validation/reference/QuantizationLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_QUANTIZATION_LAYER_H__ +#define __ARM_COMPUTE_TEST_QUANTIZATION_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor quantization_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_QUANTIZATION_LAYER_H__ */ diff --git a/tests/validation/reference/ReductionOperation.cpp b/tests/validation/reference/ReductionOperation.cpp new file mode 100644 index 0000000000..acfcc09cea --- /dev/null +++ b/tests/validation/reference/ReductionOperation.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2017 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 "ReductionOperation.h" + +#include "tests/validation/Helpers.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +template +struct square +{ + T operator()(const T &lhs, const T &rhs) const + { + return (lhs + rhs * rhs); + } +}; + +template +T reduce_operation(T *ptr, int reduce_elements, ReductionOperation op) +{ + switch(op) + { + case ReductionOperation::SUM_SQUARE: + return std::accumulate(ptr, ptr + reduce_elements, 0.f, square()); + default: + ARM_COMPUTE_ERROR("Unsupported reduction operation"); + } +} +} // namespace + +template +SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +{ + // Create reference + SimpleTensor dst{ dst_shape, src.data_type() }; + + // Compute reference + const int reduce_elems = src.shape()[axis]; + const int upper_dims = src.shape().total_size_upper(axis + 1); + + for(int du = 0; du < upper_dims; ++du) + { + if(axis == 0) + { + const T *src_row_ptr = src.data() + du * reduce_elems; + dst[du] = reduce_operation(src_row_ptr, reduce_elems, op); + } + else + { + ARM_COMPUTE_ERROR("Unsupported reduction axis"); + } + } + + return dst; +} + +template SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ReductionOperation.h b/tests/validation/reference/ReductionOperation.h new file mode 100644 index 0000000000..6da6436686 --- /dev/null +++ b/tests/validation/reference/ReductionOperation.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_REDUCTION_OPERATION_H__ +#define __ARM_COMPUTE_TEST_REDUCTION_OPERATION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FLOOR_H__ */ diff --git a/tests/validation/reference/Remap.cpp b/tests/validation/reference/Remap.cpp new file mode 100644 index 0000000000..bef5962fbf --- /dev/null +++ b/tests/validation/reference/Remap.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017 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 "Remap.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor remap(const SimpleTensor &in, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, BorderMode border_mode, + T constant_border_value) +{ + ARM_COMPUTE_ERROR_ON_MSG(border_mode == BorderMode::REPLICATE, "BorderMode not supported"); + + SimpleTensor out(in.shape(), in.data_type()); + + const int width = in.shape().x(); + const int height = in.shape().y(); + + for(int idx = 0; idx < out.num_elements(); idx++) + { + valid_mask[idx] = 1; + Coordinates src_idx; + src_idx.set(0, static_cast(std::floor(map_x[idx]))); + src_idx.set(1, static_cast(std::floor(map_y[idx]))); + if((0 <= map_y[idx]) && (map_y[idx] < height) && (0 <= map_x[idx]) && (map_x[idx] < width)) + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + out[idx] = tensor_elem_at(in, src_idx, border_mode, constant_border_value); + break; + case InterpolationPolicy::BILINEAR: + (valid_bilinear_policy(map_x[idx], map_y[idx], width, height, border_mode)) ? out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value) : valid_mask[idx] = 0; + break; + case InterpolationPolicy::AREA: + default: + ARM_COMPUTE_ERROR("Interpolation not supported"); + break; + } + } + else + { + if(border_mode == BorderMode::UNDEFINED) + { + valid_mask[idx] = 0; + } + else + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + out[idx] = constant_border_value; + break; + case InterpolationPolicy::BILINEAR: + out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value); + break; + case InterpolationPolicy::AREA: + default: + break; + } + } + } + } + + return out; +} + +template SimpleTensor remap(const SimpleTensor &src, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, + BorderMode border_mode, + uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Remap.h b/tests/validation/reference/Remap.h new file mode 100644 index 0000000000..918ba95d3c --- /dev/null +++ b/tests/validation/reference/Remap.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_REMAP_H__ +#define __ARM_COMPUTE_TEST_REMAP_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor remap(const SimpleTensor &in, SimpleTensor &map_x, SimpleTensor &map_y, SimpleTensor &valid_mask, InterpolationPolicy policy, BorderMode border_mode, + T constant_border_value = 0); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_REMAP_H__ */ diff --git a/tests/validation/reference/ReshapeLayer.cpp b/tests/validation/reference/ReshapeLayer.cpp new file mode 100644 index 0000000000..42f06e4f5a --- /dev/null +++ b/tests/validation/reference/ReshapeLayer.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 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 "ReshapeLayer.h" + +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape) +{ + ARM_COMPUTE_ERROR_ON(src.shape().total_size() != output_shape.total_size()); + + SimpleTensor dst(output_shape, src.data_type()); + std::copy_n(src.data(), src.num_elements(), dst.data()); + return dst; +} + +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +template SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ReshapeLayer.h b/tests/validation/reference/ReshapeLayer.h new file mode 100644 index 0000000000..fc6c716d7a --- /dev/null +++ b/tests/validation/reference/ReshapeLayer.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_RESHAPE_LAYER_H__ +#define __ARM_COMPUTE_TEST_RESHAPE_LAYER_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor reshape_layer(const SimpleTensor &src, const TensorShape &output_shape); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_RESHAPE_LAYER_H__ */ diff --git a/tests/validation/reference/Scale.cpp b/tests/validation/reference/Scale.cpp new file mode 100644 index 0000000000..727325f675 --- /dev/null +++ b/tests/validation/reference/Scale.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Scale.h" +#include "Utils.h" +#include "support/ToolchainSupport.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor scale(const SimpleTensor &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale) +{ + // Add 1 if ceil_policy_scale is true + const size_t round_value = ceil_policy_scale ? 1U : 0U; + TensorShape shape_scaled(in.shape()); + shape_scaled.set(0, (in.shape()[0] + round_value) * scale_x); + shape_scaled.set(1, (in.shape()[1] + round_value) * scale_y); + SimpleTensor out(shape_scaled, in.data_type()); + + // Compute the ratio between source width/height and destination width/height + const auto wr = static_cast(in.shape()[0]) / static_cast(out.shape()[0]); + const auto hr = static_cast(in.shape()[1]) / static_cast(out.shape()[1]); + + const auto width = static_cast(in.shape().x()); + const auto height = static_cast(in.shape().y()); + + // Determine border size + const int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1; + + // Area interpolation behaves as Nearest Neighbour in case of up-sampling + if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) + { + policy = InterpolationPolicy::NEAREST_NEIGHBOR; + } + + for(int element_idx = 0, count = 0; element_idx < out.num_elements(); ++element_idx, ++count) + { + Coordinates id = index2coord(out.shape(), element_idx); + int idx = id.x(); + int idy = id.y(); + float x_src = 0; + float y_src = 0; + + switch(sampling_policy) + { + case SamplingPolicy::TOP_LEFT: + x_src = idx * wr; + y_src = idy * hr; + break; + case SamplingPolicy::CENTER: + x_src = (idx + 0.5f) * wr - 0.5f; + y_src = (idy + 0.5f) * hr - 0.5f; + break; + default: + ARM_COMPUTE_ERROR("Unsupported sampling policy."); + break; + } + + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + { + //Calculate the source coords without -0.5f is equivalent to round the x_scr/y_src coords + x_src = (idx + 0.5f) * wr; + y_src = (idy + 0.5f) * hr; + id.set(0, x_src); + id.set(1, y_src); + + // If coordinates in range of tensor's width or height + if(is_valid_pixel_index(x_src, y_src, width, height, border_size)) + { + out[element_idx] = tensor_elem_at(in, id, border_mode, constant_border_value); + } + break; + } + case InterpolationPolicy::BILINEAR: + { + id.set(0, std::floor(x_src)); + id.set(1, std::floor(y_src)); + if(is_valid_pixel_index(x_src, y_src, width, height, border_size)) + { + out[element_idx] = bilinear_policy(in, id, x_src, y_src, border_mode, constant_border_value); + } + else + { + if(border_mode == BorderMode::CONSTANT) + { + out[element_idx] = constant_border_value; + } + else if(border_mode == BorderMode::REPLICATE) + { + id.set(0, clamp(static_cast(x_src), 0, width - 1)); + id.set(1, clamp(static_cast(y_src), 0, height - 1)); + out[element_idx] = in[coord2index(in.shape(), id)]; + } + } + break; + } + case InterpolationPolicy::AREA: + { + int x_from = std::floor(idx * wr - 0.5f - x_src); + int y_from = std::floor(idy * hr - 0.5f - y_src); + int x_to = std::ceil((idx + 1) * wr - 0.5f - x_src); + int y_to = std::ceil((idy + 1) * hr - 0.5f - y_src); + const int xi = std::floor(x_src); + const int yi = std::floor(y_src); + + // Clamp position to borders + x_src = std::max(-static_cast(border_size), std::min(x_src, static_cast(width - 1 + border_size))); + y_src = std::max(-static_cast(border_size), std::min(y_src, static_cast(height - 1 + border_size))); + + // Clamp bounding box offsets to borders + x_from = ((x_src + x_from) < -border_size) ? -border_size : x_from; + y_from = ((y_src + y_from) < -border_size) ? -border_size : y_from; + x_to = ((x_src + x_to) >= (width + border_size)) ? (width - 1 + border_size) : x_to; + y_to = ((y_src + y_to) >= (height + border_size)) ? (height - 1 + border_size) : y_to; + ARM_COMPUTE_ERROR_ON((x_to - x_from + 1) == 0 || (y_to - y_from + 1) == 0); + + float sum = 0; + for(int j = yi + y_from, je = yi + y_to; j <= je; ++j) + { + for(int i = xi + x_from, ie = xi + x_to; i <= ie; ++i) + { + id.set(0, static_cast(i)); + id.set(1, static_cast(j)); + sum += tensor_elem_at(in, id, border_mode, constant_border_value); + } + } + out[element_idx] = sum / ((x_to - x_from + 1) * (y_to - y_from + 1)); + + break; + } + default: + ARM_COMPUTE_ERROR("Unsupported interpolation mode"); + } + } + + return out; +} + +template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale); +template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, int16_t constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale); +template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, half constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale); +template SimpleTensor scale(const SimpleTensor &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, float constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Scale.h b/tests/validation/reference/Scale.h new file mode 100644 index 0000000000..566e30af10 --- /dev/null +++ b/tests/validation/reference/Scale.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_SCALE_H__ +#define __ARM_COMPUTE_TEST_SCALE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor scale(const SimpleTensor &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value = 0, + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool ceil_policy_scale = false); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SCALE_H__ */ diff --git a/tests/validation/reference/Scharr.cpp b/tests/validation/reference/Scharr.cpp new file mode 100644 index 0000000000..98e4d62dba --- /dev/null +++ b/tests/validation/reference/Scharr.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2017 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 "Scharr.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +const std::array scharr_3_x{ { -3, 0, 3, -10, 0, 10, -3, 0, 3 } }; +const std::array scharr_3_y{ { -3, -10, -3, 0, 0, 0, 3, 10, 3 } }; + +const std::map> masks +{ + { 3, { scharr_3_x.data(), scharr_3_y.data() } } +}; + +template +struct data_type; + +template <> +struct data_type +{ + const static DataType value = DataType::S16; +}; +} // namespace + +template +std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) +{ + const auto shape_size = static_cast(filter_size); + + SimpleTensor dst_x(src.shape(), data_type::value, src.num_channels()); + SimpleTensor dst_y(src.shape(), data_type::value, src.num_channels()); + + ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + + if(!is_in_valid_region(valid_region, coord)) + { + continue; + } + + switch(gradient_dimension) + { + case GradientDimension::GRAD_X: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_Y: + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_XY: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); + break; + default: + ARM_COMPUTE_ERROR("Gradient dimension not supported"); + } + } + + return std::make_pair(dst_x, dst_y); +} + +template std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, + GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Scharr.h b/tests/validation/reference/Scharr.h new file mode 100644 index 0000000000..8f383811cf --- /dev/null +++ b/tests/validation/reference/Scharr.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_SCHARR_H__ +#define __ARM_COMPUTE_TEST_SCHARR_H__ + +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::pair, SimpleTensor> scharr(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SCHARR_H__ */ diff --git a/tests/validation/reference/Sobel.cpp b/tests/validation/reference/Sobel.cpp new file mode 100644 index 0000000000..ff0e11d3a8 --- /dev/null +++ b/tests/validation/reference/Sobel.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2017 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 "Sobel.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +const std::array sobel_3_x{ { -1, 0, 1, -2, 0, 2, -1, 0, 1 } }; +const std::array sobel_3_y{ { -1, -2, -1, 0, 0, 0, 1, 2, 1 } }; + +const std::array sobel_5_x{ { + -1, -2, 0, 2, 1, + -4, -8, 0, 8, 4, + -6, -12, 0, 12, 6, + -4, -8, 0, 8, 4, + -1, -2, 0, 2, 1 + } }; + +const std::array sobel_5_y{ { + -1, -4, -6, -4, -1, + -2, -8, -12, -8, -2, + 0, 0, 0, 0, 0, + 2, 8, 12, 8, 2, + 1, 4, 6, 4, 1 + } }; + +const std::array sobel_7_x{ { + -1, -4, -5, 0, 5, 4, 1, + -6, -24, -30, 0, 30, 24, 6, + -15, -60, -75, 0, 75, 60, 15, + -20, -80, -100, 0, 100, 80, 20, + -15, -60, -75, 0, 75, 60, 15, + -6, -24, -30, 0, 30, 24, 6, + -1, -4, -5, 0, 5, 4, 1 + } }; + +const std::array sobel_7_y{ { + -1, -6, -15, -20, -15, -6, -1, + -4, -24, -60, -80, -60, -24, -4, + -5, -30, -75, -100, -75, -30, -5, + 0, 0, 0, 0, 0, 0, 0, + 5, 30, 75, 100, 75, 30, 5, + 4, 24, 60, 80, 60, 24, 4, + 1, 6, 15, 20, 15, 6, 1 + } }; + +const std::map> masks +{ + { 3, { sobel_3_x.data(), sobel_3_y.data() } }, + { 5, { sobel_5_x.data(), sobel_5_y.data() } }, + { 7, { sobel_7_x.data(), sobel_7_y.data() } }, +}; + +template +struct data_type; + +template <> +struct data_type +{ + const static DataType value = DataType::S16; +}; + +template <> +struct data_type +{ + const static DataType value = DataType::S32; +}; +} // namespace + +template +std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) +{ + SimpleTensor dst_x(src.shape(), data_type::value, src.num_channels()); + SimpleTensor dst_y(src.shape(), data_type::value, src.num_channels()); + + ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + + if(!is_in_valid_region(valid_region, coord)) + { + continue; + } + switch(gradient_dimension) + { + case GradientDimension::GRAD_X: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, + constant_border_value); + break; + case GradientDimension::GRAD_Y: + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, + constant_border_value); + break; + case GradientDimension::GRAD_XY: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, + constant_border_value); + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast(filter_size), static_cast(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, + constant_border_value); + break; + default: + ARM_COMPUTE_ERROR("Gradient dimension not supported"); + } + } + + return std::make_pair(dst_x, dst_y); +} + +template std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, + GradientDimension gradient_dimension); +template std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, + GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Sobel.h b/tests/validation/reference/Sobel.h new file mode 100644 index 0000000000..9099f1a932 --- /dev/null +++ b/tests/validation/reference/Sobel.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 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_SOBEL_H__ +#define __ARM_COMPUTE_TEST_SOBEL_H__ + +#include "arm_compute/core/Types.h" +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::pair, SimpleTensor> sobel(const SimpleTensor &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SOBEL_H__ */ diff --git a/tests/validation/reference/SoftmaxLayer.cpp b/tests/validation/reference/SoftmaxLayer.cpp new file mode 100644 index 0000000000..8e8cc1bd25 --- /dev/null +++ b/tests/validation/reference/SoftmaxLayer.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2017 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 "SoftmaxLayer.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor softmax_layer(const SimpleTensor &src) +{ + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const int cols = src.shape()[0]; + const int upper_dims = src.num_elements() / cols; + + for(int r = 0; r < upper_dims; ++r) + { + const T *src_row_ptr = src.data() + r * cols; + T *dst_row_ptr = dst.data() + r * cols; + + // Find max + const T max = *std::max_element(src_row_ptr, src_row_ptr + cols); + + // Regularize + T sum(0.f); + std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&sum, max](T val) + { + const T res(std::exp(val - max)); + sum += res; + return res; + }); + + // Normalize + std::transform(dst_row_ptr, dst_row_ptr + cols, dst_row_ptr, [sum](T val) + { + return val / sum; + }); + } + + return dst; +} + +template ::value, int>::type> +SimpleTensor softmax_layer(const SimpleTensor &src) +{ + using namespace fixed_point_arithmetic; + + // Create reference + SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; + + // Compute reference + const int cols = src.shape()[0]; + const int upper_dims = src.num_elements() / cols; + + for(int r = 0; r < upper_dims; ++r) + { + const T *src_row_ptr = src.data() + r * cols; + T *dst_row_ptr = dst.data() + r * cols; + + // Find max + const fixed_point max(*std::max_element(src_row_ptr, src_row_ptr + cols), src.fixed_point_position(), true); + + // Regularize + using promoted_type = fixed_point_arithmetic::traits::promote_t; + fixed_point sum(0, src.fixed_point_position(), true); + std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&](T val) + { + const fixed_point res = exp(fixed_point(val, src.fixed_point_position(), true) - max); + sum = add(sum, fixed_point(res.raw(), src.fixed_point_position(), true)); + return res.raw(); + }); + + // Normalize + fixed_point saturated_sum(sum); + std::transform(dst_row_ptr, dst_row_ptr + cols, dst_row_ptr, [&](T val) + { + return div(fixed_point(val, src.fixed_point_position(), true), saturated_sum).raw(); + }); + } + + return dst; +} + +template <> +SimpleTensor softmax_layer(const SimpleTensor &src) +{ + // Note: Output quantization info should always have scale = 1/256 and offset = 0 + const QuantizationInfo output_quantization_info = QuantizationInfo(1.f / 256, 0); + + SimpleTensor src_tmp = convert_from_asymmetric(src); + SimpleTensor dst_tmp = softmax_layer(src_tmp); + SimpleTensor dst = convert_to_asymmetric(dst_tmp, output_quantization_info); + return dst; +} + +template SimpleTensor softmax_layer(const SimpleTensor &src); +template SimpleTensor softmax_layer(const SimpleTensor &src); +template SimpleTensor softmax_layer(const SimpleTensor &src); +template SimpleTensor softmax_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/SoftmaxLayer.h b/tests/validation/reference/SoftmaxLayer.h new file mode 100644 index 0000000000..ab79bc4850 --- /dev/null +++ b/tests/validation/reference/SoftmaxLayer.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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_SOFTMAX_LAYER_H__ +#define __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type = 0> +SimpleTensor softmax_layer(const SimpleTensor &src); + +template ::value, int>::type = 0> +SimpleTensor softmax_layer(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ */ diff --git a/tests/validation/reference/TableLookup.cpp b/tests/validation/reference/TableLookup.cpp new file mode 100644 index 0000000000..7f105d99ca --- /dev/null +++ b/tests/validation/reference/TableLookup.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 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 "TableLookup.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut) +{ + SimpleTensor result(src.shape(), src.data_type()); + + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = rawlut.at(src[i]); + } + + return result; +} + +template SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); +template SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/TableLookup.h b/tests/validation/reference/TableLookup.h new file mode 100644 index 0000000000..3fdecac660 --- /dev/null +++ b/tests/validation/reference/TableLookup.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_TABLE_LOOKUP_H__ +#define __ARM_COMPUTE_TEST_TABLE_LOOKUP_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor table_lookup(const SimpleTensor &src, const std::map &rawlut); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_TABLE_LOOKUP_H__ */ diff --git a/tests/validation/reference/Threshold.cpp b/tests/validation/reference/Threshold.cpp new file mode 100644 index 0000000000..d0ef31df04 --- /dev/null +++ b/tests/validation/reference/Threshold.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017 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 src 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 src 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. src NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS src THE + * SOFTWARE. + */ +#include "Threshold.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor threshold(const SimpleTensor &src, T threshold, T false_value, T true_value, ThresholdType type, T upper) +{ + SimpleTensor dst(src.shape(), src.data_type()); + + switch(type) + { + case ThresholdType::BINARY: + for(int i = 0; i < src.num_elements(); ++i) + { + dst[i] = ((src[i] > threshold) ? true_value : false_value); + } + break; + case ThresholdType::RANGE: + for(int i = 0; i < src.num_elements(); ++i) + { + if(src[i] > upper) + { + dst[i] = false_value; + } + else if(src[i] < threshold) + { + dst[i] = false_value; + } + else + { + dst[i] = true_value; + } + } + break; + default: + ARM_COMPUTE_ERROR("Thresholding type not recognised"); + break; + } + + return dst; +} + +template SimpleTensor threshold(const SimpleTensor &src, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Threshold.h b/tests/validation/reference/Threshold.h new file mode 100644 index 0000000000..fbe2dba19b --- /dev/null +++ b/tests/validation/reference/Threshold.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_THRESHOLD_H__ +#define __ARM_COMPUTE_TEST_THRESHOLD_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor threshold(const SimpleTensor &src, T threshold, T false_value, T true_value, ThresholdType type, T upper); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_THRESHOLD_H__ */ diff --git a/tests/validation/reference/Transpose.cpp b/tests/validation/reference/Transpose.cpp new file mode 100644 index 0000000000..9f2e62e1aa --- /dev/null +++ b/tests/validation/reference/Transpose.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 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 "Transpose.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor transpose(const SimpleTensor &src) +{ + // Make rows the columns of the original shape + TensorShape dst_shape{ src.shape().y(), src.shape().x() }; + + // Create reference + SimpleTensor dst{ dst_shape, src.data_type() }; + + // Compute reference + for(int i = 0; i < src.num_elements(); ++i) + { + const Coordinates coord = index2coord(src.shape(), i); + const Coordinates dst_coord{ coord.y(), coord.x() }; + const size_t dst_index = coord2index(dst.shape(), dst_coord); + + dst[dst_index] = src[i]; + } + + return dst; +} + +template SimpleTensor transpose(const SimpleTensor &src); +template SimpleTensor transpose(const SimpleTensor &src); +template SimpleTensor transpose(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Transpose.h b/tests/validation/reference/Transpose.h new file mode 100644 index 0000000000..3f42f41253 --- /dev/null +++ b/tests/validation/reference/Transpose.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_TRANSPOSE_H__ +#define __ARM_COMPUTE_TEST_TRANSPOSE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor transpose(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_TRANSPOSE_H__ */ diff --git a/tests/validation/reference/Utils.cpp b/tests/validation/reference/Utils.cpp new file mode 100644 index 0000000000..d163e8436f --- /dev/null +++ b/tests/validation/reference/Utils.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2017 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 "Utils.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +// Return the bilinear value at a specified coordinate with different border modes +template +T bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value) +{ + const int idx = std::floor(xn); + const int idy = std::floor(yn); + + const float dx = xn - idx; + const float dy = yn - idy; + const float dx_1 = 1.0f - dx; + const float dy_1 = 1.0f - dy; + + const T border_value = constant_border_value; + + id.set(0, idx); + id.set(1, idy); + const float tl = tensor_elem_at(in, id, border_mode, border_value); + id.set(0, idx + 1); + id.set(1, idy); + const float tr = tensor_elem_at(in, id, border_mode, border_value); + id.set(0, idx); + id.set(1, idy + 1); + const float bl = tensor_elem_at(in, id, border_mode, border_value); + id.set(0, idx + 1); + id.set(1, idy + 1); + const float br = tensor_elem_at(in, id, border_mode, border_value); + + return static_cast(tl * (dx_1 * dy_1) + tr * (dx * dy_1) + bl * (dx_1 * dy) + br * (dx * dy)); +} + +template uint8_t bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, uint8_t constant_border_value); +template int16_t bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, int16_t constant_border_value); +template half bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, half constant_border_value); +template float bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, float constant_border_value); + +RawTensor transpose(const RawTensor &src, int chunk_width) +{ + // Create reference + TensorShape dst_shape(src.shape()); + dst_shape.set(0, src.shape().y() * chunk_width); + dst_shape.set(1, std::ceil(src.shape().x() / static_cast(chunk_width))); + + RawTensor dst{ dst_shape, src.data_type() }; + + // Compute reference + uint8_t *out_ptr = dst.data(); + + for(int i = 0; i < dst.num_elements(); i += chunk_width) + { + Coordinates coord = index2coord(dst.shape(), i); + size_t coord_x = coord.x(); + coord.set(0, coord.y() * chunk_width); + coord.set(1, coord_x / chunk_width); + + const int num_elements = std::min(chunk_width, src.shape().x() - coord.x()); + + std::copy_n(static_cast(src(coord)), num_elements * src.element_size(), out_ptr); + + out_ptr += chunk_width * dst.element_size(); + } + + return dst; +} + +bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) +{ + if(border_mode != BorderMode::UNDEFINED) + { + return true; + } + if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) + { + return true; + } + return false; +} +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Utils.h b/tests/validation/reference/Utils.h new file mode 100644 index 0000000000..2aa77c6ff7 --- /dev/null +++ b/tests/validation/reference/Utils.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2017 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_VALIDATION_UTILS_H__ +#define __ARM_COMPUTE_TEST_VALIDATION_UTILS_H__ + +#include "arm_compute/core/Types.h" +#include "tests/Globals.h" +#include "tests/ILutAccessor.h" +#include "tests/Types.h" + +#include +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +/** Checks if a pixel has valid coordinates + * + * @param x X coordinate + * @param y Y coordinate + * @param width Width of the image + * @param height Height of the image + * @param border_size Border size + * + * @return True if pixel is valid else false + */ +inline bool is_valid_pixel_index(int x, int y, int width, int height, int border_size) +{ + return ((x >= -border_size) && (y >= -border_size) && (x < (width + border_size)) && (y < height + border_size)); +} + +// Return a tensor element at a specified coordinate with different border modes +template +T tensor_elem_at(const SimpleTensor &src, Coordinates coord, BorderMode border_mode, T constant_border_value) +{ + const int x = coord.x(); + const int y = coord.y(); + const int width = src.shape().x(); + const int height = src.shape().y(); + + // If coordinates beyond range of tensor's width or height + if(x < 0 || y < 0 || x >= width || y >= height) + { + if(border_mode == BorderMode::REPLICATE) + { + coord.set(0, std::max(0, std::min(x, width - 1))); + coord.set(1, std::max(0, std::min(y, height - 1))); + } + else + { + return constant_border_value; + } + } + + return src[coord2index(src.shape(), coord)]; +} + +template +T bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value); + +/* Apply 2D spatial filter on a single element of @p in at coordinates @p coord + * + * - filter sizes have to be odd number + * - Row major order of filter assumed + * - TO_ZERO rounding policy assumed + * - SATURATE convert policy assumed + */ +template +void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor &src, SimpleTensor &dst, const TensorShape &filter_shape, const V *filter_itr, double scale, BorderMode border_mode, + T constant_border_value = T(0)) +{ + double val = 0.; + const int x = coord.x(); + const int y = coord.y(); + for(int j = y - static_cast(filter_shape[1] / 2); j <= y + static_cast(filter_shape[1] / 2); ++j) + { + for(int i = x - static_cast(filter_shape[0] / 2); i <= x + static_cast(filter_shape[0] / 2); ++i) + { + coord.set(0, i); + coord.set(1, j); + val += static_cast(*filter_itr) * tensor_elem_at(src, coord, border_mode, constant_border_value); + ++filter_itr; + } + } + coord.set(0, x); + coord.set(1, y); + dst[coord2index(src.shape(), coord)] = saturate_cast(support::cpp11::trunc(val * scale)); +} + +RawTensor transpose(const RawTensor &src, int chunk_width = 1); + +/** Fill matrix random. + * + * @param[in,out] matrix Matrix + */ +template +inline void fill_warp_matrix(std::array &matrix) +{ + std::mt19937 gen(library.get()->seed()); + std::uniform_real_distribution dist(-1, 1); + for(auto &x : matrix) + { + x = dist(gen); + } + if(SIZE == 9) + { + // This is only used in Warp Perspective, we set M[3][3] = 1 so that Z0 is not 0 and we avoid division by 0. + matrix[8] = 1.f; + } +} + +bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode); +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_VALIDATION_UTILS_H__ */ diff --git a/tests/validation/reference/UtilsQuantizedAsymm.h b/tests/validation/reference/UtilsQuantizedAsymm.h new file mode 100644 index 0000000000..b7b69d588a --- /dev/null +++ b/tests/validation/reference/UtilsQuantizedAsymm.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 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_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ +#define __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +/** Rounded to nearest division by a power-of-two. */ +inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) +{ + const int32_t mask = (1 << exponent) - 1; + const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0); + return (x >> exponent) + ((x & mask) > threshold ? 1 : 0); +} + +/** Multiplication of two integers. The same as ARMv7 NEON VQRDMULH instruction. */ +inline int32_t asymm_int_mult(int32_t a, int32_t b) +{ + bool overflow = a == b && a == std::numeric_limits::min(); + int64_t a_64(a); + int64_t b_64(b); + int64_t ab_64 = a_64 * b_64; + int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); + int32_t ab_x2_high32 = static_cast((ab_64 + nudge) / (1ll << 31)); + return overflow ? std::numeric_limits::max() : ab_x2_high32; +} +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H__ */ diff --git a/tests/validation/reference/WarpAffine.cpp b/tests/validation/reference/WarpAffine.cpp new file mode 100644 index 0000000000..7b903b7661 --- /dev/null +++ b/tests/validation/reference/WarpAffine.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017 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 "WarpAffine.h" + +#include "Utils.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) +{ + if(border_mode != BorderMode::UNDEFINED) + { + return true; + } + if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) + { + return true; + } + return false; +} + +template +SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + + // x0 = M00 * x + M01 * y + M02 + // y0 = M10 * x + M11 * y + M12 + const float M00 = matrix[0]; + const float M10 = matrix[1]; + const float M01 = matrix[0 + 1 * 2]; + const float M11 = matrix[1 + 1 * 2]; + const float M02 = matrix[0 + 2 * 2]; + const float M12 = matrix[1 + 2 * 2]; + + const int width = src.shape().x(); + const int height = src.shape().y(); + + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + valid_mask[element_idx] = 1; + Coordinates id = index2coord(src.shape(), element_idx); + int idx = id.x(); + int idy = id.y(); + + float x0 = M00 * idx + M01 * idy + M02; + float y0 = M10 * idx + M11 * idy + M12; + + id.set(0, static_cast(std::floor(x0))); + id.set(1, static_cast(std::floor(y0))); + if((0 <= y0) && (y0 < height) && (0 <= x0) && (x0 < width)) + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); + break; + case InterpolationPolicy::BILINEAR: + (valid_bilinear_policy(x0, y0, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value) : + valid_mask[element_idx] = 0; + break; + case InterpolationPolicy::AREA: + default: + ARM_COMPUTE_ERROR("Interpolation not supported"); + } + } + else + { + if(border_mode == BorderMode::UNDEFINED) + { + valid_mask[element_idx] = 0; + } + else + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + if(border_mode == BorderMode::CONSTANT) + { + dst[element_idx] = constant_border_value; + } + else if(border_mode == BorderMode::REPLICATE) + { + id.set(0, std::max(0, std::min(static_cast(x0), width - 1))); + id.set(1, std::max(0, std::min(static_cast(y0), height - 1))); + dst[element_idx] = src[coord2index(src.shape(), id)]; + } + break; + case InterpolationPolicy::BILINEAR: + dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value); + break; + case InterpolationPolicy::AREA: + default: + ARM_COMPUTE_ERROR("Interpolation not supported"); + } + } + } + } + + return dst; +} + +template SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, + uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute \ No newline at end of file diff --git a/tests/validation/reference/WarpAffine.h b/tests/validation/reference/WarpAffine.h new file mode 100644 index 0000000000..973b1b2e29 --- /dev/null +++ b/tests/validation/reference/WarpAffine.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_WARP_AFFINE_H__ +#define __ARM_COMPUTE_TEST_WARP_AFFINE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor warp_affine(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_WARP_AFFINE_H__ */ diff --git a/tests/validation/reference/WarpPerspective.cpp b/tests/validation/reference/WarpPerspective.cpp new file mode 100644 index 0000000000..7a50253d69 --- /dev/null +++ b/tests/validation/reference/WarpPerspective.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2017 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/Helpers.h" + +#include "Utils.h" +#include "WarpPerspective.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) +{ + SimpleTensor dst(src.shape(), src.data_type()); + + // x0 = M00 * x + M01 * y + M02 + // y0 = M10 * x + M11 * y + M12 + // z0 = M20 * x + M21 * y + M22 + // xn = x0 / z0 + // yn = y0 / z0 + const float M00 = matrix[0]; + const float M10 = matrix[1]; + const float M20 = matrix[2]; + const float M01 = matrix[0 + 1 * 3]; + const float M11 = matrix[1 + 1 * 3]; + const float M21 = matrix[2 + 1 * 3]; + const float M02 = matrix[0 + 2 * 3]; + const float M12 = matrix[1 + 2 * 3]; + const float M22 = matrix[2 + 2 * 3]; + + const int width = src.shape().x(); + const int height = src.shape().y(); + + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) + { + valid_mask[element_idx] = 1; + Coordinates id = index2coord(src.shape(), element_idx); + const int idx = id.x(); + const int idy = id.y(); + const float z0 = M20 * idx + M21 * idy + M22; + + const float x0 = (M00 * idx + M01 * idy + M02); + const float y0 = (M10 * idx + M11 * idy + M12); + + const float xn = x0 / z0; + const float yn = y0 / z0; + id.set(0, static_cast(std::floor(xn))); + id.set(1, static_cast(std::floor(yn))); + if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width)) + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); + break; + case InterpolationPolicy::BILINEAR: + (valid_bilinear_policy(xn, yn, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value) : valid_mask[element_idx] = 0; + break; + case InterpolationPolicy::AREA: + default: + ARM_COMPUTE_ERROR("Interpolation not supported"); + break; + } + } + else + { + if(border_mode == BorderMode::UNDEFINED) + { + valid_mask[element_idx] = 0; + } + else + { + switch(policy) + { + case InterpolationPolicy::NEAREST_NEIGHBOR: + if(border_mode == BorderMode::CONSTANT) + { + dst[element_idx] = constant_border_value; + } + else if(border_mode == BorderMode::REPLICATE) + { + id.set(0, std::max(0, std::min(static_cast(xn), width - 1))); + id.set(1, std::max(0, std::min(static_cast(yn), height - 1))); + dst[element_idx] = src[coord2index(src.shape(), id)]; + } + break; + case InterpolationPolicy::BILINEAR: + dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value); + break; + case InterpolationPolicy::AREA: + default: + ARM_COMPUTE_ERROR("Interpolation not supported"); + break; + } + } + } + } + return dst; +} + +template SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, + uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/WarpPerspective.h b/tests/validation/reference/WarpPerspective.h new file mode 100644 index 0000000000..2367f4d6dc --- /dev/null +++ b/tests/validation/reference/WarpPerspective.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_WARP_PERSPECTIVE_H__ +#define __ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor warp_perspective(const SimpleTensor &src, SimpleTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H__ */ -- cgit v1.2.1