CUDAのサンプルで"cannot find -lGL"でハマった件
ちょっとハマった、というか「しょーもな」って感じのポイントなんだけど。いちおうメモしておく。
CUDAをインストールしたら、まずはsampleを動かしてみたくなるんだけど、nbodyをビルドしようとしたら以下のエラーが発生した。OSはUbuntu 14.04.5、CUDAは7.5。
$ cd /usr/local/cuda/samples/5_Simulations/nbody $ make >>> WARNING - libGLU.so not found, refer to CUDA Getting Started Guide for how to find and install them. <<< >>> WARNING - libX11.so not found, refer to CUDA Getting Started Guide for how to find and install them. <<< >>> WARNING - gl.h not found, refer to CUDA Getting Started Guide for how to find and install them. <<< >>> WARNING - glu.h not found, refer to CUDA Getting Started Guide for how to find and install them. <<< >>> WARNING - Xlib.h not found, refer to CUDA Getting Started Guide for how to find and install them. <<<
はーん。OpenGL関連がないのかー。
なのでapt-getで必要そうなライブラリをインストールする。
$ sudo apt-get install freeglut3-dev libglu1-mesa-dev
これでmakeし直したらいいと思ったら、「libGLなんて見つからないよ」とエラーが出てきた。
$ sudo make "/usr/local/cuda-7.5"/bin/nvcc -ccbin g++ -I../../common/inc -m64 -ftz=true -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -o bodysystemcuda.o -c bodysystemcuda.cu "/usr/local/cuda-7.5"/bin/nvcc -ccbin g++ -I../../common/inc -m64 -ftz=true -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -o nbody.o -c nbody.cpp "/usr/local/cuda-7.5"/bin/nvcc -ccbin g++ -I../../common/inc -m64 -ftz=true -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -o render_particles.o -c render_particles.cpp "/usr/local/cuda-7.5"/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -o nbody bodysystemcuda.o nbody.o render_particles.o -L../../common/lib/linux/x86_64 -L/usr/lib/"nvidia-352" -lGL -lGLU -lX11 -lglut -lGLEW /usr/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit status make: *** [nbody] Error 1
いや、そんなはずはない。さっきインストールしたでしょ?
と思ってlocaleとか使って調べたら、なんか変なシンボリックリンクが貼ってあってあるだけだった。
ブログだと色がついてないからわかりにくいと思うけど、libGL.soの参照先が存在しないファイルを指定してる。
#同ディレクトリに「libGL.so.1.2.0」はない
#素のUbuntuターミナルだと赤色になっていると思う。
$ ll /usr/lib/x86_64-linux-gnu/mesa/ total 76 drwxr-xr-x 2 root root 4096 9月 25 00:16 ./ drwxr-xr-x 95 root root 69632 9月 25 00:16 ../ -rw-r--r-- 1 root root 31 7月 1 05:45 ld.so.conf lrwxrwxrwx 1 root root 14 1月 13 2016 libGL.so -> libGL.so.1.2.0
下記の方法がよいかわかんないけど、libGLがちゃんとある場所にシンボリックリンクを指定してあげることにした。
$ cd /usr/lib $ sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1.0.0 libGL.so
これでビルドしたら上手くいった。
やっぱりGPGPUと言えばこのsampleですよねー。
$ sudo make "/usr/local/cuda-7.5"/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -o nbody bodysystemcuda.o nbody.o render_particles.o -L../../common/lib/linux/x86_64 -L/usr/lib/"nvidia-352" -lGL -lGLU -lX11 -lglut -lGLEW mkdir -p ../../bin/x86_64/linux/release cp nbody ../../bin/x86_64/linux/release $ ./nbody Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. -fullscreen (run n-body simulation in fullscreen mode) -fp64 (use double precision floating point values for simulation) -hostmem (stores simulation data in host memory) -benchmark (run benchmark to measure performance) -numbodies=<N> (number of bodies (>= 1) to run in simulation) -device=<d> (where d=0,1,2.... for the CUDA device to use) -numdevices=<i> (where i=(number of CUDA devices > 0) to use for simulation) -compare (compares simulation results running once on the default GPU and once on the CPU) -cpu (run n-body simulation on the CPU) -tipsy=<file.bin> (load a tipsy model file for simulation) NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled. > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation > Compute 5.2 CUDA device: [GeForce GTX 980 Ti]
LLVM3.9をインストールする
冬コミのネタなんかないかなーと思ってて、「そういえばLLVM3.9出たのかー」と思ってとりあえずインストールしてみた。ちなみにOSはUbuntu14.04を使ったよ。
LLVM Download Page
↑ここから「LLVM source code」をダウンロードしてくる。
いつも通りcmake使ってビルドするかー、と思ったら最新のcmakeが必要になってた。
$ mkdir build $ cd build/ $ cmake -D CMAKE_INSTALL_PREFIX=/usr/local/llvm-3.9 .. CMake Error at CMakeLists.txt:3 (cmake_minimum_required): CMake 3.4.3 or higher is required. You are running version 2.8.12.2 -- Configuring incomplete, errors occurred! $ cmake --version cmake version 2.8.12.2
まぁ仕方ないのでcmakeの最新版を取得して、ビルドとインストールした。
#cmakeも今は最新が3.6.2とかなんだ。へぇ〜。
Download | CMake
↑ここから「cmake-3.6.2.tar.gz」をクリックして落とす。
$ cd cmake-3.6.2 $ ./configure $ make -j4 $ sudo make install
割とすんなりインストールできた。で、LLVMのビルドに再チャレンジ。
$ cmake -D CMAKE_INSTALL_PREFIX=/usr/local/llvm-3.9 .. -- No build type selected, default to Debug -- The C compiler identification is GNU 4.8.4 -- The CXX compiler identification is GNU 4.8.4 -- The ASM compiler identification is GNU -- Found assembler: /usr/bin/cc
上手くいったみたい。あとはmakeするだけ。
#なんか最後の98%くらいで「やけにChrome重いなー」と思ったら、
#メモリ使用率が13GBとかなってビビった。
$ make -j4
make終わったしあとはinstallだけだなと思ったら、HDDの容量が少なくなっててインストールできないことに気づいた!!!
たぶんinstallしたら10GBくらい使うのかな?ビルドしたディレクトリも13GBになってた。1TBのHDDに交換したら再チャレンジするか。。。
$ du -d 1 --block-size=M . 263M ./cmake-3.6.2 13875M ./llvm-3.9.0.src