Fix a few build warnings:
authorRob Hughes <robert.hughes@arm.com>
Wed, 20 May 2020 14:27:37 +0000 (15:27 +0100)
committerRob Hughes <robert.hughes@arm.com>
Tue, 2 Jun 2020 13:55:30 +0000 (13:55 +0000)
* Remove redundant asserts for unsigned ints being positive
* Remove unneeded include of lightweight_test.hpp header
* Remove unused exception variable names
* Replace hardcoded 0.0f with T() for some template functions
* Add a few static_casts

Change-Id: I290b0433cf995f6d0199422eaa10f816e5fd8eb9
Signed-off-by: Robert Hughes <robert.hughes@arm.com>
profiling/server/src/basePipeServer/tests/BasePipeServerTests.cpp
src/armnn/test/UtilityTests.cpp
src/armnnTfLiteParser/test/GetBuffer.cpp
src/backends/backendsCommon/test/JsonPrinterTestImpl.cpp
src/backends/backendsCommon/test/layerTests/Conv2dTestImpl.cpp
src/backends/backendsCommon/test/layerTests/LstmTestImpl.cpp
src/backends/backendsCommon/test/layerTests/TransposeConvolution2dTestImpl.cpp
src/profiling/test/ProfilingMocks.hpp
src/profiling/test/SendCounterPacketTests.cpp
tests/NetworkExecutionUtils/NetworkExecutionUtils.hpp

index c97fecd..57fc9e9 100644 (file)
@@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(BasePipeServerTest)
     unsigned int readBufferSize = packetBuffer->GetSize();
 
     BOOST_TEST(readBuffer);
-    BOOST_TEST(readBufferSize > 0);
+    BOOST_TEST(readBufferSize > 0u);
 
     socketProfilingConnection.WritePacket(readBuffer,readBufferSize);
     bufferManager.MarkRead(packetBuffer);
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(BasePipeServerTest)
     readBufferSize = packetBuffer->GetSize();
 
     BOOST_TEST(readBuffer);
-    BOOST_TEST(readBufferSize > 0);
+    BOOST_TEST(readBufferSize > 0u);
 
     socketProfilingConnection.WritePacket(readBuffer,readBufferSize);
     bufferManager.MarkRead(packetBuffer);
index af56364..8d933eb 100644 (file)
@@ -4,7 +4,6 @@
 //
 
 #include <boost/test/unit_test.hpp>
-#include <boost/core/lightweight_test.hpp>
 
 #define ARMNN_POLYMORPHIC_CAST_TESTABLE
 #define ARMNN_NUMERIC_CAST_TESTABLE
index 6eecf4f..cccdbce 100644 (file)
@@ -120,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(GetBufferCheckParseException, GetBufferFixture)
 {
     //Check if armnn::ParseException thrown when invalid buffer index used
     TfLiteParser::ModelPtr model = TfLiteParser::LoadModelFromBinary(m_GraphBinary.data(), m_GraphBinary.size());
-    BOOST_CHECK_THROW(TfLiteParser::GetBuffer(model, 4)->data.empty(), armnn::Exception);
+    BOOST_CHECK_THROW(TfLiteParser::GetBuffer(model, 4), armnn::Exception);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
index 2aa713f..50dc61b 100644 (file)
@@ -65,7 +65,7 @@ std::vector<double> ExtractMeasurements(const std::string& exp)
                 armnn::stringUtils::StringTrim(numberString, "\t,\n");
                 numbers.push_back(std::stod(numberString));
             }
-            catch (std::invalid_argument const& e)
+            catch (std::invalid_argument const&)
             {
                 BOOST_FAIL("Could not convert measurements to double: " + numberString);
             }
@@ -80,7 +80,7 @@ std::vector<double> ExtractMeasurements(const std::string& exp)
                 armnn::stringUtils::StringTrim(numberString, "\t,\n");
                 numbers.push_back(std::stod(numberString));
             }
-            catch (std::invalid_argument const& e)
+            catch (std::invalid_argument const&)
             {
                 BOOST_FAIL("Could not convert measurements to double: " + numberString);
             }
index 154ece2..acc888e 100644 (file)
@@ -76,7 +76,7 @@ boost::multi_array<T, 1> GetBias2(bool biasEnabled, float qScale)
     if(biasEnabled)
     {
         armnn::TensorInfo biasDesc({static_cast<unsigned int>(Bias2.size())}, ArmnnType);
-        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias2, qScale, 0.0f));
+        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias2, qScale, 0));
         return bias;
     }
     else
@@ -92,7 +92,7 @@ boost::multi_array<T, 1> GetBias4(bool biasEnabled, float qScale)
     if(biasEnabled)
     {
         armnn::TensorInfo biasDesc({static_cast<unsigned int>(Bias4.size())}, ArmnnType);
-        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias4, qScale, 0.0f));
+        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias4, qScale, 0));
         return bias;
     }
     else
