【TIPS】Ubuntu14.04でCUDAを使ってみる – インストールしてサンプルが動くまで –

スポンサーリンク

コンテンツ

とりあえず動いたのでメモ。検索するといろんな方法が出てきますが、自分が動いた方法でのメモです

CUDA用のグラフィックボードとドライバのインストール

前の記事をどうぞ!
Linuxブログ : PCを自作したので、Ubuntu14.04を新マシンに移行した時のメモ 1.内蔵LANとグラボの認識
nvidia Geforce750 Tiを使ってます。

公式からDL

https://developer.nvidia.com/cuda-downloads#linux
からどうぞ。

cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb をダウンロードしました。
クリックの仕方はこんな感じ
範囲を選択_001

書かれたとおりにインストール

  sudo dpkg -i cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
  sudo apt-get update
  sudo apt-get install cuda

を実行するとOKでした。

パスを通す

以下を~/.bashrcの末尾に追加してから

export CUDA_HOME=/usr/local/cuda-7.5 
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64 
 
PATH=${CUDA_HOME}/bin:${PATH} 
export PATH

適用します。以下のコマンドで.bashrcを再読み込み

  source .bashrc

サンプルを動かす

$ cuda-install-samples-7.5.sh ~
$ cd ~/NVIDIA_CUDA-7.5_Samples
$ cd 1_Utilities/deviceQuery
$ make
でサンプルをmake後

./deviceQuery

で、以下のような内容が出るとOKだと思います

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 750 Ti"
  CUDA Driver Version / Runtime Version          7.5 / 7.5
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 2047 MBytes (2146762752 bytes)
  ( 5) Multiprocessors, (128) CUDA Cores/MP:     640 CUDA Cores
  GPU Max Clock rate:                            1084 MHz (1.08 GHz)
  Memory Clock rate:                             2700 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 7.5, CUDA Runtime Version = 7.5, NumDevs = 1, Device0 = GeForce GTX 750 Ti
Result = PASS

たぶんグラボのレポート用コマンドじゃないかと

CUDA=グラボといえばグラフィカルなサンプルのほうがいい!

と思ったのでサンプルを漁っていたら、それっぽいのが以下のコマンドで動きました

cd ~/NVIDIA_CUDA-7.5_Samples/2_Graphics/Mandelbrot
make

でmake後

./Mandelbrot

を実行します。

こんなのが出てくるとたぶんOKです
Screenshot from 2016-01-18 16:09:08

A押すと色変わったりしましたが、目に悪そうなアニメーションだったのですぐ止めました…

サンプルを一覧表示すると

