HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nnapi_provider_factory.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 #pragma once
4 
5 #include "onnxruntime_c_api.h"
6 
7 // NNAPIFlags are bool options we want to set for NNAPI EP
8 // This enum is defined as bit flags, and cannot have negative value
9 // To generate an uint32_t nnapi_flags for using with OrtSessionOptionsAppendExecutionProvider_Nnapi below,
10 // uint32_t nnapi_flags = 0;
11 // nnapi_flags |= NNAPI_FLAG_USE_FP16;
12 enum NNAPIFlags {
14 
15  // Using fp16 relaxation in NNAPI EP, this may improve perf but may also reduce precision
17 
18  // Use NCHW layout in NNAPI EP, this is only available after Android API level 29
19  // Please note for now, NNAPI perform worse using NCHW compare to using NHWC
21 
22  // Prevent NNAPI from using CPU devices.
23  //
24  // NNAPI is more efficient using GPU or NPU for execution, and NNAPI might fall back to its own CPU implementation
25  // for operations not supported by GPU/NPU. The CPU implementation of NNAPI (which is called nnapi-reference)
26  // might be less efficient than the optimized versions of the operation of ORT. It might be advantageous to disable
27  // the NNAPI CPU fallback and handle execution using ORT kernels.
28  //
29  // For some models, if NNAPI would use CPU to execute an operation, and this flag is set, the execution of the
30  // model may fall back to ORT kernels.
31  //
32  // This option is only available after Android API level 29, and will be ignored for Android API level 28-
33  //
34  // For NNAPI device assignments, see https://developer.android.com/ndk/guides/neuralnetworks#device-assignment
35  // For NNAPI CPU fallback, see https://developer.android.com/ndk/guides/neuralnetworks#cpu-fallback
36  //
37  // Please note, the NNAPI EP will return error status if both NNAPI_FLAG_CPU_DISABLED
38  // and NNAPI_FLAG_CPU_ONLY flags are set
40 
41  // Using CPU only in NNAPI EP, this may decrease the perf but will provide
42  // reference output value without precision loss, which is useful for validation
43  //
44  // Please note, the NNAPI EP will return error status if both NNAPI_FLAG_CPU_DISABLED
45  // and NNAPI_FLAG_CPU_ONLY flags are set
47 
48  // Keep NNAPI_FLAG_LAST at the end of the enum definition
49  // And assign the last NNAPIFlag to it
51 };
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 ORT_EXPORT ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nnapi,
58  _In_ OrtSessionOptions* options, uint32_t nnapi_flags);
59 
60 #ifdef __cplusplus
61 }
62 #endif
#define _In_
#define ORT_EXPORT
ORT_EXPORT ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nnapi, _In_ OrtSessionOptions *options, uint32_t nnapi_flags)