#![doc = include_str!("../README.md")]
#![allow(
    non_camel_case_types,
    non_upper_case_globals,
    non_snake_case,
    clippy::missing_transmute_annotations
)]

#[cfg(test)]
mod tests;

pub mod buffer;
pub mod command;
pub mod device;
pub mod dispatch;
pub mod encoder;
pub mod ffi;
pub mod pipeline;
pub mod shader;
pub mod sync;
pub mod texture;

pub use buffer::Buffer;
pub use command::{Commands, Queue};
pub use device::Gpu;
pub use dispatch::{Batch, Dispatch, GpuFuture};
pub use encoder::{Copier, Encoder};
pub use pipeline::Pipeline;
pub use shader::{Shader, ShaderLib};
pub use sync::{Event, Fence, SharedEvent};
pub use texture::Texture;

// Memory foundation โ€” re-export for single-import convenience
pub use unimem::{Block, Layout, MemError, Tape};

// Re-export fp16 from acpu (single source of truth for numeric conversions)
pub use acpu::numeric::fp16::{f32_to_fp16, fp16_to_f32};
pub use acpu::{cast_f16_f32, cast_f32_f16};

/// Execute a closure inside an autorelease pool.
/// Use this to scope autoreleased ObjC objects (e.g. from `commands_unretained`).
/// The pool is drained even if the closure panics (unwind-safe).
#[inline]
pub fn autorelease_pool<F, R>(f: F) -> R
where
    F: FnOnce() -> R,
{
    struct PoolGuard(*mut std::ffi::c_void);
    impl Drop for PoolGuard {
        #[mutants::skip] // RAII pool drain โ€” leak on skip, not testable
        fn drop(&mut self) {
            unsafe { ffi::objc_autoreleasePoolPop(self.0) }
        }
    }
    let pool = unsafe { ffi::objc_autoreleasePoolPush() };
    let _guard = PoolGuard(pool);
    f()
}

/// Errors returned by aruminium operations.
#[derive(Debug)]
#[non_exhaustive]
pub enum GpuError {
    /// No Metal-capable GPU found on this system.
    DeviceNotFound,
    /// GPU buffer allocation failed.
    BufferCreationFailed(String),
    /// MSL shader compilation failed (includes compiler diagnostic).
    LibraryCompilationFailed(String),
    /// Named function not found in compiled shader library.
    FunctionNotFound(String),
    /// Compute pipeline creation failed.
    PipelineCreationFailed(String),
    /// Command buffer execution failed.
    CommandBufferError(String),
    /// Could not create a command encoder.
    EncoderCreationFailed,
    /// Could not create a command queue.
    QueueCreationFailed,
    /// Texture creation failed.
    TextureCreationFailed(String),
    /// Filesystem I/O error.
    Io(std::io::Error),
}

impl std::fmt::Display for GpuError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            GpuError::DeviceNotFound => write!(f, "No Metal device found"),
            GpuError::BufferCreationFailed(msg) => write!(f, "Buffer creation failed: {}", msg),
            GpuError::LibraryCompilationFailed(msg) => {
                write!(f, "Shader compilation failed: {}", msg)
            }
            GpuError::FunctionNotFound(name) => write!(f, "Function not found: {}", name),
            GpuError::PipelineCreationFailed(msg) => {
                write!(f, "Pipeline creation failed: {}", msg)
            }
            GpuError::CommandBufferError(msg) => write!(f, "Command buffer error: {}", msg),
            GpuError::EncoderCreationFailed => write!(f, "Encoder creation failed"),
            GpuError::QueueCreationFailed => write!(f, "Command queue creation failed"),
            GpuError::TextureCreationFailed(msg) => {
                write!(f, "Texture creation failed: {}", msg)
            }
            GpuError::Io(e) => write!(f, "IO error: {}", e),
        }
    }
}

impl std::error::Error for GpuError {}

impl From<std::io::Error> for GpuError {
    fn from(e: std::io::Error) -> Self {
        GpuError::Io(e)
    }
}

Synonyms

bbg/src/lib.rs
optica/src/lib.rs
zheng/src/lib.rs
nox/rs/lib.rs
honeycrisp/src/lib.rs
trident/src/lib.rs
lens/src/lib.rs
strata/src/lib.rs
rs/macros/src/lib.rs
strata/nebu/rs/lib.rs
honeycrisp/rane/src/lib.rs
honeycrisp/acpu/src/lib.rs
lens/core/src/lib.rs
rs/mir-format/src/lib.rs
rs/core/src/lib.rs
hemera/wgsl/src/lib.rs
strata/kuro/rs/lib.rs
radio/iroh-ffi/src/lib.rs
cyb/src-tauri/src/lib.rs
strata/core/src/lib.rs
radio/iroh-docs/src/lib.rs
strata/compute/src/lib.rs
lens/porphyry/src/lib.rs
radio/cyber-bao/src/lib.rs
radio/iroh-relay/src/lib.rs
lens/assayer/src/lib.rs
lens/brakedown/src/lib.rs
radio/iroh-car/src/lib.rs
honeycrisp/unimem/src/lib.rs
lens/binius/src/lib.rs
hemera/rs/src/lib.rs
strata/ext/src/lib.rs
radio/iroh/src/lib.rs
radio/iroh-gossip/src/lib.rs
strata/proof/src/lib.rs
radio/iroh-blobs/src/lib.rs
radio/iroh-base/src/lib.rs
radio/iroh-dns-server/src/lib.rs
radio/iroh-willow/src/lib.rs
lens/ikat/src/lib.rs
rs/tests/macro-integration/src/lib.rs
cw-cyber/contracts/hub-networks/src/lib.rs
radio/tests/integration/src/lib.rs
cw-cyber/contracts/litium-core/src/lib.rs
strata/trop/wgsl/src/lib.rs
strata/kuro/wgsl/src/lib.rs
cw-cyber/contracts/hub-protocols/src/lib.rs
cw-cyber/contracts/cw-cyber-gift/src/lib.rs
strata/trop/rs/src/lib.rs
cw-cyber/contracts/cybernet/src/lib.rs
cw-cyber/contracts/hub-channels/src/lib.rs
strata/nebu/wgsl/src/lib.rs
cw-cyber/contracts/graph-filter/src/lib.rs
cw-cyber/contracts/litium-stake/src/lib.rs
trident/editor/zed/src/lib.rs
radio/iroh-ffi/iroh-js/src/lib.rs
cw-cyber/contracts/hub-tokens/src/lib.rs
cyb/cyb/cyb-services/src/lib.rs
cw-cyber/packages/hub-base/src/lib.rs
strata/genies/rs/src/lib.rs
cw-cyber/contracts/std-test/src/lib.rs
cw-cyber/packages/cyber-std-test/src/lib.rs
cw-cyber/contracts/litium-refer/src/lib.rs
strata/jali/rs/src/lib.rs
cw-cyber/contracts/hub-libs/src/lib.rs
cw-cyber/contracts/litium-wrap/src/lib.rs
cw-cyber/packages/cyber-std/src/lib.rs
strata/genies/wgsl/src/lib.rs
cw-cyber/contracts/hub-skills/src/lib.rs
strata/jali/wgsl/src/lib.rs
cw-cyber/contracts/cw-cyber-subgraph/src/lib.rs
radio/iroh/bench/src/lib.rs
cw-cyber/contracts/litium-mine/src/lib.rs
cw-cyber/contracts/cw-cyber-passport/src/lib.rs

Neighbours