1#[cfg(feature = "gpu")]
24#[path = "gpu/helpers.rs"]
25mod helpers;
26
27#[cfg(feature = "gpu")]
28#[path = "gpu/gpu_backend.rs"]
29mod gpu_backend;
30
31#[cfg(all(test, feature = "gpu"))]
32#[path = "gpu/gpu_backend_tests.rs"]
33mod gpu_backend_tests;
34
35#[cfg(all(test, feature = "gpu", feature = "persistence"))]
36#[path = "gpu/gpu_csr_tests.rs"]
37mod gpu_csr_extended_tests;
38
39#[cfg(feature = "gpu")]
40#[path = "gpu/pq_gpu.rs"]
41pub mod pq_gpu;
42
43#[cfg(all(feature = "gpu", feature = "persistence"))]
44#[path = "gpu/gpu_csr.rs"]
45pub mod gpu_csr;
46
47#[cfg(all(feature = "gpu", feature = "persistence"))]
48#[path = "gpu/gpu_traversal_buffers.rs"]
49mod gpu_traversal_buffers;
50
51#[cfg(all(feature = "gpu", feature = "persistence"))]
52#[path = "gpu/gpu_traversal_pipelines.rs"]
53mod gpu_traversal_pipelines;
54
55#[cfg(all(feature = "gpu", feature = "persistence"))]
56#[path = "gpu/gpu_traversal.rs"]
57pub mod gpu_traversal;
58
59#[cfg(feature = "gpu")]
60pub use gpu_backend::GpuAccelerator;
61#[cfg(all(feature = "gpu", feature = "persistence"))]
62pub use gpu_traversal::{should_traverse_gpu, GpuTraversalContext, GpuTraversalStats};
63#[cfg(feature = "gpu")]
64pub use pq_gpu::{gpu_kmeans_assign, should_use_gpu, PqGpuContext};
65
66#[cfg(not(feature = "gpu"))]
68#[must_use]
69pub fn should_use_gpu(_n: usize, _k: usize, _subspace_dim: usize) -> bool {
70 false
71}
72
73#[cfg(not(all(feature = "gpu", feature = "persistence")))]
75#[must_use]
76pub fn should_traverse_gpu(_num_vectors: usize, _dimension: usize) -> bool {
77 false
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
82#[allow(dead_code)] pub(crate) enum ComputeBackend {
84 #[default]
86 Simd,
87 #[cfg(feature = "gpu")]
89 Gpu,
90}
91
92#[allow(dead_code)] impl ComputeBackend {
94 #[must_use]
98 pub fn best_available() -> Self {
99 #[cfg(feature = "gpu")]
100 {
101 if gpu_backend::GpuAccelerator::is_available() {
102 return Self::Gpu;
103 }
104 }
105 Self::Simd
106 }
107
108 #[must_use]
110 pub fn gpu_available() -> bool {
111 #[cfg(feature = "gpu")]
112 {
113 gpu_backend::GpuAccelerator::is_available()
114 }
115 #[cfg(not(feature = "gpu"))]
116 {
117 false
118 }
119 }
120}