Nux C API  0.0.1
C API of NPU Engine
Macros | Typedefs | Enumerations | Functions
nux.h File Reference
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define profiler_resource_t_CPU   (uint32_t)1
 
#define profiler_resource_t_NPU   (uint32_t)2
 

Typedefs

typedef enum Axis Axis
 
typedef enum TensorDataType TensorDataType
 Represent tensor data type. More...
 
typedef enum nux_error_t nux_error_t
 Represent a return status of a function that can fail. More...
 
typedef enum nux_log_level_t nux_log_level_t
 
typedef enum profiler_format_t profiler_format_t
 
typedef struct BlockingSession BlockingSession
 
typedef struct CompletionQueue_ContextPtr CompletionQueue_ContextPtr
 
typedef struct Model Model
 
typedef struct Nux Nux
 
typedef struct NuxModel NuxModel
 
typedef struct OpaqueTensor OpaqueTensor
 
typedef struct ProfilerGuard ProfilerGuard
 
typedef struct SessionOptions SessionOptions
 
typedef struct Submitter_ContextPtr Submitter_ContextPtr
 
typedef struct Task Task
 
typedef struct TaskModel TaskModel
 
typedef struct TensorArray TensorArray
 
typedef struct TensorDesc TensorDesc
 
typedef struct Nuxnux_handle_t
 Nux handle. More...
 
typedef uintptr_t nux_buffer_len_t
 Byte length of a data buffer. More...
 
typedef struct Modelnux_sync_model_t
 Handle of a synchronous model. More...
 
typedef struct OpaqueTensornux_tensor_t
 Handle of tensor. More...
 
typedef uint8_t * nux_buffer_t
 Pointer to a data buffer. More...
 
typedef uintptr_t RequestId
 
typedef RequestId nux_request_id_t
 Identifier to distinguish tasks in a task model. More...
 
typedef uint32_t OutputIndex
 
typedef OutputIndex nux_output_index_t
 Index of an output tensor, used in task model. More...
 
typedef void(* nux_output_callback_t) (nux_request_id_t, nux_output_index_t, nux_buffer_t, nux_buffer_len_t)
 Callback function called per tensor output when a task of a task model is completed. More...
 
typedef void(* nux_error_callback_t) (nux_request_id_t, enum nux_error_t)
 Callback function called when a task fails to complete. More...
 
typedef void(* nux_finish_callback_t) (nux_request_id_t)
 Callback function which is finally called when a task is completed. More...
 
typedef struct TaskModelnux_task_model_t
 Handle of a task model. More...
 
typedef struct Tasknux_task_t
 Handle of a task of a task model. More...
 
typedef uint32_t InputIndex
 
typedef InputIndex nux_input_index_t
 Index of an input tensor, used in task model. More...
 
typedef struct SessionOptionsnux_session_option_t
 Session option. More...
 
typedef const struct BlockingSessionnux_session_t
 Session. More...
 
typedef const struct NuxModelnux_model_t
 Model. More...
 
typedef struct TensorArraynux_tensor_array_t
 
typedef struct Submitter_ContextPtrnux_async_session_t
 Async Session. More...
 
typedef struct CompletionQueue_ContextPtrnux_completion_queue_t
 
typedef void * nux_context_t
 Context pointer. More...
 
typedef const struct TensorDescnux_tensor_desc_t
 
typedef char * nux_string_t
 A null-terminated C string. More...
 
typedef enum TensorDataType nux_tensor_dtype_t
 Represent a data type of tensor. More...
 
typedef uint32_t profiler_resource_t
 
typedef struct ProfilerGuardprofiler_handle_t
 
typedef Span * profiler_span_t
 
typedef const Config * npu_config_t
 

Enumerations

enum  Axis {
  axis_width = 0 , axis_height = 1 , axis_channel = 2 , axis_batch = 3 ,
  axis_width_outer = 4 , axis_height_outer = 5 , axis_channel_outer = 6 , axis_batch_outer = 7 ,
  axis_unknown = 8 , axis_group = 9 , axis_group_outer = 10
}
 
enum  TensorDataType {
  tensor_data_type_float32 = 0 , tensor_data_type_uint8 = 1 , tensor_data_type_int8 = 2 , tensor_data_type_int32 = 3 ,
  tensor_data_type_int64 = 4 , tensor_data_type_bfloat16 = 5 , tensor_data_type_bool = 6 , tensor_data_type_int4 = 7 ,
  tensor_data_type_float8_e5m2 = 8 , tensor_data_type_float8_e4m3 = 9 , tensor_data_type_int16 = 10 , tensor_data_type_float16 = 11
}
 Represent tensor data type. More...
 
enum  nux_error_t {
  nux_error_t_success = 0 , nux_error_t_nux_creation_failed = 1 , nux_error_t_model_deploy_failed = 2 , nux_error_t_model_execution_failed = 3 ,
  nux_error_t_invalid_input_index = 4 , nux_error_t_invalid_output_index = 5 , nux_error_t_invalid_buffer = 6 , nux_error_t_invalid_inputs = 7 ,
  nux_error_t_invalid_outputs = 8 , nux_error_t_get_task_failed = 9 , nux_error_t_dump_profile_failed = 10 , nux_error_t_queue_wait_timeout = 11 ,
  nux_error_t_queue_no_data = 12 , nux_error_t_incompatible_model = 13 , nux_error_t_compilation_failed = 14 , nux_error_t_internal_error = 15 ,
  nux_error_t_invalid_yaml = 16 , nux_error_t_incompatible_api_client_error = 17 , nux_error_t_api_client_init_failed = 18 , nux_error_t_no_api_key = 19 ,
  nux_error_t_null_pointer_exception = 20 , nux_error_t_invalid_session_options = 21 , nux_error_t_session_terminated = 22 , nux_error_t_device_busy = 23 ,
  nux_error_t_tensor_name_not_found = 24 , nux_error_t_unsupported_feature = 25 , nux_error_t_npu_interrupt = 26 , nux_error_t_npu_error = 27 ,
  nux_error_t_queue_full = 28 , nux_error_t_queue_empty = 29 , nux_error_t_invalid_compiler_config = 30
}
 Represent a return status of a function that can fail. More...
 
enum  nux_log_level_t { nux_log_level_t_off = 0 , nux_log_level_t_error = 1 , nux_log_level_t_warn = 2 , nux_log_level_t_info = 3 }
 
enum  profiler_format_t { profiler_format_t_chrome_trace = 0 , profiler_format_t_csv_trace = 1 }
 

Functions

const char * version (void)
 Return a version of Nux native library. More...
 
const char * git_short_hash (void)
 Return a short Git hash of Nux native library. More...
 
const char * build_timestamp (void)
 Return a build timestamp of Nux native library. More...
 
