Skip to content

Instantly share code, notes, and snippets.

@Enet4
Created April 12, 2018 19:59
Show Gist options
  • Save Enet4/8a7068ec20967bb4bd4f399949cadd2a to your computer and use it in GitHub Desktop.
Save Enet4/8a7068ec20967bb4bd4f399949cadd2a to your computer and use it in GitHub Desktop.
usage of an index on both cpu and gpu in faiss-rs
let res = StandardGpuResources::new()?;
// create an index and place it on GPU memory
let mut index = index_factory(8, "Flat", MetricType::L2)?
.into_gpu(&res, 0)?;
index.add(get_data())?;
let my_query = get_query();
let result = index.search(&my_query, 5)?;
assert_eq!(result.labels, vec![2, 1, 0, 3, 4]);
// now back to the CPU!
let mut index = index.into_cpu()?;
let result = index.search(&my_query, 5)?;
// should get approximately the same results
assert_eq!(result.labels, vec![2, 1, 0, 3, 4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment