Caffe2 - C++ API
A deep learning, cross platform ML framework
dlnnapi.h
1 #include <stdbool.h>
2 #include <stdint.h>
3 
4 #include "NeuralNetworks.h"
5 
6 #define DLNNAPI_FUNCTION_COUNT 23
7 
8 #define DLNNAPI_FLAG_VERSION_MASK 0xFF
9 /* Android 8.1, API 27 version */
10 #define DLNNAPI_FLAG_VERSION_27 0x01
11 
12 /* clang-format off */
13 /* nn api function types */
14 typedef int (*ANeuralNetworksMemory_createFromFd_fn)(size_t size, int protect, int fd, size_t offset, ANeuralNetworksMemory** memory);
15 
16 typedef void (*ANeuralNetworksMemory_free_fn)(ANeuralNetworksMemory* memory);
17 
18 typedef int (*ANeuralNetworksModel_create_fn)(ANeuralNetworksModel** model);
19 
20 typedef int (*ANeuralNetworksModel_finish_fn)(ANeuralNetworksModel* model);
21 
22 typedef void (*ANeuralNetworksModel_free_fn)(ANeuralNetworksModel* model);
23 
24 typedef int (*ANeuralNetworksCompilation_create_fn)(ANeuralNetworksModel* model, ANeuralNetworksCompilation** compilation);
25 
26 typedef void (*ANeuralNetworksCompilation_free_fn)(ANeuralNetworksCompilation* compilation);
27 
28 typedef int (*ANeuralNetworksCompilation_setPreference_fn)(ANeuralNetworksCompilation* compilation, int32_t preference);
29 
30 typedef int (*ANeuralNetworksCompilation_finish_fn)(ANeuralNetworksCompilation* compilation);
31 
32 typedef int (*ANeuralNetworksModel_addOperand_fn)(ANeuralNetworksModel* model, const ANeuralNetworksOperandType* type);
33 
34 typedef int (*ANeuralNetworksModel_setOperandValue_fn)(ANeuralNetworksModel* model, int32_t index, const void* buffer, size_t length);
35 
36 typedef int (*ANeuralNetworksModel_setOperandValueFromMemory_fn)(ANeuralNetworksModel* model, int32_t index, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
37 
38 typedef int (*ANeuralNetworksModel_addOperation_fn)(ANeuralNetworksModel* model, ANeuralNetworksOperationType type, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs);
39 
40 typedef int (*ANeuralNetworksModel_identifyInputsAndOutputs_fn)(ANeuralNetworksModel* model, uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount, const uint32_t* outputs);
41 
42 typedef int (*ANeuralNetworksExecution_create_fn)(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution);
43 
44 typedef void (*ANeuralNetworksExecution_free_fn)(ANeuralNetworksExecution* execution);
45 
46 typedef int (*ANeuralNetworksExecution_setInput_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const void* buffer, size_t length);
47 
48 typedef int (*ANeuralNetworksExecution_setInputFromMemory_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
49 
50 typedef int (*ANeuralNetworksExecution_setOutput_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, void* buffer, size_t length);
51 
52 typedef int (*ANeuralNetworksExecution_setOutputFromMemory_fn)(ANeuralNetworksExecution* execution, int32_t index, const ANeuralNetworksOperandType* type, const ANeuralNetworksMemory* memory, size_t offset, size_t length);
53 
54 typedef int (*ANeuralNetworksExecution_startCompute_fn)(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event);
55 
56 typedef int (*ANeuralNetworksEvent_wait_fn)(ANeuralNetworksEvent* event);
57 
58 typedef void (*ANeuralNetworksEvent_free_fn)(ANeuralNetworksEvent* event);
59 
60 struct dlnnapi {
61  void* handle;
62  uint32_t flags;
63  union {
64  struct {
65  /* ndk-r16b */
66  ANeuralNetworksMemory_createFromFd_fn ANeuralNetworksMemory_createFromFd;
67  ANeuralNetworksMemory_free_fn ANeuralNetworksMemory_free;
68  ANeuralNetworksModel_create_fn ANeuralNetworksModel_create;
69  ANeuralNetworksModel_finish_fn ANeuralNetworksModel_finish;
70  ANeuralNetworksModel_free_fn ANeuralNetworksModel_free;
71  ANeuralNetworksCompilation_create_fn ANeuralNetworksCompilation_create;
72  ANeuralNetworksCompilation_free_fn ANeuralNetworksCompilation_free;
73  ANeuralNetworksCompilation_setPreference_fn ANeuralNetworksCompilation_setPreference;
74  ANeuralNetworksCompilation_finish_fn ANeuralNetworksCompilation_finish;
75  ANeuralNetworksModel_addOperand_fn ANeuralNetworksModel_addOperand;
76  ANeuralNetworksModel_setOperandValue_fn ANeuralNetworksModel_setOperandValue;
77  ANeuralNetworksModel_setOperandValueFromMemory_fn ANeuralNetworksModel_setOperandValueFromMemory;
78  ANeuralNetworksModel_addOperation_fn ANeuralNetworksModel_addOperation;
79  ANeuralNetworksModel_identifyInputsAndOutputs_fn ANeuralNetworksModel_identifyInputsAndOutputs;
80  ANeuralNetworksExecution_create_fn ANeuralNetworksExecution_create;
81  ANeuralNetworksExecution_free_fn ANeuralNetworksExecution_free;
82  ANeuralNetworksExecution_setInput_fn ANeuralNetworksExecution_setInput;
83  ANeuralNetworksExecution_setInputFromMemory_fn ANeuralNetworksExecution_setInputFromMemory;
84  ANeuralNetworksExecution_setOutput_fn ANeuralNetworksExecution_setOutput;
85  ANeuralNetworksExecution_setOutputFromMemory_fn ANeuralNetworksExecution_setOutputFromMemory;
86  ANeuralNetworksExecution_startCompute_fn ANeuralNetworksExecution_startCompute;
87  ANeuralNetworksEvent_wait_fn ANeuralNetworksEvent_wait;
88  ANeuralNetworksEvent_free_fn ANeuralNetworksEvent_free;
89  };
90  void* functions[DLNNAPI_FUNCTION_COUNT];
91  };
92 };
93 /* clang-format on */
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 bool dlnnapi_load(struct dlnnapi* nnapi, uint32_t flags);
100 void dlnnapi_free(struct dlnnapi* nnapi);
101 
102 #ifdef __cplusplus
103 } /* extern "C" */
104 #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.