void enable_logging (enum nux_log_level_t _log_level)
 Enable a logger with a specific log level. More...
 
void register_signal_handler (void)
 Register Ctrl-C signal handler to exit process. More...
 
enum nux_error_t create_nux (nux_handle_t *nux)
 Creates a new nux handle. More...
 
void destroy_nux (nux_handle_t nux)
 Destroy the Nux handle and release its resources. More...
 
enum nux_error_t nux_create_sync_model (nux_handle_t nux, const uint8_t *buffer, nux_buffer_len_t len, nux_sync_model_t *model)
 Create an instance of a synchronous model. More...
 
void destroy_sync_model (nux_sync_model_t model)
 Destroy the sync model and release its resources. More...
 
uint32_t model_count_inputs (nux_sync_model_t model)
 Return the number of input tensors of a given sync model. More...
 
uint32_t model_count_outputs (nux_sync_model_t model)
 Return the number of output tensors of a given sync model. More...
 
enum nux_error_t model_input_tensor (nux_sync_model_t model, uint32_t index, nux_tensor_t *tensor)
 Get the handle of a specified input tensor from a given sync model. More...
 
enum nux_error_t model_output_tensor (nux_sync_model_t model, uint32_t index, nux_tensor_t *tensor)
 Get the handle of a specified output tensor from a given sync model. More...
 
enum nux_error_t model_run (nux_sync_model_t model)
 Run a single inference task. More...
 
enum nux_error_t tensor_get_buffer (nux_tensor_t tensor, nux_buffer_t *buffer, nux_buffer_len_t *len)
 Get a pointer to the data buffer of a given tensor. More...
 
enum nux_error_t tensor_fill_buffer (nux_tensor_t tensor, nux_buffer_t buffer, nux_buffer_len_t len)
 Copy data into the data buffer of a specified input tensor. More...
 
enum nux_error_t tensor_set_buffer (nux_tensor_t tensor, nux_buffer_t buffer, nux_buffer_len_t len, void(*free)(uint8_t *, uintptr_t))
 Specify a pointer to a data buffer to a specified input tensor. More...
 
enum nux_error_t nux_create_task_model (nux_handle_t nux, const uint8_t *buffer, nux_buffer_len_t len, uint32_t max_batch, nux_output_callback_t output_callback, nux_error_callback_t error_callback, nux_finish_callback_t finish_callback, nux_task_model_t *task_model)
 Create an instance of a task model. More...
 
void destroy_task_model (nux_task_model_t task_model)
 Destroy the task model and release its resources. More...
 
bool task_model_is_all_task_done (nux_task_model_t task_model)
 Return true if there's no running tasks, or false if any task is still running. More...
 
enum nux_error_t task_model_get_task (nux_task_model_t task_model, nux_task_t *task)
 Get a task handle from a specified task model. More...
 
enum nux_error_t task_model_try_get_task (nux_task_model_t task_model, nux_task_t *task)
 (non-blocking) Get a task handle from the specified task model. More...
 
void destroy_task (nux_task_t task)
 Destroy the task and release its resources. More...
 
enum nux_error_t task_execute (nux_task_t task, nux_request_id_t request_id)
 Request one asynchronous inference task. More...
 
nux_buffer_t task_input (nux_task_t task, nux_input_index_t index)
 Return a mutable pointer to the buffer of the specified input tensor. More...
 
nux_buffer_len_t task_input_size (nux_task_t task, nux_input_index_t index)
 Return the buffer length in bytes of the specified input tensor. More...
 
nux_session_option_t nux_session_option_create (void)
 Create a session option. More...
 
void nux_session_option_set_device (nux_session_option_t builder, const char *devname)
 Set a NPU device to the given session option. More...
 
void nux_session_option_set_worker_num (nux_session_option_t builder, uintptr_t num)
 Set the number of workers to the given session option. More...
 
void nux_session_option_set_batch_size (nux_session_option_t builder, uintptr_t num)
 Set the batch size of input tensors. More...
 
void nux_session_option_set_compiler_log_path (nux_session_option_t builder, const char *path)
 Set the file path to which the compiler saves log messages. More...
 
void nux_session_option_enable_compiler_hints (nux_session_option_t builder, bool enable)
 Enable the compiler hints. More...
 
void nux_session_option_set_input_queue_size (nux_session_option_t builder, uintptr_t len)
 Set the input queue size of async session. More...
 
void nux_session_option_set_output_queue_size (nux_session_option_t builder, uintptr_t len)
 Set the output queue size of async session. More...
 
enum nux_error_t nux_session_option_set_compiler_config (nux_session_option_t option, const char *yaml)
 Set a compiler config to the given session option. More...
 
void nux_session_option_destroy (nux_session_option_t option)
 Destroy a session option. More...
 
enum nux_error_t nux_session_create (nux_buffer_t model_binary, nux_buffer_len_t model_binary_len, nux_session_option_t option, nux_session_t *out_sess)
 Create a session. More...
 
nux_model_t nux_session_get_model (nux_session_t sess)
 Get the pointer of the Model of a given session. More...
 
enum nux_error_t nux_session_run (nux_session_t sess, nux_tensor_array_t inputs, nux_tensor_array_t outputs)
 Run an inference task. More...
 
enum nux_error_t nux_session_run_with (nux_session_t sess, const char *const *input_names, uintptr_t input_len, const char *const *output_names, uintptr_t output_len, nux_tensor_array_t inputs, nux_tensor_array_t outputs)
 Run an inference task with tensor names The number of input/output tensors and its corresponding names must be the same. More...
 
void nux_session_destroy (nux_session_t sess)
 Destroy a session. More...
 
enum nux_error_t nux_async_session_create (nux_buffer_t model_binary, nux_buffer_len_t model_binary_len, nux_session_option_t option, nux_async_session_t *out_sess, nux_completion_queue_t *out_queue)
 Create an asynchronous session and a queue to receive the results. More...
 
enum nux_error_t nux_async_session_run (nux_async_session_t sess, nux_context_t context, nux_tensor_array_t inputs)
 Submit an inference task asynchronously. It returns immediately. More...
 
bool nux_completion_queue_next (nux_completion_queue_t queue, nux_context_t *context, nux_tensor_array_t *outputs, enum nux_error_t *error)
 Wait until it receives any completion event, which can be success or fail. More...
 
bool nux_completion_queue_try_next (nux_completion_queue_t queue, nux_context_t *context, nux_tensor_array_t *outputs, enum nux_error_t *error)
 It's almost the same as nux_completion_queue_next. However, this call immediately returns even if it hasn't received any result event after the last call. In the case, it will set error to nux_error_t_queue_no_data. More...
 
