Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tutorial examples use dynamic linkage. #343

Merged
merged 10 commits into from
Feb 21, 2018

Conversation

beauby
Copy link
Contributor

@beauby beauby commented Feb 21, 2018

No description provided.

@@ -85,6 +85,9 @@ CUOBJ= impl/BroadcastSum.o \
$(LIBNAME).a: $(CPPOBJ) $(CUOBJ)
ar r $@ $^

$(LIBNAME).$(SHAREDEXT): $(CPPOBJ) $(CUOBJ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick heads up, the clean target in 119 should probably consider this file as well.

gpu/Makefile Outdated
@@ -85,6 +85,9 @@ CUOBJ= impl/BroadcastSum.o \
$(LIBNAME).a: $(CPPOBJ) $(CUOBJ)
ar r $@ $^

$(LIBNAME).$(SHAREDEXT): $(CPPOBJ) $(CUOBJ)
$(CC) $(LDFLAGS) $(FAISSSHAREDFLAGS) -o $(LIBNAME).$(SHAREDEXT) $^ $(CUDAFLAGS)
Copy link
Contributor

@Enet4 Enet4 Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just found a slightly more serious concern: I was trying to build the GPU examples, but it was constantly failing to link:

/opt/cuda//bin/nvcc  -I /opt/cuda//targets/x86_64-linux/include/ -Xcompiler -fPIC -Xcudafe --diag_suppress=unrecognized_attribute -gencode arch=compute_37,code="compute_37" -gencode arch=compute_61,code="compute_61" --std c++11 -lineinfo -ccbin g++-6 -DFAISS_USE_FLOAT16 -o 4-GPU 4-GPU.cpp -Xcompiler \"-Wl,-rpath=../../:../../gpu/\" -L../.. -L../../gpu -lfaiss -lgpufaiss \
-I../../../ -Xcompiler -fopenmp -lcublas -Xlinker /usr/lib64/libopenblas.so.0 \

ld: 4-GPU: hidden symbol `cudaMemcpyAsync' in /opt/cuda//bin/..//lib64/libcudart_static.a(libcudart_static.a.o) is referenced by DSO
ld: final link failed: Bad value
make: *** [Makefile:28: 4-GPU] Error 1

After some research, I found that it can be related to an attempt of a dynamic library to use a statically defined reference from an object that it was not properly linked against, or something along these lines. What solves the problem here is to make libgpufaiss.so dynamically link to cudart and cublas explicitly:

    $(CC) -L$(CUDA_ROOT)/lib64 -lcublas -lcudart $(LDFLAGS) $(FAISSSHAREDFLAGS) -o $(LIBNAME).$(SHAREDEXT) $^ $(CUDAFLAGS)

This also makes the -lcublas flags in the examples redundant, and can be removed. This is also what I did for the C API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the writeup @Enet4. I pushed the suggested fixes – could you give it a try?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beauby Yes, it works now. 👍

@beauby beauby merged commit 16aed09 into facebookresearch:master Feb 21, 2018
@beauby beauby deleted the shared-lib branch February 21, 2018 14:36
CaucherWang pushed a commit to CaucherWang/faiss-learned-termination that referenced this pull request Sep 16, 2022
* Add shared lib target for GPU version.

* Dynamically link tutorial examples.

* Add shared lib to clean target in GPU Makefile.

* Add clean target to tutorial examples Makefile.

* Minor modifications to tutorial GPU examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants