From fd627ffaec8fd8801d980b4c91ee7c0607ab6aaf Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Thu, 25 Feb 2021 17:44:00 +0000 Subject: IVGCVSW-5687 Update Doxygen Docu * Update Doxygen Documentation for 21.02 release Signed-off-by: Jan Eilers Change-Id: I9ed2f9caab038836ea99d7b378d7899fe431a4e5 --- ...nvert_constants_b_float_tests_8cpp_source.xhtml | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 21.02/_convert_constants_b_float_tests_8cpp_source.xhtml (limited to '21.02/_convert_constants_b_float_tests_8cpp_source.xhtml') diff --git a/21.02/_convert_constants_b_float_tests_8cpp_source.xhtml b/21.02/_convert_constants_b_float_tests_8cpp_source.xhtml new file mode 100644 index 0000000000..51d85d6d59 --- /dev/null +++ b/21.02/_convert_constants_b_float_tests_8cpp_source.xhtml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + +ArmNN: src/armnn/test/optimizations/ConvertConstantsBFloatTests.cpp Source File + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  21.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
ConvertConstantsBFloatTests.cpp
+
+
+Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "../TestUtils.hpp"
7 
8 #include <BFloat16.hpp>
9 #include <Optimizer.hpp>
10 
11 #include <boost/test/unit_test.hpp>
12 
13 using namespace armnn;
14 
16 using namespace armnn::optimizations;
17 
18 BOOST_AUTO_TEST_CASE(ConvertConstantsFloatToBFloatTest)
19 {
20  armnn::Graph graph;
21 
22  const armnn::TensorInfo info({ 1, 1, 1, 2 }, armnn::DataType::BFloat16);
23 
24  // Create const tensor from fp32 data
25  unsigned int dims[] = { 4, 2, 1, 1 };
26  std::vector<float> floatWeights{ 0.0f, -1.0f,
27  3.8f, // 0x40733333 Round down
28  3.1055E+29f, // 0x707ADC3C Round up
29  9.149516E-10f, // 0x307B7FFF Round down
30  -3.8f, // 0xC0733333 Round down
31  -3.1055E+29f, // 0xF07ADC3C Round up
32  -9.149516E-10f // 0xB07B7FFF Round down
33  };
34  armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32), floatWeights);
35 
36  // Create simple test network
37  auto input = graph.AddLayer<armnn::InputLayer>(0, "input");
39 
41  fc->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weights);
42  fc->GetOutputSlot().SetTensorInfo(info);
43 
44  auto output = graph.AddLayer<armnn::OutputLayer>(1, "output");
45 
46  // Connect up the layers
47  input->GetOutputSlot().Connect(fc->GetInputSlot(0));
48  fc->GetOutputSlot().Connect(output->GetInputSlot(0));
49 
50  // Check tensor data type before conversion
51  BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float32);
52 
53  // Run the optimizer
55 
56  // Check tensor data type after conversion
57  BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::BFloat16);
58 
59  // Check whether data matches expected Bf16 data
60  BFloat16* data = fc->m_Weight->GetTensor<BFloat16>();
61  BOOST_CHECK(data[0] == BFloat16(0.0f));
62  BOOST_CHECK(data[1] == BFloat16(-1.0f));
63  BOOST_CHECK(data[2] == BFloat16(3.796875f)); // 0x4073
64  BOOST_CHECK(data[3] == BFloat16(3.1072295E29f)); // 0x707B
65  BOOST_CHECK(data[4] == BFloat16(9.131327E-10f)); // 0x307B
66  BOOST_CHECK(data[5] == BFloat16(-3.796875f)); // 0xC073
67  BOOST_CHECK(data[6] == BFloat16(-3.1072295E29f)); // 0xF07B
68  BOOST_CHECK(data[7] == BFloat16(-9.131327E-10f)); // 0xB07B
69 }
70 
71 BOOST_AUTO_TEST_CASE(ConvertConstantsBFloatToFloatTest)
72 {
73  armnn::Graph graph;
74 
75  const armnn::TensorInfo info({ 1, 1, 1, 2 }, armnn::DataType::Float32);
76 
77  // Create the BFloat16 precision input data
78  unsigned int dims[] = { 4, 2, 1, 1 };
79  std::vector<float> convWeightsData{ 0.f, -1.f,
80  3.796875f, // 0x4073
81  3.1072295E29f, // 0x707B
82  9.131327E-10f, // 0x307B
83  -3.796875f, // 0xC073
84  -3.1072295E29f, // 0xF07B
85  -9.131327E-10f // 0xB07B
86  };
87  std::vector<uint16_t> bfWeights(8);
88  armnnUtils::FloatingPointConverter::ConvertFloat32ToBFloat16(convWeightsData.data(), convWeightsData.size(),
89  bfWeights.data());
91 
92  //Create the simple test network
93  auto input = graph.AddLayer<armnn::InputLayer>(0, "input");
95 
97  fc->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weights);
98  fc->GetOutputSlot().SetTensorInfo(info);
99 
100  auto output = graph.AddLayer<armnn::OutputLayer>(1, "output");
101 
102  //Connect up the layers
103  input->GetOutputSlot().Connect(fc->GetInputSlot(0));
104  fc->GetOutputSlot().Connect(output->GetInputSlot(0));
105 
106  //Test the tensor info is correct.
107  BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::BFloat16);
108 
109  // Run the optimizer
111 
112  //Test the tensor info is correct.
113  BOOST_CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float32);
114 
115  // Now test the data matches float32 data
116  float* data = fc->m_Weight->GetTensor<float>();
117  BOOST_CHECK(data[0] == 0.0f);
118  BOOST_CHECK(data[1] == -1.0f);
119  BOOST_CHECK(data[2] == 3.796875f);
120  BOOST_CHECK(data[3] == 3.1072295E29f);
121  BOOST_CHECK(data[4] == 9.131327E-10f);
122  BOOST_CHECK(data[5] == -3.796875f);
123  BOOST_CHECK(data[6] == -3.1072295E29f);
124  BOOST_CHECK(data[7] == -9.131327E-10f);
125 }
126 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
+
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
+
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store Weight values.
+ + +
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:402
+ +
int Connect(InputSlot &destination)
Definition: Layer.cpp:83
+
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
+
Copyright (c) 2021 ARM Limited and Contributors.
+ +
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
+
ConvertConstants< Float32ToBFloat16, IsBFloat16Layer > ConvertConstantsFloatToBFloat
+
This layer represents a fully connected operation.
+
ConvertConstants< BFloat16ToFloat32, IsFloat32Layer > ConvertConstantsBFloatToFloat
+
A FullyConnectedDescriptor for the FullyConnectedLayer.
+
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:314
+
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
+ + +
BOOST_AUTO_TEST_SUITE_END()
+
static void ConvertFloat32ToBFloat16(const float *srcFloat32Buffer, size_t numElements, void *dstBFloat16Buffer)
+ +
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
+
void SetTensorInfo(const TensorInfo &tensorInfo) override
Definition: Layer.cpp:58
+
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:318
+ + + +
+
+ + + + -- cgit v1.2.1