onnxruntime/samples/c_cxx
gwang-msft 9e0f5fc7af
The initial PR for NNAPI EP (#4287)
* Move nnapi dnnlib to subfolder

* dnnlib compile settings

* add nnapi buildin build.py

* add onnxruntime_USE_NNAPI_BUILTIN

* compile using onnxruntime_USE_NNAPI_BUILTIN

* remove dnnlib from built in code

* Group onnxruntime_USE_NNAPI_BUILTIN sources

* add file stubs

* java 32bit compile error

* built in nnapi support 5-26

* init working version

* initializer support

* fix crash on free execution

* add dynamic input support

* bug fixes for dynamic input shape, add mul support, working on conv and batchnorm

* Add batchnormalization, add overflow check for int64 attributes

* add global average/max pool and reshape

* minor changes

* minor changes

* add skip relu and options to use different type of memory

* small bug fix for in operator relu

* bug fix for nnapi

* add transpose support, minor bug fix

* Add transpose support

* minor bug fixes, depthwise conv weight fix

* fixed the bug where the onnx model input has mismatch order than the nnapi model input

* add helper to add scalar operand

* add separated opbuilder to handle single operator

* add cast operator

* fixed reshape, moved some logs to verbose

* Add softmax and identity support, change shaper calling signature, and add support for int32 output

* changed the way to execute the NNAPI

* move NNMemory and InputOutputInfo into Model class

* add limited support for input dynamic shape

* add gemm support, fixed crash when allocating big array on stack

* add abs/exp/floor/log/sigmoid/neg/sin/sqrt/tanh support

* better dynamic input shape support;

* add more check for IsOpSupportedImpl, refactored some code

* some code style fix, switch to safeint

* Move opbuilders to a map with single instance, minor bug fixes

* add GetUniqueName for new temp tensors

* change from throw std to ort_throw

* build settings change and 3rd party notice update

* add readme for nnapi_lib, move to ort log, add comments to public functions, clean the code

* add android log sink and more logging changes, add new string for NnApiErrorDescription

* add nnapi execution options/fp16 relax

* fix a dnnlibrary build break

* addressed review comments

* address review comments, changed adding output for subgraph in NnapiExecutionProvider::GetCapability, minor issue fixes

* formatting in build.py

* more formatting fix in build.py, return fail status instead of throw in compute_func

* moved android_log_sink to platform folder, minor coding style changes

* addressed review comments
2020-06-26 00:02:39 -07:00
..
fns_candy_style_transfer make sure samples run (#2276) 2019-10-29 10:07:35 -07:00
imagenet make sure samples run (#2276) 2019-10-29 10:07:35 -07:00
include Add amd migraphx execution provider to onnx runtime (#2929) 2020-05-27 04:24:59 +08:00
MNIST Add softmax to the mnist example (#4149) 2020-06-08 09:33:50 -07:00
CMakeLists.txt The initial PR for NNAPI EP (#4287) 2020-06-26 00:02:39 -07:00
README.md Update build instructions. Make samples build and run. (#2244) 2019-10-24 10:06:47 -07:00
vs.png Document for the C/C++ samples (#1442) 2019-07-22 16:14:49 -07:00

This directory contains a few (Windows only) C/C++ sample applications for demoing onnxruntime usage:

  1. fns_candy_style_transfer: A C application that uses the FNS-Candy style transfer model to re-style images.
  2. MNIST: A windows GUI application for doing handwriting recognition
  3. imagenet: An end-to-end sample for the ImageNet Large Scale Visual Recognition Challenge 2012

Imagenet sample requires ATL libraries installed as a part of VS Studio installation.

How to build

Prerequisites

  1. Visual Studio 2015/2017/2019
  2. cmake(version >=3.13)
  3. (optional) libpng 1.6

You may get a precompiled libpng library from https://onnxruntimetestdata.blob.core.windows.net/models/libpng.zip

Install ONNX Runtime

You may either get a prebuit onnxruntime from nuget.org, or build it from source by following the build instructions. If you build it by yourself, you must append the "--build_shared_lib" flag to your build command. Open Developer Command Prompt for Visual Studio version you are going to use. This will setup necessary environment for the compiler and other things to be found.

build.bat --config RelWithDebInfo --build_shared_lib --parallel 

By default this will build a project with "C:\Program Files (x86)\onnxruntime" install destination. This is a protected folder on Windows. If you do not want to run installation with elevated priviliges you will need to override the default installation location by passing extra CMake arguments. For example:

build.bat --config RelWithDebInfo --build_shared_lib --parallel  --cmake_extra_defines CMAKE_INSTALL_PREFIX=c:\dev\ort_install

By default products of the build on Windows go to .\build\Windows<config> folder. In the case above it would be .\build\Windows\RelWithDebInfo. If you did not specify alternative installation location above you would need to open an elevated command prompt to install onnxruntime. Run the following commands.

cd .\Windows\RelWithDebInfo
msbuild INSTALL.vcxproj /p:Configuration=RelWithDebInfo

Build the samples

Open Developer Command Prompt for Visual Studio version you are going to use, change your current directory to samples\c_cxx, then run

mkdir build && cd build
cmake .. -A x64 -T host=x64 -DLIBPNG_ROOTDIR=C:\path\to\your\libpng\binary -DONNXRUNTIME_ROOTDIR=c:\dev\ort_install

You may omit the "-DLIBPNG_ROOTDIR=..." argument if you don't have the libpng library. You may omit "-DONNXRUNTIME_ROOTDIR=..." if you installed to a default location.

You may append "-Donnxruntime_USE_CUDA=ON" or "-Donnxruntime_USE_DML=ON" to the last command args if your onnxruntime binary was built with CUDA or DirectML support respectively.

You can then either open the solution in a Visual Studio and build it from there

devenv onnxruntime_samples.sln

Or build it using msbuild

msbuild onnxruntime_samples.sln /p:Configuration=Debug|Release

To run the samples make sure that your Install Folder Bin is in the path so your sample executable can find onnxruntime dll and libpng if you used it.