Skip to content

Commit

Permalink
Fix faiss swig build with version > 4.2.x (#3315)
Browse files Browse the repository at this point in the history
Summary:
Currently, faiss can't build with swig version > 4.2.x. As the #3239 mentioned.  Swig removed the support for 32bit swig/swig@9fb3a49. So SWIGTYPE_p_unsigned_long_long isn't supported any more. In this diff, we are going to remove the unsupported type from Faiss swig.

Pull Request resolved: #3315

Test Plan:
STEP 1: create a new conda env
```
conda create --name faiss_swig
conda activate faiss_swig
```

STEP 2: install dependecies from conda-forge
```
conda install -y -q python=3.11 cmake make swig mkl=2023 mkl-devel=2023 numpy scipy pytest gxx_linux-64 sysroot_linux-64=2.28 -c conda-forge
```

STEP 3: CMAKE

```
cmake -B build \
      -DBUILD_TESTING=ON \
      -DBUILD_SHARED_LIBS=ON \
      -DFAISS_ENABLE_GPU=OFF \
      -DFAISS_ENABLE_RAFT=OFF \
      -DFAISS_OPT_LEVEL=avx512 \
      -DFAISS_ENABLE_C_API=ON \
      -DPYTHON_EXECUTABLE=$(which python) \
      -DCMAKE_BUILD_TYPE=Release \
      -DBLA_VENDOR=Intel10_64_dyn \
      -DCMAKE_CUDA_FLAGS="-gencode arch=compute_75,code=sm_75" \
      .
```

STEP 4: build
```
make -C build -j faiss && make -C build -j swigfaiss
```
<img width="876" alt="Screenshot 2024-03-25 at 12 24 16 AM" src="https://github.com/facebookresearch/faiss/assets/8333898/918f0caf-398a-4361-989f-93ff547cf2b2">

Reviewed By: algoriddle

Differential Revision: D55304004

Pulled By: junjieqi

fbshipit-source-id: e958009dc637aa33b0e1a574a16a846a4abb1525
  • Loading branch information
junjieqi authored and facebook-github-bot committed Mar 29, 2024
1 parent 03db694 commit d685413
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -224,15 +224,15 @@ jobs:
- run:
name: Install env using main channel
command: |
conda install -y -q python=3.11 cmake make swig=4.0.2 mkl=2023 mkl-devel=2023 numpy scipy pytest gxx_linux-64 sysroot_linux-64
conda install -y -q python=3.11 cmake make swig mkl=2023 mkl-devel=2023 numpy scipy pytest gxx_linux-64=11.2 sysroot_linux-64
- when:
condition:
equal: [ "ON", << parameters.raft >> ]
steps:
- run:
name: Install env using conda-forge channel
command: |
conda install -y -q python=3.11 cmake make swig=4.0.2 mkl=2023 mkl-devel=2023 numpy scipy pytest gxx_linux-64 sysroot_linux-64=2.28 libraft cuda-version=11.8 cuda-toolkit -c rapidsai-nightly -c "nvidia/label/cuda-11.8.0" -c conda-forge
conda install -y -q python=3.11 cmake make swig mkl=2023 mkl-devel=2023 numpy scipy pytest gxx_linux-64=11.2 sysroot_linux-64=2.28 libraft cuda-version=11.8 cuda-toolkit -c rapidsai-nightly -c "nvidia/label/cuda-11.8.0" -c conda-forge
- when:
condition:
and:
Expand Down
2 changes: 1 addition & 1 deletion conda/faiss-gpu-raft/meta.yaml
Expand Up @@ -84,7 +84,7 @@ outputs:
build:
- {{ compiler('cxx') }}
- sysroot_linux-64 =2.17 # [linux64]
- swig =4.0.2
- swig
- cmake >=3.23.1
- make # [not win]
host:
Expand Down
4 changes: 2 additions & 2 deletions faiss/python/swigfaiss.swig
Expand Up @@ -1022,14 +1022,14 @@ PyObject *swig_ptr (PyObject *a)
return SWIG_NewPointerObj(data, SWIGTYPE_p_bool, 0);
}
if(PyArray_TYPE(ao) == NPY_UINT64) {
#ifdef SWIGWORDSIZE64
#if (__SIZEOF_LONG__ == 8)
return SWIG_NewPointerObj(data, SWIGTYPE_p_unsigned_long, 0);
#else
return SWIG_NewPointerObj(data, SWIGTYPE_p_unsigned_long_long, 0);
#endif
}
if(PyArray_TYPE(ao) == NPY_INT64) {
#ifdef SWIGWORDSIZE64
#if (__SIZEOF_LONG__ == 8)
return SWIG_NewPointerObj(data, SWIGTYPE_p_long, 0);
#else
return SWIG_NewPointerObj(data, SWIGTYPE_p_long_long, 0);
Expand Down

0 comments on commit d685413

Please sign in to comment.