fix: initializing order of gpu compile options (#4581)

Summary:
# issue
I met gpu_compile_options initialization order issue over gcc 8.4.0. Maybe related with LTO bug?

# solution
make it deterministic, no "crossing fingers" required. 😸

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4581

Reviewed By: subhadeepkaran

Differential Revision: D82647834

Pulled By: pankajsingh88

fbshipit-source-id: ead9515dc6e84987e6c8f5471318a34cc5b81086
This commit is contained in:
simshi
2025-10-16 10:25:44 -07:00
committed by meta-codesync[bot]
parent f58fd4c8ca
commit 97dc014472
2 changed files with 10 additions and 8 deletions
+5 -6
View File
@@ -748,20 +748,19 @@ bool isGpuIndexImplemented(faiss::Index* index) {
} // namespace gpu
// This is the one defined in utils.cpp
// Crossing fingers that the InitGpuCompileOptions_instance will
// be instanciated after this global variable
extern std::string gpu_compile_options;
extern std::string& ref_gpu_compile_options();
struct InitGpuCompileOptions {
InitGpuCompileOptions() {
gpu_compile_options = "GPU ";
ref_gpu_compile_options() = std::string("GPU ") +
#ifdef USE_NVIDIA_CUVS
gpu_compile_options += "NVIDIA_CUVS ";
"NVIDIA_CUVS " +
#endif
#ifdef USE_AMD_ROCM
gpu_compile_options += "AMD_ROCM ";
"AMD_ROCM " +
#endif
"";
}
};
+5 -2
View File
@@ -102,7 +102,10 @@ int sgemv_(
namespace faiss {
// this will be set at load time from GPU Faiss
std::string gpu_compile_options;
std::string& ref_gpu_compile_options() {
static std::string gpu_compile_options;
return gpu_compile_options;
}
std::string get_compile_options() {
std::string options;
@@ -124,7 +127,7 @@ std::string get_compile_options() {
options += "GENERIC ";
#endif
options += gpu_compile_options;
options += ref_gpu_compile_options();
return options;
}