neuronx 0.1.0

Bindings for the AWS Neuron runtime (libnrt).
//! Thin wrapper around libnrt, the AWS Neuron runtime.
//!
//! The raw bindings generated by bindgen are available in [`sys`]. The safe types
//! follow the libnrt objects one to one:
//! - [`Runtime`]: `nrt_init` / `nrt_close`, at most one per process.
//! - [`Model`]: a NEFF loaded on a NeuronCore, `nrt_load` / `nrt_execute`.
//! - [`Tensor`]: a device or host buffer, `nrt_tensor_allocate` / read / write.
//! - [`TensorSet`]: named tensors bound to the inputs or outputs of a model.
//!
//! Objects created from a runtime borrow it so they cannot outlive `nrt_close`.
mod error;
mod model;
mod runtime;
mod tensor;

#[allow(non_upper_case_globals, non_camel_case_types, non_snake_case, dead_code)]
#[allow(clippy::all)]
pub mod sys {
    include!(concat!(env!("OUT_DIR"), "/nrt.rs"));
}

pub use error::{Error, Result};
pub use half;
pub use model::{Model, TensorInfo, TensorUsage};
pub use runtime::{instance_info, version, InstanceInfo, Runtime, Version};
pub use tensor::{DType, Element, Placement, Tensor, TensorSet};

pub(crate) fn c_chars_to_string(chars: &[std::os::raw::c_char]) -> String {
    let bytes: Vec<u8> = chars.iter().take_while(|&&c| c != 0).map(|&c| c as u8).collect();
    String::from_utf8_lossy(&bytes).into_owned()
}