facebookresearch / faiss

A library for efficient similarity search and clustering of dense vectors.
https://faiss.ai
MIT License
31.44k stars 3.64k forks source link

cudaStream_t arguments in Python client #656

Open cjnolet opened 5 years ago

cjnolet commented 5 years ago

The Python SWIG client exposes the setDefaultStream() function on the GPU resources object but it does not seem to provide any type conversion options to pass in a Python equivalent to the C++ cudastream_t.

Is there a recommended way to accomplish this?

>>> res.setDefaultStream(0, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/raid/cjnolet/dev_env/lib/python3.5/site-packages/faiss-0.1-py3.5.egg/faiss/swigfaiss_gpu.py", line 1193, in setDefaultStream
    return _swigfaiss_gpu.StandardGpuResources_setDefaultStream(self, device, stream)
TypeError: in method 'StandardGpuResources_setDefaultStream', argument 3 of type 'cudaStream_t'

Running on:

Interface:

mdouze commented 5 years ago

Where would you get the cudastream_t from? Is it some typedef of int?

Enet4 commented 5 years ago

From what I know, cudaStream_t is defined by the CUDA runtime API, in the header cuda_runtime_api.h.

wickedfoo commented 5 years ago

It is defined in the CUDA SDK driver_types.h as a pointer:

typedef __device_builtin__ struct CUstream_st *cudaStream_t;

We should get this to work so we can pass whatever the PyTorch stream equivalent as this pointer type.

In the meantime, if you want everything to be ordered wrt the default (null) stream, you can call

res.setDefaultNullStreamAllDevices()

mdouze commented 5 years ago

I would suggest setting the Faiss stream to the default for now.

Otherwise SWIG handles unknown pointers smoothly. Just expose the function that produces the pointer and the one that consumes it in a header parsed by swig and the pointers will be passed around as expected.