Skip to content

Linker problem with cuBLAS build in Linux #74

Description

@delorytheape

I ran into problems building on a fresh install of Linux (Ubuntu 18.04) when trying to build with the cuBLAS library. Details are
OS: Ubuntu 18.04
GCC: 7.4.0
cmake: 3.14.3
Boost: 1.65.1
CUDA: 10.1.105-1
Nvidia Driver: 418.39-1
GPU: GTX1080ti
Gpufit: 12496a... Apr 12 16:11:54 2019

I used the following commands to build;

mkdir Gpufit-build
cd Gpufit-build
cmake -DCMAKE_BUILD_TYPE=RELEASE -DUSE_CUBLAS=TRUE ../Gpufit
make 

The build failed with the following statements...

../libGpufit.so: undefined reference to 'init_gemm_select'
../libGpufit.so: undefined reference to 'free_gemm_select'
../libGpufit.so: undefined reference to 'cublasLtGetVersion'
../libGpufit.so: undefined reference to 'cublasLtGetProperty'
../libGpufit.so: undefined reference to 'cublasLtCtxInit'
../libGpufit.so: undefined reference to 'cublasLtGetCudartVersion'
../libGpufit.so: undefined reference to 'cublasLtShutdownCtx'

I was able to eventually get around this (and subsequent) problem as follows;
(Note; I do not claim that this is the best way to solve the problem. It is merely what worked for me, and may be of assistance in addressing the actual problem).

  1. After installing cuda toolkit (from .deb package) I had to create symbolic links from the /usr/local/cuda directory to the cuBLAS libraries (for some odd reason with CUDA 10.1, Nvida have put these in a different location /usr/lib/x86_64-linux-gnu). The commands I used were
sudo ln -s /usr/local/cuda/libcublasLt.so /usr/lib/x86_64-linux-gnu/libcublasLt.so
sudo ln -s /usr/local/cuda/libcublasLt.so.10 /usr/lib/x86_64-linux-gnu/libcublasLt.so.10
sudo ln -s /usr/local/cuda/libcublasLt.so10.1.0.105 /usr/lib/x86_64-linux-gnu/libcublasLt.so.10.1.0.105
sudo ln -s /usr/local/cuda/libcublasLt_static.a /usr/lib/x86_64-linux-gnu/libcublasLt_static.a
sudo ln -s /usr/local/cuda/libcublas.so /usr/lib/x86_64-linux-gnu/libcublas.so
sudo ln -s /usr/local/cuda/libcublas.so.10 /usr/lib/x86_64-linux-gnu/libcublas.so.10
sudo ln -s /usr/local/cuda/libcublas.so10.1.0.105 /usr/lib/x86_64-linux-gnu/libcublas.so.10.1.0.105
sudo ln -s /usr/local/cuda/libcublas_static.a /usr/lib/x86_64-linux-gnu/libcublas_static.a
  1. To fix the build errors, it was necessary to tell the linker to include the static library libcublasLt_static.a This was achieved by modifying the files
    Gpufit repository path/Gpufit/CMakeLists.txt
    Gpufit repository path/Gpufit/examples/CMakeLists.txt
    Gpufit repository path/Gpufit/Gpufit/examples/CMakeLists.txt
    In each file, every instance of the line
target_link_libraries(${target} ${modules})

was replaced with the following line:

target_link_libraries(${target} ${modules} /usr/local/cuda/lib64/libcublasLt_static.a)

The build directory was then erased

cd <Gpufit repository path>/Gpufit-build
rm -rf *

and the cmake command rerun

cmake -DCMAKE_BUILD_TYPE=RELEASE -DUSE_CUBLAS=TRUE ../Gpufit
make

The build then succeeded.
As previously mentioned, I am not very familiar with the cmake machinery, so there may be a much better way to fix this problem than this workaround. Hope it helps anyway.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions