IVGCVSW-1946: Remove armnn/src from the include paths
[platform/upstream/armnn.git] / src / armnn / test / EndToEndTest.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include <armnn/Descriptors.hpp>
7 #include <armnn/IRuntime.hpp>
8 #include <armnn/INetwork.hpp>
9
10 #include <backendsCommon/test/QuantizeHelper.hpp>
11
12 #include <boost/core/ignore_unused.hpp>
13 #include <boost/test/unit_test.hpp>
14
15 #include <set>
16
17 BOOST_AUTO_TEST_SUITE(EndToEnd)
18
19 namespace
20 {
21
22 template<typename T>
23 bool IsFloatIterFunc(T iter)
24 {
25     boost::ignore_unused(iter);
26     return IsFloatingPointIterator<T>::value;
27 }
28
29 } //namespace
30
31 BOOST_AUTO_TEST_CASE(QuantizedHelper)
32 {
33     std::vector<float> fArray;
34     BOOST_TEST(IsFloatIterFunc(fArray.begin()) == true);
35     BOOST_TEST(IsFloatIterFunc(fArray.cbegin()) == true);
36
37     std::vector<double> dArray;
38     BOOST_TEST(IsFloatIterFunc(dArray.begin()) == true);
39
40     std::vector<int> iArray;
41     BOOST_TEST(IsFloatIterFunc(iArray.begin()) == false);
42
43     float floats[5];
44     BOOST_TEST(IsFloatIterFunc(&floats[0]) == true);
45
46     int ints[5];
47     BOOST_TEST(IsFloatIterFunc(&ints[0]) == false);
48 }
49
50 BOOST_AUTO_TEST_CASE(ErrorOnLoadNetwork)
51 {
52     using namespace armnn;
53
54     // Create runtime in which test will run
55     // Note we don't allow falling back to CpuRef if an operation (excluding inputs, outputs, etc.) isn't supported
56     IRuntime::CreationOptions options;
57     IRuntimePtr runtime(IRuntime::Create(options));
58
59     // build up the structure of the network
60     INetworkPtr net(INetwork::Create());
61
62     IConnectableLayer* input = net->AddInputLayer(0);
63
64     // This layer configuration isn't supported by CpuAcc and isn't allowed to fall back, so Optimize will return null.
65     NormalizationDescriptor descriptor;
66     IConnectableLayer* pooling = net->AddNormalizationLayer(descriptor);
67
68     IConnectableLayer* output = net->AddOutputLayer(0);
69
70     input->GetOutputSlot(0).Connect(pooling->GetInputSlot(0));
71     pooling->GetOutputSlot(0).Connect(output->GetInputSlot(0));
72
73     input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
74     pooling->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
75
76     // optimize the network
77     std::vector<BackendId> backends = {Compute::CpuAcc};
78     IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
79     BOOST_CHECK(!optNet);
80 }
81
82 BOOST_AUTO_TEST_SUITE_END()