@@ -108,7 +108,7 @@ boost::multi_array<T, 1> GetBias8(bool biasEnabled, float qScale)
     if(biasEnabled)
     {
         armnn::TensorInfo biasDesc({static_cast<unsigned int>(Bias4.size())}, ArmnnType);
-        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias8, qScale, 0.0f));
+        boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(Bias8, qScale, 0));
         return bias;
     }
     else
index 0ae55e4..c7f902a 100644 (file)
@@ -160,28 +160,28 @@ LstmNoCifgNoPeepholeNoProjectionTestImpl(
 
     LayerTestResult<T, 2> ret(outputTensorInfo);
 
-    std::vector<float> inputVector;
+    std::vector<T> inputVector;
     inputVector.assign(input.data(), input.data() + (batchSize * inputSize));
-    auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputVector);
+    auto inputTensor = MakeTensor<T,2>(inputTensorInfo, inputVector);
 
-    std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
-    auto cellStateInTensor = MakeTensor<float,2>(cellStateInTensorInfo, cellStateInVector);
+    std::vector<T> cellStateInVector(batchSize * numUnits, T());
+    auto cellStateInTensor = MakeTensor<T,2>(cellStateInTensorInfo, cellStateInVector);
 
-    std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
-    auto outputStateInTensor = MakeTensor<float,2>(outputStateInTensorInfo, outputStateInVector);
+    std::vector<T> outputStateInVector(batchSize * outputSize, T());
+    auto outputStateInTensor = MakeTensor<T,2>(outputStateInTensorInfo, outputStateInVector);
 
-    std::vector<float> scratchBufferVector(batchSize * numUnits * 4, 0.f);
-    auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector);
+    std::vector<T> scratchBufferVector(batchSize * numUnits * 4, T());
+    auto scratchBufferTensor = MakeTensor<T,2>(scratchBufferTensorInfo, scratchBufferVector);
 
-    std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f);
-    auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector);
+    std::vector<T> outputStateOutVector(batchSize * outputSize, T());
+    auto outputStateOutTensor = MakeTensor<T,2>(outputStateOutTensorInfo, outputStateOutVector);
 
-    std::vector<float> cellStateOutVector(batchSize * numUnits, 0.f);
-    auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector);
+    std::vector<T> cellStateOutVector(batchSize * numUnits, T());
+    auto cellStateOutTensor = MakeTensor<T,2>(cellStateOutTensorInfo, cellStateOutVector);
 
-    std::vector<float> outputVector;
+    std::vector<T> outputVector;
     outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize));
-    ret.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputVector);
+    ret.outputExpected = MakeTensor<T, 2>(outputTensorInfo, outputVector);
 
     std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
     std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
@@ -363,28 +363,28 @@ LstmLayerNoCifgWithPeepholeWithProjectionTestImpl(armnn::IWorkloadFactory& workl
 
     LayerTestResult<T, 2> ret(outputTensorInfo);
 
-    std::vector<float> inputVector;
+    std::vector<T> inputVector;
     inputVector.assign(input.data(), input.data() + (batchSize * inputSize));
-    auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputVector);
+    auto inputTensor = MakeTensor<T,2>(inputTensorInfo, inputVector);
 
-    std::vector<float> cellStateInVector(batchSize * numUnits, 0.f);
-    auto cellStateInTensor = MakeTensor<float,2>(cellStateInTensorInfo, cellStateInVector);
+    std::vector<T> cellStateInVector(batchSize * numUnits, T());
+    auto cellStateInTensor = MakeTensor<T,2>(cellStateInTensorInfo, cellStateInVector);
 
-    std::vector<float> outputStateInVector(batchSize * outputSize, 0.f);
-    auto outputStateInTensor = MakeTensor<float,2>(outputStateInTensorInfo, outputStateInVector);
+    std::vector<T> outputStateInVector(batchSize * outputSize, T());
+    auto outputStateInTensor = MakeTensor<T,2>(outputStateInTensorInfo, outputStateInVector);
 
-    std::vector<float> scratchBufferVector(batchSize * numUnits * 4, 0.f);
-    auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector);
+    std::vector<T> scratchBufferVector(batchSize * numUnits * 4, T());
+    auto scratchBufferTensor = MakeTensor<T,2>(scratchBufferTensorInfo, scratchBufferVector);
 
-    std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f);
-    auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector);
+    std::vector<T> outputStateOutVector(batchSize * outputSize, T());
+    auto outputStateOutTensor = MakeTensor<T,2>(outputStateOutTensorInfo, outputStateOutVector);
 
-    std::vector<float> cellStateOutVector(batchSize * numUnits, 0.f);
-    auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector);
+    std::vector<T> cellStateOutVector(batchSize * numUnits, T());
+    auto cellStateOutTensor = MakeTensor<T,2>(cellStateOutTensorInfo, cellStateOutVector);
 
-    std::vector<float> outputVector;
+    std::vector<T> outputVector;
     outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize));