bool nux_completion_queue_next_timeout (nux_completion_queue_t queue, uint64_t timeout_ms, nux_context_t *context, nux_tensor_array_t *outputs, enum nux_error_t *error)
 It's almost the same as nux_completion_queue_next. However, this call will be blocked only until a timeout occurs even if it hasn't received any result. In this case, it will set nux_error_t_queue_wait_timeout to error. More...
 
nux_model_t nux_async_session_get_model (nux_async_session_t sess)
 Get the pointer of the Model of a given asynchronous session. More...
 
void nux_async_session_destroy (nux_async_session_t sess)
 Destroy an asynchronous session. More...
 
void nux_completion_queue_destroy (nux_completion_queue_t queue)
 Destroy a completion queue. More...
 
uintptr_t nux_input_num (nux_model_t model)
 Return the number of input tensors of the given model. More...
 
uintptr_t nux_output_num (nux_model_t model)
 Return the number of output tensors of the given model. More...
 
nux_tensor_desc_t nux_tensor_desc_by_name (nux_model_t model, const char *name)
 Return the description of the tensor matched to the given name. More...
 
nux_tensor_desc_t nux_input_desc (nux_model_t model, uintptr_t index)
 Return the description of i-th input tensor of the given model. More...
 
nux_tensor_desc_t nux_output_desc (nux_model_t model, uintptr_t index)
 Return the description of i-th output tensor of the given model. More...
 
nux_string_t nux_tensor_name (nux_tensor_desc_t tensor)
 Return the tensor name and transfers its ownership to the caller. To destroy nux_string_t, please call nux_string_destroy. More...
 
uintptr_t nux_tensor_dim_num (nux_tensor_desc_t tensor)
 Return the number of dimensions of the given tensor. More...
 
uintptr_t nux_tensor_dim (nux_tensor_desc_t tensor, uintptr_t index)
 Return the dimension size of the dimension index. More...
 
uintptr_t nux_tensor_stride (nux_tensor_desc_t tensor, uintptr_t index)
 Return the stride value of the dimension index. More...
 
enum Axis nux_tensor_axis (nux_tensor_desc_t tensor, uintptr_t idx)
 Return the axis type of i-th dimension (e.g., Width, Height, Channel) More...
 
nux_tensor_dtype_t nux_tensor_dtype (nux_tensor_desc_t tensor)
 Return the tensor data type. More...
 
enum nux_error_t nux_tensor_quantization_parameter (nux_tensor_desc_t tensor, double *scale, int32_t *zero_point)
 Return the quantization parameter. More...
 
uintptr_t nux_tensor_len (nux_tensor_desc_t tensor)
 Return the total number of all elements. More...
 
uintptr_t nux_tensor_size (nux_tensor_desc_t tensor)
 Return the byte size of tensor. More...
 
nux_tensor_t nux_tensor_create (nux_tensor_desc_t desc)
 Create a tensor according to a given tensor description. More...
 
nux_tensor_t nux_tensor_create_with_buffer (nux_tensor_desc_t desc, nux_buffer_t buffer, nux_buffer_len_t len, void(*free)(uint8_t *, uintptr_t))
 Create a tensor with an exiting buffer. It doesn't copy the data. More...
 
void nux_tensor_destroy (nux_tensor_t tensor)
 Destroy a tensor. More...
 
uint8_t * nux_tensor_buffer (nux_tensor_t tensor)
 Return the pointer to the buffer of this tensor. More...
 
uintptr_t nux_tensor_buffer_size (nux_tensor_t tensor)
 Return the size of tensor buffer. More...
 
nux_tensor_array_t nux_tensor_array_allocate_by_names (nux_model_t model, const char *const *names, uintptr_t len)
 Return an array of tensors corresponding to the names with allocated buffers. More...
 
nux_tensor_array_t nux_tensor_array_create_by_names (nux_model_t model, const char *const *names, uintptr_t len)
 Return an array of tensors corresponding to the names without allocated buffers. More...
 
nux_tensor_array_t nux_tensor_array_allocate_inputs (nux_model_t model)
 Return an array of input tensors with allocated buffers. More...
 
nux_tensor_array_t nux_tensor_array_create_inputs (nux_model_t model)
 Return an array of input tensors without allocated buffers. More...
 
nux_tensor_array_t nux_tensor_array_allocate_outputs (nux_model_t model)
 Return an array of output tensors with allocated buffers. More...
 
nux_tensor_array_t nux_tensor_array_create_outputs (nux_model_t model)
 Return an array of output tensors without allocated buffers. More...
 
nux_tensor_t nux_tensor_array_get (nux_tensor_array_t array, uintptr_t index)
 Return a tensor from the given tensor array. More...
 
uintptr_t nux_tensor_array_len (nux_tensor_array_t array)
 Return the number of tensors in the given tensor array. More...
 
void nux_tensor_array_destroy (nux_tensor_array_t array)
 Destroy a tensor array. More...
 
void nux_buffer_destroy (uint8_t *buf, nux_buffer_len_t len)
 Destroy a buffer. More...
 
void nux_string_destroy (nux_string_t str)
 Destroy a buffer. More...
 
enum nux_error_t profiler_enable (profiler_resource_t resource, enum profiler_format_t format, const char *config, profiler_handle_t *profiler)
 Enable a profiler and return the profiler handle. More...
 
void profiler_disable (profiler_handle_t profiler)
 Disable a profiler. More...
 
profiler_span_t profiler_record_start (const char *record_name, bool _warm_up)
 Create beginning profiler span with specified name. More...
 
void profiler_record_end (profiler_span_t span)
 Create end profiler span with specified name. More...
 
npu_config_t get_npu_spec (const char *npuid)
 Get NPU specification by NPUID. More...
 

Macro Definition Documentation

◆ profiler_resource_t_CPU

#define profiler_resource_t_CPU   (uint32_t)1

◆ profiler_resource_t_NPU

#define profiler_resource_t_NPU   (uint32_t)2

Typedef Documentation

◆ Axis

typedef enum Axis Axis

◆ BlockingSession

◆ CompletionQueue_ContextPtr

◆ InputIndex

typedef uint32_t InputIndex

◆ Model

typedef struct Model Model

◆ npu_config_t

typedef const Config* npu_config_t

◆ Nux

typedef struct Nux Nux

◆ nux_async_session_t

Async Session.

◆ nux_buffer_len_t

typedef uintptr_t nux_buffer_len_t

Byte length of a data buffer.

◆ nux_buffer_t

typedef uint8_t* nux_buffer_t

Pointer to a data buffer.

In Nux, it is commonly used to contain any kind of binary data like ENF binary, or a data buffer of input/output tensors.

◆ nux_completion_queue_t

◆ nux_context_t

typedef void* nux_context_t

