Struct faiss::gpu::StandardGpuResources [−][src]
pub struct StandardGpuResources { /* fields omitted */ }
Expand description
Standard GPU resources descriptor.
Examples
GPU resources are meant to be passed to an index implementation’s
into_gpu
or to_gpu
methods.
use faiss::{StandardGpuResources, MetricType}; use faiss::index::flat::FlatIndex; let gpu = StandardGpuResources::new()?; let index = FlatIndex::new(64, MetricType::L2)?; let gpu_index = index.into_gpu(&gpu, 0)?;
Since GPU implementations are not thread-safe, attempting to use the GPU resources from another thread is not allowed.
ⓘ
use faiss::{GpuResources, StandardGpuResources}; use faiss::index::flat::FlatIndex; use std::sync::Arc; use std::thread; let gpu = Arc::new(StandardGpuResources::new()?); let gpu_rc = gpu.clone(); thread::spawn(move || { let index = FlatIndex::new_l2(64)?; let gpu_index = index.into_gpu(&*gpu_rc, 0)?; // will not compile Ok(()) });
Other than that, indexes can share the same GPU resources, so long as neither of them cross any thread boundaries.
use faiss::{GpuResources, StandardGpuResources, MetricType, index_factory}; let mut gpu = StandardGpuResources::new()?; let index1 = index_factory(64, "Flat", MetricType::L2)? .into_gpu(&gpu, 0)?; let index2 = index_factory(32, "Flat", MetricType::InnerProduct)? .into_gpu(&gpu, 0)?;
Implementations
Trait Implementations
Obtain a raw pointer to the native GPU resource provider object.
Auto Trait Implementations
impl RefUnwindSafe for StandardGpuResources
impl !Sync for StandardGpuResources
impl Unpin for StandardGpuResources
impl UnwindSafe for StandardGpuResources