-    ret.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputVector);
+    ret.outputExpected = MakeTensor<T, 2>(outputTensorInfo, outputVector);
 
     std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
     std::unique_ptr<armnn::ITensorHandle> cellStateInHandle =
@@ -1195,27 +1195,27 @@ LayerTestResult<T, 2> LstmLayerWithCifgWithPeepholeNoProjectionTestImpl(
 
 
     // List of outputs
-    std::vector<float> scratchBufferVector(batchSize * scratchBufferSize, 0.f);
-    auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector);
+    std::vector<T> scratchBufferVector(batchSize * scratchBufferSize, T());
+    auto scratchBufferTensor = MakeTensor<T,2>(scratchBufferTensorInfo, scratchBufferVector);
     LayerTestResult<T, 2> ret0(scratchBufferTensorInfo);
 
     // Output state for a certain time step
-    std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f);
-    auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector);
+    std::vector<T> outputStateOutVector(batchSize * outputSize, T());
+    auto outputStateOutTensor = MakeTensor<T,2>(outputStateOutTensorInfo, outputStateOutVector);
     LayerTestResult<T, 2> ret1(outputStateOutTensorInfo);
 
     // Cell state for a certain time step
-    std::vector<float> cellStateOutVector(batchSize * cellSize, 0.f);
-    auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector);
+    std::vector<T> cellStateOutVector(batchSize * cellSize, T());
+    auto cellStateOutTensor = MakeTensor<T,2>(cellStateOutTensorInfo, cellStateOutVector);
     LayerTestResult<T, 2> ret2(cellStateOutTensorInfo);
 
     // Output for a certain time step
-    std::vector<float> outputVector(batchSize * outputSize, 0.f);
-    auto outputTensor = MakeTensor<float, 2>(outputTensorInfo, outputVector);
-    std::vector<float> outputData;
+    std::vector<T> outputVector(batchSize * outputSize, T());
+    auto outputTensor = MakeTensor<T, 2>(outputTensorInfo, outputVector);
+    std::vector<T> outputData;
     outputData.assign(outputExpected.data(), outputExpected.data() + batchSize*outputSize);
     LayerTestResult<T, 2> ret3(outputTensorInfo);
-    ret3.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputData);
+    ret3.outputExpected = MakeTensor<T, 2>(outputTensorInfo, outputData);
 
     // Prepare the inputs and outputs for the workload
     std::unique_ptr<armnn::ITensorHandle> inputHandle =
index 813c623..a599bae 100644 (file)
@@ -105,7 +105,7 @@ void TransposeConvolution2dTestImpl(armnn::IWorkloadFactory& workloadFactory,
     ExecuteWorkload(*workload, memoryManager);
 
     // copy output
-    output.second = std::vector<T>(output.first.GetNumElements(), 0.0f);
+    output.second = std::vector<T>(output.first.GetNumElements(), T());
     CopyDataFromITensorHandle(output.second.data(), outputHandle.get());
 }
 
index 2cd44c4..28e410f 100644 (file)
@@ -111,12 +111,12 @@ public:
 
         if(packetInfo.second != 0)
         {
-            return std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo);
+            return static_cast<long>(std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo));
         }
         else
         {
-            return std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
-            [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; });
+            return static_cast<long>(std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
+            [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; }));
         }
     }
 
@@ -142,7 +142,7 @@ public:
     {
         std::lock_guard<std::mutex> lock(m_Mutex);
 
-        return m_WrittenData.size();
+        return static_cast<unsigned long>(m_WrittenData.size());
     }
 
     void Clear()
index e7e2312..dc9671b 100644 (file)
@@ -2273,7 +2273,7 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket3)
     // Check that the buffer contains at least one Stream Metadata packet and no other packets
     const auto writtenDataSize = mockProfilingConnection.GetWrittenDataSize();
 
-    BOOST_TEST(writtenDataSize >= 1);
+    BOOST_TEST(writtenDataSize >= 1u);
     BOOST_TEST(mockProfilingConnection.CheckForPacket(
                   {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
 }
@@ -2319,7 +2319,7 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4)
     // Check that the buffer contains at least one Stream Metadata packet and no other packets
     const auto writtenDataSize = mockProfilingConnection.GetWrittenDataSize();
 
-    BOOST_TEST(writtenDataSize >= 1);
+    BOOST_TEST(writtenDataSize >= 1u);
     BOOST_TEST(mockProfilingConnection.CheckForPacket(
                   {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
 }
index ff28eb4..977a114 100644 (file)
@@ -637,7 +637,8 @@ int RunTest(const std::string& format,
             try
             {
                 // Coverity fix: An exception of type armnn::InvalidArgumentException is thrown and never caught.
-                inputTensorShapes.push_back(std::make_unique<armnn::TensorShape>(dims.size(), dims.data()));
+                inputTensorShapes.push_back(
+                    std::make_unique<armnn::TensorShape>(static_cast<unsigned int>(dims.size()), dims.data()));
             }
             catch (const armnn::InvalidArgumentException& e)
             {