use super::gpu::*;
#[test]
fn test_compute_backend_default_is_simd() {
let backend = ComputeBackend::default();
assert_eq!(backend, ComputeBackend::Simd);
}
#[cfg(not(feature = "gpu"))]
#[test]
fn test_gpu_available_false_without_feature() {
assert!(!ComputeBackend::gpu_available());
}
#[test]
fn test_compute_backend_fallback_to_simd() {
let backend = ComputeBackend::best_available();
#[cfg(feature = "gpu")]
{
if ComputeBackend::gpu_available() {
assert_eq!(
backend,
ComputeBackend::Gpu,
"best_available() must select Gpu when gpu_available() is true"
);
} else {
assert_eq!(
backend,
ComputeBackend::Simd,
"best_available() must fall back to Simd when GPU is unavailable"
);
}
}
#[cfg(not(feature = "gpu"))]
assert_eq!(backend, ComputeBackend::Simd);
}
#[test]
fn test_gpu_available_consistency() {
let first = ComputeBackend::gpu_available();
let second = ComputeBackend::gpu_available();
let third = ComputeBackend::gpu_available();
assert_eq!(first, second, "gpu_available() must be consistent");
assert_eq!(second, third, "gpu_available() must be consistent");
#[cfg(not(feature = "gpu"))]
assert!(
!first,
"gpu_available() must be false without the gpu feature"
);
#[cfg(feature = "gpu")]
{
use super::gpu::GpuAccelerator;
assert_eq!(
first,
GpuAccelerator::is_available(),
"gpu_available() must agree with the cached GpuAccelerator::is_available() probe"
);
}
}
#[cfg(feature = "gpu")]
#[test]
fn test_gpu_accelerator_none_without_gpu() {
use super::gpu::GpuAccelerator;
let gpu = GpuAccelerator::new();
if gpu.is_none() {
assert!(
!GpuAccelerator::is_available(),
"GpuAccelerator::new() returned None while is_available() reported true"
);
}
}