use crate::error::{BarracudaError, Result};
use std::sync::Arc;
pub mod akida;
pub mod akida_executor;
pub mod async_submit;
pub mod autotune;
pub mod backend;
pub mod batched_encoder;
pub mod cache_hierarchy;
pub mod capabilities;
pub mod compute_pipeline;
pub mod coral_compiler;
mod device_types;
pub mod driver_profile;
pub mod fma_policy;
pub mod hardware_calibration;
pub mod kernel_router;
pub mod latency;
pub mod pipeline_cache;
pub mod precision_brain;
pub mod precision_tier;
pub mod probe;
pub mod probe_throughput;
pub mod registry;
mod routing;
pub mod silicon_profile;
#[cfg(feature = "sovereign-dispatch")]
pub mod sovereign_device;
#[cfg(feature = "sovereign-dispatch")]
mod sovereign_discovery;
#[cfg(feature = "sovereign-dispatch")]
mod sovereign_dispatch_wire;
pub mod substrate;
pub mod tensor_context;
pub mod unified;
pub mod vendor;
pub mod warmup;
mod wgpu_backend;
pub mod wgpu_device;
pub use autotune::{AutoTuner, GLOBAL_TUNER, GpuCalibration};
pub use warmup::{
WarmupConfig, WarmupOp, WarmupResult, WarmupWorkloadHint, warmup_device, warmup_pool,
};
pub use pipeline_cache::clear_global_cache;
pub use tensor_context::{
BatchGuard, BufferPool, PooledBuffer, TensorContext, TensorContextStats, clear_global_contexts,
get_device_context, high_capacity_limits, science_limits,
};
pub use akida::{AkidaBoard, AkidaCapabilities, BoardHealth, detect_akida_boards};
pub use akida_executor::{AkidaExecutor, NeuromorphicComparison};
pub use async_submit::{AsyncReadback, AsyncSubmitter};
pub use backend::{BufferBinding, DispatchDescriptor, GpuBackend};
pub use batched_encoder::BatchedEncoder;
pub use cache_hierarchy::{
CacheAwareTiler, CacheLevel, CacheResidency, MainMemory, SubstrateMemoryHierarchy, TileConfig,
};
pub use capabilities::{
DeviceCapabilities, EigensolveStrategy, Fp64Rate, Fp64Strategy, PrecisionRoutingAdvice,
WorkloadType, optimal_workgroup_size_arch, workgroup_size_2d_for_arch, workgroup_size_for_arch,
};
pub use compute_pipeline::{
BatchedComputeDispatch, ComputeDispatch, storage_bgl_entry, uniform_bgl_entry,
};
pub use kernel_router::{
ComputeWorkload, KernelRouter, KernelTarget, MatmulPrecision, NpuModelInfo,
};
pub use registry::{
BackendInfo, DeviceCapabilities as PhysicalDeviceCapabilities, DeviceRegistry, DeviceVendor,
PhysicalDevice, PhysicalDeviceId,
};
#[cfg(feature = "sovereign-dispatch")]
pub use sovereign_device::SovereignDevice;
pub use substrate::{Substrate, SubstrateCapability, SubstrateType};
pub use unified::{Capability, Device, DeviceContext, DeviceInfo, WorkloadHint};
pub use wgpu_device::WgpuDevice;
pub use fma_policy::{FmaPolicy, domain_requires_separate_fma};
pub use hardware_calibration::HardwareCalibration;
pub use precision_brain::PrecisionBrain;
pub use precision_tier::{PhysicsDomain, PrecisionBrainAdvice, PrecisionTier};
pub mod test_pool;
pub mod test_harness;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeviceSelection {
Gpu,
Cpu,
Npu,
Sovereign,
}
impl DeviceSelection {
#[must_use]
pub fn supports_wgsl(self) -> bool {
matches!(self, Self::Gpu | Self::Cpu | Self::Sovereign)
}
#[must_use]
pub fn is_event_driven(self) -> bool {
matches!(self, Self::Npu)
}
#[must_use]
pub fn is_sovereign(self) -> bool {
matches!(self, Self::Sovereign)
}
}
#[must_use]
pub fn sovereign_available() -> bool {
#[cfg(feature = "sovereign-dispatch")]
{
sovereign_device::SovereignDevice::with_auto_device().is_ok_and(|d| d.has_dispatch())
}
#[cfg(not(feature = "sovereign-dispatch"))]
false
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HardwareWorkload {
TensorOps,
NeuralNetwork,
SpikingNetwork,
ReservoirComputing,
Genomics,
Bioinformatics,
ScientificCompute,
HomomorphicEncryption,
}
#[derive(Debug, Clone)]
pub enum DiscoveredDevice {
Wgpu(Arc<WgpuDevice>),
#[cfg(feature = "sovereign-dispatch")]
Sovereign(Arc<sovereign_device::SovereignDevice>),
}
impl DiscoveredDevice {
#[must_use]
pub fn name(&self) -> String {
match self {
Self::Wgpu(d) => d.adapter_info().name.clone(),
#[cfg(feature = "sovereign-dispatch")]
Self::Sovereign(d) => {
use backend::GpuBackend;
d.name().to_owned()
}
}
}
#[must_use]
pub fn has_f64_shaders(&self) -> bool {
match self {
Self::Wgpu(d) => d.has_f64_shaders(),
#[cfg(feature = "sovereign-dispatch")]
Self::Sovereign(d) => {
use backend::GpuBackend;
d.has_f64_shaders()
}
}
}
#[must_use]
pub fn wgpu_device(&self) -> Option<&Arc<WgpuDevice>> {
match self {
Self::Wgpu(d) => Some(d),
#[cfg(feature = "sovereign-dispatch")]
Self::Sovereign(_) => None,
}
}
#[must_use]
pub fn is_sovereign(&self) -> bool {
match self {
Self::Wgpu(_) => false,
#[cfg(feature = "sovereign-dispatch")]
Self::Sovereign(_) => true,
}
}
pub fn require_wgpu(self) -> Result<Arc<WgpuDevice>> {
match self {
Self::Wgpu(d) => Ok(d),
#[cfg(feature = "sovereign-dispatch")]
Self::Sovereign(_) => Err(BarracudaError::device(
"Operation requires a local wgpu device; sovereign IPC cannot provide local buffers",
)),
}
}
}
pub struct Auto;
impl Auto {
#[expect(
clippy::new_ret_no_self,
reason = "Auto is a discovery namespace, not a constructible type"
)]
pub async fn new() -> Result<DiscoveredDevice> {
if let Ok(dev) = WgpuDevice::new().await {
return Ok(DiscoveredDevice::Wgpu(Arc::new(dev)));
}
if let Ok(dev) = WgpuDevice::new_cpu_relaxed().await {
tracing::info!("GPU unavailable, using CPU software rasterizer");
return Ok(DiscoveredDevice::Wgpu(Arc::new(dev)));
}
#[cfg(feature = "sovereign-dispatch")]
if sovereign_available() {
if let Ok(sov) = sovereign_device::SovereignDevice::with_auto_device() {
tracing::info!(
"wgpu unavailable, using sovereign IPC dispatch via shader.compile+compute.dispatch peers"
);
return Ok(DiscoveredDevice::Sovereign(Arc::new(sov)));
}
}
Err(BarracudaError::device(
"No compute device available (GPU, CPU software rasterizer, \
and sovereign IPC all unavailable)",
))
}
pub async fn new_wgpu() -> Result<Arc<WgpuDevice>> {
if let Ok(dev) = WgpuDevice::new().await {
return Ok(Arc::new(dev));
}
if let Ok(dev) = WgpuDevice::new_cpu_relaxed().await {
tracing::info!("GPU unavailable, using CPU software rasterizer");
return Ok(Arc::new(dev));
}
Err(BarracudaError::device(
"No wgpu device available (GPU and CPU software rasterizer both unavailable)",
))
}
pub async fn new_fresh() -> Result<WgpuDevice> {
WgpuDevice::new().await
}
}