c++linuxgpuintel-mklfaiss

Compile hello.cpp. flags - C++ FAISS GPU


I would like to use FAISS C++ GPU externally in another repo. Therefore, I created a hello.cpp and tried to compile it without going into the faiss directory. Inside the faiss directory, compilation seems fine to me.

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <random>
#include <sys/time.h>
#include <faiss/gpu/GpuIndexIVFPQ.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <faiss/gpu/GpuCloner.h>
#include <faiss/utils/random.h> 
#include <fstream> 
#include <faiss/gpu/utils/DeviceUtils.h>
#include <faiss/gpu/utils/Timer.h>
#include <string>
#include <iostream>
#include <faiss/gpu/GpuAutoTune.h>
#include <faiss/index_io.h>
using namespace std;

double elapsed() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec + tv.tv_usec * 1e-6;
}
int main() {
    double t0 = elapsed();
    printf("[%.3f s] Hello World! :))\n",
           elapsed() - t0);
    faiss::gpu::StandardGpuResources res; // Without this line, nvcc works.

    return 0;
}

Command:

/usr/local/cuda/bin/nvcc /home/hossamamer/hello.cpp -lcublas -lfaiss -o myCublasApp

Output:

/usr/bin/ld: warning: libmkl_intel_lp64.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libmkl_gnu_thread.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libmkl_core.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `dgemm_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `dgetri_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `dgetrf_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `ssyrk_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgetrf_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgelsd_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgemm_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `dgesvd_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `dsyev_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgeqrf_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sorgqr_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgesvd_'
/usr/bin/ld: /usr/local/lib/libfaiss.so: undefined reference to `sgetri_'
collect2: error: ld returned 1 exit status

Any help? Can I also do this using the make command? What is the command?


Solution

  • According to your logs:

    /usr/bin/ld: warning: libmkl_intel_lp64.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
    /usr/bin/ld: warning: libmkl_gnu_thread.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
    /usr/bin/ld: warning: libmkl_core.so, needed by /usr/local/lib/libfaiss.so, not found (try using -rpath or -rpath-link)
    

    You faiss installed in /usr/local, and it compile with mkl as blas library. So you need to install mkl for using it. As you say:

    Inside the faiss directory, compilation seems fine to me.

    It seems your mkl library is already in your build source tree, you could try to find them if already in your faiss build directory.