Caffe2 - C++ API
A deep learning, cross platform ML framework
dlnnapi.h
1 
17 #include <stdbool.h>
18 #include <stdint.h>
19 
20 #include "NeuralNetworks.h"
21 
22 #define DLNNAPI_FUNCTION_COUNT 23
23 
24 #define DLNNAPI_FLAG_VERSION_MASK 0xFF
25 /* Android 8.1, API 27 version */
26 #define DLNNAPI_FLAG_VERSION_27 0x01
27 
28 /* clang-format off */
29 /* nn api function types */
30 typedef int (*ANeuralNetworksMemory_createFromFd_fn)(size_t size, int protect, int fd, size_t offset, ANeuralNetworksMemory** memory);
31 
32 typedef void (*ANeuralNetworksMemory_free_fn)(ANeuralNetworksMemory* memory);
33 
34 typedef int (*ANeuralNetworksModel_create_fn)(ANeuralNetworksModel** model);
35 
36 typedef int (*ANeuralNetworksModel_finish_fn)(ANeuralNetworksModel* model);
37 
38 typedef void (*ANeuralNetworksModel_free_fn)(ANeuralNetworksModel* model);
39 
40 typedef int (*ANeuralNetworksCompilation_create_fn)(ANeuralNetworksModel* model, ANeuralNetworksCompilation** compilation);
41 
42 typedef void (*ANeuralNetworksCompilation_free_fn)(ANeuralNetworksCompilation* compilation);
43 
44 typedef int (*ANeuralNetworksCompilation_setPreference_fn)(ANeuralNetworksCompilation* compilation, int32_t preference);
45 
46 typedef int (*ANeuralNetworksCompilation_finish_fn)(ANeuralNetworksCompilation* compilation);
47 
48 typedef int (*ANeuralNetworksModel_addOperand_fn)(ANeuralNetworksModel* model, const ANeuralNetworksOperandType* type);
49 
50 typedef int (*ANeuralNetworksModel_setOperandValue_fn)(ANeuralNetworksModel* model, int32_t index, const void* buffer, size_t length);
51 
52 typedef int (*ANeuralNetworksModel_setOperandValueFromMemory_fn)(ANeuralNetworksModel* model, int32_t index, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
53 
54 typedef int (*ANeuralNetworksModel_addOperation_fn)(ANeuralNetworksModel* model, ANeuralNetworksOperationType type, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs);
55 
56 typedef int (*ANeuralNetworksModel_identifyInputsAndOutputs_fn)(ANeuralNetworksModel* model, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs);
57 
58 typedef int (*ANeuralNetworksExecution_create_fn)(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution);
59 
60 typedef void (*ANeuralNetworksExecution_free_fn)(ANeuralNetworksExecution* execution);
61 
62 typedef int (*ANeuralNetworksExecution_setInput_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const void* buffer, size_t length);
63 
64 typedef int (*ANeuralNetworksExecution_setInputFromMemory_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
65 
66 typedef int (*ANeuralNetworksExecution_setOutput_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, void* buffer, size_t length);
67 
68 typedef int (*ANeuralNetworksExecution_setOutputFromMemory_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
69 
70 typedef int (*ANeuralNetworksExecution_startCompute_fn)(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event);
71 
72 typedef int (*ANeuralNetworksEvent_wait_fn)(ANeuralNetworksEvent* event);
73 
74 typedef void (*ANeuralNetworksEvent_free_fn)(ANeuralNetworksEvent* event);
75 
76 struct dlnnapi {
77  void* handle;
78  uint32_t flags;
79  union {
80  struct {
81  /* ndk-r16b */
82  ANeuralNetworksMemory_createFromFd_fn ANeuralNetworksMemory_createFromFd;
83  ANeuralNetworksMemory_free_fn ANeuralNetworksMemory_free;
84  ANeuralNetworksModel_create_fn ANeuralNetworksModel_create;
85  ANeuralNetworksModel_finish_fn ANeuralNetworksModel_finish;
86  ANeuralNetworksModel_free_fn ANeuralNetworksModel_free;
87  ANeuralNetworksCompilation_create_fn ANeuralNetworksCompilation_create;
88  ANeuralNetworksCompilation_free_fn ANeuralNetworksCompilation_free;
89  ANeuralNetworksCompilation_setPreference_fn ANeuralNetworksCompilation_setPreference;
90  ANeuralNetworksCompilation_finish_fn ANeuralNetworksCompilation_finish;
91  ANeuralNetworksModel_addOperand_fn ANeuralNetworksModel_addOperand;
92  ANeuralNetworksModel_setOperandValue_fn ANeuralNetworksModel_setOperandValue;
93  ANeuralNetworksModel_setOperandValueFromMemory_fn ANeuralNetworksModel_setOperandValueFromMemory;
94  ANeuralNetworksModel_addOperation_fn ANeuralNetworksModel_addOperation;
95  ANeuralNetworksModel_identifyInputsAndOutputs_fn ANeuralNetworksModel_identifyInputsAndOutputs;
96  ANeuralNetworksExecution_create_fn ANeuralNetworksExecution_create;
97  ANeuralNetworksExecution_free_fn ANeuralNetworksExecution_free;
98  ANeuralNetworksExecution_setInput_fn ANeuralNetworksExecution_setInput;
99  ANeuralNetworksExecution_setInputFromMemory_fn ANeuralNetworksExecution_setInputFromMemory;
100  ANeuralNetworksExecution_setOutput_fn ANeuralNetworksExecution_setOutput;
101  ANeuralNetworksExecution_setOutputFromMemory_fn ANeuralNetworksExecution_setOutputFromMemory;
102  ANeuralNetworksExecution_startCompute_fn ANeuralNetworksExecution_startCompute;
103  ANeuralNetworksEvent_wait_fn ANeuralNetworksEvent_wait;
104  ANeuralNetworksEvent_free_fn ANeuralNetworksEvent_free;
105  };
106  void* functions[DLNNAPI_FUNCTION_COUNT];
107  };
108 };
109 /* clang-format on */
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
115 bool dlnnapi_load(struct dlnnapi* nnapi, uint32_t flags);
116 void dlnnapi_free(struct dlnnapi* nnapi);
117 
118 #ifdef __cplusplus
119 } /* extern "C" */
120 #endif
struct ANeuralNetworksExecution ANeuralNetworksExecution
ANeuralNetworksExecution is an opaque type that can be used to apply a machine learning model to a se...
struct ANeuralNetworksCompilation ANeuralNetworksCompilation
ANeuralNetworksCompilation is an opaque type that can be used to compile a machine learning model...
ANeuralNetworksOperandType describes the type of an operand.
struct ANeuralNetworksModel ANeuralNetworksModel
ANeuralNetworksModel is an opaque type that contains a description of the mathematical operations tha...
struct ANeuralNetworksEvent ANeuralNetworksEvent
ANeuralNetworksEvent is an opaque type that represents an event that will be signaled once an executi...
struct ANeuralNetworksMemory ANeuralNetworksMemory
ANeuralNetworksMemory is an opaque type that represents memory.