aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp
diff options
context:
space:
mode:
authorRob Hughes <robert.hughes@arm.com>2019-09-24 09:34:53 +0100
committerJim Flynn Arm <jim.flynn@arm.com>2019-09-25 02:44:48 +0000
commit95e73d77b9a79f7d350a39d85f07d09cd58422cc (patch)
tree8b713e8d29d433a28b29b8a9ce34052e8cccd08c /src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp
parent4833cea9036df428634cf64d8f1c4b54fc5da41f (diff)
downloadarmnn-95e73d77b9a79f7d350a39d85f07d09cd58422cc.tar.gz
NNXSW-1826 Move tests for Optimization classes to separate files
This splits up the >1000 line OptimizerTests.cpp file. Each Optimization class now has its own test file, all of which are in a subfolder of tests called "optimizations". The original OptimizerTests.cpp now contains mostly (completely?) tests for validating output shapes, which perhaps should be moved to test files specific to the layer types they are testing. Change-Id: Icd1196cad8b720abcb156921aab1adbd4026756b Signed-off-by: Rob Hughes <robert.hughes@arm.com>
Diffstat (limited to 'src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp')
-rw-r--r--src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp b/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp
new file mode 100644
index 0000000000..b40bd2de41
--- /dev/null
+++ b/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "../TestUtils.hpp"
+
+#include <Optimizer.hpp>
+#include <Half.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+using namespace armnn;
+
+BOOST_AUTO_TEST_SUITE(Optimizer)
+using namespace armnn::optimizations;
+
+BOOST_AUTO_TEST_CASE(ConvertConstantsFloatToHalfTest)
+{
+ armnn::Graph graph;
+
+ const armnn::TensorInfo info({ 1, 1, 1, 2 }, armnn::DataType::Float16);
+
+ // Create const tensor from fp32 data
+ unsigned int dims[] = { 4, 1, 1, 1 };
+ std::vector<float> floatWeights{ 1.0f, 2.0f, 3.0f, 4.0f };
+ armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32), floatWeights);
+
+ // Create simple test network
+ auto input = graph.AddLayer<armnn::InputLayer>(0, "input");
+ input->GetOutputSlot().SetTensorInfo(info);
+
+ auto fc = graph.AddLayer<armnn::FullyConnectedLayer>(armnn::FullyConnectedDescriptor(), "fc");
+ fc->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weights);
+ fc->GetOutputSlot().SetTensorInfo(info);
+
+ auto output = graph.AddLayer<armnn::OutputLayer>(1, "output");
+
+ // Connect up the layers
+ input->GetOutputSlot().Connect(fc->GetInputSlot(0));
+ fc->GetOutputSlot().Connect(output->GetInputSlot(0));
+
+ // Check tensor data type before conversion
+ BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float32);
+
+ // Run the optimizer
+ armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(ConvertConstantsFloatToHalf()));
+
+ // Check tensor data type after conversion
+ BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float16);
+
+ // Check whether data matches expected fp16 data
+ Half* data = fc->m_Weight->GetTensor<Half>();
+ BOOST_CHECK(data[0] == Half(1.0f));
+ BOOST_CHECK(data[1] == Half(2.0f));
+ BOOST_CHECK(data[2] == Half(3.0f));
+ BOOST_CHECK(data[3] == Half(4.0f));
+}
+
+BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file