.
├── 0_Simple
│   ├── UnifiedMemoryStreams
│   ├── asyncAPI
│   ├── cdpSimplePrint
│   ├── cdpSimpleQuicksort
│   ├── clock
│   ├── clock_nvrtc
│   ├── cppIntegration
│   ├── cppOverload
│   ├── cudaOpenMP
│   ├── inlinePTX
│   ├── inlinePTX_nvrtc
│   ├── matrixMul
│   ├── matrixMulCUBLAS
│   ├── matrixMulDrv
│   ├── matrixMul_nvrtc
│   ├── simpleAssert
│   ├── simpleAssert_nvrtc
│   ├── simpleAtomicIntrinsics
│   ├── simpleAtomicIntrinsics_nvrtc
│   ├── simpleCallback
│   ├── simpleCubemapTexture
│   ├── simpleIPC
│   ├── simpleLayeredTexture
│   ├── simpleMPI
│   ├── simpleMultiCopy
│   ├── simpleMultiGPU
│   ├── simpleOccupancy
│   ├── simpleP2P
│   ├── simplePitchLinearTexture
│   ├── simplePrintf
│   ├── simpleSeparateCompilation
│   ├── simpleStreams
│   ├── simpleSurfaceWrite
│   ├── simpleTemplates
│   ├── simpleTemplates_nvrtc
│   ├── simpleTexture
│   ├── simpleTextureDrv
│   ├── simpleVoteIntrinsics
│   ├── simpleVoteIntrinsics_nvrtc
│   ├── simpleZeroCopy
│   ├── template
│   ├── template_runtime
│   ├── vectorAdd
│   ├── vectorAddDrv
│   └── vectorAdd_nvrtc
├── 1_Utilities
│   ├── bandwidthTest
│   ├── deviceQuery
│   ├── deviceQueryDrv
│   └── p2pBandwidthLatencyTest
├── 2_Graphics
│   ├── Mandelbrot
│   ├── bindlessTexture
│   ├── marchingCubes
│   ├── simpleGL
│   ├── simpleGLES
│   ├── simpleGLES_EGLOutput
│   ├── simpleGLES_screen
│   ├── simpleTexture3D
│   ├── volumeFiltering
│   └── volumeRender
├── 3_Imaging
│   ├── HSOpticalFlow
│   ├── SobelFilter
│   ├── bicubicTexture
│   ├── bilateralFilter
│   ├── boxFilter
│   ├── convolutionFFT2D
│   ├── convolutionSeparable
│   ├── convolutionTexture
│   ├── cudaDecodeGL
│   ├── dct8x8
│   ├── dwtHaar1D
│   ├── dxtc
│   ├── histogram
│   ├── imageDenoising
│   ├── postProcessGL
│   ├── recursiveGaussian
│   ├── simpleCUDA2GL
│   └── stereoDisparity
├── 4_Finance
│   ├── BlackScholes
│   ├── BlackScholes_nvrtc
│   ├── MonteCarloMultiGPU
│   ├── SobolQRNG
│   ├── binomialOptions
│   ├── binomialOptions_nvrtc
│   ├── quasirandomGenerator
│   └── quasirandomGenerator_nvrtc
├── 5_Simulations
│   ├── fluidsGL
│   ├── nbody
│   ├── nbody_opengles
│   ├── nbody_screen
│   ├── oceanFFT
│   ├── particles
│   └── smokeParticles
├── 6_Advanced
│   ├── FDTD3d
│   ├── FunctionPointers
│   ├── StreamPriorities
│   ├── alignedTypes
│   ├── cdpAdvancedQuicksort
│   ├── cdpBezierTessellation
│   ├── cdpLUDecomposition
│   ├── cdpQuadtree
│   ├── concurrentKernels
│   ├── eigenvalues
│   ├── fastWalshTransform
│   ├── interval
│   ├── lineOfSight
│   ├── matrixMulDynlinkJIT
│   ├── mergeSort
│   ├── newdelete
│   ├── ptxjit
│   ├── radixSortThrust
│   ├── reduction
│   ├── scalarProd
│   ├── scan
│   ├── segmentationTreeThrust
│   ├── shfl_scan
│   ├── simpleHyperQ
│   ├── sortingNetworks
│   ├── threadFenceReduction
│   ├── threadMigration
│   └── transpose
├── 7_CUDALibraries
│   ├── MC_EstimatePiInlineP
│   ├── MC_EstimatePiInlineQ
│   ├── MC_EstimatePiP
│   ├── MC_EstimatePiQ
│   ├── MC_SingleAsianOptionP
│   ├── MersenneTwisterGP11213
│   ├── batchCUBLAS
│   ├── boxFilterNPP
│   ├── common
│   ├── conjugateGradient
│   ├── conjugateGradientPrecond
│   ├── conjugateGradientUM
│   ├── cuHook
│   ├── cuSolverDn_LinearSolver
│   ├── cuSolverRf
│   ├── cuSolverSp_LinearSolver
│   ├── freeImageInteropNPP
│   ├── histEqualizationNPP
│   ├── jpegNPP
│   ├── randomFog
│   ├── simpleCUBLAS
│   ├── simpleCUFFT
│   ├── simpleCUFFT_2d_MGPU
│   ├── simpleCUFFT_MGPU
│   ├── simpleCUFFT_callback
│   └── simpleDevLibCUBLAS

と、FinanceやらSimulationといった色んな物があるので、興味あるものをmakeしてみると楽しいんじゃないでしょうか!

というメモ。

Installing CUDA Toolkit 7.5 on Ubuntu 14.04 Linux | R Tutorialさんの記事が参考になりました!ありがとうございます!

トラブル

いろんな記事を見ながら最初にCUDAを入れたのですが

sudo apt-get install nvidia-cuda-toolkit

をしたあとにnvidia公式の方法でcudaを入れようとするとapt-get cudaのときに「満たされない依存関係があります」と怒られてインストール不可でした。gccのバージョンがどうのこうの言っていたような。

とりあえず

sudo apt-get remove nvidia-cuda-toolkit

でremoveしてからnvidia公式の方法で入れるとOKでした。