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 FaissGpuResources
fn inner_ptr(&self) -> *mut FaissGpuResources
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 use Read moresource§fn set_temp_memory(&mut self, size: usize) -> Result<()>
fn set_temp_memory(&mut self, size: usize) -> Result<()>
Specify that we wish to use a certain fixed size of memory on
all devices as temporary memory Read more
source§impl GpuResources for StandardGpuResources
impl GpuResources for StandardGpuResources
source§fn inner_ptr(&self) -> *mut FaissGpuResources
fn inner_ptr(&self) -> *mut FaissGpuResources
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 use Read moresource§fn set_temp_memory(&mut self, size: usize) -> Result<()>
fn set_temp_memory(&mut self, size: usize) -> Result<()>
Specify that we wish to use a certain fixed size of memory on
all devices as temporary memory Read more