1 #ifndef furiosa_libnux_bindings_h
2 #define furiosa_libnux_bindings_h
356 #define profiler_resource_t_CPU (uint32_t)1
357 #define profiler_resource_t_NPU (uint32_t)2
424 const uint8_t *buffer,
542 void (*free)(uint8_t*, uintptr_t));
565 const uint8_t *buffer,
822 const char *
const *input_names,
824 const char *
const *output_names,
825 uintptr_t output_len,
1036 void (*free)(uint8_t*, uintptr_t));
void nux_async_session_destroy(nux_async_session_t sess)
Destroy an asynchronous session.
void register_signal_handler(void)
Register Ctrl-C signal handler to exit process.
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.
nux_tensor_array_t nux_tensor_array_create_inputs(nux_model_t model)
Return an array of input tensors without allocated buffers.
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.
uint32_t InputIndex
Definition: nux.h:307
void destroy_sync_model(nux_sync_model_t model)
Destroy the sync model and release its resources.
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_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.
void nux_session_option_set_input_queue_size(nux_session_option_t builder, uintptr_t len)
Set the input queue size of async session.
uintptr_t nux_tensor_size(nux_tensor_desc_t tensor)
Return the byte size of tensor.
struct Task Task
Definition: nux.h:215
enum nux_error_t nux_tensor_quantization_parameter(nux_tensor_desc_t tensor, double *scale, int32_t *zero_point)
Return the quantization parameter.
struct CompletionQueue_ContextPtr * nux_completion_queue_t
Definition: nux.h:336
void(* nux_error_callback_t)(nux_request_id_t, enum nux_error_t)
Callback function called when a task fails to complete.
Definition: nux.h:283
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.
struct Model * nux_sync_model_t
Handle of a synchronous model.
Definition: nux.h:240
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.
OutputIndex nux_output_index_t
Index of an output tensor, used in task model.
Definition: nux.h:269
struct TaskModel * nux_task_model_t
Handle of a task model.
Definition: nux.h:298
struct Submitter_ContextPtr * nux_async_session_t
Async Session.
Definition: nux.h:334
struct TensorArray * nux_tensor_array_t
Definition: nux.h:329
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.
void nux_session_option_destroy(nux_session_option_t option)
Destroy a session option.
TensorDataType
Represent tensor data type.
Definition: nux.h:34
@ tensor_data_type_int4
Definition: nux.h:42
@ tensor_data_type_int64
Definition: nux.h:39
@ tensor_data_type_int16
Definition: nux.h:45
@ tensor_data_type_bool
Definition: nux.h:41
@ tensor_data_type_float8_e4m3
Definition: nux.h:44
@ tensor_data_type_float32
Definition: nux.h:35
@ tensor_data_type_int8
Definition: nux.h:37
@ tensor_data_type_bfloat16
Definition: nux.h:40
@ tensor_data_type_uint8
Definition: nux.h:36
@ tensor_data_type_float8_e5m2
Definition: nux.h:43
@ tensor_data_type_float16
Definition: nux.h:46
@ tensor_data_type_int32
Definition: nux.h:38
struct OpaqueTensor OpaqueTensor
Definition: nux.h:207
nux_tensor_t nux_tensor_array_get(nux_tensor_array_t array, uintptr_t index)
Return a tensor from the given tensor array.
struct NuxModel NuxModel
Definition: nux.h:205
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.
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.
Definition: nux.h:278
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.
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.
void enable_logging(enum nux_log_level_t _log_level)
Enable a logger with a specific log level.
uintptr_t nux_tensor_array_len(nux_tensor_array_t array)
Return the number of tensors in the given tensor array.
nux_tensor_t nux_tensor_create(nux_tensor_desc_t desc)
Create a tensor according to a given tensor description.
void nux_tensor_array_destroy(nux_tensor_array_t array)
Destroy a tensor array.
uintptr_t nux_tensor_dim_num(nux_tensor_desc_t tensor)
Return the number of dimensions of the given tensor.
Span * profiler_span_t
Definition: nux.h:361
struct ProfilerGuard * profiler_handle_t
Definition: nux.h:359
void nux_session_option_set_device(nux_session_option_t builder, const char *devname)
Set a NPU device to the given session option.
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.
nux_error_t
Represent a return status of a function that can fail.
Definition: nux.h:52
@ nux_error_t_session_terminated
Definition: nux.h:150
@ nux_error_t_queue_no_data
Definition: nux.h:110
@ nux_error_t_npu_interrupt
Definition: nux.h:166
@ nux_error_t_invalid_outputs
Definition: nux.h:92
@ nux_error_t_model_deploy_failed
Definition: nux.h:65
@ nux_error_t_queue_full
Definition: nux.h:174
@ nux_error_t_invalid_session_options
Definition: nux.h:146
@ nux_error_t_tensor_name_not_found
Definition: nux.h:158
@ nux_error_t_unsupported_feature
Definition: nux.h:162
@ nux_error_t_invalid_yaml
Definition: nux.h:126
@ nux_error_t_invalid_output_index
Definition: nux.h:80
@ nux_error_t_invalid_inputs
Definition: nux.h:88
@ nux_error_t_dump_profile_failed
Definition: nux.h:102
@ nux_error_t_no_api_key
Definition: nux.h:138
@ nux_error_t_npu_error
Definition: nux.h:170
@ nux_error_t_invalid_compiler_config
Definition: nux.h:182
@ nux_error_t_queue_wait_timeout
Definition: nux.h:106
@ nux_error_t_null_pointer_exception
Definition: nux.h:142
@ nux_error_t_device_busy
Definition: nux.h:154
@ nux_error_t_get_task_failed
Definition: nux.h:98
@ nux_error_t_incompatible_model
Definition: nux.h:114
@ nux_error_t_success
Definition: nux.h:56
@ nux_error_t_compilation_failed
Definition: nux.h:118
@ nux_error_t_api_client_init_failed
Definition: nux.h:134
@ nux_error_t_queue_empty
Definition: nux.h:178
@ nux_error_t_incompatible_api_client_error
Definition: nux.h:130
@ nux_error_t_model_execution_failed
Definition: nux.h:70
@ nux_error_t_invalid_buffer
Definition: nux.h:84
@ nux_error_t_invalid_input_index
Definition: nux.h:75
@ nux_error_t_nux_creation_failed
Definition: nux.h:60
@ nux_error_t_internal_error
Definition: nux.h:122
nux_log_level_t
Definition: nux.h:185
@ nux_log_level_t_warn
Definition: nux.h:188
@ nux_log_level_t_off
Definition: nux.h:186
@ nux_log_level_t_info
Definition: nux.h:189
@ nux_log_level_t_error
Definition: nux.h:187
profiler_format_t
Definition: nux.h:192
@ profiler_format_t_chrome_trace
Definition: nux.h:193
@ profiler_format_t_csv_trace
Definition: nux.h:194
void nux_string_destroy(nux_string_t str)
Destroy a buffer.
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.
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_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_model_t nux_session_get_model(nux_session_t sess)
Get the pointer of the Model of a given session.
uintptr_t nux_tensor_len(nux_tensor_desc_t tensor)
Return the total number of all elements.
void destroy_task_model(nux_task_model_t task_model)
Destroy the task model and release its resources.
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.
uintptr_t nux_input_num(nux_model_t model)
Return the number of input tensors of the given model.
nux_tensor_array_t nux_tensor_array_allocate_inputs(nux_model_t model)
Return an array of input tensors with allocated buffers.
npu_config_t get_npu_spec(const char *npuid)
Get NPU specification by NPUID.
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.
InputIndex nux_input_index_t
Index of an input tensor, used in task model.
Definition: nux.h:312
uintptr_t RequestId
Definition: nux.h:257
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.
const char * build_timestamp(void)
Return a build timestamp of Nux native library.
uint32_t OutputIndex
Definition: nux.h:264
RequestId nux_request_id_t
Identifier to distinguish tasks in a task model.
Definition: nux.h:262
void nux_tensor_destroy(nux_tensor_t tensor)
Destroy a tensor.
uint32_t profiler_resource_t
Definition: nux.h:355
void destroy_task(nux_task_t task)
Destroy the task and release its resources.
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)
struct Nux * nux_handle_t
Nux handle.
Definition: nux.h:228
struct TaskModel TaskModel
Definition: nux.h:217
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.
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.
nux_tensor_array_t nux_tensor_array_create_outputs(nux_model_t model)
Return an array of output tensors without allocated buffers.
struct OpaqueTensor * nux_tensor_t
Handle of tensor.
Definition: nux.h:247
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.
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 ...
const struct TensorDesc * nux_tensor_desc_t
Definition: nux.h:343
enum TensorDataType nux_tensor_dtype_t
Represent a data type of tensor.
Definition: nux.h:353
struct Nux Nux
Definition: nux.h:203
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.
uint32_t model_count_outputs(nux_sync_model_t model)
Return the number of output tensors of a given sync model.
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.
const char * git_short_hash(void)
Return a short Git hash of Nux native library.
uintptr_t nux_tensor_buffer_size(nux_tensor_t tensor)
Return the size of tensor buffer.
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.
nux_model_t nux_async_session_get_model(nux_async_session_t sess)
Get the pointer of the Model of a given asynchronous session.
void nux_buffer_destroy(uint8_t *buf, nux_buffer_len_t len)
Destroy a buffer.
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.
struct Model Model
Definition: nux.h:201
struct CompletionQueue_ContextPtr CompletionQueue_ContextPtr
Definition: nux.h:199
nux_session_option_t nux_session_option_create(void)
Create a session option.
void nux_session_option_set_batch_size(nux_session_option_t builder, uintptr_t num)
Set the batch size of input tensors.
uint32_t model_count_inputs(nux_sync_model_t model)
Return the number of input tensors of a given sync model.
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.
void nux_session_option_enable_compiler_hints(nux_session_option_t builder, bool enable)
Enable the compiler hints.
void(* nux_finish_callback_t)(nux_request_id_t)
Callback function which is finally called when a task is completed.
Definition: nux.h:291
struct Submitter_ContextPtr Submitter_ContextPtr
Definition: nux.h:213
char * nux_string_t
A null-terminated C string.
Definition: nux.h:348
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.
struct Task * nux_task_t
Handle of a task of a task model.
Definition: nux.h:305
const struct BlockingSession * nux_session_t
Session.
Definition: nux.h:322
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.
struct SessionOptions * nux_session_option_t
Session option.
Definition: nux.h:317
nux_tensor_dtype_t nux_tensor_dtype(nux_tensor_desc_t tensor)
Return the tensor data type.
uint8_t * nux_tensor_buffer(nux_tensor_t tensor)
Return the pointer to the buffer of this tensor.
uintptr_t nux_output_num(nux_model_t model)
Return the number of output tensors of the given model.
void profiler_disable(profiler_handle_t profiler)
Disable a profiler.
profiler_span_t profiler_record_start(const char *record_name, bool _warm_up)
Create beginning profiler span with specified name.
void nux_session_option_set_output_queue_size(nux_session_option_t builder, uintptr_t len)
Set the output queue size of async session.
struct BlockingSession BlockingSession
Definition: nux.h:197
void nux_session_destroy(nux_session_t sess)
Destroy a session.
@ axis_batch
Definition: nux.h:21
@ axis_channel
Definition: nux.h:17
@ axis_unknown
Definition: nux.h:26
@ axis_group
Definition: nux.h:27
@ axis_width_outer
Definition: nux.h:22
@ axis_width
Definition: nux.h:12
@ axis_height_outer
Definition: nux.h:23
@ axis_batch_outer
Definition: nux.h:25
@ axis_group_outer
Definition: nux.h:28
@ axis_height
Definition: nux.h:13
@ axis_channel_outer
Definition: nux.h:24
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 ti...
void nux_completion_queue_destroy(nux_completion_queue_t queue)
Destroy a completion queue.
enum nux_error_t create_nux(nux_handle_t *nux)
Creates a new nux handle.
void profiler_record_end(profiler_span_t span)
Create end profiler span with specified name.
const char * version(void)
Return a version of Nux native library.
enum nux_error_t model_run(nux_sync_model_t model)
Run a single inference task.
uintptr_t nux_buffer_len_t
Byte length of a data buffer.
Definition: nux.h:233
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 name...
struct ProfilerGuard ProfilerGuard
Definition: nux.h:209
const Config * npu_config_t
Definition: nux.h:363
struct SessionOptions SessionOptions
Definition: nux.h:211
uintptr_t nux_tensor_dim(nux_tensor_desc_t tensor, uintptr_t index)
Return the dimension size of the dimension index.
struct TensorDesc TensorDesc
Definition: nux.h:221
void * nux_context_t
Context pointer.
Definition: nux.h:341
uintptr_t nux_tensor_stride(nux_tensor_desc_t tensor, uintptr_t index)
Return the stride value of the dimension index.
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,...
uint8_t * nux_buffer_t
Pointer to a data buffer.
Definition: nux.h:255
void destroy_nux(nux_handle_t nux)
Destroy the Nux handle and release its resources.
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.
enum nux_error_t task_execute(nux_task_t task, nux_request_id_t request_id)
Request one asynchronous inference task.
struct TensorArray TensorArray
Definition: nux.h:219
const struct NuxModel * nux_model_t
Model.
Definition: nux.h:327