diff options
author | Nikhil Raj <nikhil.raj@arm.com> | 2023-02-24 10:28:19 +0000 |
---|---|---|
committer | Nikhil Raj <nikhil.raj@arm.com> | 2023-02-24 10:28:19 +0000 |
commit | 8d2ca734165a068478df7cffa46185680b05cd20 (patch) | |
tree | 0433a7e6b007fe4639334c4438e58e9872a34b20 /23.02/_simple_sample_8cpp-example.xhtml | |
parent | cb0630959aeae05bc2ae9f6d80cf5f5983a8fb77 (diff) | |
download | armnn-8d2ca734165a068478df7cffa46185680b05cd20.tar.gz |
Update Doxygen docu for 23.02
Signed-off-by: Nikhil Raj <nikhil.raj@arm.com>
Change-Id: Ie6c19a27d50fefab2796b2b5875374e81f5bf971
Diffstat (limited to '23.02/_simple_sample_8cpp-example.xhtml')
-rw-r--r-- | 23.02/_simple_sample_8cpp-example.xhtml | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/23.02/_simple_sample_8cpp-example.xhtml b/23.02/_simple_sample_8cpp-example.xhtml new file mode 100644 index 0000000000..6d0536725f --- /dev/null +++ b/23.02/_simple_sample_8cpp-example.xhtml @@ -0,0 +1,115 @@ +<!-- Copyright (c) 2020 ARM Limited. --> +<!-- --> +<!-- SPDX-License-Identifier: MIT --> +<!-- --> +<!-- HTML header for doxygen 1.8.13--> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> +<meta http-equiv="X-UA-Compatible" content="IE=9"/> +<meta name="generator" content="Doxygen 1.8.13"/> +<meta name="robots" content="NOINDEX, NOFOLLOW" /> +<meta name="viewport" content="width=device-width, initial-scale=1"/> +<title>ArmNN: SimpleSample.cpp</title> +<link href="tabs.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="jquery.js"></script> +<script type="text/javascript" src="dynsections.js"></script> +<link href="navtree.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="resize.js"></script> +<script type="text/javascript" src="navtreedata.js"></script> +<script type="text/javascript" src="navtree.js"></script> +<script type="text/javascript"> + $(document).ready(initResizable); +</script> +<link href="search/search.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="search/searchdata.js"></script> +<script type="text/javascript" src="search/search.js"></script> +<script type="text/x-mathjax-config"> + MathJax.Hub.Config({ + extensions: ["tex2jax.js"], + jax: ["input/TeX","output/HTML-CSS"], +}); +</script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script> +<link href="doxygen.css" rel="stylesheet" type="text/css" /> +<link href="stylesheet.css" rel="stylesheet" type="text/css"/> +</head> +<body> +<div id="top"><!-- do not remove this div, it is closed by doxygen! --> +<div id="titlearea"> +<table cellspacing="0" cellpadding="0"> + <tbody> + <tr style="height: 56px;"> + <img alt="ArmNN" src="Arm_NN_horizontal_blue.png" style="max-width: 10rem; margin-top: .5rem; margin-left 10px"/> + <td style="padding-left: 0.5em;"> + <div id="projectname"> +  <span id="projectnumber">23.02</span> + </div> + </td> + </tr> + </tbody> +</table> +</div> +<!-- end header part --> +<!-- Generated by Doxygen 1.8.13 --> +<script type="text/javascript"> +var searchBox = new SearchBox("searchBox", "search",false,'Search'); +</script> +<script type="text/javascript" src="menudata.js"></script> +<script type="text/javascript" src="menu.js"></script> +<script type="text/javascript"> +$(function() { + initMenu('',true,false,'search.php','Search'); + $(document).ready(function() { init_search(); }); +}); +</script> +<div id="main-nav"></div> +</div><!-- top --> +<div id="side-nav" class="ui-resizable side-nav-resizable"> + <div id="nav-tree"> + <div id="nav-tree-contents"> + <div id="nav-sync" class="sync"></div> + </div> + </div> + <div id="splitbar" style="-moz-user-select:none;" + class="ui-resizable-handle"> + </div> +</div> +<script type="text/javascript"> +$(document).ready(function(){initNavTree('_simple_sample_8cpp-example.xhtml','');}); +</script> +<div id="doc-content"> +<!-- window showing the filter options --> +<div id="MSearchSelectWindow" + onmouseover="return searchBox.OnSearchSelectShow()" + onmouseout="return searchBox.OnSearchSelectHide()" + onkeydown="return searchBox.OnSearchSelectKey(event)"> +</div> + +<!-- iframe showing the search results (closed by default) --> +<div id="MSearchResultsWindow"> +<iframe src="javascript:void(0)" frameborder="0" + name="MSearchResults" id="MSearchResults"> +</iframe> +</div> + +<div class="header"> + <div class="headertitle"> +<div class="title">SimpleSample.cpp</div> </div> +</div><!--header--> +<div class="contents"> +<p>This is a very simple example which uses the Arm NN SDK API to create a neural network which consists of nothing else but a single fully connected layer with a single weights value. It's as minimalistic as it can get.</p> +<dl class="section note"><dt>Note</dt><dd>Most of our users won't use our API to create a network manually. Usually you would use one of our software tools like the <a class="el" href="parsers.xhtml#S6_tf_lite_parser">TfLite Parser</a> that will translate a TfLite model into Arm NN for you. Still it's a very nice example to see how an Arm NN network is created, optimized and executed.</dd></dl> +<p>(You can find more complex examples using the TfLite Parser in samples/ObjectDetection and samples/SpeechRecognition. And another example using <a class="el" href="md_python_pyarmnn__r_e_a_d_m_e.xhtml">PyArmnn</a> in samples/ImageClassification)</p> +<div class="fragment"><div class="line"><span class="comment">//</span></div><div class="line"><span class="comment">// Copyright © 2017 Arm Ltd. All rights reserved.</span></div><div class="line"><span class="comment">// SPDX-License-Identifier: MIT</span></div><div class="line"><span class="comment">//</span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="_i_network_8hpp.xhtml">armnn/INetwork.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="_i_runtime_8hpp.xhtml">armnn/IRuntime.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="_utils_8hpp.xhtml">armnn/Utils.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="_descriptors_8hpp.xhtml">armnn/Descriptors.hpp</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <iostream></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">/// A simple example of using the ArmNN SDK API. In this sample, the users single input number is multiplied by 1.0f</span></div><div class="line"><span class="comment">/// using a fully connected layer with a single neuron to produce an output number that is the same as the input.</span></div><div class="line"><span class="comment"></span><span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="_armnn_converter_8cpp.xhtml#a0ddf1224851353fc92bfbff6f499fa97">main</a>()</div><div class="line">{</div><div class="line"> <span class="keyword">using namespace </span><a class="code" href="namespacearmnn.xhtml">armnn</a>;</div><div class="line"></div><div class="line"> <span class="keywordtype">float</span> number;</div><div class="line"> std::cout << <span class="stringliteral">"Please enter a number: "</span> << std::endl;</div><div class="line"> std::cin >> number;</div><div class="line"></div><div class="line"> <span class="comment">// Turn on logging to standard output</span></div><div class="line"> <span class="comment">// This is useful in this sample so that users can learn more about what is going on</span></div><div class="line"> <a name="a1"></a><a class="code" href="namespacearmnn.xhtml#aa59f7a819c3e29d10ffc41e5c0616872">ConfigureLogging</a>(<span class="keyword">true</span>, <span class="keyword">false</span>, <a name="a2"></a><a class="code" href="namespacearmnn.xhtml#a93a3ba385cad27c4774e5fe64c025d3da0eaadb4fcb48a0a0ed7bc9868be9fbaa">LogSeverity::Warning</a>);</div><div class="line"></div><div class="line"> <span class="comment">// Construct ArmNN network</span></div><div class="line"> <a class="code" href="namespacearmnn.xhtml#a0d8160388a127c1a23b37bc88dc6e2ec">NetworkId</a> networkIdentifier;</div><div class="line"> <a class="code" href="namespacearmnn.xhtml#ace74f6f9feb95a964a49d79458232703">INetworkPtr</a> myNetwork = <a name="a3"></a><a class="code" href="classarmnn_1_1_i_network.xhtml#a41ce159095e95f7cd4174ce5d4662697">INetwork::Create</a>();</div><div class="line"></div><div class="line"> <span class="keywordtype">float</span> weightsData[] = {1.0f}; <span class="comment">// Identity</span></div><div class="line"> <a name="_a4"></a><a class="code" href="classarmnn_1_1_tensor_info.xhtml">TensorInfo</a> weightsInfo(<a name="_a5"></a><a class="code" href="classarmnn_1_1_tensor_shape.xhtml">TensorShape</a>({1, 1}), <a name="a6"></a><a class="code" href="namespacearmnn.xhtml#ad8ed01ff3ff33333d8e19db4d2818bb6a166495adc0d0f53bee6baecc577f5204">DataType::Float32</a>, 0.0f, 0, <span class="keyword">true</span>);</div><div class="line"> weightsInfo.<a name="a7"></a><a class="code" href="classarmnn_1_1_tensor_info.xhtml#a8ffca1e21bdfa7f945617acd606aac91">SetConstant</a>();</div><div class="line"> <a name="_a8"></a><a class="code" href="classarmnn_1_1_const_tensor.xhtml">ConstTensor</a> weights(weightsInfo, weightsData);</div><div class="line"></div><div class="line"> <span class="comment">// Constant layer that now holds weights data for FullyConnected</span></div><div class="line"> <a name="_a9"></a><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml">IConnectableLayer</a>* <span class="keyword">const</span> constantWeightsLayer = myNetwork->AddConstantLayer(weights, <span class="stringliteral">"const weights"</span>);</div><div class="line"></div><div class="line"> <a name="_a10"></a><a class="code" href="structarmnn_1_1_fully_connected_descriptor.xhtml">FullyConnectedDescriptor</a> fullyConnectedDesc;</div><div class="line"> <a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml">IConnectableLayer</a>* <span class="keyword">const</span> fullyConnectedLayer = myNetwork->AddFullyConnectedLayer(fullyConnectedDesc,</div><div class="line"> <span class="stringliteral">"fully connected"</span>);</div><div class="line"> <a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml">IConnectableLayer</a>* <a name="_a11"></a><a class="code" href="classarmnn_1_1_input_layer.xhtml">InputLayer</a> = myNetwork->AddInputLayer(0);</div><div class="line"> <a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml">IConnectableLayer</a>* <a name="_a12"></a><a class="code" href="classarmnn_1_1_output_layer.xhtml">OutputLayer</a> = myNetwork->AddOutputLayer(0);</div><div class="line"></div><div class="line"> InputLayer-><a name="a13"></a><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a name="a14"></a><a class="code" href="classarmnn_1_1_i_output_slot.xhtml#ac1835f8756a9f03c02fcf9664e3a0fce">Connect</a>(fullyConnectedLayer-><a name="a15"></a><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a6ec9e0eb66d7d6a01240492a0b18104c">GetInputSlot</a>(0));</div><div class="line"> constantWeightsLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a class="code" href="classarmnn_1_1_i_output_slot.xhtml#ac1835f8756a9f03c02fcf9664e3a0fce">Connect</a>(fullyConnectedLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a6ec9e0eb66d7d6a01240492a0b18104c">GetInputSlot</a>(1));</div><div class="line"> fullyConnectedLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a class="code" href="classarmnn_1_1_i_output_slot.xhtml#ac1835f8756a9f03c02fcf9664e3a0fce">Connect</a>(OutputLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a6ec9e0eb66d7d6a01240492a0b18104c">GetInputSlot</a>(0));</div><div class="line"></div><div class="line"> <span class="comment">// Create ArmNN runtime</span></div><div class="line"> <a name="_a16"></a><a class="code" href="structarmnn_1_1_i_runtime_1_1_creation_options.xhtml">IRuntime::CreationOptions</a> options; <span class="comment">// default options</span></div><div class="line"> <a class="code" href="namespacearmnn.xhtml#a150468a02bd7b2d2d061c4aaaee939f0">IRuntimePtr</a> run = <a name="a17"></a><a class="code" href="classarmnn_1_1_i_runtime.xhtml#ad44ecd3700748dc30dc4bbe34ba5bde7">IRuntime::Create</a>(options);</div><div class="line"></div><div class="line"> <span class="comment">//Set the tensors in the network.</span></div><div class="line"> <a class="code" href="classarmnn_1_1_tensor_info.xhtml">TensorInfo</a> inputTensorInfo(<a class="code" href="classarmnn_1_1_tensor_shape.xhtml">TensorShape</a>({1, 1}), <a class="code" href="namespacearmnn.xhtml#ad8ed01ff3ff33333d8e19db4d2818bb6a166495adc0d0f53bee6baecc577f5204">DataType::Float32</a>);</div><div class="line"> InputLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a name="a18"></a><a class="code" href="classarmnn_1_1_i_output_slot.xhtml#a5ee4a6c9a2481245487b1b1a70d20fd0">SetTensorInfo</a>(inputTensorInfo);</div><div class="line"></div><div class="line"> <a class="code" href="classarmnn_1_1_tensor_info.xhtml">TensorInfo</a> outputTensorInfo(<a class="code" href="classarmnn_1_1_tensor_shape.xhtml">TensorShape</a>({1, 1}), <a class="code" href="namespacearmnn.xhtml#ad8ed01ff3ff33333d8e19db4d2818bb6a166495adc0d0f53bee6baecc577f5204">DataType::Float32</a>);</div><div class="line"> fullyConnectedLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a class="code" href="classarmnn_1_1_i_output_slot.xhtml#a5ee4a6c9a2481245487b1b1a70d20fd0">SetTensorInfo</a>(outputTensorInfo);</div><div class="line"> constantWeightsLayer-><a class="code" href="classarmnn_1_1_i_connectable_layer.xhtml#a80ac4eda2e7f2757ec9dd96fc96dbd16">GetOutputSlot</a>(0).<a class="code" href="classarmnn_1_1_i_output_slot.xhtml#a5ee4a6c9a2481245487b1b1a70d20fd0">SetTensorInfo</a>(weightsInfo);</div><div class="line"></div><div class="line"> <span class="comment">// Optimise ArmNN network</span></div><div class="line"> <a class="code" href="namespacearmnn.xhtml#a674efcf6cbdb9e831d653ff0e821fb38">IOptimizedNetworkPtr</a> optNet = <a name="a19"></a><a class="code" href="namespacearmnn.xhtml#a82e98ef05fd67036d1195ba17174d685">Optimize</a>(*myNetwork, {<a name="a20"></a><a class="code" href="namespacearmnn.xhtml#ae2f04a162585c0a5222a537efd5456aea83c2c4e9b658ccafbcbe6309c5d84c64">Compute::CpuRef</a>}, run->GetDeviceSpec());</div><div class="line"> <span class="keywordflow">if</span> (!optNet)</div><div class="line"> {</div><div class="line"> <span class="comment">// This shouldn't happen for this simple sample, with reference backend.</span></div><div class="line"> <span class="comment">// But in general usage Optimize could fail if the hardware at runtime cannot</span></div><div class="line"> <span class="comment">// support the model that has been provided.</span></div><div class="line"> std::cerr << <span class="stringliteral">"Error: Failed to optimise the input network."</span> << std::endl;</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Load graph into runtime</span></div><div class="line"> run->LoadNetwork(networkIdentifier, std::move(optNet));</div><div class="line"></div><div class="line"> <span class="comment">//Creates structures for inputs and outputs.</span></div><div class="line"> std::vector<float> inputData{number};</div><div class="line"> std::vector<float> outputData(1);</div><div class="line"></div><div class="line"> inputTensorInfo = run->GetInputTensorInfo(networkIdentifier, 0);</div><div class="line"> inputTensorInfo.<a class="code" href="classarmnn_1_1_tensor_info.xhtml#a8ffca1e21bdfa7f945617acd606aac91">SetConstant</a>(<span class="keyword">true</span>);</div><div class="line"> <a class="code" href="namespacearmnn.xhtml#aa01bce88f89975a5a031db4cc8861527">InputTensors</a> inputTensors{{0, <a class="code" href="classarmnn_1_1_const_tensor.xhtml">armnn::ConstTensor</a>(inputTensorInfo,</div><div class="line"> inputData.data())}};</div><div class="line"> <a class="code" href="namespacearmnn.xhtml#a8f091a512915d1cb29a4ebf13dfc53ea">OutputTensors</a> outputTensors{{0, <a name="_a21"></a><a class="code" href="classarmnn_1_1_tensor.xhtml">armnn::Tensor</a>(run->GetOutputTensorInfo(networkIdentifier, 0),</div><div class="line"> outputData.data())}};</div><div class="line"></div><div class="line"> <span class="comment">// Execute network</span></div><div class="line"> run->EnqueueWorkload(networkIdentifier, inputTensors, outputTensors);</div><div class="line"></div><div class="line"> std::cout << <span class="stringliteral">"Your number was "</span> << outputData[0] << std::endl;</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents --> +</div><!-- doc-content --> +<!-- start footer part --> +<div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> + <ul> + <li class="footer">Generated on Fri Feb 24 2023 10:24:24 for ArmNN by + <a href="http://www.doxygen.org/index.html"> + <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li> + </ul> +</div> +</body> +</html> |