From 171214c8ff275c90cd4f7fc23a34ec2c83b5ea39 Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Wed, 9 Sep 2020 09:07:37 +0100 Subject: IVGCVSW-5300 Remove some boost::numeric_cast from armnn/backends * Replaced with armnn/utility/NumericCast.hpp * Some exclusions in reference backend * Excluded as requires float implementation in NumericCast.hpp Signed-off-by: Matthew Sloyan Change-Id: I9e4e9cd502c865452128fa04415fd6f250baa855 --- .../test/layerTests/ActivationTestImpl.cpp | 10 +- .../test/layerTests/Conv2dTestImpl.cpp | 101 +++++++++++---------- .../test/layerTests/LstmTestImpl.cpp | 19 ++-- .../test/layerTests/NormalizationTestImpl.cpp | 10 +- .../test/layerTests/Pooling2dTestImpl.cpp | 17 ++-- 5 files changed, 82 insertions(+), 75 deletions(-) (limited to 'src/backends/backendsCommon/test/layerTests') diff --git a/src/backends/backendsCommon/test/layerTests/ActivationTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/ActivationTestImpl.cpp index 543ea7716a..6d83b1ca99 100644 --- a/src/backends/backendsCommon/test/layerTests/ActivationTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/ActivationTestImpl.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include #include @@ -1261,10 +1263,10 @@ LayerTestResult CompareActivationTestImpl( LayerTestResult ret(outputTensorInfo); auto boostArrayExtents = boost::extents - [boost::numeric_cast(batchSize)] - [boost::numeric_cast(channels)] - [boost::numeric_cast(height)] - [boost::numeric_cast(width)]; + [armnn::numeric_cast(batchSize)] + [armnn::numeric_cast(channels)] + [armnn::numeric_cast(height)] + [armnn::numeric_cast(width)]; ret.output.resize(boostArrayExtents); ret.outputExpected.resize(boostArrayExtents); diff --git a/src/backends/backendsCommon/test/layerTests/Conv2dTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/Conv2dTestImpl.cpp index e99a26e81e..690d1cd66f 100644 --- a/src/backends/backendsCommon/test/layerTests/Conv2dTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/Conv2dTestImpl.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -219,20 +220,20 @@ LayerTestResult SimpleConvolution2dTestImpl( uint32_t dilationY = 1) { armnn::IgnoreUnused(memoryManager); - unsigned int inputHeight = boost::numeric_cast(originalInput.shape()[2]); - unsigned int inputWidth = boost::numeric_cast(originalInput.shape()[3]); - unsigned int inputChannels = boost::numeric_cast(originalInput.shape()[1]); - unsigned int inputNum = boost::numeric_cast(originalInput.shape()[0]); + unsigned int inputHeight = armnn::numeric_cast(originalInput.shape()[2]); + unsigned int inputWidth = armnn::numeric_cast(originalInput.shape()[3]); + unsigned int inputChannels = armnn::numeric_cast(originalInput.shape()[1]); + unsigned int inputNum = armnn::numeric_cast(originalInput.shape()[0]); - unsigned int outputHeight = boost::numeric_cast(originalOutputExpected.shape()[2]); - unsigned int outputWidth = boost::numeric_cast(originalOutputExpected.shape()[3]); - unsigned int outputChannels = boost::numeric_cast(originalOutputExpected.shape()[1]); - unsigned int outputNum = boost::numeric_cast(originalOutputExpected.shape()[0]); + unsigned int outputHeight = armnn::numeric_cast(originalOutputExpected.shape()[2]); + unsigned int outputWidth = armnn::numeric_cast(originalOutputExpected.shape()[3]); + unsigned int outputChannels = armnn::numeric_cast(originalOutputExpected.shape()[1]); + unsigned int outputNum = armnn::numeric_cast(originalOutputExpected.shape()[0]); - unsigned int kernelHeight = boost::numeric_cast(originalKernel.shape()[2]); - unsigned int kernelWidth = boost::numeric_cast(originalKernel.shape()[3]); - unsigned int kernelChannels = boost::numeric_cast(originalKernel.shape()[1]); - unsigned int kernelDepthMul = boost::numeric_cast(originalKernel.shape()[0]); + unsigned int kernelHeight = armnn::numeric_cast(originalKernel.shape()[2]); + unsigned int kernelWidth = armnn::numeric_cast(originalKernel.shape()[3]); + unsigned int kernelChannels = armnn::numeric_cast(originalKernel.shape()[1]); + unsigned int kernelDepthMul = armnn::numeric_cast(originalKernel.shape()[0]); bool biasEnabled = bias.size() > 0; @@ -385,20 +386,20 @@ LayerTestResult SimpleConvolution2dNhwcTestImpl( uint32_t strideY = 1) { armnn::IgnoreUnused(qScale, qOffset); - unsigned int inputNum = boost::numeric_cast(input.shape()[0]); - unsigned int inputChannels = boost::numeric_cast(input.shape()[3]); - unsigned int inputHeight = boost::numeric_cast(input.shape()[1]); - unsigned int inputWidth = boost::numeric_cast(input.shape()[2]); + unsigned int inputNum = armnn::numeric_cast(input.shape()[0]); + unsigned int inputChannels = armnn::numeric_cast(input.shape()[3]); + unsigned int inputHeight = armnn::numeric_cast(input.shape()[1]); + unsigned int inputWidth = armnn::numeric_cast(input.shape()[2]); - unsigned int kernelChanMul = boost::numeric_cast(kernel.shape()[0]); - unsigned int kernelChannels = boost::numeric_cast(kernel.shape()[3]); - unsigned int kernelHeight = boost::numeric_cast(kernel.shape()[1]); - unsigned int kernelWidth = boost::numeric_cast(kernel.shape()[2]); + unsigned int kernelChanMul = armnn::numeric_cast(kernel.shape()[0]); + unsigned int kernelChannels = armnn::numeric_cast(kernel.shape()[3]); + unsigned int kernelHeight = armnn::numeric_cast(kernel.shape()[1]); + unsigned int kernelWidth = armnn::numeric_cast(kernel.shape()[2]); - unsigned int outputNum = boost::numeric_cast(outputExpected.shape()[0]); - unsigned int outputChannels = boost::numeric_cast(outputExpected.shape()[3]); - unsigned int outputHeight = boost::numeric_cast(outputExpected.shape()[1]); - unsigned int outputWidth = boost::numeric_cast(outputExpected.shape()[2]); + unsigned int outputNum = armnn::numeric_cast(outputExpected.shape()[0]); + unsigned int outputChannels = armnn::numeric_cast(outputExpected.shape()[3]); + unsigned int outputHeight = armnn::numeric_cast(outputExpected.shape()[1]); + unsigned int outputWidth = armnn::numeric_cast(outputExpected.shape()[2]); bool biasEnabled = bias.size() > 0; @@ -1643,18 +1644,18 @@ LayerTestResult DepthwiseConvolution2dAsymmetricTestImpl( uint32_t strideX = 1, uint32_t strideY = 1) { - unsigned int inputNum = boost::numeric_cast(input.shape()[0]); - unsigned int inputChannels = boost::numeric_cast(input.shape()[1]); - unsigned int inputHeight = boost::numeric_cast(input.shape()[2]); - unsigned int inputWidth = boost::numeric_cast(input.shape()[3]); - unsigned int kernelChanMul = boost::numeric_cast(kernel.shape()[0]); - unsigned int kernelChannels = boost::numeric_cast(kernel.shape()[1]); - unsigned int kernelHeight = boost::numeric_cast(kernel.shape()[2]); - unsigned int kernelWidth = boost::numeric_cast(kernel.shape()[3]); - unsigned int outputNum = boost::numeric_cast(outputExpected.shape()[0]); - unsigned int outputChannels = boost::numeric_cast(outputExpected.shape()[1]); - unsigned int outputHeight = boost::numeric_cast(outputExpected.shape()[2]); - unsigned int outputWidth = boost::numeric_cast(outputExpected.shape()[3]); + unsigned int inputNum = armnn::numeric_cast(input.shape()[0]); + unsigned int inputChannels = armnn::numeric_cast(input.shape()[1]); + unsigned int inputHeight = armnn::numeric_cast(input.shape()[2]); + unsigned int inputWidth = armnn::numeric_cast(input.shape()[3]); + unsigned int kernelChanMul = armnn::numeric_cast(kernel.shape()[0]); + unsigned int kernelChannels = armnn::numeric_cast(kernel.shape()[1]); + unsigned int kernelHeight = armnn::numeric_cast(kernel.shape()[2]); + unsigned int kernelWidth = armnn::numeric_cast(kernel.shape()[3]); + unsigned int outputNum = armnn::numeric_cast(outputExpected.shape()[0]); + unsigned int outputChannels = armnn::numeric_cast(outputExpected.shape()[1]); + unsigned int outputHeight = armnn::numeric_cast(outputExpected.shape()[2]); + unsigned int outputWidth = armnn::numeric_cast(outputExpected.shape()[3]); // If a bias is used, its size must equal the number of output channels. bool biasEnabled = bias.size() > 0; @@ -2151,20 +2152,20 @@ LayerTestResult DepthwiseConvolution2dTestImpl( uint32_t dilationX = 1, uint32_t dilationY = 1) { - unsigned int inputHeight = boost::numeric_cast(originalInput.shape()[2]); - unsigned int inputWidth = boost::numeric_cast(originalInput.shape()[3]); - unsigned int inputChannels = boost::numeric_cast(originalInput.shape()[1]); - unsigned int inputNum = boost::numeric_cast(originalInput.shape()[0]); - - unsigned int outputHeight = boost::numeric_cast(originalOutputExpected.shape()[2]); - unsigned int outputWidth = boost::numeric_cast(originalOutputExpected.shape()[3]); - unsigned int outputChannels = boost::numeric_cast(originalOutputExpected.shape()[1]); - unsigned int outputNum = boost::numeric_cast(originalOutputExpected.shape()[0]); - - unsigned int kernelHeight = boost::numeric_cast(originalKernel.shape()[2]); - unsigned int kernelWidth = boost::numeric_cast(originalKernel.shape()[3]); - unsigned int kernelChannels = boost::numeric_cast(originalKernel.shape()[1]); - unsigned int kernelDepthMul = boost::numeric_cast(originalKernel.shape()[0]); + unsigned int inputHeight = armnn::numeric_cast(originalInput.shape()[2]); + unsigned int inputWidth = armnn::numeric_cast(originalInput.shape()[3]); + unsigned int inputChannels = armnn::numeric_cast(originalInput.shape()[1]); + unsigned int inputNum = armnn::numeric_cast(originalInput.shape()[0]); + + unsigned int outputHeight = armnn::numeric_cast(originalOutputExpected.shape()[2]); + unsigned int outputWidth = armnn::numeric_cast(originalOutputExpected.shape()[3]); + unsigned int outputChannels = armnn::numeric_cast(originalOutputExpected.shape()[1]); + unsigned int outputNum = armnn::numeric_cast(originalOutputExpected.shape()[0]); + + unsigned int kernelHeight = armnn::numeric_cast(originalKernel.shape()[2]); + unsigned int kernelWidth = armnn::numeric_cast(originalKernel.shape()[3]); + unsigned int kernelChannels = armnn::numeric_cast(originalKernel.shape()[1]); + unsigned int kernelDepthMul = armnn::numeric_cast(originalKernel.shape()[0]); bool biasEnabled = bias.size() > 0; diff --git a/src/backends/backendsCommon/test/layerTests/LstmTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/LstmTestImpl.cpp index 8f39f42452..088ca3b4c2 100644 --- a/src/backends/backendsCommon/test/layerTests/LstmTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/LstmTestImpl.cpp @@ -7,6 +7,7 @@ #include +#include #include @@ -144,9 +145,9 @@ LstmNoCifgNoPeepholeNoProjectionTestImpl( armnn::DataType constantDataType = armnn::DataType::Float32) { IgnoreUnused(memoryManager); - unsigned int batchSize = boost::numeric_cast(input.shape()[0]); - unsigned int inputSize = boost::numeric_cast(input.shape()[1]); - unsigned int outputSize = boost::numeric_cast(outputExpected.shape()[1]); + unsigned int batchSize = armnn::numeric_cast(input.shape()[0]); + unsigned int inputSize = armnn::numeric_cast(input.shape()[1]); + unsigned int outputSize = armnn::numeric_cast(outputExpected.shape()[1]); // cellSize and outputSize have the same size when there is no projection. unsigned numUnits = outputSize; @@ -1069,10 +1070,10 @@ LayerTestResult LstmLayerWithCifgWithPeepholeNoProjectionTestImpl( bool peepholeEnabled = true; bool projectionEnabled = false; // These are not the input and the output of Lstm yet - unsigned int batchSize = boost::numeric_cast(input.shape()[0]); - unsigned int inputSize = boost::numeric_cast(input.shape()[1]); + unsigned int batchSize = armnn::numeric_cast(input.shape()[0]); + unsigned int inputSize = armnn::numeric_cast(input.shape()[1]); - unsigned int outputSize = boost::numeric_cast(outputExpected.shape()[1]); + unsigned int outputSize = armnn::numeric_cast(outputExpected.shape()[1]); const unsigned int cellSize = outputSize; @@ -1560,9 +1561,9 @@ LayerTestResult QuantizedLstmTestImpl( const boost::multi_array& outputExpected) { IgnoreUnused(memoryManager); - auto numBatches = boost::numeric_cast(input.shape()[0]); - auto inputSize = boost::numeric_cast(input.shape()[1]); - auto outputSize = boost::numeric_cast(outputExpected.shape()[1]); + auto numBatches = armnn::numeric_cast(input.shape()[0]); + auto inputSize = armnn::numeric_cast(input.shape()[1]); + auto outputSize = armnn::numeric_cast(outputExpected.shape()[1]); // Scale/Offset for input/output, cellState In/Out, weights, bias float inputOutputScale = 0.0078125f; diff --git a/src/backends/backendsCommon/test/layerTests/NormalizationTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/NormalizationTestImpl.cpp index b42b180dc9..2e8e16f0c2 100644 --- a/src/backends/backendsCommon/test/layerTests/NormalizationTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/NormalizationTestImpl.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include @@ -102,7 +104,7 @@ LayerTestResult SimpleNormalizationTestImpl( // pow((kappa + (accumulatedScale * alpha)), beta) // ...where accumulatedScale is the sum of every element squared. float divisor[inputNum]; - for(int i = 0; i < boost::numeric_cast(inputNum); i++) + for(int i = 0; i < armnn::numeric_cast(inputNum); i++) { float accumulatedScale = input[i][0][0][0]*input[i][0][0][0] + input[i][0][0][1]*input[i][0][0][1] + @@ -129,11 +131,11 @@ LayerTestResult SimpleNormalizationTestImpl( // ...where adjacent channels means within half the normSize for the channel // The test data has only one channel, so this is simplified below. std::vector outputVector; - for (int n = 0; n < boost::numeric_cast(inputNum); ++n) + for (int n = 0; n < armnn::numeric_cast(inputNum); ++n) { - for (int h = 0; h < boost::numeric_cast(inputHeight); ++h) + for (int h = 0; h < armnn::numeric_cast(inputHeight); ++h) { - for (int w = 0; w < boost::numeric_cast(inputWidth); ++w) + for (int w = 0; w < armnn::numeric_cast(inputWidth); ++w) { float accumulatedScale = input[n][0][h][w]*input[n][0][h][w]; float scale = powf((kappa + accumulatedScale * alpha), -beta); diff --git a/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp index a4f87ff3ed..70e2e61475 100644 --- a/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp @@ -15,6 +15,7 @@ #include #include +#include #include @@ -48,15 +49,15 @@ LayerTestResult SimplePooling2dTestImpl( auto widthIndex = dimensionIndices.GetWidthIndex(); auto channelsIndex = dimensionIndices.GetChannelsIndex(); - unsigned int inputHeight = boost::numeric_cast(input.shape()[heightIndex]); - unsigned int inputWidth = boost::numeric_cast(input.shape()[widthIndex]); - unsigned int inputChannels = boost::numeric_cast(input.shape()[channelsIndex]); - unsigned int inputBatchSize = boost::numeric_cast(input.shape()[0]); + unsigned int inputHeight = armnn::numeric_cast(input.shape()[heightIndex]); + unsigned int inputWidth = armnn::numeric_cast(input.shape()[widthIndex]); + unsigned int inputChannels = armnn::numeric_cast(input.shape()[channelsIndex]); + unsigned int inputBatchSize = armnn::numeric_cast(input.shape()[0]); - unsigned int outputHeight = boost::numeric_cast(outputExpected.shape()[heightIndex]); - unsigned int outputWidth = boost::numeric_cast(outputExpected.shape()[widthIndex]); - unsigned int outputChannels = boost::numeric_cast(outputExpected.shape()[channelsIndex]); - unsigned int outputBatchSize = boost::numeric_cast(outputExpected.shape()[0]); + unsigned int outputHeight = armnn::numeric_cast(outputExpected.shape()[heightIndex]); + unsigned int outputWidth = armnn::numeric_cast(outputExpected.shape()[widthIndex]); + unsigned int outputChannels = armnn::numeric_cast(outputExpected.shape()[channelsIndex]); + unsigned int outputBatchSize = armnn::numeric_cast(outputExpected.shape()[0]); armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo( inputBatchSize, inputChannels, inputHeight, inputWidth, dataLayout, ArmnnType); -- cgit v1.2.1