Skip to content

Commit 97dc014

Browse files
simshimeta-codesync[bot]
authored andcommitted
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: #4581 Reviewed By: subhadeepkaran Differential Revision: D82647834 Pulled By: pankajsingh88 fbshipit-source-id: ead9515dc6e84987e6c8f5471318a34cc5b81086
1 parent f58fd4c commit 97dc014

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

faiss/gpu/GpuIndex.cu

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,20 +748,19 @@ bool isGpuIndexImplemented(faiss::Index* index) {
748748
} // namespace gpu
749749

750750
// This is the one defined in utils.cpp
751-
// Crossing fingers that the InitGpuCompileOptions_instance will
752-
// be instanciated after this global variable
753-
extern std::string gpu_compile_options;
751+
extern std::string& ref_gpu_compile_options();
754752

755753
struct InitGpuCompileOptions {
756754
InitGpuCompileOptions() {
757-
gpu_compile_options = "GPU ";
755+
ref_gpu_compile_options() = std::string("GPU ") +
758756
#ifdef USE_NVIDIA_CUVS
759-
gpu_compile_options += "NVIDIA_CUVS ";
757+
"NVIDIA_CUVS " +
760758
#endif
761759

762760
#ifdef USE_AMD_ROCM
763-
gpu_compile_options += "AMD_ROCM ";
761+
"AMD_ROCM " +
764762
#endif
763+
"";
765764
}
766765
};
767766

faiss/utils/utils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ int sgemv_(
102102
namespace faiss {
103103

104104
// this will be set at load time from GPU Faiss
105-
std::string gpu_compile_options;
105+
std::string& ref_gpu_compile_options() {
106+
static std::string gpu_compile_options;
107+
return gpu_compile_options;
108+
}
106109

107110
std::string get_compile_options() {
108111
std::string options;
@@ -124,7 +127,7 @@ std::string get_compile_options() {
124127
options += "GENERIC ";
125128
#endif
126129

127-
options += gpu_compile_options;
130+
options += ref_gpu_compile_options();
128131

129132
return options;
130133
}

0 commit comments

Comments
 (0)