#![allow(dead_code)]
#![allow(non_local_definitions)]
use pyo3::prelude::*;
mod error;
mod model;
mod session;
mod tensor;
pub use error::RonnError;
pub use model::PyModel;
pub use session::PySession;
pub use tensor::PyTensor;
#[pymodule]
fn ronn(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<PyModel>()?;
m.add_class::<PySession>()?;
m.add_class::<PyTensor>()?;
m.add_class::<PyOptimizationLevel>()?;
m.add_class::<PyProviderType>()?;
m.add_class::<PyBatchConfig>()?;
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
Ok(())
}
#[pyclass(name = "OptimizationLevel")]
#[derive(Clone)]
pub struct PyOptimizationLevel {
inner: ronn_core::OptimizationLevel,
}
#[pymethods]
impl PyOptimizationLevel {
#[staticmethod]
fn none() -> Self {
Self {
inner: ronn_core::OptimizationLevel::None,
}
}
#[staticmethod]
fn basic() -> Self {
Self {
inner: ronn_core::OptimizationLevel::Basic,
}
}
#[staticmethod]
fn default() -> Self {
Self {
inner: ronn_core::OptimizationLevel::Basic,
}
}
#[staticmethod]
fn aggressive() -> Self {
Self {
inner: ronn_core::OptimizationLevel::Aggressive,
}
}
}
impl Default for PyOptimizationLevel {
fn default() -> Self {
Self::default()
}
}
#[pyclass(name = "ProviderType")]
#[derive(Clone)]
pub struct PyProviderType {
inner: ronn_core::ProviderId,
}
#[pymethods]
impl PyProviderType {
#[staticmethod]
fn cpu() -> Self {
Self {
inner: ronn_core::ProviderId::CPU,
}
}
#[staticmethod]
fn gpu() -> Self {
Self {
inner: ronn_core::ProviderId::GPU,
}
}
#[staticmethod]
fn bitnet() -> Self {
Self {
inner: ronn_core::ProviderId::BitNet,
}
}
#[staticmethod]
fn wasm() -> Self {
Self {
inner: ronn_core::ProviderId::WebAssembly,
}
}
}
impl Default for PyProviderType {
fn default() -> Self {
Self::cpu()
}
}
#[pyclass(name = "BatchConfig")]
#[derive(Clone)]
pub struct PyBatchConfig {
#[pyo3(get, set)]
pub max_batch_size: usize,
#[pyo3(get, set)]
pub timeout_ms: u64,
#[pyo3(get, set)]
pub queue_capacity: usize,
}
#[pymethods]
impl PyBatchConfig {
#[new]
#[pyo3(signature = (max_batch_size=32, timeout_ms=10, queue_capacity=1024))]
fn new(max_batch_size: usize, timeout_ms: u64, queue_capacity: usize) -> Self {
Self {
max_batch_size,
timeout_ms,
queue_capacity,
}
}
}
impl Default for PyBatchConfig {
fn default() -> Self {
Self::new(32, 10, 1024)
}
}