Wednesday, May 16, 2012

pngwriter-0.5.4 on Kubuntu 12.04

Simple fix

Get source

wget http://downloads.sourceforge.net/project/pngwriter/pngwriter/pngwriter-0.5.4/pngwriter-0.5.4.tar.gz
tar xfz pngwriter-0.5.4.tar.gz
cd pngwriter-0.5.4

make sure libpng and freetype are installed
sudo apt-get install libpng12-dev libfreetype6-dev

link freetype2 to freetype
sudo ln -s /usr/include/freetype2/freetype/ /usr/include/freetype

In examples/pngtest.cc line 48 change:

#include <iostream.h>
to 
#include <iostream>

In make.include.linux change:

LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpng -lpngwriter
to
ifdef P_FREETYPE
LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpngwriter -lpng
else
LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpngwriter -lpng -lfreetype
endif

Make and install
make
sudo make install

and finally use it link freetype2 to freetype:
sudo ln -s /usr/include/freetype2/freetype /usr/include/freetype

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