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 --- src/backends/reference/RefLayerSupport.cpp | 7 +-- src/backends/reference/workloads/ArgMinMax.cpp | 4 +- .../reference/workloads/DetectionPostProcess.cpp | 7 +-- src/backends/reference/workloads/Gather.cpp | 5 +- src/backends/reference/workloads/LogSoftmax.cpp | 9 ++-- src/backends/reference/workloads/Mean.cpp | 4 +- src/backends/reference/workloads/Pooling2d.cpp | 53 +++++++++++----------- .../workloads/RefL2NormalizationWorkload.cpp | 17 ++++--- .../workloads/RefNormalizationWorkload.cpp | 25 +++++----- src/backends/reference/workloads/StridedSlice.cpp | 13 +++--- 10 files changed, 70 insertions(+), 74 deletions(-) (limited to 'src/backends/reference') diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 5e3c96d31d..52c079fae4 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -9,17 +9,14 @@ #include #include #include +#include #include #include -#include - #include #include -using namespace boost; - namespace armnn { @@ -1326,7 +1323,7 @@ bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, } else { - auto outputDim = input.GetNumDimensions() - boost::numeric_cast(descriptor.m_Axis.size()); + auto outputDim = input.GetNumDimensions() - armnn::numeric_cast(descriptor.m_Axis.size()); if (outputDim > 0) { diff --git a/src/backends/reference/workloads/ArgMinMax.cpp b/src/backends/reference/workloads/ArgMinMax.cpp index 637aa17013..c455c52e5a 100644 --- a/src/backends/reference/workloads/ArgMinMax.cpp +++ b/src/backends/reference/workloads/ArgMinMax.cpp @@ -7,7 +7,7 @@ #include -#include +#include namespace armnn { @@ -39,7 +39,7 @@ void ArgMinMax(Decoder& in, int32_t* out, const TensorInfo& inputTensorIn tmpIndex = i; } } - out[outer * innerElements + inner] = boost::numeric_cast(tmpIndex); + out[outer * innerElements + inner] = armnn::numeric_cast(tmpIndex); } } } diff --git a/src/backends/reference/workloads/DetectionPostProcess.cpp b/src/backends/reference/workloads/DetectionPostProcess.cpp index 61a504ec6b..ce07110da9 100644 --- a/src/backends/reference/workloads/DetectionPostProcess.cpp +++ b/src/backends/reference/workloads/DetectionPostProcess.cpp @@ -6,6 +6,7 @@ #include "DetectionPostProcess.hpp" #include +#include #include @@ -67,7 +68,7 @@ std::vector NonMaxSuppression(unsigned int numBoxes, } // Sort the indices based on scores. - unsigned int numAboveThreshold = boost::numeric_cast(scoresAboveThreshold.size()); + unsigned int numAboveThreshold = armnn::numeric_cast(scoresAboveThreshold.size()); std::vector sortedIndices = GenerateRangeK(numAboveThreshold); TopKSort(numAboveThreshold, sortedIndices.data(), scoresAboveThreshold.data(), numAboveThreshold); @@ -267,7 +268,7 @@ void DetectionPostProcess(const TensorInfo& boxEncodingsInfo, } // Select max detection numbers of the highest score across all classes - unsigned int numSelected = boost::numeric_cast(selectedBoxesAfterNms.size()); + unsigned int numSelected = armnn::numeric_cast(selectedBoxesAfterNms.size()); unsigned int numOutput = std::min(desc.m_MaxDetections, numSelected); // Sort the max scores among the selected indices. @@ -311,7 +312,7 @@ void DetectionPostProcess(const TensorInfo& boxEncodingsInfo, desc.m_MaxDetections, desc.m_NmsIouThreshold); - unsigned int numSelected = boost::numeric_cast(selectedIndices.size()); + unsigned int numSelected = armnn::numeric_cast(selectedIndices.size()); unsigned int numOutput = std::min(desc.m_MaxDetections, numSelected); AllocateOutputData(detectionBoxesInfo.GetShape()[1], numOutput, boxCorners, selectedIndices, diff --git a/src/backends/reference/workloads/Gather.cpp b/src/backends/reference/workloads/Gather.cpp index 3e2190c81b..03aa2458f5 100644 --- a/src/backends/reference/workloads/Gather.cpp +++ b/src/backends/reference/workloads/Gather.cpp @@ -9,8 +9,7 @@ #include #include - -#include +#include namespace armnn { @@ -37,7 +36,7 @@ void Gather(const TensorInfo& paramsInfo, unsigned int outIndex = 0; for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i) { - unsigned int indx = boost::numeric_cast(indices[i]); + unsigned int indx = armnn::numeric_cast(indices[i]); ARMNN_ASSERT(indices[i] >= 0 && indx < paramsShape[0]); diff --git a/src/backends/reference/workloads/LogSoftmax.cpp b/src/backends/reference/workloads/LogSoftmax.cpp index 1998f50c87..2b6384913e 100644 --- a/src/backends/reference/workloads/LogSoftmax.cpp +++ b/src/backends/reference/workloads/LogSoftmax.cpp @@ -8,17 +8,16 @@ #include #include #include +#include #include -#include - namespace { inline bool ValidateAxis(int axis, unsigned int numDimensions) { - const int sNumDimensions = boost::numeric_cast(numDimensions); + const int sNumDimensions = armnn::numeric_cast(numDimensions); return axis < sNumDimensions && axis >= -sNumDimensions; } @@ -40,8 +39,8 @@ void LogSoftmax(Decoder& input, IgnoreUnused(axisIsValid); unsigned int uAxis = descriptor.m_Axis < 0 ? - numDimensions - boost::numeric_cast(std::abs(descriptor.m_Axis)) : - boost::numeric_cast(descriptor.m_Axis); + numDimensions - armnn::numeric_cast(std::abs(descriptor.m_Axis)) : + armnn::numeric_cast(descriptor.m_Axis); const TensorShape& inputShape = inputInfo.GetShape(); const unsigned int outerSize = armnnUtils::GetNumElementsBetween(inputShape, 0, uAxis); diff --git a/src/backends/reference/workloads/Mean.cpp b/src/backends/reference/workloads/Mean.cpp index 72080ef042..e43a4d5312 100644 --- a/src/backends/reference/workloads/Mean.cpp +++ b/src/backends/reference/workloads/Mean.cpp @@ -6,6 +6,8 @@ #include "Mean.hpp" #include +#include + #include #include @@ -111,7 +113,7 @@ void Mean(const armnn::TensorInfo& inputInfo, resolvedAxis.push_back(idx); } } - auto numResolvedAxis = boost::numeric_cast(resolvedAxis.size()); + auto numResolvedAxis = armnn::numeric_cast(resolvedAxis.size()); // Iterates through input_data and sum up the reduced axis. for (bool hasNext = true; hasNext; hasNext = NextIndex(inputNumDims, inputDims, tempIndex)) diff --git a/src/backends/reference/workloads/Pooling2d.cpp b/src/backends/reference/workloads/Pooling2d.cpp index 9b220619a4..435671ffad 100644 --- a/src/backends/reference/workloads/Pooling2d.cpp +++ b/src/backends/reference/workloads/Pooling2d.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -151,20 +152,20 @@ void Pooling2d(Decoder& rInputDecoder, auto heightIndex = dataLayout.GetHeightIndex(); auto widthIndex = dataLayout.GetWidthIndex(); - const int batchSize = boost::numeric_cast(outputInfo.GetShape()[0]); - const int channels = boost::numeric_cast(outputInfo.GetShape()[channelsIndex]); - const int heightOutput = boost::numeric_cast(outputInfo.GetShape()[heightIndex]); - const int widthOutput = boost::numeric_cast(outputInfo.GetShape()[widthIndex]); - const int heightInput = boost::numeric_cast(inputInfo.GetShape()[heightIndex]); - const int widthInput = boost::numeric_cast(inputInfo.GetShape()[widthIndex]); - const int padLeft = boost::numeric_cast(params.m_PadLeft); - const int padRight = boost::numeric_cast(params.m_PadRight); - const int padTop = boost::numeric_cast(params.m_PadTop); - const int padBottom = boost::numeric_cast(params.m_PadBottom); - const int strideX = boost::numeric_cast(params.m_StrideX); - const int strideY = boost::numeric_cast(params.m_StrideY); - const int poolHeight = boost::numeric_cast(params.m_PoolHeight); - const int poolWidth = boost::numeric_cast(params.m_PoolWidth); + const int batchSize = armnn::numeric_cast(outputInfo.GetShape()[0]); + const int channels = armnn::numeric_cast(outputInfo.GetShape()[channelsIndex]); + const int heightOutput = armnn::numeric_cast(outputInfo.GetShape()[heightIndex]); + const int widthOutput = armnn::numeric_cast(outputInfo.GetShape()[widthIndex]); + const int heightInput = armnn::numeric_cast(inputInfo.GetShape()[heightIndex]); + const int widthInput = armnn::numeric_cast(inputInfo.GetShape()[widthIndex]); + const int padLeft = armnn::numeric_cast(params.m_PadLeft); + const int padRight = armnn::numeric_cast(params.m_PadRight); + const int padTop = armnn::numeric_cast(params.m_PadTop); + const int padBottom = armnn::numeric_cast(params.m_PadBottom); + const int strideX = armnn::numeric_cast(params.m_StrideX); + const int strideY = armnn::numeric_cast(params.m_StrideY); + const int poolHeight = armnn::numeric_cast(params.m_PoolHeight); + const int poolWidth = armnn::numeric_cast(params.m_PoolWidth); float defaultInitializer = DefaultInitializer(params.m_PoolType); @@ -221,10 +222,10 @@ void Pooling2d(Decoder& rInputDecoder, result = 0.0f; unsigned int outputIndex = dataLayout.GetIndex(outputShape, - boost::numeric_cast(n), - boost::numeric_cast(c), - boost::numeric_cast(yOutput), - boost::numeric_cast(xOutput)); + armnn::numeric_cast(n), + armnn::numeric_cast(c), + armnn::numeric_cast(yOutput), + armnn::numeric_cast(xOutput)); rOutputEncoder[outputIndex]; rOutputEncoder.Set(result); continue; @@ -244,10 +245,10 @@ void Pooling2d(Decoder& rInputDecoder, for (auto xInput = wstart; xInput < wend; xInput++) { unsigned int inputIndex = dataLayout.GetIndex(inputShape, - boost::numeric_cast(n), - boost::numeric_cast(c), - boost::numeric_cast(yInput), - boost::numeric_cast(xInput)); + armnn::numeric_cast(n), + armnn::numeric_cast(c), + armnn::numeric_cast(yInput), + armnn::numeric_cast(xInput)); rInputDecoder[inputIndex]; float inval = rInputDecoder.Get(); @@ -259,10 +260,10 @@ void Pooling2d(Decoder& rInputDecoder, execute(result, poolAreaSize); unsigned int outputIndex = dataLayout.GetIndex(outputShape, - boost::numeric_cast(n), - boost::numeric_cast(c), - boost::numeric_cast(yOutput), - boost::numeric_cast(xOutput)); + armnn::numeric_cast(n), + armnn::numeric_cast(c), + armnn::numeric_cast(yOutput), + armnn::numeric_cast(xOutput)); rOutputEncoder[outputIndex]; rOutputEncoder.Set(result); diff --git a/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp b/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp index 6fec1abe6f..f80901edc9 100644 --- a/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp +++ b/src/backends/reference/workloads/RefL2NormalizationWorkload.cpp @@ -11,8 +11,7 @@ #include #include - -#include +#include #include @@ -39,26 +38,26 @@ void RefL2NormalizationWorkload::Execute() const const TensorShape& shape = inputInfo.GetShape(); unsigned int paddedShapeArray[4]; - const int idxShift = 4 - boost::numeric_cast(shape.GetNumDimensions()); + const int idxShift = 4 - armnn::numeric_cast(shape.GetNumDimensions()); const unsigned int batches = (idxShift == 0) ? shape[0] : 1; paddedShapeArray[0] = batches; - const int channelsIdx = boost::numeric_cast(dataLayout.GetChannelsIndex()); + const int channelsIdx = armnn::numeric_cast(dataLayout.GetChannelsIndex()); const unsigned int channels = (channelsIdx - idxShift >= 0) - ? shape[boost::numeric_cast(channelsIdx - idxShift)] + ? shape[armnn::numeric_cast(channelsIdx - idxShift)] : 1; paddedShapeArray[channelsIdx] = channels; - const int heightIdx = boost::numeric_cast(dataLayout.GetHeightIndex()); + const int heightIdx = armnn::numeric_cast(dataLayout.GetHeightIndex()); const unsigned int height = (heightIdx - idxShift >= 0) - ? shape[boost::numeric_cast(heightIdx - idxShift)] + ? shape[armnn::numeric_cast(heightIdx - idxShift)] : 1; paddedShapeArray[heightIdx] = height; - const int widthIdx = boost::numeric_cast(dataLayout.GetWidthIndex()); + const int widthIdx = armnn::numeric_cast(dataLayout.GetWidthIndex()); const unsigned int width = (widthIdx - idxShift >= 0) - ? shape[boost::numeric_cast(widthIdx - idxShift)] + ? shape[armnn::numeric_cast(widthIdx - idxShift)] : 1; paddedShapeArray[widthIdx] = width; diff --git a/src/backends/reference/workloads/RefNormalizationWorkload.cpp b/src/backends/reference/workloads/RefNormalizationWorkload.cpp index a41f68349a..d5d2104cba 100644 --- a/src/backends/reference/workloads/RefNormalizationWorkload.cpp +++ b/src/backends/reference/workloads/RefNormalizationWorkload.cpp @@ -8,11 +8,10 @@ #include #include #include +#include #include -#include - #include "RefWorkloadUtils.hpp" #include "Decoders.hpp" #include "Encoders.hpp" @@ -37,7 +36,7 @@ void NormalizeWithinUingLbr(Decoder& inputData, const unsigned int rows = tensorShape[2]; const unsigned int cols = tensorShape[3]; - int radius = boost::numeric_cast(norm_size / 2u); /* Strong Assumption on rounding Mode */ + int radius = armnn::numeric_cast(norm_size / 2u); /* Strong Assumption on rounding Mode */ for (unsigned int n = 0; n < batchSize; n++) { @@ -52,23 +51,23 @@ void NormalizeWithinUingLbr(Decoder& inputData, { for (int x = -radius; x <= radius; x++) { - int i = boost::numeric_cast(w) + x; - int j = boost::numeric_cast(h) + y; + int i = armnn::numeric_cast(w) + x; + int j = armnn::numeric_cast(h) + y; - if ((i < 0) || (i >= boost::numeric_cast(cols))) + if ((i < 0) || (i >= armnn::numeric_cast(cols))) { continue; } - if ((j < 0) || (j >= boost::numeric_cast(rows))) + if ((j < 0) || (j >= armnn::numeric_cast(rows))) { continue; } unsigned int inputIndex = n * cols * rows * depth + c * cols * rows + - boost::numeric_cast(j) * cols + - boost::numeric_cast(i); + armnn::numeric_cast(j) * cols + + armnn::numeric_cast(i); inputData[inputIndex]; float inval = inputData.Get(); @@ -106,7 +105,7 @@ void NormalizeAcrossUingLbr(Decoder& inputData, const unsigned int rows = tensorShape[dataLayoutIndexed.GetHeightIndex()]; const unsigned int cols = tensorShape[dataLayoutIndexed.GetWidthIndex()]; - int radius = boost::numeric_cast(norm_size / 2u); /* Strong Assumption on rounding Mode */ + int radius = armnn::numeric_cast(norm_size / 2u); /* Strong Assumption on rounding Mode */ for (unsigned int n = 0; n < batchSize; n++) { @@ -119,16 +118,16 @@ void NormalizeAcrossUingLbr(Decoder& inputData, float accumulated_scale = 0.0; for (int z = -radius; z <= radius; z++) { - int k = boost::numeric_cast(c) + z; + int k = armnn::numeric_cast(c) + z; - if ((k < 0) || (k >= boost::numeric_cast(depth))) + if ((k < 0) || (k >= armnn::numeric_cast(depth))) { continue; } unsigned inputIndex = dataLayoutIndexed.GetIndex(tensorShape, n, - boost::numeric_cast(k), + armnn::numeric_cast(k), h, w); diff --git a/src/backends/reference/workloads/StridedSlice.cpp b/src/backends/reference/workloads/StridedSlice.cpp index b00b049ff6..c5fb121cb3 100644 --- a/src/backends/reference/workloads/StridedSlice.cpp +++ b/src/backends/reference/workloads/StridedSlice.cpp @@ -8,8 +8,7 @@ #include #include - -#include +#include #include @@ -24,7 +23,7 @@ void PadParams(StridedSliceDescriptor& p, unsigned int dimCount) ARMNN_ASSERT_MSG(dimCount <= 4, "Expected input with at most 4 dimensions"); const unsigned int beginIndicesCount = - boost::numeric_cast(p.m_Begin.size()); + armnn::numeric_cast(p.m_Begin.size()); ARMNN_ASSERT(dimCount >= beginIndicesCount); const unsigned int padCount = dimCount - beginIndicesCount; @@ -116,7 +115,7 @@ void StridedSlice(const TensorInfo& inputInfo, const int start3 = paddedParams.GetStartForAxis(inputShape, 3); const int stop3 = paddedParams.GetStopForAxis (inputShape, 3, start3); - const int step = boost::numeric_cast(dataTypeSize); + const int step = armnn::numeric_cast(dataTypeSize); for (int in0 = start0; !LoopCondition(in0, stop0, paddedParams.m_Stride[0]); @@ -134,9 +133,9 @@ void StridedSlice(const TensorInfo& inputInfo, !LoopCondition(in3, stop3, paddedParams.m_Stride[3]); in3 += paddedParams.m_Stride[3]) { - int dim1 = boost::numeric_cast(inputShape[1]); - int dim2 = boost::numeric_cast(inputShape[2]); - int dim3 = boost::numeric_cast(inputShape[3]); + int dim1 = armnn::numeric_cast(inputShape[1]); + int dim2 = armnn::numeric_cast(inputShape[2]); + int dim3 = armnn::numeric_cast(inputShape[3]); int inputOffset = (((in0 * dim1 + in1) * dim2 + in2) * dim3 + in3) * step; ::memcpy(output, input + inputOffset, dataTypeSize); -- cgit v1.2.1