aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /samples
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'samples')
-rw-r--r--samples/CMakeLists.txt4
-rw-r--r--samples/SimpleSample.cpp68
2 files changed, 72 insertions, 0 deletions
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
new file mode 100644
index 0000000000..3009ac9a67
--- /dev/null
+++ b/samples/CMakeLists.txt
@@ -0,0 +1,4 @@
+if(BUILD_SAMPLE_APP)
+ add_executable(SimpleSample SimpleSample.cpp)
+ target_link_libraries(SimpleSample armnn pthread)
+endif()
diff --git a/samples/SimpleSample.cpp b/samples/SimpleSample.cpp
new file mode 100644
index 0000000000..43cd93f432
--- /dev/null
+++ b/samples/SimpleSample.cpp
@@ -0,0 +1,68 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#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.
+int main()
+{
+ using namespace armnn;
+
+ float number;
+ std::cout << "Please enter a number: " << std::endl;
+ std::cin >> number;
+
+ // Construct ArmNN network
+ armnn::NetworkId networkIdentifier;
+ INetworkPtr myNetwork = INetwork::Create();
+
+ armnn::FullyConnectedDescriptor fullyConnectedDesc;
+ float weightsData[] = {1.0f}; // Identity
+ TensorInfo weightsInfo(TensorShape({1, 1}), DataType::Float32);
+ armnn::ConstTensor weights(weightsInfo, weightsData);
+ IConnectableLayer *fullyConnected = myNetwork->AddFullyConnectedLayer(fullyConnectedDesc, weights,
+ "fully connected");
+
+ IConnectableLayer *InputLayer = myNetwork->AddInputLayer(0);
+ IConnectableLayer *OutputLayer = myNetwork->AddOutputLayer(0);
+
+ InputLayer->GetOutputSlot(0).Connect(fullyConnected->GetInputSlot(0));
+ fullyConnected->GetOutputSlot(0).Connect(OutputLayer->GetInputSlot(0));
+
+ // Create ArmNN runtime
+ IRuntime::CreationOptions options; // default options
+ IRuntimePtr run = IRuntime::Create(options);
+
+ //Set the tensors in the network.
+ TensorInfo inputTensorInfo(TensorShape({1, 1}), DataType::Float32);
+ InputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo);
+
+ TensorInfo outputTensorInfo(TensorShape({1, 1}), DataType::Float32);
+ fullyConnected->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ // Optimise ArmNN network
+ armnn::IOptimizedNetworkPtr optNet = Optimize(*myNetwork, {Compute::CpuRef}, run->GetDeviceSpec());
+
+ // Load graph into runtime
+ run->LoadNetwork(networkIdentifier, std::move(optNet));
+
+ //Creates structures for inputs and outputs.
+ std::vector<float> inputData{number};
+ std::vector<float> outputData(1);
+
+
+ armnn::InputTensors inputTensors{{0, armnn::ConstTensor(run->GetInputTensorInfo(networkIdentifier, 0),
+ inputData.data())}};
+ armnn::OutputTensors outputTensors{{0, armnn::Tensor(run->GetOutputTensorInfo(networkIdentifier, 0),
+ outputData.data())}};
+
+ // Execute network
+ run->EnqueueWorkload(networkIdentifier, inputTensors, outputTensors);
+
+ std::cout << "Your number was " << outputData[0] << std::endl;
+ return 0;
+
+}