pub mod heat_kernel;
pub mod navier_stokes_kernel;
pub mod stress_assembly;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum GpuError {
#[error("GPU backend is unavailable; falling back to CPU")]
BackendUnavailable,
#[error("GPU kernel dispatch error: {0}")]
DispatchError(String),
#[error("GPU kernel input error: {0}")]
InvalidInput(String),
}
pub type GpuResult<T> = Result<T, GpuError>;
#[inline]
pub fn backend_available() -> bool {
#[cfg(feature = "gpu")]
{
true
}
#[cfg(not(feature = "gpu"))]
{
false
}
}
pub use heat_kernel::HeatKernelDispatcher;
pub use navier_stokes_kernel::NavierStokesKernelDispatcher;
pub use stress_assembly::{
FemElementKind, GpuElementContribution, GpuElementDescriptor, StressAssemblyDispatcher,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn backend_available_matches_feature() {
#[cfg(feature = "gpu")]
assert!(backend_available());
#[cfg(not(feature = "gpu"))]
assert!(!backend_available());
}
#[test]
fn gpu_error_display() {
assert!(GpuError::BackendUnavailable
.to_string()
.contains("unavailable"));
assert!(GpuError::DispatchError("foo".to_string())
.to_string()
.contains("foo"));
assert!(GpuError::InvalidInput("bad".to_string())
.to_string()
.contains("bad"));
}
}