Tuesday, May 15, 2012

CUDA 4.2.9 and Kubuntu 12.04

When trying to get CUDA 4.2.9  toolkit, drivers and SDK to work on Kubuntu 12.04 I had to sort out a number of small issues.

First DONT install any other Nvidia drivers! I did this in my first attempt and ended up not having any success and finally just reinstalled Kubuntu.

1.  Install pre requisites
     sudo apt-get -y install build-essential freeglut3-dev libxmu-dev libxi-dev

2.  Install the toolkit.
  wget http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/cudatoolkit_4.2.9_linux_64_rhel5.5.run
  chmod +x cudatoolkit_4.2.9_linux_64_rhel5.5.run
  sudo ./cudatoolkit_4.2.9_linux_64_rhel5.5.run


  sudo sh -c "echo PATH=$PATH:/usr/local/cuda/bin >> /etc/environment"
  sudo sh -c "echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/lib >> /etc/environment"

3.  Install the driver.
     Note, trying to do this from the source, gave me endless hassle, if you want to attempt this go the second part of this section.  If you want to make life easy just do it from the repositories.
        sudo apt-get -y install nvidia-current-dev
     make sure your LD_LIBRARY_PATH includes /usr/lib/nvidia-current
       sudo sh -c "echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia-current >> /etc/environment"

    This didn't really work for me so you can link some things manually (below), or you can add -L/usr/lib/nvidia-current/ to the relevant Makefiles.
      sudo ln -s /usr/lib/nvidia-current/libcuda.so /usr/local/cuda/lib64/
      sudo ln -s /usr/lib/nvidia-current/libGL.so /usr/local/cuda/lib64/
      sudo ln -s /usr/lib/nvidia-current/libcuda.so /usr/lib/

   OR get the source and do it manually.

     Boot up into 'recovery mode' (By holding/tapping right shift during boot to get to the grub menu).

     Select root from the menu to get a terminal.

     Remount the file system to write access.
    mount -o remount,rw /

     Next set-up the environment, by purging driver pakage, and getting kernel source
     sudo apt-get update
     sudo apt-get purge nvidia-current
     sudo apt-get install linux-source linux-headers-generic linux-image              

     Next download, build and Install the drivers:
     wget http://developer.download.nvidia.com/compute/cuda/4_2/rel/drivers/devdriver_4.2_linux_64_295.41.run
     chmod +x devdriver_4.2_linux_64_295.41.run
     sudo ./devdriver_4.2_linux_64_295.41.run

     You may need to blacklist the nouveau and other nvidia drivers:

     sudo sh -c "
echo blacklist nouveau >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist lbm-nouveau >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist nvidia-173 >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist nvidia-96 >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist nvidia-current-updates >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist nvidia-173-updates >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo blacklist nvidia-96-updates >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo alias nouveau off >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "
echo alias lbm-nouveau off >> /etc/modprobe.d/nvidia-graphics-drivers.conf"
     sudo sh -c "echo options nouveau modeset=0 >/etc/modprobe.d/nvidia-graphics-drivers.conf"

4.  Install the SDK
     wget http://developer.download.nvidia.com/compute/cuda/4_2/rel/sdk/gpucomputingsdk_4.2.9_linux.run
     chmod +x gpucomputingsdk_4.2.9_linux.run
     ./gpucomputingsdk_4.2.9_linux.run

     make will fail

    undefined reference to 'gluErrorString'

   This post helped me sort it out

    My soulution was:

    Open C/common/common.mk and CUDALibraries/common/common_cudalib.mk and put $(RENDERCHECKGLLIB) befor ${OPENGLLIB} in all the relevant places.

I then got:

freeImageInteropNPP.cpp:(.text+0x6bd): undefined reference to `nppGetLibVersion'

freeImageInteropNPP.cpp:(.text+0x6c6): undefined reference to `nppGetGpuComputeCapability'

freeImageInteropNPP.cpp:(.text+0x713): undefined reference to `nppGetGpuNumSMs'

freeImageInteropNPP.cpp:(.text+0x71a): undefined reference to `nppGetGpuName'

/tmp/cc11BgVS.o: In function `main':

freeImageInteropNPP.cpp:(.text+0x131d): undefined reference to `nppiMalloc_8u_C1'

