Monday, December 03, 2012

Getting Nvidia Optimus working on my Lenovo Ideapad Y580 Ubuntu/Kubuntu

So I recently got a Lenovo Ideapad Y580 in the hope I could use it to do some CUDA coding at a  conference I recently went to.  Well I got back from the trip and I still hadn't got CUDA or the optimums card working under Linux, finally on a second trip I got frustrated enough to fix it. It took many re-installs and web searches to get it all to work so I though I might outline the steps. I hope it helps someone else....

So I installed various Ubuntu and Kubuntu versions and kernel and found the one that works is kernel 3.5.0-17 or greater, so I installed Kubuntu 12.10 and updated to the latest kernel.
  sudo apt-get -y update
  $ sudo apt-get -y install linux-headers-generic
  sudo apt-get -y upgrade

So the Y580 uses NVIDIA's Optimus technology which works great on Windows but is not directly supported on Linux. However using Bumblebee and optirun one can asses the discreet NVIDIA 660M
 A possible solution is to install Bumblebee and to access the card with optirun. There is however a bug in the kernel which means Bumblebee will not work, it gives an e=something like:
  [   94.384435] [ERROR]Cannot access secondary GPU - error: Could not load GPU driver
  [   94.384481] [ERROR]Aborting because fallback start is disabled.

There is however a work around hack, installing the acpi-handle-hack module.

First dl and install the hack (taken from here):
  $ git clone git:// -b hack-lenovo
  $ cd bbswitch
  $ sudo mkdir /usr/src/acpi-handle-hack-0.0.1
  $ sudo cp Makefile acpi-handle-hack.c /usr/src/acpi-handle-hack-0.0.1
  $ sudo cp dkms/acpi-handle-hack.conf /usr/src/acpi-handle-hack-0.0.1/dkms.conf
  $ sudo dkms add acpi-handle-hack/0.0.1
  $ sudo dkms build acpi-handle-hack/0.0.1
  $ sudo dkms install acpi-handle-hack/0.0.1

Next get the hack to load on boot:
  $ echo acpi-handle-hack | sudo tee -a /etc/modules
  $ sudo update-initramfs -u

Now Install bumblebee and drivers
  $ sudo apt-get install -y bumblebee bumblebee-nvidia nvidia-current

Reboot to get it all loaded
  $ sudo reboot

Now if you try
  $ optirun glxspheres

You should get something like:
  $ [  128.872061] [ERROR]Cannot access secondary GPU - error: [XORG] (EE) NVIDIA(0): Failed to initialize the NVIDIA GPU at PCI:1:0:0.  Please
  $ [  128.872091] [ERROR]Aborting because fallback start is disabled.

The answer to this one I got here, and that is to edit /etc/bumblebee/xorg.conf.nvidia and change the Option "ConnectedMonitor" "DFP" line to Option "UseDisplayDevice" "none" and restart bumblebee:
  $ sudo restart bumblebee

Then try:
  $ glxspheres
  $ optirun glxspheres

You should see the difference! I go from ~20fps to ~170fps, now that's what I'm talking about!

Now to install CUDA you can see my previous post, noting that you can skip the driver install as it should be already done.

You will have to install gcc 4.4
  $ sudo apt-get install -y gcc-4.4 g++-4.4
  $ sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc

And tell nvcc to use it with the directive: --compiler-bindir=/usr/local/cuda/bin

Wednesday, May 16, 2012

pngwriter-0.5.4 on Kubuntu 12.04

Simple fix

Get source

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/ line 48 change:

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

In make.include.linux change:

LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpng -lpngwriter
LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpngwriter -lpng
LIBS= -L../src -L$(PREFIX)/lib/ -lz -lpngwriter -lpng -lfreetype

Make and install
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.
  chmod +x
  sudo ./

  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/ /usr/local/cuda/lib64/
      sudo ln -s /usr/lib/nvidia-current/ /usr/local/cuda/lib64/
      sudo ln -s /usr/lib/nvidia-current/ /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:
     chmod +x
     sudo ./

     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
     chmod +x

     make will fail

    undefined reference to 'gluErrorString'

   This post helped me sort it out

    My soulution was:

    Open C/common/ and CUDALibraries/common/ 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:


in the Makefile and change

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


Thursday, July 13, 2006

They broke into my car.

I’ve been very busy the last couple weeks.

Unfortunately I broke up with Sarah two weeks ago, we both (I hope) agreed we were better off just being friends. I’m currently house sitting with here at a house at Obs, I really do love Obs!

I got a job working tech support for PG Computers, not really the direction I want to go fore I’d rather be a developer but it’s a job, and I am really enjoying it. I really love learning new stuff and I have learnt a couple new tricks.
My car got broken into this morning, someone broke on of the back windows to get in. All they took was a blanket and a jersey, it makes me feel it was someone who was just cold. I realise how privileged I really am.

Wednesday, June 21, 2006


I haven’t been posting much but then life has been pretty standard.

I went for a very nice bouldering session on Sunday with Julia and Nick. We went to three boulders in Newlands/Cecilia forest, the first boulder, the river boulder is grate, is pretty small with only one or two problems, I really enjoyed the one, and I’m def going to stick it next time!The only problem is that its pretty rough and I came away with a few grazed elbows and knees, and sore fingers .