Context pointer.

◆ nux_error_callback_t

typedef void(* nux_error_callback_t) (nux_request_id_t, enum nux_error_t)

Callback function called when a task fails to complete.

◆ nux_error_t

typedef enum nux_error_t nux_error_t

Represent a return status of a function that can fail.

◆ nux_finish_callback_t

typedef void(* nux_finish_callback_t) (nux_request_id_t)

Callback function which is finally called when a task is completed.

Unlike nux_output_callback_t, this callback function is called only once after nux_output_callback_t is called for all output tensors.

◆ nux_handle_t

typedef struct Nux* nux_handle_t

Nux handle.

create_nux initializes an instance of nux_handle_t.

◆ nux_input_index_t

Index of an input tensor, used in task model.

◆ nux_log_level_t

◆ nux_model_t

typedef const struct NuxModel* nux_model_t

Model.

◆ nux_output_callback_t

typedef void(* nux_output_callback_t) (nux_request_id_t, nux_output_index_t, nux_buffer_t, nux_buffer_len_t)

Callback function called per tensor output when a task of a task model is completed.

For example, if one model has 2 output tensors, this function will be called 2 times upon each task's completion.

◆ nux_output_index_t

Index of an output tensor, used in task model.

◆ nux_request_id_t

Identifier to distinguish tasks in a task model.

◆ nux_session_option_t

Session option.

◆ nux_session_t

typedef const struct BlockingSession* nux_session_t

Session.

◆ nux_string_t

typedef char* nux_string_t

A null-terminated C string.

◆ nux_sync_model_t

typedef struct Model* nux_sync_model_t

Handle of a synchronous model.

nux_create_sync_model initializes an instance of nux_sync_model_t.

◆ nux_task_model_t

typedef struct TaskModel* nux_task_model_t

Handle of a task model.

nux_create_task_model creates an instance of nux_task_model_t.

◆ nux_task_t

typedef struct Task* nux_task_t

Handle of a task of a task model.

task_model_get_task or task_model_try_get_task returns an instance of nux_task_t.

◆ nux_tensor_array_t

◆ nux_tensor_desc_t

typedef const struct TensorDesc* nux_tensor_desc_t

◆ nux_tensor_dtype_t

Represent a data type of tensor.

◆ nux_tensor_t

typedef struct OpaqueTensor* nux_tensor_t

Handle of tensor.

model_input_tensor or model_output_tensor returns an instance of nux_tensor_t.

◆ NuxModel

typedef struct NuxModel NuxModel

◆ OpaqueTensor

typedef struct OpaqueTensor OpaqueTensor

◆ OutputIndex

typedef uint32_t OutputIndex

◆ profiler_format_t

◆ profiler_handle_t

◆ profiler_resource_t

typedef uint32_t profiler_resource_t

◆ profiler_span_t

typedef Span* profiler_span_t

◆ ProfilerGuard

typedef struct ProfilerGuard ProfilerGuard

◆ RequestId

typedef uintptr_t RequestId

◆ SessionOptions

◆ Submitter_ContextPtr

◆ Task

typedef struct Task Task

◆ TaskModel

typedef struct TaskModel TaskModel

◆ TensorArray

typedef struct TensorArray TensorArray

◆ TensorDataType

Represent tensor data type.

◆ TensorDesc

typedef struct TensorDesc TensorDesc

Enumeration Type Documentation

◆ Axis

enum Axis
Enumerator
axis_width 
axis_height 
axis_channel 

For convolution weights, this axis is also known as an input channel.

axis_batch 

For convolution weights, this axis is also known as an output channel or feature map.

axis_width_outer 
axis_height_outer 
axis_channel_outer 
axis_batch_outer 
axis_unknown 
axis_group 
axis_group_outer 

◆ nux_error_t

Represent a return status of a function that can fail.

Enumerator
nux_error_t_success 

When a function call is successful

nux_error_t_nux_creation_failed 

When create_nux fails to initialize

nux_error_t_model_deploy_failed 

When deploying a model to an executor fails. See also nux_create_sync_model, nux_create_task_model for more details.

nux_error_t_model_execution_failed 

When running an inference task fails. See also model_run, task_execute for more details.

nux_error_t_invalid_input_index 

When the given index of an input tensor is invalid. See also model_input_tensor for more details.

nux_error_t_invalid_output_index 

When the given index of an output tensor is invalid. See also model_output_tensor for more details.

nux_error_t_invalid_buffer 

When a data buffer is invalid. See tensor_set_buffer for more details.

nux_error_t_invalid_inputs 

When the input tensors are invalid

nux_error_t_invalid_outputs 

When the output tensors are invalid

nux_error_t_get_task_failed 

When task_model_get_task or task_model_try_get_task fails to return an available task slot. This error code can have different meanings in both functions. Please see task_model_get_task and task_model_try_get_task for more details.

nux_error_t_dump_profile_failed 

reserved

nux_error_t_queue_wait_timeout 

When waiting for completion queue is timed out

nux_error_t_queue_no_data 

When there's no data in completion queue

nux_error_t_incompatible_model 

When loading a model image fails

nux_error_t_compilation_failed 

When the compiler fails to transform a given model image to a binary for NPU

nux_error_t_internal_error 

Internal error

nux_error_t_invalid_yaml 

Invalid yaml syntax

nux_error_t_incompatible_api_client_error 

incompatible api client error

nux_error_t_api_client_init_failed 

when api client fails to initialize

nux_error_t_no_api_key 

No API Key

nux_error_t_null_pointer_exception 

Null pointer exception

nux_error_t_invalid_session_options 

Invalid session option

nux_error_t_session_terminated 

Session termination

nux_error_t_device_busy 

NPU device is busy

nux_error_t_tensor_name_not_found 

Tensor name not found in a given model

nux_error_t_unsupported_feature 

Unsupported feature

nux_error_t_npu_interrupt 

Npu interrupt

nux_error_t_npu_error 

Npu error, TODO, specify all errors in here

nux_error_t_queue_full 

When a queue is full

nux_error_t_queue_empty 

When a queue is empty

nux_error_t_invalid_compiler_config 

When a compiler config is invalid

◆ nux_log_level_t

Enumerator
nux_log_level_t_off 
nux_log_level_t_error 
nux_log_level_t_warn 
nux_log_level_t_info 

◆ profiler_format_t

Enumerator
profiler_format_t_chrome_trace 
profiler_format_t_csv_trace 

◆ TensorDataType

Represent tensor data type.

Enumerator
tensor_data_type_float32 
tensor_data_type_uint8 
tensor_data_type_int8 
tensor_data_type_int32 
tensor_data_type_int64 
tensor_data_type_bfloat16 
tensor_data_type_bool 
tensor_data_type_int4 
tensor_data_type_float8_e5m2 
tensor_data_type_float8_e4m3 
tensor_data_type_int16 
tensor_data_type_float16 

