Nux C API
0.0.1
C API of NPU Engine
|
Go to the documentation of this file. 1 #ifndef furiosa_libnux_bindings_h
2 #define furiosa_libnux_bindings_h
327 #endif // __cplusplus
384 const uint8_t *buffer,
502 void (*free)(uint8_t*, uintptr_t));
525 const uint8_t *buffer,
762 const char *
const *input_names,
764 const char *
const *output_names,
765 uintptr_t output_len,
964 void (*free)(uint8_t*, uintptr_t));
1135 #endif // __cplusplus
@ nux_error_t_internal_error
Definition: nux.h:115
void nux_session_option_set_compiler_log_path(nux_session_option_t builder, const char *path)
Set the file path to which the compiler save log messages.
enum nux_error_t create_nux(nux_handle_t *nux)
Creates a new nux handle.
@ tensor_data_type_uint8
Definition: nux.h:34
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:244
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)
uintptr_t nux_tensor_size(nux_tensor_desc_t tensor)
Return the byte size of tensor.
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.
nux_session_option_t nux_session_option_create(void)
Create a session option.
void compiler_options_memory_analysis(compiler_options_t options, const char *path)
Set a path to which a memory analysis in HTML is saved.
void compiler_options_input(compiler_options_t options, const char *path)
Set an input path.
struct TensorArray TensorArray
Definition: nux.h:185
@ nux_error_t_unsupported_feature
Definition: nux.h:155
@ nux_error_t_queue_wait_timeout
Definition: nux.h:99
struct Model Model
Definition: nux.h:169
@ nux_log_level_t_warn
Definition: nux.h:161
struct Nux Nux
Definition: nux.h:171
@ nux_log_level_t_info
Definition: nux.h:162
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.
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.
void destroy_sync_model(nux_sync_model_t model)
Destroy the sync model and release its resources.
nux_error_t
Represent a return status of a function that can fail.
Definition: nux.h:45
void compiler_options_split_after_lower(compiler_options_t options, bool split_after_lower)
Enable the split after lower.
InputIndex nux_input_index_t
Index of an input tensor, used in task model.
Definition: nux.h:278
@ axis_width_outer
Definition: nux.h:22
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.
void destroy_task_model(nux_task_model_t task_model)
Destroy the task model and release its resources.
void compiler_options_target_npu(compiler_options_t options, const char *target_npu)
Enable target NPU (available NPUs: warboy, warboy-2pe)
CompilerOptions * compiler_options_t
Definition: nux.h:323
struct SessionOptions * nux_session_option_t
Session option.
Definition: nux.h:283
char * nux_string_t
A null-terminated C string.
Definition: nux.h:314
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 compiler_options_target_ir(compiler_options_t options, const char *target_ir)
Set a target ir (one of dfg, ldfg, cdfg, gir, sir, lir, enf)
const struct NuxModel * nux_model_t
Model.
Definition: nux.h:293
@ tensor_data_type_int64
Definition: nux.h:37
struct OpaqueTensor OpaqueTensor
Definition: nux.h:175
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_set_input_queue_size(nux_session_option_t builder, uintptr_t len)
Set the input queue size of async session.
@ nux_error_t_incompatible_api_client_error
Definition: nux.h:123
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 ...
@ nux_error_t_no_api_key
Definition: nux.h:131
npu_config_t get_npu_spec(const char *npuid)
Get NPU specification by NPUID.
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.
struct SessionOptions SessionOptions
Definition: nux.h:177
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.
nux_tensor_array_t nux_tensor_array_create_outputs(nux_model_t model)
Return an array of output tensors without allocated buffers.
void compiler_options_batch_size(compiler_options_t options, uintptr_t batch_size)
Set an inference batch size.
@ nux_error_t_invalid_yaml
Definition: nux.h:119
@ nux_error_t_nux_creation_failed
Definition: nux.h:53
@ axis_channel_outer
Definition: nux.h:24
@ axis_batch_outer
Definition: nux.h:25
@ tensor_data_type_int8
Definition: nux.h:35
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_error_t_invalid_outputs
Definition: nux.h:85
struct BlockingSession BlockingSession
Definition: nux.h:165
void nux_session_option_destroy(nux_session_option_t option)
Destroy a session option.
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_model_t nux_session_get_model(nux_session_t sess)
Get the pointer of the Model of a given session.
void compiler_options_auto_batch_size(compiler_options_t options, bool enabled)
Enable the automatic batch size optimizer.
@ nux_error_t_compilation_failed
Definition: nux.h:111
void register_signal_handler(void)
Register Ctrl-C signal handler to exit process.
void nux_session_destroy(nux_session_t sess)
Destroy a session.
struct Task * nux_task_t
Handle of a task of a task model.
Definition: nux.h:271
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:249
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.
uintptr_t nux_buffer_len_t
Byte length of a data buffer.
Definition: nux.h:199
void nux_buffer_destroy(uint8_t *buf, nux_buffer_len_t len)
Destroy a buffer.
uintptr_t RequestId
Definition: nux.h:223
@ nux_error_t_session_terminated
Definition: nux.h:143
enum nux_error_t task_execute(nux_task_t task, nux_request_id_t request_id)
Request one asynchronous inference task.
nux_log_level_t
Definition: nux.h:158
@ tensor_data_type_bfloat16
Definition: nux.h:38
const typedef Config * npu_config_t
Definition: nux.h:321
struct TaskModel TaskModel
Definition: nux.h:183
void nux_tensor_destroy(nux_tensor_t tensor)
Destroy a tensor.
@ nux_error_t_device_busy
Definition: nux.h:147
void compiler_options_ga_generation_limit(compiler_options_t options, uint64_t generation_limit)
@ nux_error_t_dump_profile_failed
Definition: nux.h:95
@ nux_error_t_invalid_input_index
Definition: nux.h:68
@ nux_error_t_null_pointer_exception
Definition: nux.h:135
uintptr_t nux_tensor_dim_num(nux_tensor_desc_t tensor)
Return the number of dimensions of the given tensor.
void compiler_options_dot_graph(compiler_options_t options, const char *path)
Set a path to which a dot graph file is saved.
@ nux_error_t_invalid_buffer
Definition: nux.h:77
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.
uintptr_t nux_input_num(nux_model_t model)
Return the number of input tensors of the given model.
@ nux_error_t_model_deploy_failed
Definition: nux.h:58
void nux_tensor_array_destroy(nux_tensor_array_t array)
Destroy a tensor array.
uint8_t * nux_tensor_buffer(nux_tensor_t tensor)
Return the pointer to the buffer of this tensor.
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.
void compiler_options_ga_optimization(compiler_options_t options, bool enabled)
Enable the optimization based on the genetic algorithm.
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.
uint8_t * nux_buffer_t
Pointer to a data buffer.
Definition: nux.h:221
const char * version(void)
Return a version of Nux native library.
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.
const char * git_short_hash(void)
Return a short Git hash of Nux native library.
struct Nux * nux_handle_t
Nux handle.
Definition: nux.h:194
@ tensor_data_type_int32
Definition: nux.h:36
void destroy_nux(nux_handle_t nux)
Destroy the Nux handle and release its resources.
uintptr_t nux_tensor_array_len(nux_tensor_array_t array)
Return the number of tensors in the given tensor array.
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.
@ nux_error_t_model_execution_failed
Definition: nux.h:63
@ axis_height_outer
Definition: nux.h:23
@ axis_channel
Definition: nux.h:17
@ nux_log_level_t_error
Definition: nux.h:160
@ nux_log_level_t_off
Definition: nux.h:159
nux_tensor_array_t nux_tensor_array_allocate_inputs(nux_model_t model)
Return an array of input tensors with allocated buffers.
TensorDataType
Represent tensor data type.
Definition: nux.h:32
nux_tensor_t nux_tensor_create(nux_tensor_desc_t desc)
Create a tensor according to a given tensor description.
@ nux_error_t_invalid_output_index
Definition: nux.h:73
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,...
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.
struct Submitter_ContextPtr * nux_async_session_t
Async Session.
Definition: nux.h:300
@ axis_height
Definition: nux.h:13
enum TensorDataType nux_tensor_dtype_t
Represent a data type of tensor.
Definition: nux.h:319
void nux_string_destroy(nux_string_t str)
Destroy a buffer.
nux_tensor_array_t nux_tensor_array_create_inputs(nux_model_t model)
Return an array of input tensors without allocated buffers.
@ nux_error_t_incompatible_model
Definition: nux.h:107
@ nux_error_t_success
Definition: nux.h:49
void(* nux_finish_callback_t)(nux_request_id_t)
Callback function which is finally called when a task is completed.
Definition: nux.h:257
@ axis_batch
Definition: nux.h:21
struct Task Task
Definition: nux.h:181
const char * build_timestamp(void)
Return a build timestamp of Nux native library.
void compiler_options_ga_init_tactic(compiler_options_t options, const char *tactic)
Set the initial tactic of genetic algorithm (available tactics: heuristic or random)
nux_tensor_array_t nux_tensor_array_allocate_outputs(nux_model_t model)
Return an array of output tensors with allocated buffers.
struct NuxModel NuxModel
Definition: nux.h:173
void nux_async_session_destroy(nux_async_session_t sess)
Destroy an asynchronous session.
@ nux_error_t_queue_no_data
Definition: nux.h:103
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.
void compiler_options_ga_max_prefetch_size(compiler_options_t options, uintptr_t max_prefetch_size)
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.
struct Submitter_ContextPtr Submitter_ContextPtr
Definition: nux.h:179
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.
compiler_options_t compiler_options_create(void)
Create a compiler options.
struct Model * nux_sync_model_t
Handle of a synchronous model.
Definition: nux.h:206
@ nux_error_t_invalid_session_options
Definition: nux.h:139
const struct TensorDesc * nux_tensor_desc_t
Definition: nux.h:309
struct TensorArray * nux_tensor_array_t
Definition: nux.h:295
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...
nux_tensor_dtype_t nux_tensor_dtype(nux_tensor_desc_t tensor)
Return the tensor data type.
uint32_t model_count_outputs(nux_sync_model_t model)
Return the number of output tensors of a given sync model.
void enable_logging(enum nux_log_level_t _log_level)
Enable a logger with a specific log level.
void nux_session_option_set_device(nux_session_option_t builder, const char *devname)
Set a NPU device to the given session option.
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 compiler_options_ga_pin_tensors(compiler_options_t options, bool pin_tensors)
@ nux_error_t_tensor_name_not_found
Definition: nux.h:151
const struct BlockingSession * nux_session_t
Session.
Definition: nux.h:288
struct CompletionQueue_ContextPtr CompletionQueue_ContextPtr
Definition: nux.h:167
void * nux_context_t
Context pointer.
Definition: nux.h:307
void compiler_options_destroy(compiler_options_t options)
Destroy the compiler options.
nux_tensor_t nux_tensor_array_get(nux_tensor_array_t array, uintptr_t index)
Return a tensor from the given tensor array.
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.
void destroy_task(nux_task_t task)
Destroy the task and release its resources.
uintptr_t nux_tensor_dim(nux_tensor_desc_t tensor, uintptr_t index)
Return the dimension size of the dimension index.
struct OpaqueTensor * nux_tensor_t
Handle of tensor.
Definition: nux.h:213
void compiler_options_output(compiler_options_t options, const char *path)
Set an output path.
enum nux_error_t compiler_run(compiler_options_t options)
Run compiler.
@ axis_width
Definition: nux.h:12
enum nux_error_t model_run(nux_sync_model_t model)
Run a single inference task.
void nux_completion_queue_destroy(nux_completion_queue_t queue)
Destroy a completion queue.
OutputIndex nux_output_index_t
Index of an output tensor, used in task model.
Definition: nux.h:235
void nux_session_option_set_output_queue_size(nux_session_option_t builder, uintptr_t len)
Set the output queue size of async session.
RequestId nux_request_id_t
Identifier to distinguish tasks in a task model.
Definition: nux.h:228
@ tensor_data_type_bool
Definition: nux.h:39
@ nux_error_t_invalid_inputs
Definition: nux.h:81
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.
void compiler_options_ga_population_size(compiler_options_t options, uintptr_t population_size)
@ axis_unknown
Definition: nux.h:26
uint32_t OutputIndex
Definition: nux.h:230
uint32_t InputIndex
Definition: nux.h:273
uintptr_t nux_tensor_buffer_size(nux_tensor_t tensor)
Return the size of tensor buffer.
nux_model_t nux_async_session_get_model(nux_async_session_t sess)
Get the pointer of the Model of a given asynchronous session.
uint32_t model_count_inputs(nux_sync_model_t model)
Return the number of input tensors of a given sync model.
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_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.
@ tensor_data_type_float32
Definition: nux.h:33
struct TaskModel * nux_task_model_t
Handle of a task model.
Definition: nux.h:264
uintptr_t nux_output_num(nux_model_t model)
Return the number of output tensors of the given model.
struct CompletionQueue_ContextPtr * nux_completion_queue_t
Definition: nux.h:302
void compiler_options_ga_nondeterministic(compiler_options_t options, bool nondeterministic)
@ nux_error_t_get_task_failed
Definition: nux.h:91
@ nux_error_t_api_client_init_failed
Definition: nux.h:127
struct TensorDesc TensorDesc
Definition: nux.h:187
uintptr_t nux_tensor_len(nux_tensor_desc_t tensor)
Return the total number of all elements.
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.