By the time we got to the second boulder my fingers were pretty shot I did one clime which absolutely grated my left had, but we did some climb maintenance, mooing rocks ect. We removing one good sized rock, making me rely feel like a kid again digging in the mud :)

The third boulder was The Den which is a really nice boulder, I’m looking forward to more climbing on it. Most of the problems are really hard with few feet, but a challenge is always good!

Find picks here.

Saturday, May 20, 2006


I'm not posting to often :/

I haven’t been doing very much lately, I found out yesterday that I cant register for UNISA Computer science midyear so i have the rest of the year off, so i may do some traveling and work or just get a job here.

Two weekneds ago on the Saterday, I lead a hike up Indiafenster and down left face B two weeks ago, it was really nice hike, it was very wet and inclement so only three other people pitched. The hike up was very nice, we got most of the tourists in the cable car to wave on their way by. We had lunch at Meclears and set of to the top of Left Face B, as we got their the clouds closed in and it began to rain, we decided the group was experienced enough to go down in the rain so we set off. We missed a lot of the view and didn’t have any manger incidents, we saw a pair of Himalayan Tar on one of the ledges, so they defiantly haven’t all been shot. The pick is of the rest of the hikers on the way down left Face B.

The sunday after that wasn’t to wet so Julia, Roark and myself went to Paarl Rock to do some multi pitch climbing. The trip there was fun, we got pretty lost in Paarl and after consulting a number of locals in pretty bad Africans we found the road up to the rock. Due to the recently passed front the dirt roads were pretty exciting leaving Spud, my car, totally encrusted with mud. We got to the crag and hiked to the base of a 2 pitch climb which was to be Roark’s firs multi pitch. We decided to climb with only one rope which in hind site wasn’t to good with three people, we had some interesting anchoring at the pitch but we got through it. The photo is of all of us on setup at the anchors. The second climb was a saga! We were short of time so we decided to climb only the first two pitches, the climb is vertical for +-15m and then has a +-5m horizontal traverse t to the right. Julia set off to lead the first pitch,. sho got to the traverse and was two tired to complete the climb so, she came down and I had to finish it, I got to the chains with some very creative climbing and the worst rope drag I’ve ever experienced! I was literally having to pull slack with all my strength and then clime a bit and then putt some more, I got to the anchor cleaned it, cleaning the rest of the climb was very exciting, in the end I could only clean three quarters of the horizontal section lowering me was interesting because of the rope drag I had to jump and throw my wait around just to get down. Once I got down I had to re climb most of the climb and clean the rest of the draws. Once the climb was clean I then had a very exciting swing, because I was at the end of the traverse and was just to tired to climb the rest, so I came off and just had to live with the swing. All in all a very nice day, and we all decide we’re def going back some time.

I have really been enjoying winter, loving the rain. I was feeling a bit down on Thursday so I decided I need to get out, so I cycled up to Kirstenboch and spent some time with my mom who left for London yesterday. I then went on a hike up Skeleton Gorge and to the top, it was exactly what I needed some good alone time in the rain. The section of Skeleton through the river was a raging torrent, I went through barefoot and even managed to get my pants pretty soaked but I loved it. The top was cold and windy as I expected and there was no one to be seen. I met tow other crazy hikers in the river section of skellies on the way down, I think they were very surprised when they met a solitary soaked barefoot hiker coming down from then top. We had a chat I took a photo for them and I went down and enjoyed a warm cup of soup at my Mom’s office.

Wednesday, April 19, 2006

Boland Hike

What a nice week, I had quiet a good week planned. Unfortunately I hurt my ankle on Thru two weeks prior, that put an end to my plans to go climbing with Julea at Kleinmont for the weekend.
By Monday my ankle was healed enough that I could go on a hike. We did three days of the Boland trail. We started at LaMotte Forest station, hiking 8km to Landroskop Hut (LRK). The hiking was interesting, we were a group of not the most experienced hiker so it took us some time but it was real fun. LRK is a really nice hut with a big central fire place and benches all around, we had a good night and drank most of our booz in order to lighten our packs.

Every1 at the start of the hike

The next mooring was a 18km hike to our second night, Berg Hut (BSG). We lost 5 people, who had to go home early, we hiked the first 4km with them and they then proceeded to the car while we turned off the road and hike up a long valley for most of the day, which took a lot out of some people as the sun was really killer. The final downhill to the hut which looked very promising on the map turned out to be very overgrown and very difficult. Suffice to say most people were very happy to reach the hut. Supper at the hut was good fun everyone except me was in one cooking group and Patrick had been caring a frozen bolognaise they cooked the pasta on all the reaming stoves, they had a good meal and maid Patrick’s pack much lighter for the third day.
The third day real killed me, I was caring heavy and we had to be back early enough to get Jess home for Pesach. Getting to the cars was a good relief and the shower I took at the cars had to rate in the top three showers I’ve ever taken. We then maid a mission to go and get some Mc Donald’s on the way home. I must say I’m not the world’s biggest fan of Mc Donald’s, but after 3 days in the mountains it was exactly what I needed.

McD's on the way home.