Created
April 12, 2018 19:59
-
-
Save Enet4/8a7068ec20967bb4bd4f399949cadd2a to your computer and use it in GitHub Desktop.
usage of an index on both cpu and gpu in faiss-rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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