CUDA:インストール
まず、最初のインストールする上ですごく参考になったサイト
http://d.hatena.ne.jp/iRiE/20120309/1331303439
詳しくは上記のサイトを参考にして欲しいのですがubuntu12.04でのインストールをまとめると
display driver
sudo apt-get install nvidia-current
cuda toolkit
wget http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/cudatoolkit_4.1.28_linux_64_ubuntu11.04.run chmod a+x cudatoolkit_4.1.28_linux_64_ubuntu11.04.run sudo ./cudatoolkit_4.1.28_linux_64_ubuntu11.04.run
library and path /etc/ld.so.conf.d/cuda.confに
export PATH="/usr/local/cuda/bin:$PATH" export LIBRARY_PATH="/usr/lib/nvidia-current:$LIBRARY_PATH"
wget http://developer.download.nvidia.com/compute/cuda/4_1/rel/sdk/gpucomputingsdk_4.1.28_linux.run chmod a+x gpucomputingsdk_4.1.28_linux.run ./gpucomputingsdk_4.1.28_linux.run
以下のerrorの修正
../../lib/librendercheckgl_x86_64.a(rendercheck_gl.cpp.o): In function `CheckBackBuffer::checkStatus(char const*, int, bool)': rendercheck_gl.cpp:(.text+0xfbb): undefined reference to `gluErrorString' collect2: ld はステータス 1 で終了しました make[1]: *** [../../bin/linux/release/recursiveGaussian] エラー 1 make[1]: ディレクトリ `/home/irie/NVIDIA_GPU_Computing_SDK/C/src/recursiveGaussian' から出ます make: *** [src/recursiveGaussian/Makefile.ph_build] エラー 2
~/NVIDIA_GPU_Computing_SDK/C/common/common.mkの270,274,281の$(RENDERCHECKGLLIB)の位置を先頭にする
LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} -ldl -rdynamic LIB += -lcuda $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB}
サンプルプログラムのビルド、64bit環境固有の問題
cd ~/NVIDIA_GPU_Computing_SDK/C/lib for i in *_x86_64.a; do ln -sv $i ${i%_x86_64.a}.a; done
上記の設定をしたのに以下のようなエラーがでました。
imageSegmentationNPP.cpp:(.text+0xd0f): undefined reference to `nppGetLibVersion' imageSegmentationNPP.cpp:(.text+0xd18): undefined reference to `nppGetGpuComputeCapability' imageSegmentationNPP.cpp:(.text+0xd5b): undefined reference to `nppGetGpuNumSMs' imageSegmentationNPP.cpp:(.text+0xd62): undefined reference to `nppGetGpuName' /tmp/ccZNjlD1.o: In function `main': imageSegmentationNPP.cpp:(.text+0x1360): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x13b9): undefined reference to `cudaMemcpy2D' imageSegmentationNPP.cpp:(.text+0x13d5): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x1447): undefined reference to `cudaMemcpy2D' imageSegmentationNPP.cpp:(.text+0x1463): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x14ad): undefined reference to `nppiSub_32s_C1RSfs' imageSegmentationNPP.cpp:(.text+0x14fa): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x1553): undefined reference to `cudaMemcpy2D' imageSegmentationNPP.cpp:(.text+0x156f): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x1597): undefined reference to `nppiSet_32s_C1R' imageSegmentationNPP.cpp:(.text+0x15d6): undefined reference to `nppiCopy_32s_C1R' imageSegmentationNPP.cpp:(.text+0x1623): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x167c): undefined reference to `cudaMemcpy2D' imageSegmentationNPP.cpp:(.text+0x1698): undefined reference to `nppiMalloc_32s_C1' imageSegmentationNPP.cpp:(.text+0x16c0): undefined reference to `nppiSet_32s_C1R' imageSegmentationNPP.cpp:(.text+0x16ff): undefined reference to `nppiCopy_32s_C1R' imageSegmentationNPP.cpp:(.text+0x1718): undefined reference to `nppiGraphcutGetSize' imageSegmentationNPP.cpp:(.text+0x1753): undefined reference to `nppiGraphcutInitAlloc' imageSegmentationNPP.cpp:(.text+0x1786): undefined reference to `cudaEventCreate' imageSegmentationNPP.cpp:(.text+0x1795): undefined reference to `cudaEventCreate' imageSegmentationNPP.cpp:(.text+0x17a9): undefined reference to `cudaEventRecord' imageSegmentationNPP.cpp:(.text+0x1835): undefined reference to `nppiGraphcut_32s8u' imageSegmentationNPP.cpp:(.text+0x1849): undefined reference to `cudaEventRecord' imageSegmentationNPP.cpp:(.text+0x1858): undefined reference to `cudaEventSynchronize' imageSegmentationNPP.cpp:(.text+0x1878): undefined reference to `cudaEventElapsedTime' imageSegmentationNPP.cpp:(.text+0x1939): undefined reference to `nppiMulC_8u_C1IRSfs' imageSegmentationNPP.cpp:(.text+0x1aff): undefined reference to `nppiGraphcutFree' imageSegmentationNPP.cpp:(.text+0x1b0e): undefined reference to `cudaFree' imageSegmentationNPP.cpp:(.text+0x1b1d): undefined reference to `cudaFree' imageSegmentationNPP.cpp:(.text+0x1b2c): undefined reference to `cudaFree' imageSegmentationNPP.cpp:(.text+0x1b3b): undefined reference to `cudaFree' imageSegmentationNPP.cpp:(.text+0x1b4a): undefined reference to `cudaFree' /tmp/ccZNjlD1.o:imageSegmentationNPP.cpp:(.text+0x1b59): more undefined references to `cudaFree' follow /tmp/ccZNjlD1.o: In function `npp::ImageAllocator<unsigned char, 1ul>::Malloc2D(unsigned int, unsigned int, unsigned int*, bool)': imageSegmentationNPP.cpp:(.text._ZN3npp14ImageAllocatorIhLm1EE8Malloc2DEjjPjb[npp::ImageAllocator<unsigned char, 1ul>::Malloc2D(unsigned int, unsigned int, unsigned int*, bool)]+0x119): undefined reference to `nppiMalloc_8u_C1' /tmp/ccZNjlD1.o: In function `npp::ImageAllocator<unsigned char, 1ul>::Free2D(unsigned char*)': imageSegmentationNPP.cpp:(.text._ZN3npp14ImageAllocatorIhLm1EE6Free2DEPh[npp::ImageAllocator<unsigned char, 1ul>::Free2D(unsigned char*)]+0x14): undefined reference to `nppiFree' /tmp/ccZNjlD1.o: In function `npp::ImageAllocator<unsigned char, 1ul>::DeviceToHostCopy2D(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long, unsigned long)': imageSegmentationNPP.cpp:(.text._ZN3npp14ImageAllocatorIhLm1EE18DeviceToHostCopy2DEPhmPKhmmm[npp::ImageAllocator<unsigned char, 1ul>::DeviceToHostCopy2D(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long, unsigned long)]+0x4c): undefined reference to `cudaMemcpy2D' /tmp/ccZNjlD1.o: In function `cudaSafeCallNoSync(cudaError, char const*, int)': imageSegmentationNPP.cpp:(.text._Z18cudaSafeCallNoSync9cudaErrorPKci[cudaSafeCallNoSync(cudaError, char const*, int)]+0x72): undefined reference to `cudaGetErrorString' /tmp/ccZNjlD1.o: In function `cudaDeviceInit()': imageSegmentationNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x26): undefined reference to `cudaGetDeviceCount' imageSegmentationNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x173): undefined reference to `cudaGetDeviceProperties' imageSegmentationNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x1d9): undefined reference to `cudaSetDevice' /tmp/ccZNjlD1.o: In function `cudaError cudaMalloc<unsigned char>(unsigned char**, unsigned long)': imageSegmentationNPP.cpp:(.text._Z10cudaMallocIhE9cudaErrorPPT_m[cudaError cudaMalloc<unsigned char>(unsigned char**, unsigned long)]+0x1f): undefined reference to `cudaMalloc' ../../common/lib/libUtilNPP_x86_64.a(ImageIO.cpp.o): In function `npp::saveImage(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, npp::ImageNPP<unsigned char, 1u> const&)': ImageIO.cpp:(.text+0x881): undefined reference to `cudaMemcpy2D' ../../common/lib/libUtilNPP_x86_64.a(ImageIO.cpp.o): In function `npp::loadImage(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, npp::ImageNPP<unsigned char, 1u>&)': ImageIO.cpp:(.text+0xba7): undefined reference to `nppiMalloc_8u_C1' ImageIO.cpp:(.text+0xbe4): undefined reference to `cudaMemcpy2D' ImageIO.cpp:(.text+0xc27): undefined reference to `nppiFree' collect2: ld はステータス 1 で終了しました make[2]: *** [all] エラー 1 make[2]: ディレクトリ `/home/ono/NVIDIA_GPU_Computing_SDK/CUDALibraries/src/imageSegmentationNPP' から出ます make[1]: *** [src/imageSegmentationNPP/Makefile.ph_build] エラー 2 make[1]: ディレクトリ `/home/ono/NVIDIA_GPU_Computing_SDK/CUDALibraries' から出ます make: *** [all] エラー 2
対処法:またライブラリーの順番が悪いようでだったので修正。NVIDIA_GPU_Computing_SDK/CUDALibraries/srcの中にある以下の
boxFilterNPP, imageSegmentationNPP, freeImageInteropNPP, histEqualizationNPP
ディレクトリの中のmakefileの$(LIB)を書き換える。
41行目:$(CXX) $(INC) -o boxFilterNPP boxFilterNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH) 41行目:$(CXX) $(INC) -o imageSegmentationNPP imageSegmentationNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH) 41行目:$(CXX) $(INC) -o freeImageInteropNPP freeImageInteropNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH) 41行目:$(CXX) $(INC) -o histEqualizationNPP histEqualizationNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)
必要なものをインストール
sudo apt-get install gcc-4.4 g++-4.4 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 10