Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid GPU device for faiss.GpuIndexFlatL2() #2092

Closed
preethiseshadri518 opened this issue Oct 27, 2021 · 2 comments
Closed

Invalid GPU device for faiss.GpuIndexFlatL2() #2092

preethiseshadri518 opened this issue Oct 27, 2021 · 2 comments
Labels

Comments

@preethiseshadri518
Copy link

I am trying to use FAISS to perform a similarity search using GPUs. However, I seem to have trouble specifying the GPU device correctly.

Here is what I do to specify the GPU device when I run code in tensorflow. This works properly if I want to run code in my jupyter notebook using device 2.

import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" 
os.environ['CUDA_VISIBLE_DEVICES'] = '2'

However, I seem to have an issue when I try to setup faiss.GpuIndexFlatL2. I get the following error: Error in faiss::gpu::GpuIndex::GpuIndex(std::shared_ptr<faiss::gpu::GpuResources>, int, faiss::MetricType, float, faiss::gpu::GpuIndexConfig) at /__w/faiss-wheels/faiss-wheels/faiss/faiss/gpu/GpuIndex.cu:53: Error: 'config_.device < getNumDevices()' failed: Invalid GPU device 2

features = np.random.random((1000, 768)) # just a placeholder for now
res = faiss.StandardGpuResources()
config = faiss.GpuIndexFlatConfig()
config.useFloat16 = False
config.device = 2
index = faiss.GpuIndexFlatL2(res, features, config)

I have also tried changing config.device to other device numbers 0, 1, 2, etc. since I have access to 8 GPU devices and the same thing happens for all of them except for device 0, where I get a OOM message (cudaMalloc error out of memory). Note: I am using faiss-gpu 1.7.1.

Any ideas on what is happening and how to fix this issue? Thanks!

@mdouze mdouze added the GPU label Nov 10, 2021
@mdouze
Copy link
Contributor

mdouze commented Nov 10, 2021

CUDA_VISIBLE_DEVICES is restricted to only GPU #2 so it is normal that only GPU 0 is visible (CUDA_VISIBLE_DEVICES maps GPU 2 to the only visible GPU at index 0).

@phanxuanduc1996
Copy link

I used Anaconda, I installed bellow, it worked. If you use Docker, please install Miniconda.
conda install faiss-gpu cudatoolkit=11.1 -c pytorch-gpu
conda install -c anaconda pytorch-gpu

@mdouze mdouze closed this as completed Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants