faiss
faiss copied to clipboard
build error on windows by vs2022
Summary
1>.../faiss-1.7.4\faiss/gpu/impl/PQCodeDistances-inl.cuh(541): error : expected an expression 1> auto outDistancesCodeViewCols = outCodeDistancesView.view<2>({coarseIndices.getSize(0) * coarseIndices.getSize(1), 1> ^ 1> 1>1 error detected in the compilation of ".../faiss-1.7.4/faiss/gpu/impl/IVFPQ.cu".
Platform
OS: WIN11
Faiss version: 1.7.4
Installed from: just build for c++; cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DFAISS_ENABLE_GPU=ON -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON
Faiss compilation options:
Running on:
- [x] CPU
- [x] GPU
Interface:
- [x] C++
Reproduction instructions
please do not post screenshots.
Although we don't support compiling GPU Faiss for windows, if there is an easy fix then we'd intergrate it. It seems that VC++ does not support some syntax here.
https://github.com/facebookresearch/faiss/blob/main/faiss/gpu/impl/PQCodeDistances-inl.cuh#L541
@wickedfoo any idea what's the issue here?
create a personal dirty-hack to workaround this issue: https://github.com/yexiangyu/faiss/tree/v1.7.4-win
If anybody else comes across this, I was able to solve this specific build error.
Before you compile, edit 2 lines in faiss/gpu/impl/PQCodeDistances-inl.cuh:
- line 506:
auto outCodeDistancesView = outCodeDistancesF.view<3>(
->auto outCodeDistancesView = outCodeDistancesF.template view<3>(
- line 541:
auto outDistancesCodeViewCols = outCodeDistancesView.view<2>(
->auto outDistancesCodeViewCols = outCodeDistancesView.template view<2>(
I am pretty inexperienced in C++, so I do not necessarily know if only one of these lines is necessary, but changing both lines worked for me and I'm too scared to touch it again.
A good explanation of why the template
keyword makes an appearance here can be found in the Eigen docs. Basically, it can be ambiguous whether the angle brackets are comparison operators or template parameters. I think MSVC is expecting another expression to be compared to (outCodeDistancesView.view < 2)
inside the brackets, so it throws an error because it finds an initializer list.
Worth pointing out that unless there is some way to bulk-dllimport everything in a header or something like that, the lack of __declspec(dllimport)
in headers means that you still cannot link to a built shared library unless you want to manually update every header. I have yet to test building as a static library on Windows, but I could build a faiss.dll with GPU support seemingly fine on Windows, even if I cannot use it.