Function Documentation

◆ build_timestamp()

const char* build_timestamp ( void  )

Return a build timestamp of Nux native library.

◆ create_nux()

enum nux_error_t create_nux ( nux_handle_t nux)

Creates a new nux handle.

Parameters
[out]nuxMutable pointer to receive a created Nux handle
Returns
nux_error_t_success if successful, or it will return nux_error_t_nux_creation_failed.

◆ destroy_nux()

void destroy_nux ( nux_handle_t  nux)

Destroy the Nux handle and release its resources.

Parameters
nuxNux handle to be destroyed. It must not be NULL.

◆ destroy_sync_model()

void destroy_sync_model ( nux_sync_model_t  model)

Destroy the sync model and release its resources.

Parameters
modelSync model to be destroyed, and it must not be NULL.

◆ destroy_task()

void destroy_task ( nux_task_t  task)

Destroy the task and release its resources.

Remarks
Once you call task_execute with a task, the task will get destroyed automatically. Please do not call destroy_task with the task which is already passed to task_execute.
Parameters
taskTask to be destroyed

◆ destroy_task_model()

void destroy_task_model ( nux_task_model_t  task_model)

Destroy the task model and release its resources.

Parameters
task_modelTask model to be destroyed

◆ enable_logging()

void enable_logging ( enum nux_log_level_t  _log_level)

Enable a logger with a specific log level.

Parameters
log_levelLog level (off, error, warn, info)

◆ get_npu_spec()

npu_config_t get_npu_spec ( const char *  npuid)

Get NPU specification by NPUID.

Parameters
npuidNPUID, indicating a specific NPU configuration with a certain NPU chip. Currently, available NPUIDs are WARBOY and WARBOY-2PE.
Returns
A reference of the a specific NPU specification. The ownership is not transferred to the caller.

◆ git_short_hash()

const char* git_short_hash ( void  )

Return a short Git hash of Nux native library.

◆ model_count_inputs()

uint32_t model_count_inputs ( nux_sync_model_t  model)

Return the number of input tensors of a given sync model.

A model can have more than one input tensor. This function returns how many input tensors this model has.

Parameters
modelSync model
Returns
Output tensors of this model

◆ model_count_outputs()

uint32_t model_count_outputs ( nux_sync_model_t  model)

Return the number of output tensors of a given sync model.

A model can have more than one output tensor. This function returns how many output tensors this model has.

Parameters
modelSync model
Returns
Output tensors of this model

◆ model_input_tensor()

enum nux_error_t model_input_tensor ( nux_sync_model_t  model,
uint32_t  index,
nux_tensor_t tensor 
)

Get the handle of a specified input tensor from a given sync model.

Remarks
An input tensor handle will be valid until destroy_sync_model with this model is called.
Parameters
modelSync model
indexInput tensor index
[out]tensorMutable pointer to receive the handle of a specified input tensor

◆ model_output_tensor()

enum nux_error_t model_output_tensor ( nux_sync_model_t  model,
uint32_t  index,
nux_tensor_t tensor 
)

Get the handle of a specified output tensor from a given sync model.

Remarks
Output tensor handle will be valid until destroy_sync_model with this model is called.
Parameters
modelSync model
indexOutput tensor index
[out]tensorMutable pointer to receive a specified output tensor handle

◆ model_run()

enum nux_error_t model_run ( nux_sync_model_t  model)

Run a single inference task.

Before calling this function, you must fill input tensors with proper data. Please refer to model_input_tensor and tensor_set_buffer to learn how to fill input tensors with data.

◆ nux_async_session_create()

enum nux_error_t nux_async_session_create ( nux_buffer_t  model_binary,
nux_buffer_len_t  model_binary_len,
nux_session_option_t  option,
nux_async_session_t out_sess,
nux_completion_queue_t out_queue 
)

Create an asynchronous session and a queue to receive the results.

nux_async_session_t allows users to submit inference tasks. nux_completion_queue_t is an iterator to receive the result in the asynchronous way. See also nux_async_session_run and nux_completion_queue_next.

Parameters
model_binaryBuffer which contains a model binary
model_binary_lenLength of model_binary
optionSession option. If it is null, the default option will be used.
[out]out_sessMutable pointer to an instance of async session
[out]out_queueMutable pointer to an instance of async completion queue

◆ nux_async_session_destroy()

void nux_async_session_destroy ( nux_async_session_t  sess)

Destroy an asynchronous session.

◆ nux_async_session_get_model()

nux_model_t nux_async_session_get_model ( nux_async_session_t  sess)

Get the pointer of the Model of a given asynchronous session.

Parameters
sessHandle of asynchronous session instance. It must not be NULL.
Returns
Pointer of the Model of a given asynchronous session

◆ nux_async_session_run()

enum nux_error_t nux_async_session_run ( nux_async_session_t  sess,
nux_context_t  context,
nux_tensor_array_t  inputs 
)

Submit an inference task asynchronously. It returns immediately.

You can receive the completed inference results through nux_completion_queue_t. please refer to nux_completion_queue_next to know how to receive the completed results.

Parameters
sessHandle of asynchronous session
<tt>context</tt>is a void pointer, so you can pass any data to context. Generally, context can be used to identify what's the completion event. Also, sophisticated data structure can be used to to do more as soon as you receive the completion event. You must make sure the pointer must be valid as long as you want to use a passed context even after you receive the completion event.
inputsan array of tensors

◆ nux_buffer_destroy()

void nux_buffer_destroy ( uint8_t *  buf,
nux_buffer_len_t  len 
)

Destroy a buffer.

Parameters
bufferByte buffer to be destroyed. It must not be NULL.
lenByte length of buffer

◆ nux_completion_queue_destroy()

void nux_completion_queue_destroy ( nux_completion_queue_t  queue)

Destroy a completion queue.

◆ nux_completion_queue_next()

bool nux_completion_queue_next ( nux_completion_queue_t  queue,
nux_context_t context,
nux_tensor_array_t outputs,
enum nux_error_t error 
)

Wait until it receives any completion event, which can be success or fail.

Parameters
queueAsync completion queue
[out]contextA pointer of the context value that you passed to nux_async_session_run
[out]outputsOutput tensors
[out]errornux_error_t_success if successful, nux_error_t_session_terminated if the async session is terminated, or it will return other error value.
Returns
True if async_session is still alive, or False.

◆ nux_completion_queue_next_timeout()

bool nux_completion_queue_next_timeout ( nux_completion_queue_t  queue,
uint64_t  timeout_ms,
nux_context_t context,
nux_tensor_array_t outputs,
enum nux_error_t error 
)

