aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bentham <Matthew.Bentham@arm.com>2020-01-17 09:36:49 +0000
committermike.kelly <mike.kelly@arm.com>2020-01-17 12:25:52 +0000
commit93b622f96935e4d239104f6512499a57290da07f (patch)
treeeaa74b6f4e59455ba8a77fd5db16565d63ef99bb
parentf48afc6c385cda14e34b0121e02adcb853dedc87 (diff)
downloadarmnn-93b622f96935e4d239104f6512499a57290da07f.tar.gz
Github #320 Add logging and error checking to SimpleSample
These things are frequently asked questions, so I think it makes sense to add them to the basic sample. Signed-off-by: Matthew Bentham <Matthew.Bentham@arm.com> Change-Id: I17cacb37fbe87e2a8fb14e7b7e85ebc528575386
-rw-r--r--samples/SimpleSample.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/samples/SimpleSample.cpp b/samples/SimpleSample.cpp
index ed7c0bfb08..5276d74a4d 100644
--- a/samples/SimpleSample.cpp
+++ b/samples/SimpleSample.cpp
@@ -2,8 +2,12 @@
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
+#include <armnn/INetwork.hpp>
+#include <armnn/IRuntime.hpp>
+#include <armnn/Utils.hpp>
+#include <armnn/Descriptors.hpp>
+
#include <iostream>
-#include "armnn/ArmNN.hpp"
/// A simple example of using the ArmNN SDK API. In this sample, the users single input number is multiplied by 1.0f
/// using a fully connected layer with a single neuron to produce an output number that is the same as the input.
@@ -15,6 +19,10 @@ int main()
std::cout << "Please enter a number: " << std::endl;
std::cin >> number;
+ // Turn on logging to standard output
+ // This is useful in this sample so that users can learn more about what is going on
+ armnn::ConfigureLogging(true, false, LogSeverity::Warning);
+
// Construct ArmNN network
armnn::NetworkId networkIdentifier;
INetworkPtr myNetwork = INetwork::Create();
@@ -47,6 +55,14 @@ int main()
// Optimise ArmNN network
armnn::IOptimizedNetworkPtr optNet = Optimize(*myNetwork, {Compute::CpuRef}, run->GetDeviceSpec());
+ if (!optNet)
+ {
+ // This shouldn't happen for this simple sample, with reference backend.
+ // But in general usage Optimize could fail if the hardware at runtime cannot
+ // support the model that has been provided.
+ std::cerr << "Error: Failed to optimise the input network." << std::endl;
+ return 1;
+ }
// Load graph into runtime
run->LoadNetwork(networkIdentifier, std::move(optNet));