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§

source§

impl StandardGpuResources

source

pub fn new() -> Result<Self>

Create a standard GPU resources object.

Trait Implementations§

source§

impl Debug for StandardGpuResources

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'g> GpuResources for &'g mut StandardGpuResources

source§

fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider

Obtain a raw pointer to the native GPU resources object.
source§

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
source§

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
source§

fn set_pinned_memory(&mut self, size: usize) -> Result<()>

Set amount of pinned memory to allocate, for async GPU <-> CPU transfers
source§

impl GpuResources for StandardGpuResources

source§

fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider

Obtain a raw pointer to the native GPU resources object.
source§

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
source§

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
source§

fn set_pinned_memory(&mut self, size: usize) -> Result<()>

Set amount of pinned memory to allocate, for async GPU <-> CPU transfers
source§

impl GpuResourcesProvider for StandardGpuResources

source§

fn inner_ptr(&self) -> *mut FaissGpuResourcesProvider

Obtain a raw pointer to the native GPU resource provider object.
source§

impl Send for StandardGpuResources

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.