Skip to main content

feagi_npu_runtime/
lib.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/*
5 * Copyright 2025 Neuraville Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20//! # FEAGI Runtime Abstraction
21//!
22//! Cross-platform runtime traits and implementations for neural processing.
23//!
24//! This crate provides:
25//! - **Traits** (always available): `Runtime`, `NeuronStorage`, `SynapseStorage`
26//! - **Std Implementation** (behind `std` feature): `StdRuntime` for desktop/server
27//! - **Embedded Implementation** (behind `embedded` feature): `EmbeddedRuntime` for no_std
28//!
29//! ## Features
30//!
31//! - `default` = `[]` (traits only, no_std compatible)
32//! - `std` = Standard library runtime implementation (Vec-based, parallel)
33//! - `embedded` = Embedded runtime implementation (fixed arrays, no_std)
34//! - `alloc` = Heap allocation without std (for some trait methods)
35//!
36//! ## Usage
37//!
38//! ### Desktop/Server
39//! ```toml
40//! [dependencies]
41//! feagi-npu-runtime = { version = "2.0", features = ["std"] }
42//! ```
43//!
44//! ```rust
45//! use feagi_npu_runtime::StdRuntime;
46//! let runtime = StdRuntime::new();
47//! ```
48//!
49//! ### Embedded
50//! ```toml
51//! [dependencies]
52//! feagi-npu-runtime = { version = "2.0", features = ["embedded"], default-features = false }
53//! ```
54//!
55//! ```rust
56//! use feagi_npu_runtime::embedded::EmbeddedRuntime;
57//! let runtime = EmbeddedRuntime::new();
58//! ```
59//!
60//! ### Traits Only (for custom implementations)
61//! ```toml
62//! [dependencies]
63//! feagi-npu-runtime = { version = "2.0", default-features = false }
64//! ```
65//!
66//! ```rust
67//! use feagi_npu_runtime::{Runtime, NeuronStorage, SynapseStorage};
68//! // Implement your own runtime
69//! ```
70
71#![warn(missing_docs)]
72
73#[cfg(feature = "std")]
74extern crate std;
75
76/// Crate version from Cargo.toml
77pub const VERSION: &str = env!("CARGO_PKG_VERSION");
78
79// Traits module (always available)
80pub mod traits;
81
82// Re-export traits for convenience
83pub use traits::{NeuralValue, NeuronStorage, Result, Runtime, RuntimeError, SynapseStorage};
84
85// Standard library implementation (behind "std" feature)
86#[cfg(feature = "std")]
87pub mod std_impl;
88
89// Re-export std module contents for convenience (backward compatibility)
90#[cfg(feature = "std")]
91pub use std_impl::{NeuronArray as StdNeuronArray, StdRuntime, SynapseArray as StdSynapseArray};
92
93// Embedded implementation (behind "embedded" feature)
94#[cfg(feature = "embedded")]
95pub mod embedded_impl;
96
97// Re-export embedded module contents for convenience
98#[cfg(feature = "embedded")]
99pub use embedded_impl::{
100    EmbeddedRuntime, NeuronArray as EmbeddedNeuronArray, SynapseArray as EmbeddedSynapseArray,
101};
102
103// Convenience module for embedded (re-exports from embedded_impl)
104/// Embedded runtime implementations for no_std environments
105#[cfg(feature = "embedded")]
106pub mod embedded {
107    pub use super::embedded_impl::{EmbeddedRuntime, NeuronArray, SynapseArray};
108}
109
110/// Version of the runtime trait API
111///
112/// Increment this when making breaking changes to the trait API.
113pub const RUNTIME_TRAIT_VERSION: u32 = 1;
114
115/// Get the runtime trait API version
116pub const fn runtime_trait_version() -> u32 {
117    RUNTIME_TRAIT_VERSION
118}