freeImageInteropNPP.cpp:(.text+0x144c): undefined reference to `cudaMemcpy2D'

freeImageInteropNPP.cpp:(.text+0x15a0): undefined reference to `nppiMalloc_8u_C1'
freeImageInteropNPP.cpp:(.text+0x16cb): undefined reference to `nppiFilterBox_8u_C1R'
freeImageInteropNPP.cpp:(.text+0x1941): undefined reference to `cudaMemcpy2D'
freeImageInteropNPP.cpp:(.text+0x1b58): undefined reference to `cudaDeviceReset'
/tmp/cc11BgVS.o: In function `cudaSafeCallNoSync(cudaError, char const*, int)':
freeImageInteropNPP.cpp:(.text._Z18cudaSafeCallNoSync9cudaErrorPKci[cudaSafeCallNoSync(cudaError, char const*, int)]+0x23): undefined reference to `cudaGetErrorString'
/tmp/cc11BgVS.o: In function `cudaDeviceInit()':
freeImageInteropNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x26): undefined reference to `cudaGetDeviceCount'
freeImageInteropNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x173): undefined reference to `cudaGetDeviceProperties'
freeImageInteropNPP.cpp:(.text._Z14cudaDeviceInitv[cudaDeviceInit()]+0x1d9): undefined reference to `cudaSetDevice'
collect2: ld returned 1 exit status

The problem here is that library's are placed before the source files, simple fix: 
In the boxFilterNPP, imageSegmentationNPP, freeImageInteropNPPhistEqualizationNPP and
Makefiles and put $(LIB) after the source files:


$(CXX) $(INC) -o boxFilterNPP boxFilterNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)


$(CXX) $(INC) -o imageSegmentationNPP imageSegmentationNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)


$(CXX) $(INC)   -o freeImageInteropNPP freeImageInteropNPP.cpp $(LIB)  -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)

$(CXX) $(INC) -o histEqualizationNPP histEqualizationNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)


Finally to fix errors in randomFog:
Include

USERENDERCHECKGL := 1

in the Makefile and change

RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
to
RENDERCHECKGLLIB := -L../../../C/lib -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)

in common_cudalib.mk



9 Comments:

Blogger regis perdreau said...

many thanks for the fix. Regis

5:04 PM  
Blogger confluence said...

Thanks for this post; it was very useful. :)

I installed nvidia-cuda-toolkit from a PPA:
https://launchpad.net/~yani/+archive/iatsl

That also took care of the drivers and all the other dependencies, so I only had to install the toolkit.

Apart from the problems you listed, I got "kernel launches from templates are not allowed in system files" errors in radixSortThrust. This apparently happens because thrust puts its headers in a place nvcc doesn't like. I symlinked /usr/include/thrust to /usr/lib/nvidia-cuda-toolkit/include/thrust, and that fixed it. There was an empty thrust directory already there, so the lack of a symlink may have been the result of a bad upgrade.

7:42 AM  
Blogger L T said...

This comment has been removed by the author.

10:10 PM  
Blogger L T said...

Thanks for the post, I used it fix the issue compiling randomFog on my Ubuntu 12.04 64-bit install with the 4.2.9 CUDA toolkit/SDK along with the script posted here:

http://fcns.eu/2012/05/24/cuda-4-2-9-sdk-compile-on-ubuntu-12-04-lts-fails-with-undefined-reference-to-gluerrorstring/

Unlike confluence, I installed the toolkit and SDK from scratch and ended up with the following dependencies and paths:

sudo apt-get install build-essential libx11-dev libglu-dev freeglut3-dev libXmu-dev libXi-dev

http://stackoverflow.com/questions/2716293/trying-to-make-cuda-sdk-ld-cannot-find-library-ldconfig-says-it-can

Between all of those instructions, I managed to compile every example. Cheers!

10:14 PM  
Blogger feelmjawlk said...

Thanks!

4:24 PM  
Blogger Miguel Casas-Sanchez said...

Hi Chris thanks for the post, helped me a lot.

Also, I wanted to link CUDA with opencv and gstreamer, but libUtilNPP would not exist in .so (shared object/ shared library) format, so just for reference, I had to modify in the file CUDALibraries/common/UtilNPP/CMakeLists.txt the word "STATIC" with "SHARED".

Just in case someone bounces against this later on.
M

4:58 AM  
Blogger PRAVIN P said...

Thanx..... your post meant me a LOT...

12:42 PM  
Blogger Joey Gannon said...

This post was a lifesaver for me. I'm not sure how any reasonable person is supposed to figure this out. Thanks!

12:59 PM  
Blogger Heribert Hurtig said...

Found an easier way: (and I had two drivers running - cuda did not want to show up)

0. Downloaded the cuda_6.5.14_linux_64.run package

https://developer.nvidia.com/cuda-downloads

and extracted it. There are three run files in it which we will need)

Logoff and login to text console.

1. sudo apt-get remove --purge nvidia*
(to remove all old NVIDIA rubbish)

REBOOT - to console again.

2. sudo ./NVIDIA-Linux-x86_64-340.29.run
(This is included in the cuda package! Do *not* take a diff one!)

3. then cuda-linux64 ... package.

4. Finally (optional I guess) The cuda-samples... package.

Reboot - Done.

But thanks for your help too!

10:55 AM  

Post a Comment

<< Home