It's almost the same as nux_completion_queue_next. However, this call will be blocked only until a timeout occurs even if it hasn't received any result. In this case, it will set nux_error_t_queue_wait_timeout to error.

Parameters
queueAsync completion queue
timeout_msHow long to wait before giving up, and its time unit is milliseconds.
[out]contextA pointer of the context value that you passed to nux_async_session_run
[out]outputsOutput tensors
[out]errornux_error_t_success if successful, nux_error_t_session_terminated if the async session is terminated, #queue_wait_timeout if no data is received until the timeout, or it will return other error value.
Returns
True if async_session is still alive, or False.

◆ nux_completion_queue_try_next()

bool nux_completion_queue_try_next ( nux_completion_queue_t  queue,
nux_context_t context,
nux_tensor_array_t outputs,
enum nux_error_t error 
)

It's almost the same as nux_completion_queue_next. However, this call immediately returns even if it hasn't received any result event after the last call. In the case, it will set error to nux_error_t_queue_no_data.

Parameters
queueAsync completion queue
[out]contextA pointer of the context value that you passed to nux_async_session_run
[out]outputsOutput tensors
[out]errornux_error_t_success if successful, nux_error_t_session_terminated if the async session is terminated, nux_error_t_queue_no_data if no result is received, or it will return other error value.
Returns
True if async_session is still alive, or False.

◆ nux_create_sync_model()

enum nux_error_t nux_create_sync_model ( nux_handle_t  nux,
const uint8_t *  buffer,
nux_buffer_len_t  len,
nux_sync_model_t model 
)

Create an instance of a synchronous model.

It creates a synchronous model to execute a compiled ENF binary. The synchronous model provides APIs to run a single inference task with one input batch at a time.

Parameters
nuxNux handle
bufferByte buffer containing ENF binary
lenByte length of buffer
[out]modelMutable pointer to receive the handle of a created sync model

◆ nux_create_task_model()

enum nux_error_t nux_create_task_model ( nux_handle_t  nux,
const uint8_t *  buffer,
nux_buffer_len_t  len,
uint32_t  max_batch,
nux_output_callback_t  output_callback,
nux_error_callback_t  error_callback,
nux_finish_callback_t  finish_callback,
nux_task_model_t task_model 
)

Create an instance of a task model.

It allows users to run multiple inference tasks asynchronously and simultaneously. When each task is completed or failed, corresponding callback functions will be called with nux_request_id_t, an identifier of a task request. See also task_execute for more details.

Parameters
nuxNux handle
bufferByte buffer containing ENF binary
lenByte length of buffer
max_batchNumber of concurrent running tasks It can be limited according to internal configurations and HW capacity.
output_callbackCallback function invoked when a task is completed. It will be called per output tensor. Please see nux_output_callback_t for more details.
error_callbackCallback function invoked when a task is failed.
finish_callbackCallback function which will be called finally after the output_callback is called after all output tensors.
task_modelMutable pointer to receive the handle of a created task model

◆ nux_input_desc()

nux_tensor_desc_t nux_input_desc ( nux_model_t  model,
uintptr_t  index 
)

Return the description of i-th input tensor of the given model.

◆ nux_input_num()

uintptr_t nux_input_num ( nux_model_t  model)

Return the number of input tensors of the given model.

◆ nux_output_desc()

nux_tensor_desc_t nux_output_desc ( nux_model_t  model,
uintptr_t  index 
)

Return the description of i-th output tensor of the given model.

◆ nux_output_num()

uintptr_t nux_output_num ( nux_model_t  model)

Return the number of output tensors of the given model.

◆ nux_session_create()

enum nux_error_t nux_session_create ( nux_buffer_t  model_binary,
nux_buffer_len_t  model_binary_len,
nux_session_option_t  option,
nux_session_t out_sess 
)

Create a session.

Session provides simple and synchronous APIs to run inference tasks from a loaded model.

Parameters
model_binaryBuffer which contains a model binary
model_binary_lenLength of model_binary
optionSession option. If it is null, the default option will be used.
[out]sessMutable pointer to receive a created Nux handle
Returns
nux_error_t_success if successful. or it will return other error value.

◆ nux_session_destroy()

void nux_session_destroy ( nux_session_t  sess)

Destroy a session.

Parameters
sessHandle of Session instance to be destroyed. It must not be NULL.

◆ nux_session_get_model()

nux_model_t nux_session_get_model ( nux_session_t  sess)

Get the pointer of the Model of a given session.

Parameters
sessHandle of session instance. It must not be NULL.
Returns
Pointer of the Model of a given session

◆ nux_session_option_create()

nux_session_option_t nux_session_option_create ( void  )

Create a session option.

It allows to specify more options for a session.

Returns
Session option

◆ nux_session_option_destroy()

void nux_session_option_destroy ( nux_session_option_t  option)

Destroy a session option.

◆ nux_session_option_enable_compiler_hints()

void nux_session_option_enable_compiler_hints ( nux_session_option_t  builder,
bool  enable 
)

Enable the compiler hints.

The compilation step prints out the hints of model performances as warning logs if True.

Parameters
optionSession option
pathLog path

◆ nux_session_option_set_batch_size()

void nux_session_option_set_batch_size ( nux_session_option_t  builder,
uintptr_t  num 
)

Set the batch size of input tensors.

The batch size allows to add the dimension of input tensors to feed each inference.

Parameters
optionSession option
numBatch size

◆ nux_session_option_set_compiler_config()

enum nux_error_t nux_session_option_set_compiler_config ( nux_session_option_t  option,
const char *  yaml 
)

Set a compiler config to the given session option.

If compiler config is not set, Session will use a default compiler config.

Parameters
optionSession option
yamlA yaml formatted string of compiler option
Returns
nux_error_t_success if successful. or nux_error_t_invalid_yaml if yaml is not a valid yaml document.

◆ nux_session_option_set_compiler_log_path()

void nux_session_option_set_compiler_log_path ( nux_session_option_t  builder,
const char *  path 
)

Set the file path to which the compiler saves log messages.

Parameters
optionSession option
pathLog path

◆ nux_session_option_set_device()

void nux_session_option_set_device ( nux_session_option_t  builder,
const char *  devname 
)

Set a NPU device to the given session option.

If NPU device is not set, Session will use the default NPU device npu0pe0.

Parameters
optionSession option
devnameA NPU device name (e.g., npu0pe0, npu1pe0)

◆ nux_session_option_set_input_queue_size()

void nux_session_option_set_input_queue_size ( nux_session_option_t  builder,
uintptr_t  len 
)

Set the input queue size of async session.

