LoginSignup
18
17

More than 5 years have passed since last update.

CUDAもcmakeでコンパイルする

Posted at

CUDAのインストール(Fedora)

Fedoraだと公式でリポジトリ(rpmで配布されている)を取得した後、

yum install cuda

で入れると問題が少いと思う。現在(2014/8/21)Fedora20ではCUDA6.5が入る。
rpmfusionのnVidiaドライバーを使用してる場合は/etc/yum.repos.d/cuda.repoを書き換えて
標準で無効にしておくと問題が少い。

/etc/yum.repos.d/cuda.repo
[cuda]
name=cuda
baseurl=http://developer.download.nvidia.com/compute/cuda/repos/fedora20/x86_64
enabled=0 # 無効化
gpgcheck=1
gpgkey=http://developer.download.nvidia.com/compute/cuda/repos/GPGKEY

この場合

yum --enable-repo=cuda install cuda # install
yum --enable-repo=cuda update       # update

とする必要がある。

cmakeでコンパイル

CUDAのコンパイルにはnvccを用いる。
nsightを使用したくない場合、cmakeを使えばいろいろ勝手に設定してくれる。

/usr/local/cuda/samples/0_Simple/vectorAdd/vectorAdd.cuあたりをとりあえずコピーしてくる。

vectorAdd/CMakeLists.txt
          vectorAdd.cu

のようになっているとする。このvectorAdd.cuをコンパイルする最小のCMakeLists.txtは以下の通りだ:

vectorAdd/CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package(CUDA REQUIRED)
cuda_add_executable(vectorAdd vectorAdd.cu)

これで

cmake .
make

とすればvectorAddがコンパイルされる。
せっかくなのでバージョン情報等も出してもいいだろう。

vectorAdd/CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package(CUDA REQUIRED)
message("-- CUDA --")
message("Version: " ${CUDA_VERSION})
message("Library: " ${CUDA_CUDA_LIBRARY})
message("Runtime: " ${CUDA_CUDART_LIBRARY})
cuda_add_executable(vectorAdd vectorAdd.cu)

他のオプションについては

cmake --help-module FindCUDA

とすれば見れる。

18
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
17