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§

Create a standard GPU resources object.

Trait Implementations§

Formats the value using the given formatter. Read more
Obtain a raw pointer to the native GPU resources object.
Disable allocation of temporary memory; all temporary memory requests will call cudaMalloc / cudaFree at the point of use Read more
Specify that we wish to use a certain fixed size of memory on all devices as temporary memory Read more
Specify that we wish to use a certain fraction of memory on all devices as temporary memory Read more
Set amount of pinned memory to allocate, for async GPU <-> CPU transfers Read more
Obtain a raw pointer to the native GPU resources object.
Disable allocation of temporary memory; all temporary memory requests will call cudaMalloc / cudaFree at the point of use Read more
Specify that we wish to use a certain fixed size of memory on all devices as temporary memory Read more
Specify that we wish to use a certain fraction of memory on all devices as temporary memory Read more
Set amount of pinned memory to allocate, for async GPU <-> CPU transfers Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.