async session has both input and output queues. The input queue keeps inference requests until the async session handles them. If it is not set, async session will have the unlimited input queue size by default. An unlimited input queue will keep the requests as much as your system's memory allow.

When a input queue length is specified and the queue is full, the caller of async session will be blocked until async session digests the requests. It's useful especially when you want backpressure.

Parameters
optionSession option
numThe input queue size, and it must be > 0 and < 2^31.

◆ nux_session_option_set_output_queue_size()

void nux_session_option_set_output_queue_size ( nux_session_option_t  builder,
uintptr_t  len 
)

Set the output queue size of async session.

async session has both input and output queues. The output queue keeps inference results until the consumer drains the results. If it is not set, async session will have the unlimited output queue size by default. An unlimited output queue will keep the responses as much as your system's memory allow.

When a output queue length is specified and the queue is full, async session will be blocked until consumers drain the results. It's useful especially when you want to prevent the out of memory issue.

Parameters
optionSession option
numThe output queue size, and it must be be > 0 and < 2^31.

◆ nux_session_option_set_worker_num()

void nux_session_option_set_worker_num ( nux_session_option_t  builder,
uintptr_t  num 
)

Set the number of workers to the given session option.

The number of workers means how many workers handle the inference requests. By default, the number of workers is 1.

Parameters
optionSession option
numThe number of workers, and it must be a positive integer.

◆ nux_session_run()

enum nux_error_t nux_session_run ( nux_session_t  sess,
nux_tensor_array_t  inputs,
nux_tensor_array_t  outputs 
)

Run an inference task.

Parameters
sessHandle of Session instance. It must not be NULL.
inputsInput tensors
outputsOutput tensors
Returns
nux_error_t_success if successful. or it will return other error value.

◆ nux_session_run_with()

enum nux_error_t nux_session_run_with ( nux_session_t  sess,
const char *const *  input_names,
uintptr_t  input_len,
const char *const *  output_names,
uintptr_t  output_len,
nux_tensor_array_t  inputs,
nux_tensor_array_t  outputs 
)

Run an inference task with tensor names The number of input/output tensors and its corresponding names must be the same.

Parameters
sessHandle of Session instance. It must not be NULL.
input_namesAn array of input tensor names
input_lenNumber of input tensor names
output_namesAn array of output tensor names
output_lenNumber of output tensor names
inputsInput tensors
outputsOutput tensors
Returns
nux_error_t_success if successful. or it will return other error value.

◆ nux_string_destroy()

void nux_string_destroy ( nux_string_t  str)

Destroy a buffer.

Parameters
bufferByte buffer to be destroyed. It must not be NULL.
lenByte length of buffer

◆ nux_tensor_array_allocate_by_names()

nux_tensor_array_t nux_tensor_array_allocate_by_names ( nux_model_t  model,
const char *const *  names,
uintptr_t  len 
)

Return an array of tensors corresponding to the names with allocated buffers.

◆ nux_tensor_array_allocate_inputs()

nux_tensor_array_t nux_tensor_array_allocate_inputs ( nux_model_t  model)

Return an array of input tensors with allocated buffers.

This function is generally used with tensor_fill_buffer.

◆ nux_tensor_array_allocate_outputs()

nux_tensor_array_t nux_tensor_array_allocate_outputs ( nux_model_t  model)

Return an array of output tensors with allocated buffers.

◆ nux_tensor_array_create_by_names()

nux_tensor_array_t nux_tensor_array_create_by_names ( nux_model_t  model,
const char *const *  names,
uintptr_t  len 
)

Return an array of tensors corresponding to the names without allocated buffers.

◆ nux_tensor_array_create_inputs()

nux_tensor_array_t nux_tensor_array_create_inputs ( nux_model_t  model)

Return an array of input tensors without allocated buffers.

This function is generally used with tensor_set_buffer.

◆ nux_tensor_array_create_outputs()

nux_tensor_array_t nux_tensor_array_create_outputs ( nux_model_t  model)

Return an array of output tensors without allocated buffers.

◆ nux_tensor_array_destroy()

void nux_tensor_array_destroy ( nux_tensor_array_t  array)

Destroy a tensor array.

◆ nux_tensor_array_get()

nux_tensor_t nux_tensor_array_get ( nux_tensor_array_t  array,
uintptr_t  index 
)

Return a tensor from the given tensor array.

◆ nux_tensor_array_len()

uintptr_t nux_tensor_array_len ( nux_tensor_array_t  array)

Return the number of tensors in the given tensor array.

◆ nux_tensor_axis()

enum Axis nux_tensor_axis ( nux_tensor_desc_t  tensor,
uintptr_t  idx 
)

Return the axis type of i-th dimension (e.g., Width, Height, Channel)

◆ nux_tensor_buffer()

uint8_t* nux_tensor_buffer ( nux_tensor_t  tensor)

Return the pointer to the buffer of this tensor.

◆ nux_tensor_buffer_size()

uintptr_t nux_tensor_buffer_size ( nux_tensor_t  tensor)

Return the size of tensor buffer.

◆ nux_tensor_create()

nux_tensor_t nux_tensor_create ( nux_tensor_desc_t  desc)

Create a tensor according to a given tensor description.

You have to call nux_tensor_destroy to release the resource of a create tensor.

◆ nux_tensor_create_with_buffer()

nux_tensor_t nux_tensor_create_with_buffer ( nux_tensor_desc_t  desc,
nux_buffer_t  buffer,
nux_buffer_len_t  len,
void(*)(uint8_t *, uintptr_t)  free 
)

Create a tensor with an exiting buffer. It doesn't copy the data.

◆ nux_tensor_desc_by_name()

nux_tensor_desc_t nux_tensor_desc_by_name ( nux_model_t  model,
const char *  name 
)

Return the description of the tensor matched to the given name.

Returns
the tensor descriptor if there exists Tensor matched to a given name, or null.

◆ nux_tensor_destroy()

void nux_tensor_destroy ( nux_tensor_t  tensor)

Destroy a tensor.

◆ nux_tensor_dim()

uintptr_t nux_tensor_dim ( nux_tensor_desc_t  tensor,
uintptr_t  index 
)

Return the dimension size of the dimension index.

◆ nux_tensor_dim_num()

uintptr_t nux_tensor_dim_num ( nux_tensor_desc_t  tensor)

Return the number of dimensions of the given tensor.

◆ nux_tensor_dtype()

nux_tensor_dtype_t nux_tensor_dtype ( nux_tensor_desc_t  tensor)

Return the tensor data type.

◆ nux_tensor_len()

uintptr_t nux_tensor_len ( nux_tensor_desc_t  tensor)

Return the total number of all elements.

◆ nux_tensor_name()

nux_string_t nux_tensor_name ( nux_tensor_desc_t  tensor)

