Documentation for <dnnets.h>
Table of contents
- dnnets_add_clip()
- dnnets_add_elu()
- dnnets_add_layer_norm()
- dnnets_add_leaky_relu()
- dnnets_add_linear()
- dnnets_add_relu()
- dnnets_add_relu6()
- dnnets_add_sigmoid()
- dnnets_add_tanh()
- struct dnnets_clip
- dnnets_create()
- dnnets_deinit()
- struct dnnets_elu
- dnnets_forward_pass()
- dnnets_free_model()
- dnnets_free_model_definition()
- dnnets_get_output_buffer()
- dnnets_get_output_len()
- dnnets_init()
- struct dnnets_layer_norm
- struct dnnets_leaky_relu
- struct dnnets_linear
- dnnets_load_dnnf()
- dnnets_load_json()
- struct dnnets_model
- struct dnnets_model_definition
- dnnets_new_model_definition()
- dnnets_print_layers()
- enum dnnets_result
- dnnets_write_dnnf()
- dnnets_write_json()
dnnets_add_clip() ¶
enum dnnets_result dnnets_add_clip(struct dnnets_model_definition *model_definition, struct dnnets_clip cfg, uint32_t size);
Adds a new clipping layer to the model_definition.
dnnets_add_elu() ¶
enum dnnets_result dnnets_add_elu(struct dnnets_model_definition *model_definition, struct dnnets_elu cfg, uint32_t size);
Adds a new ELU layer to the model_definition.
dnnets_add_layer_norm() ¶
enum dnnets_result dnnets_add_layer_norm(struct dnnets_model_definition *model_definition, struct dnnets_layer_norm cfg, uint32_t size);
Adds a new "layer normalization" layer to the model_definition.
dnnets_add_leaky_relu() ¶
enum dnnets_result dnnets_add_leaky_relu(struct dnnets_model_definition *model_definition, struct dnnets_leaky_relu, uint32_t size);
Adds a new LeakyReLU layer to the model_definition.
dnnets_add_linear() ¶
enum dnnets_result dnnets_add_linear(struct dnnets_model_definition *model_definition, struct dnnets_linear cfg, uint32_t size);
Adds a new linear layer to the model_definition.
dnnets_add_relu() ¶
enum dnnets_result dnnets_add_relu(struct dnnets_model_definition *model_definition, uint32_t size);
Adds a new ReLU layer to the model_definition.
dnnets_add_relu6() ¶
enum dnnets_result dnnets_add_relu6(struct dnnets_model_definition *model_definition, uint32_t size);
Adds a new ReLU6 layer to the model_definition.
dnnets_add_sigmoid() ¶
enum dnnets_result dnnets_add_sigmoid(struct dnnets_model_definition *model_definition, uint32_t size);
Adds a new sigmoid layer to the model_definition.
dnnets_add_tanh() ¶
enum dnnets_result dnnets_add_tanh(struct dnnets_model_definition *model_definition, uint32_t size);
Adds a new tanh layer to the model_definition.
struct dnnets_clip ¶
struct dnnets_clip { /** minimum value */ float min; /** maximum value */ float max; };
The configuration for a clipping layer.
dnnets_create() ¶
enum dnnets_result dnnets_create(struct dnnets_model **model, struct dnnets_model_definition *model_definition);
Creates a new model from the given definition. When the model will no longer be used, don't forget to call dnnets_free_model().
This function can be called multiple times for the same definition. This might be useful if it is desired to run the same model on multiple threads concurrently.
The model will not reference any part of the model definition. This also applies to the memory of the passed weights and biases. All values will be copied so that the model owns all the data.
dnnets_deinit() ¶
enum dnnets_result dnnets_deinit(void);
Deinitializes the library. Call dnnets_init() if you need to use the libary again at some later point.
This function returns DNNETS_MEMORY_LEAK if a memory leak has been detected. Otherwise, DNNETS_SUCCESS will be returned.
struct dnnets_elu ¶
struct dnnets_elu { /** Alpha */ float alpha; };
The configuration for an ELU layer.
dnnets_forward_pass() ¶
void dnnets_forward_pass(struct dnnets_model *model, const float *input, uint32_t input_len);
Runs a forward pass for the given model and input. This operation modifies the buffers contained within the model. Therefore, concurrent execution of this function for the same model will cause issues.
To obtain the results of the forward pass, use dnnets_get_output_buffer(). The length of the output layer is also available using dnnets_get_output_len().
dnnets_free_model() ¶
void dnnets_free_model(struct dnnets_model *model);
Frees the resources allocated by the given model. The passed pointer will no longer be valid after this operation.
dnnets_free_model_definition() ¶
void dnnets_free_model_definition(struct dnnets_model_definition *model_definition);
Frees the resources owned by a model definition. The passed pointer is invalid once this function returns.
dnnets_get_output_buffer() ¶
float *dnnets_get_output_buffer(struct dnnets_model *model);
Returns a pointer to the output buffer of the given model. The results of a forward pass are available in this buffer after calling dnnets_forward_pass(). Use dnnets_get_output_len() to get the size of the output layer.
dnnets_get_output_len() ¶
uint32_t dnnets_get_output_len(struct dnnets_model *model);
Returns the size of the output layer for the given model.
dnnets_init() ¶
void dnnets_init(void);
Initializes the dnnets library. Call dnnets_deinit() once the library will no longer be used.
struct dnnets_layer_norm ¶
struct dnnets_layer_norm { /** * The weights of this layer. * The values are sorted by the index of the neuron of this layer. */ float *weights; /** * The biases of this layer. * The values are sorted by the index of the neuron of this layer. */ float *biases; /** Epsilon */ float eps; };
The configuration for a "Layer normalization" layer.
struct dnnets_leaky_relu ¶
struct dnnets_leaky_relu { /** Controls the angle of the negative slope */ float negative_slope; };
The configuration for a LeakyReLU layer.
struct dnnets_linear ¶
struct dnnets_linear { /** * The weights of this layer. * The values are sorted by the index of the neuron of this layer first. * The secodary sorting criteria is the index of the corresponding * neuron in the previous layer that serves as an input for this layer. */ float *weights; /** * The biases of this layer. * The values are sorted by the index of the neuron of this layer. */ float *biases; };
The configuration for a linear layer.
dnnets_load_dnnf() ¶
enum dnnets_result dnnets_load_dnnf(struct dnnets_model **model, const char *path);
Loads a model from a DNNF file. When the model will no longer be used, don't forget to call dnnets_free_model().
dnnets_load_json() ¶
enum dnnets_result dnnets_load_json(struct dnnets_model **model, const char *path);
Loads a model from a JSON file. When the model will no longer be used, don't forget to call dnnets_free_model().
struct dnnets_model ¶
struct dnnets_model;
A model. The exact layout of this struct is not available in the C interface of the library.
struct dnnets_model_definition ¶
struct dnnets_model_definition;
A model definition. The exact layout of this struct is not available in the C interface of the library.
dnnets_new_model_definition() ¶
enum dnnets_result dnnets_new_model_definition(struct dnnets_model_definition **model_definition, uint32_t input_layer_size);
Creates a new model definition. The pointer to this definition will be written to the address pointed to by model_definition. When the model is no longer required (usually after calling dnnets_create()), call dnnets_free_model_definition() to free the allocated resources of the definition.
The struct dnnets_model generated through dnnets_create() can still be used after calling this function.
dnnets_print_layers() ¶
void dnnets_print_layers(struct dnnets_model *model);
Prints the layers and configuration values of the given model to stderr. Weights and biases are excluded to keep the output readable.
This function is intended for debugging use only.
enum dnnets_result ¶
enum dnnets_result { DNNETS_SUCCESS, DNNETS_UNSUPPORTED_LAYER_TYPE, DNNETS_MALFORMED_POLICY_DEFINITION, DNNETS_WEIGHTS_BIASES_MISMATCH, DNNETS_WRONG_NUMBER_OF_WEIGHTS, DNNETS_WRONG_LAYER_SIZE, DNNTES_HEADER_MISMATCH, DNNETS_MEMORY_LEAK, DNNETS_FILE_NOT_FOUND, DNNETS_OUT_OF_MEMORY, DNNETS_PATH_ALREADY_EXISTS, DNNETS_ACCESS_DENIED, DNNETS_PIPE_BUSY, DNNETS_NO_DEVICE, DNNETS_NAME_TOO_LONG, DNNETS_BAD_PATH_NAME, DNNETS_UNEXPECTED, DNNETS_NETWORK_NOT_FOUND, DNNETS_ANTIVIRUS_INTERFERENCE, DNNETS_SYM_LINK_LOOP, DNNETS_PROCESS_FD_QUOTA_EXCEEDED, DNNETS_SYSTEM_FD_QUOTA_EXCEEDED, DNNETS_SYSTEM_RESOURCES, DNNETS_FILE_TOO_BIG, DNNETS_IS_DIR, DNNETS_NO_SPACE_LEFT, DNNETS_NOT_DIR, DNNETS_DEVICE_BUSY, DNNETS_FILE_LOCKS_UNSUPPORTED, DNNETS_FILE_BUSY, DNNETS_WOULD_BLOCK, DNNETS_OVERFLOW, DNNETS_INVALID_CHARACTER, DNNETS_UNEXPECTED_TOKEN, DNNETS_INVALID_NUMBER, DNNETS_INVALID_ENUM_TAG, DNNETS_DUPLICATE_FIELD, DNNETS_UNKNOWN_FIELD, DNNETS_MISSING_FIELD, DNNETS_LENGTH_MISMATCH, DNNETS_SYNTAX_ERROR, DNNETS_UNEXPECTED_END_OF_INPUT, DNNETS_VALUE_TOO_LONG, DNNETS_READ_FAILED, DNNETS_END_OF_STREAM, DNNETS_PERMISSION_DENIED, DNNETS_WRITE_FAILED, DNNETS_CANCELED, DNNETS_READ_ONLY_FILESYSTEM, };
A value indicating the return status of a function call in this library. DNNETS_SUCCESS indicates success. Other values indicate an error.
dnnets_write_dnnf() ¶
enum dnnets_result dnnets_write_dnnf(struct dnnets_model **model, const char *path);
Writes a model to a DNNF file.
dnnets_write_json() ¶
enum dnnets_result dnnets_write_json(struct dnnets_model **model, const char *path);
Writes a model to a JSON file.