Caffe2 - C++ API
A deep learning, cross platform ML framework
NeuralNetworks.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
26 #ifndef ANDROID_ML_NN_RUNTIME_NEURAL_NETWORKS_H
27 #define ANDROID_ML_NN_RUNTIME_NEURAL_NETWORKS_H
28 
29 /******************************************************************
30  *
31  * IMPORTANT NOTICE:
32  *
33  * This file is part of Android's set of stable system headers
34  * exposed by the Android NDK (Native Development Kit).
35  *
36  * Third-party source AND binary code relies on the definitions
37  * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
38  *
39  * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
40  * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
41  * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
42  * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
43  */
44 
45 #if __ANDROID_API__ >= __ANDROID_API_O_MR1__
46 
47 #include <stddef.h>
48 #include <stdint.h>
49 #include <sys/cdefs.h>
50 
51 __BEGIN_DECLS
52 
63 typedef enum {
72 
90 } OperandCode;
91 
97 typedef enum {
132 
183 
206 
277 
353 
383 
403 
435 
450 
486 
530 
553 
602 
631 
653 
687 
789 
839 
870 
890 
910 
930 
952 
972 
1020 
1046 
1075 
1146 
1165 } OperationCode;
1166 
1171 typedef enum {
1180 } FuseCode;
1181 
1186 typedef enum {
1204 
1212 } PaddingCode;
1213 
1217 typedef enum {
1233 } PreferenceCode;
1234 
1238 typedef enum {
1239  ANEURALNETWORKS_NO_ERROR = 0,
1240  ANEURALNETWORKS_OUT_OF_MEMORY = 1,
1241  ANEURALNETWORKS_INCOMPLETE = 2,
1242  ANEURALNETWORKS_UNEXPECTED_NULL = 3,
1243  ANEURALNETWORKS_BAD_DATA = 4,
1244  ANEURALNETWORKS_OP_FAILED = 5,
1245  ANEURALNETWORKS_UNMAPPABLE = 5,
1246  ANEURALNETWORKS_BAD_STATE = 6,
1247 } ResultCode;
1248 
1254 enum {
1255  ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES = 128
1256 };
1257 
1277 
1303 
1335 
1370 
1377  int32_t type;
1379  uint32_t dimensionCount;
1381  const uint32_t* dimensions;
1386  float scale;
1387  int32_t zeroPoint;
1389 
1390 typedef int32_t ANeuralNetworksOperationType;
1391 
1397 
1398 
1421 int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset,
1422  ANeuralNetworksMemory** memory);
1423 
1434 
1457 
1470 
1487 
1518 
1551  const void* buffer, size_t length);
1552 
1581  const ANeuralNetworksMemory* memory,
1582  size_t offset, size_t length);
1583 
1605  ANeuralNetworksOperationType type, uint32_t inputCount,
1606  const uint32_t* inputs, uint32_t outputCount,
1607  const uint32_t* outputs);
1608 
1631  const uint32_t* inputs, uint32_t outputCount,
1632  const uint32_t* outputs);
1633 
1660  ANeuralNetworksCompilation** compilation);
1661 
1674 
1690  int32_t preference);
1691 
1708 
1725  ANeuralNetworksExecution** execution);
1726 
1743 
1771 int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution* execution, int32_t index,
1772  const ANeuralNetworksOperandType* type, const void* buffer,
1773  size_t length);
1774 
1807  const ANeuralNetworksMemory* memory, size_t offset,
1808  size_t length);
1809 
1837 int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* execution, int32_t index,
1838  const ANeuralNetworksOperandType* type, void* buffer,
1839  size_t length);
1840 
1873  const ANeuralNetworksMemory* memory, size_t offset,
1874  size_t length);
1875 
1902  ANeuralNetworksEvent** event);
1903 
1915 
1922 
1923 __END_DECLS
1924 
1925 #endif // __ANDROID_API__ >= 27
1926 
1927 #endif // ANDROID_ML_NN_RUNTIME_NEURAL_NETWORKS_H
1928 
struct ANeuralNetworksExecution ANeuralNetworksExecution
ANeuralNetworksExecution is an opaque type that can be used to apply a machine learning model to a se...
Concatenates the input tensors along the given dimension.
Computes sigmoid activation on the input tensor element-wise.
Prefer returning a single answer as fast as possible, even if this causes more power consumption...
struct ANeuralNetworksCompilation ANeuralNetworksCompilation
ANeuralNetworksCompilation is an opaque type that can be used to compile a machine learning model...
FuseCode
Fused activation function types.
Resizes images to given size using the bilinear interpretation.
Performs an 2-D convolution operation.
Dequantizes the input tensor.
The following entries are used to declare tensors.
Projects an input to a bit vector via locality senstive hashing.
Looks up sub-tensors in the input tensor using a key-value map.
int ANeuralNetworksCompilation_setPreference(ANeuralNetworksCompilation *compilation, int32_t preference)
Sets the execution preference.
An unsigned 32 bit integer scalar value.
void ANeuralNetworksModel_free(ANeuralNetworksModel *model)
Destroy a model.
int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, void *buffer, size_t length)
Associate a user buffer with an output of the model of the ANeuralNetworksExecution.
int ANeuralNetworksCompilation_create(ANeuralNetworksModel *model, ANeuralNetworksCompilation **compilation)
Create a ANeuralNetworksCompilation to compile the given model.
void ANeuralNetworksMemory_free(ANeuralNetworksMemory *memory)
Delete a memory object.
Applies L2 normalization along the depth dimension.
int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel *model, uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs)
Specfifies which operands will be the model&#39;s inputs and outputs.
int32_t type
The data type, e.g ANEURALNETWORKS_INT8.
Fused ReLU6 activation function.
Fused ReLU1 activation function.
int ANeuralNetworksModel_finish(ANeuralNetworksModel *model)
Indicate that we have finished modifying a model.
PreferenceCode
Execution preferences.
Performs an 2-D max pooling operation.
The following entries are used to declare scalars.
Computes rectified linear 1 activation on the input tensor element-wise.
Performs a depthwise 2-D convolution operation.
Computes element-wise floor() on the input tensor.
ANeuralNetworksOperandType describes the type of an operand.
Multiplies two tensors, element-wise.
Performs a 2-D average pooling operation.
A basic recurrent neural network layer.
Reshapes a tensor.
Computes rectified linear activation on the input tensor element-wise.
Performs an 2-D L2 pooling operation.
Fused ReLU activation function.
OperandCode
Operand types.
Long short-term memory unit (LSTM) recurrent network layer.
uint32_t dimensionCount
The number of dimensions.
Denotes a fully (densely) connected layer, which connects all elements in the input tensor with each ...
Computes the softmax activation on the input tensor element-wise, per batch, by normalizing the input...
struct ANeuralNetworksModel ANeuralNetworksModel
ANeuralNetworksModel is an opaque type that contains a description of the mathematical operations tha...
Rearranges data from depth into blocks of spatial data.
struct ANeuralNetworksEvent ANeuralNetworksEvent
ANeuralNetworksEvent is an opaque type that represents an event that will be signaled once an executi...
Prefer maximizing the throughput of successive frames, for example when processing successive frames ...
int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, ANeuralNetworksEvent **event)
Schedule evaluation of the execution.
A signed 32 bit integer scalar value.
Adds two tensors, element-wise.
void ANeuralNetworksEvent_free(ANeuralNetworksEvent *event)
Destroys the event.
Computes hyperbolic tangent of input tensor element-wise.
A tensor of 8 bit integers that represent real numbers.
int ANeuralNetworksExecution_setInputFromMemory(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
Associate part of a memory object with an input of the model of the ANeuralNetworksExecution.
int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, ANeuralNetworksOperationType type, uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs)
Add an operation to a model.
Applies Local Response Normalization along the depth dimension.
int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model, const ANeuralNetworksOperandType *type)
Add an operand to a model.
void ANeuralNetworksExecution_free(ANeuralNetworksExecution *execution)
Destroy an execution.
int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation, ANeuralNetworksExecution **execution)
Create a ANeuralNetworksExecution to apply the given compilation.
int ANeuralNetworksModel_create(ANeuralNetworksModel **model)
Create an empty ANeuralNetworksModel.
NO fused activation function.
int ANeuralNetworksExecution_setOutputFromMemory(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
Associate part of a memory object with an output of the model of the ANeuralNetworksExecution.
OperationCode
Operation types.
int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset, ANeuralNetworksMemory **memory)
Creates a shared memory object from a file descriptor.
SVDF op is a kind of stateful layer derived from the notion that a densely connected layer that&#39;s pro...
float scale
These two fields are only used for quantized tensors.
Looks up sub-tensors in the input tensor.
PaddingCode
Implicit padding algorithms.
ResultCode
Result codes.
struct ANeuralNetworksOperandType ANeuralNetworksOperandType
ANeuralNetworksOperandType describes the type of an operand.
Computes rectified linear 6 activation on the input tensor element-wise.
int ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation *compilation)
Indicate that we have finished modifying a compilation.
Prefer executing in a way that minimizes battery drain.
A tensor of 32 bit integer values.
const uint32_t * dimensions
The dimensions of the tensor.
struct ANeuralNetworksMemory ANeuralNetworksMemory
ANeuralNetworksMemory is an opaque type that represents memory.
Rearranges blocks of spatial data, into depth.
int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const void *buffer, size_t length)
Associate a user buffer with an input of the model of the ANeuralNetworksExecution.
int ANeuralNetworksEvent_wait(ANeuralNetworksEvent *event)
Waits until the execution completes.
void ANeuralNetworksCompilation_free(ANeuralNetworksCompilation *compilation)
Destroy a compilation.
int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t index, const void *buffer, size_t length)
Sets an operand to a constant value.
int ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
Sets an operand to a value stored in a memory object.