Return the tensor name and transfers its ownership to the caller. To destroy nux_string_t, please call nux_string_destroy.

Parameters
Tensordescriptor
Returns
Tensor name if the specific tensor has its name, or null.

◆ nux_tensor_quantization_parameter()

enum nux_error_t nux_tensor_quantization_parameter ( nux_tensor_desc_t  tensor,
double *  scale,
int32_t *  zero_point 
)

Return the quantization parameter.

Currently only supports per-tensor quantized case.

◆ nux_tensor_size()

uintptr_t nux_tensor_size ( nux_tensor_desc_t  tensor)

Return the byte size of tensor.

It will be useful when you have to fill the tensor buffer with data.

◆ nux_tensor_stride()

uintptr_t nux_tensor_stride ( nux_tensor_desc_t  tensor,
uintptr_t  index 
)

Return the stride value of the dimension index.

◆ profiler_disable()

void profiler_disable ( profiler_handle_t  profiler)

Disable a profiler.

Parameters
profilerA profiler handle to be disabled.

◆ profiler_enable()

enum nux_error_t profiler_enable ( profiler_resource_t  resource,
enum profiler_format_t  format,
const char *  config,
profiler_handle_t profiler 
)

Enable a profiler and return the profiler handle.

Parameters
resourceTarget resource to be profiled. e.g. CPU or NPU.
formatProfiler format. e.g. ChromeTrace.
configFormat specific config. You need to pass valid arguments for the format.
[out]profilerA profiler handle.
Returns
nux_error_t_success if successful, or or nux_error_t_invalid_yaml if config is not a valid yaml document.

◆ profiler_record_end()

void profiler_record_end ( profiler_span_t  span)

Create end profiler span with specified name.

Parameters
Aspan handle.

◆ profiler_record_start()

profiler_span_t profiler_record_start ( const char *  record_name,
bool  _warm_up 
)

Create beginning profiler span with specified name.

Parameters
record_nameProfiler record span name.
warm_upIf true, do not record profiler result, and just warm up.
Returns
A span handle.

◆ register_signal_handler()

void register_signal_handler ( void  )

Register Ctrl-C signal handler to exit process.

◆ task_execute()

enum nux_error_t task_execute ( nux_task_t  task,
nux_request_id_t  request_id 
)

Request one asynchronous inference task.

task_execute submits a request for an inference task identified by task. Once a task is completed, output_callback function passed to nux_create_task_model will be called with a distinct output index per output tensor. finish_callback function will be also called after output_callback function is called for all output tensors.

Remarks
Once you call task_execute with a task, the task will get destroyed automatically. Please do not call destroy_task with the task which is already passed to task_execute.
Parameters
taskTask handle obtained from calling task_model_get_task or task_model_try_get_task.
request_idAn positive integer to distinguish task requests. The behavior of task_execute doesn't rely on a request_id value at all. request_id will be just passed to callback functions.
Returns
nux_error_t_success if successful. or nux_error_t_model_execution_failed if failed.

◆ task_input()

nux_buffer_t task_input ( nux_task_t  task,
nux_input_index_t  index 
)

Return a mutable pointer to the buffer of the specified input tensor.

Parameters
taskTask handle
indexIndex of the input tensor
Returns
A mutable pointer to the data buffer of the given input tensor

◆ task_input_size()

nux_buffer_len_t task_input_size ( nux_task_t  task,
nux_input_index_t  index 
)

Return the buffer length in bytes of the specified input tensor.

Parameters
taskTask handle
indexIndex of the input tensor

◆ task_model_get_task()

enum nux_error_t task_model_get_task ( nux_task_model_t  task_model,
nux_task_t task 
)

Get a task handle from a specified task model.

When there's no available task in a given task model, it will block until new task is available.

Parameters
task_modelHandle of a task model
[out]taskMutable pointer to receive the handle of a created task

◆ task_model_is_all_task_done()

bool task_model_is_all_task_done ( nux_task_model_t  task_model)

Return true if there's no running tasks, or false if any task is still running.

Parameters
task_modelTask handle

◆ task_model_try_get_task()

enum nux_error_t task_model_try_get_task ( nux_task_model_t  task_model,
nux_task_t task 
)

(non-blocking) Get a task handle from the specified task model.

It's the non-blocking version of task_model_get_task. This function returns an available task, or it will return immediately nux_error_t_get_task_failed if there's no available task in a given task model.

Parameters
task_modelHandle of a task model
[out]taskMutable pointer to receive the handle of a created task

◆ tensor_fill_buffer()

enum nux_error_t tensor_fill_buffer ( nux_tensor_t  tensor,
nux_buffer_t  buffer,
nux_buffer_len_t  len 
)

Copy data into the data buffer of a specified input tensor.

To execute model_run, you first need to fill input tensors with data. tensor_fill_buffer copies the data into the data buffer of a specified input tensor.

Parameters
tensorTensor handle into which you want to copy input data
bufferPointer to the data buffer
lenByte length of buffer
Returns
nux_error_t_success if successful, or nux_error_t_invalid_buffer if buffer is invalid.

◆ tensor_get_buffer()

enum nux_error_t tensor_get_buffer ( nux_tensor_t  tensor,
nux_buffer_t buffer,
nux_buffer_len_t len 
)

Get a pointer to the data buffer of a given tensor.

Once model_run is called, the inference result will be written into output tensors. This function returns a pointer to the data buffer of a specified output tensor.

Remarks
the buffers of output tensors are valid until destroy_sync_model is called.
Parameters
tensorTensor from which you want to get a pointer of the data buffer
[out]bufferMutable pointer to receive the pointer to the data buffer
[out]lenByte length of buffer
Returns
nux_error_t_success if successful

◆ tensor_set_buffer()

enum nux_error_t tensor_set_buffer ( nux_tensor_t  tensor,
nux_buffer_t  buffer,
nux_buffer_len_t  len,
void(*)(uint8_t *, uintptr_t)  free 
)

Specify a pointer to a data buffer to a specified input tensor.

This function is almost same to tensor_fill_buffer. However, tensor takes the ownership of the buffer with free function to deallocate the buffer. Ensure that nothing else uses the pointer after calling this function.

if free is null, tensor will not deallocate the buffer. It can be useful when you want to reuse the buffer or buffer is on a stack area of a function. Please ensure that the buffer must be deallocated manually by users in order to prevent the memory leak.

Parameters
tensorTensor handle into which you want to copy input data
bufferPointer to the data buffer
lenByte length of buffer
freea function pointer to deallocate a buffer. If free is null, tensor will not deallocate the data.
Returns
nux_error_t_success if successful, or nux_error_t_invalid_buffer if buffer is invalid.

◆ version()

const char* version ( void  )

Return a version of Nux native library.