Struct faiss::gpu::StandardGpuResources
source · pub struct StandardGpuResources { /* private fields */ }
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§
source§impl Debug for StandardGpuResources
impl Debug for StandardGpuResources
source§impl<'g> GpuResources for &'g mut StandardGpuResources
impl<'g> GpuResources for &'g mut StandardGpuResources
source§fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
Obtain a raw pointer to the native GPU resources object.
source§fn no_temp_memory(&mut self) -> Result<()>
fn no_temp_memory(&mut self) -> Result<()>
Disable allocation of temporary memory; all temporary memory
requests will call
cudaMalloc
/ cudaFree
at the point of usesource§impl GpuResources for StandardGpuResources
impl GpuResources for StandardGpuResources
source§fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
Obtain a raw pointer to the native GPU resources object.
source§fn no_temp_memory(&mut self) -> Result<()>
fn no_temp_memory(&mut self) -> Result<()>
Disable allocation of temporary memory; all temporary memory
requests will call
cudaMalloc
/ cudaFree
at the point of usesource§impl GpuResourcesProvider for StandardGpuResources
impl GpuResourcesProvider for StandardGpuResources
source§fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider
Obtain a raw pointer to the native GPU resource provider object.
impl Send for StandardGpuResources
Auto Trait Implementations§
impl RefUnwindSafe for StandardGpuResources
impl !Sync for StandardGpuResources
impl Unpin for StandardGpuResources
impl UnwindSafe for StandardGpuResources
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more