Archive

Archive for the ‘Linux’ Category

Compiling and running CUDA 2.3 SDK and toolkit on ubuntu 9.10 x64 (64-bit)

February 20th, 2010 mat 2 comments

I’ve heard a lot about CUDA, such as how it is 10,000% faster at cracking wireless passwords over a conventional program/hardware, but never really got around to testing it out before now. This post details the steps required to compile and setup CUDA 2.3 SDK and toolkit on ubuntu 9.10.

Downloads
You are required to have an Nvidia graphics driver (relatively new version) already installed. First download the CUDA toolkit and CUDA sdk from the Nvidia CUDA 2.3 download page.

Install the toolkit

# Make file executable
chmod +x cudatoolkit_2.3_linux_64_ubuntu9.04.run
# Run it as superuser
sudo ./cudatoolkit_2.3_linux_64_ubuntu9.04.run

You now need to edit your .bashrc file in your home directory to include the paths (so your CUDA binaries can be found by the system)

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

Note if you are using 32bit then “lib64″ should be replaced with just “lib”

Install the SDK

# Make file executable
chmod +x cudasdk_2.3_linux.run
# Run it as normal user
./cudasdk_2.3_linux.run

You should now have a NVIDIA_GPU_Computing_SDK folder in your home directory. Change directory into the C folder inside this one.

cd NVIDIA_GPU_Computing_SDK/C

In this folder is a make file which will compile all the Nvidia SDK and all the demos, in order for this to work in ubuntu 9.10 (x64) you will need to install several dependencies. By installing these before attempting to make will save you a lot of time, if you are getting errors please scroll down to the problems section to see if they are already covered.

# Install the necessary libraries
sudo apt-get install freeglut3 freeglut3-dev libx11-dev mesa-common-dev libxmu6

Making and running demos

You can then run the make command, once this is ran all of the executables will be placed in NVIDIA_GPU_Computing_SDK/C/bin/linux/released . We can check that our computer has an useable CUDA device install by running the deviceQuery program:

cd ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/released
./deviceQuery

This should output something similar to the following:

# ./deviceQuery
CUDA Device Query (Runtime API) version (CUDART static linking)
There is 1 device supporting CUDA

Device 0: "GeForce GTX 260"
  CUDA Driver Version:                           2.30
  CUDA Runtime Version:                          2.30
  CUDA Capability Major revision number:         1
  CUDA Capability Minor revision number:         3
  Total amount of global memory:                 938803200 bytes
  Number of multiprocessors:                     27
  Number of cores:                               216
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       16384 bytes
  Total number of registers available per block: 16384
  Warp size:                                     32
  Maximum number of threads per block:           512
  Maximum sizes of each dimension of a block:    512 x 512 x 64
  Maximum sizes of each dimension of a grid:     65535 x 65535 x 1
  Maximum memory pitch:                          262144 bytes
  Texture alignment:                             256 bytes
  Clock rate:                                    1.47 GHz
  Concurrent copy and execution:                 Yes
  Run time limit on kernels:                     Yes
  Integrated:                                    No
  Support host page-locked memory mapping:       Yes
  Compute mode:                                  Default (multiple host threads can use this device simultaneously)

Test PASSED

Now that we can see CUDA is successfully installed and a suitable device is found we can run some of nvidia’s more ascetically pleasing demos:

./fluidsGL
CUDA SDK example fluidsGL on ubuntu 9.10 x64

CUDA SDK example fluidsGL on ubuntu 9.10 x64

./smokeParticles
CUDA SDK example smokeparticles on ubuntu 9.10 x64

CUDA SDK example smokeparticles on ubuntu 9.10 x64

./particles
CUDA SDK example particles on ubuntu 9.10 x64

CUDA SDK example particles on ubuntu 9.10 x64

./postProcessGL
CUDA SDK example postProcessGL on ubuntu 9.10 x64 (teapot)

CUDA SDK example postProcessGL on ubuntu 9.10 x64 (teapot)

Problems


libxi (Nvidia forum link)

make[1]: Leaving directory `/home/mat/NVIDIA_GPU_Computing_SDK/C/common'
make[1]: Entering directory `/home/mat/NVIDIA_GPU_Computing_SDK/C/common'
In file included from ./../common/inc/paramgl.h:24,
                 from src/paramgl.cpp:19:
./../common/inc/GL/glut.h:60:20: error: GL/glu.h: No such file or directory
make[1]: *** [obj/release/paramgl.cpp.o] Error 1
make[1]: Leaving directory `/home/mat/NVIDIA_GPU_Computing_SDK/C/common'
make: *** [lib/libparamgl.so] Error 2
sudo apt-get install freeglut3 freeglut3-dev libx11-dev mesa-common-dev
/usr/include/bits/mathcalls.h:350: error: inline function ‘int __signbitf(float)’ cannot be declared weak
/usr/include/bits/mathcalls.h:350: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
/usr/include/bits/mathinline.h:36: error: inline function ‘int __signbitf(float)’ cannot be declared weak
/usr/include/bits/mathinline.h:42: error: inline function ‘int __signbit(double)’ cannot be declared weak
/usr/include/bits/mathinline.h:48: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
/usr/local/cuda/bin/../include/math_functions.h:442: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
make[1]: *** [obj/release/particleSystem.cu.o] Error 255
make[1]: Leaving directory `/home/mat/NVIDIA_GPU_Computing_SDK/C/src/particles'
make: *** [src/particles/Makefile.ph_build] Error 2

The problem is due to having gcc 4.4 installed rather than 4.3, it is possible to install the older version of this compiler but it is simpler to modify common/common.mk and add the following extra flag (Nvidia forum link):

# Change:
NVCCFLAGS += --compiler-options -fno-strict-aliasing
# To:
NVCCFLAGS += --compiler-options -fno-strict-aliasing --compiler-options -fno-inline

and change the -O2

# Change:
COMMONFLAGS += -O2
# To:
COMMONFLAGS += -O0

The two remaining errors you may encounter are very similar and arrise from missing libraries:

libxi (Nvidia forum link)

/usr/bin/ld: cannot find -lXi
collect2: ld returned 1 exit status
make[1]: *** [../../bin/linux/release/particles] Error 1
sudo apt-get install libxi-dev

libxmu (Nvidia forum link)

/usr/bin/ld: cannot find -lXmu
collect2: ld returned 1 exit status
make[1]: *** [../../bin/linux/release/particles] Error 1
sudo apt-get install libxmu-dev libxmu6
Categories: Linux, misc Tags: , , , ,

Utilising the notification system in KDE or Gnome in bash scripts (ubuntu 9.10 / linux)

February 18th, 2010 mat No comments

So you want to use the nice notification features available in your desktop environment (KDE or Gnome) from a script you wrote? Below explains how to do just that for the two different environments.

KDE

The code below will use kdialog (should be installed along with kde) to create a popup message that displays for 3 seconds before closing:

kdialog --passivepopup 'notification message!' 3

This should look like the image below:

kdialog passive popup notification

kdialog passive popup notification

Source: stackoverflow

Gnome

A similar tool is available for gnome, but to the best of my knowledge (I don’t really use gnome) you need to install a package. The libnotify-

sudo apt-get install libnotify-bin

The command notify-send can then be used to create notifications from your script.

notify-send -t 3000 "notification title" "notification text"

Where 3000 is the timeout in milliseconds (so 3 seconds). notify-send features some nice additional options such as the ability to include images eg:

notify-send -i /home/user/exampleicon.png -t 3000 "notification title" "notification text"

Source: Coder’s Talk

Categories: Linux, bash Tags: , ,

Bash: Script to convert .flv to mp3

January 18th, 2010 mat No comments

Flash Video (.FLV) is currently a very popular format of online videos, inparticular youtube. This post explains how to use a simple script to extract the sound from a flash video file and turn it into an mp3.

In order for the script to work you will need to download ffmpeg (to decode the video) and lame (to encode the mp3). This can be achieve in ubuntu by opening a terminal and running the following or alternatively you can use your package manager GUI to search and download the packages for you.

sudo apt-get install ffmpeg lame

You then need to create a new file named “flv2mp3.sh” and paste the following into it using your preferred text editor (which hopefully isn’t VI). Save the file and then change the file permissions so that it is executable (by running:`chmod a+x flv2mp3.sh` in the terminal or via the gui in you file browser)

#!/bin/sh
# this script should convert files from FLV to WAV and then to MP3
echo " "
echo "  Welcome to FLV to MP3 converter!  version 0.1"
echo " "
infile_name="$@"
# exit if the user did not enter anything:
if [ -z "$infile_name" ]; then
    echo " "
    echo "You did not tell me the file name, so I will exit now."
    echo " "
    exit
fi
echo " "
ffmpeg -i "$infile_name" -acodec pcm_s16le -ac 2 -ab 128k -vn -y "${infile_name%.flv}.wav"
lame --preset cd "${infile_name%.flv}.wav" "${infile_name%.flv}.mp3"
rm "${infile_name%.flv}.wav"
echo " "
echo "OK. I'm done! Have fun!"
echo " "
exit

You should now be able to convert a flashvideo into an mp3 by running the following command (changing the filenames to fit your purpose):
sh flv2mp3.sh videofilename.flv mp3audiofilename.mp3

Extra: Youtube
In linux it might be worth noting that youtube downloads the flv’s to your /tmp folder and you can easily copy them or convert to mp3’s (Ensure video is completly finished loading).

Also there is an application called ‘youtube-dl’ which can be installed from the repositories

sudo apt-get install youtube-dl

and then run using

youtube-dl http://www.youtube.com/video_to_borrow

Of course it’s up to your moral guidance to decide what you can and can’t download.

Categories: Linux, bash, web Tags: , , , ,

Programming Android Apps: SDK and Eclipse (ubuntu)

January 5th, 2010 mat 4 comments

Android is a brilliant smart phone operating system, this is the start of a short series of guides for starting to program applications for it using the android SDK.

Android SDK
Download the android SDK

Once downloaded untar the SDK

tar xvzf android-sdk_r04-linux_86.tgz

The SDK is not complete as additional files need to be downloaded in order to compile for different versions of android. Open the SDK and AVG management application by moving into the SDK folder and running the following.

sh tools/android

In the avaliable packages select the android versions you wish to develop for, and begin downloading them. Should this fail please read the next section, otherwise skip ahead.

Failing to download
If you cannot download from the google website, goto settings and select “force https://… source to be fetched using http://” and click save and apply.

android force http

forcing SDK and AVD manager http instead of https for android

If this still does not work (as was the case for me) it is possible that for some reason a configuration file was not created for this program, this can be solved by creating it manually:

echo sdkman.force.http=true > ~/.android/androidtool.cfg

Creating Android Virtual Devices
You can create virtual android phones using the SDK and AVD manager, click the Virtual Device tab and select new. Enter a name for the device, and a size for the sd card and simply click create AVD.

android create avd

creation of an android virtual device

Once you’ve created you Virtual Device(s) it should look like the following:

android avd's

Android Virtual Devices

You can test these virtual devices and see how nicely the phones are emulated. This is much more useful once you begin writing applications.

Android virtual device

Android Virtual Device in action

Eclipse

I would highly recommend using eclipse as it, along with the android plugin, greatly simplifies production and testing of applications.

Download eclipse from the ubuntu repositories (or from the eclipse website)

sudo apt-get install eclipse

If you do not already have java installed then you will need to install it.

sudo apt-get install sun-java6-jdk sun-java6-jre

You will need to add the following line to your .bashrc in your home folder so that the android tools can be used in eclipse (and other programs).

export PATH=${PATH}:/home/user/android/sdk/tools

* replace /home/user/android/sdk with the path to where you downloaded the SDK

Installing the android plugin for eclipse
Google’s eclipse plugin install guide.

In eclipse goto help then Install new software and then add the google plugin url

https://dl-ssl.google.com/android/eclipse/

Install software

Install new software in eclipse

Then install Android DDMS and Android Development Tools.

Should you receive errors (like I did) relating to a missing package you will need to add the eclipse repository and install the missing packages.

http://download.eclipse.org/releases/galileo

You should then have a fully working eclipse with android plugin.

Eclipse main window

Eclipse main window

What next?
Now you should have everything setup in order to develop and android applications. I would recommend the google tutorials:

Categories: Android, Linux Tags: , , ,

acid3 tests firefox chrome konqueror arora on ubuntu x64 karmic

September 3rd, 2009 mat No comments

I preformed some acid3 tests on the browsers I currently had installed.

Chrome: It is sexy (only thing holding it back in Linux is the lack of flash support)
Score: 100/100
Version: 4.0.203.2

acid3-test-chrome

Opera: I used to use opera however not really any more, just installed it for this test.
Score: 100/100
Version: 10.00 (build 4585)

acid3-test-opera

Arora: I don’t tend to use Arora, however I’ve heard alot of good things about it. It is a light-weight browser based on web-kit (as are chrome, safari and konqueror) and excels at its speed, highly recommended for notebooks which don’t need the bloat of firefox.
Score: 100/100 Linktest failed.
Version:0.8.0

acid3-test-arora

Firefox: It seems to handle flash better (without crashing) and has lots of useful plugins.
Score: 93/100
Version: 3.5.2
acid3-ff

Konqueror:
Score: 89/100 Linktest failed.
Version: 4.3.1
acid3-konq

Google’s chrome comes first (with chrome having smoother and faster animation) followed by Opera and closely followed by Arora only failing on the link test, then firefox and trailing is konqueror. But I still love konqueror as its so convenient have filemanager and web-browser in one.

Categories: Linux, web Tags: ,

Partitions and disk space in linux

September 3rd, 2009 mat No comments

I’m sure there are many ways to see the partitions and corresponding diskspace in linux, but here is the method I found:

$df -m
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda2 7513 5937 1576 80% /
tmpfs 1005 0 1005 0% /lib/init/rw
varrun 1005 1 1005 1% /var/run
varlock 1005 0 1005 0% /var/lock
udev 1005 1 1005 1% /dev
tmpfs 1005 1 1005 1% /dev/shm
/dev/sdc1 469453 353295 92311 80% /media/x
/dev/sdd1 1408345 979205 429141 70% /media/z

or visually:

df -m screenshot

I kept struggeling to remember what letters it was, as there are many two letter commands beginning with d in linux… (dc, dd, df, dh, do, dl, du). I now remember it, because ‘f’ is next to the ‘d’ key on my keyboard, and because df probably stands for disk-free.

For more information check out this site

Categories: Linux, bash Tags: ,

Free

May 17th, 2009 mat 1 comment

Using the free command gives output something like this (-m just tells free to output in megabytes):

free -m
total used free shared buffers cached
Mem: 2013 1996 17 0 27 1381
-/+ buffers/cache: 588 1425
Swap: 956 0 956

This is useful but annoying as it doesn’t show you how much memory is actually free. Files that are used are kept in the ram (referred to as caching). If the memory is needed it is simply overwritten, however if the file is used again it is already in the memory which saves time.

I wrote a quick little bash line to get the actually memory in use or the actual memory free. I use grep to select the right line from the output of free, and then use awk to do the string manipulation and math.

Memory in use

free -m | grep Mem | awk ‘{x=$3-$7; print x}’

Memory free

free -m | grep Mem | awk ‘{x=$2-($3-$7); print x}’

Categories: Linux, bash Tags: , , ,

Karamba – System Monitor Basis

May 17th, 2009 mat No comments

karamba1

I posted my superkaramba system monitor on kde-look.org. Hopefully it will be useful to some people as a basis for their own system monitors. Note that it’s transparent not grey, so looks a little better with the whole screen included in the second picture.

karamba

Categories: Linux Tags: , , ,

apt – no public key error

May 17th, 2009 mat No comments

If you add a new repository to apt (/etc/apt/sources.list) you may get the following error when running ’sudo apt-get update’:

Reading package lists… Done
W: There is no public key available for the following key IDs:
[Key]
W: You may want to run apt-get update to correct these problems

As you probably already guessed, running ’sudo apt-get update’ will result in exactly the same problem. This is because the new repository’s key needs to verified. This is done by the following:

gpg –keyserver subkeys.pgp.net –recv [Key]
gpg –export [Key] | sudo apt-key add -

replace [Key] with the key you want to add

This can also be made slightly easier by using a bash variable:

$1=[key]
gpg –keyserver subkeys.pgp.net –recv $1
gpg –export $1 | sudo apt-key add -

replace [Key] with the key you want to add

or as a bash script:

#!/bin/sh
gpg –keyserver subkeys.pgp.net –recv $1
gpg –export $1 | sudo apt-key add -

ran by the following:

./key [key]

replace [Key] with the key you want to add
which then you could place in /bin so you could simply run

Script can be downloaded here

Categories: Linux, bash Tags: , ,

Bash: mass image and video conversions

May 16th, 2009 mat No comments

Linux has many useful command line programs that will convert from one file format to another.

  • convert – converts images (part of ImageMagick)
  • convert input.jpg -resize 500×500 output.jpg

    converts input.jpg to output.jpg resized to 500 by 500 pixels

  • mencoder – converts video files
  • mencoder -ovc lavc -oac mp3lame -o output.avi input.flv

    converts input.flv to output.avi

    Now lets look at some bash:

    for i in *.jpg; do echo $i; done

    This is a for loop which will assign and iterate over a variable i to every item it finds that matches *.jpg in the current directory. It will simple echo the name of the file to the console and then finish. Only really useful for testing the command works, now lets put a conversion command in instead of the echo.

    for i in *.jpg; do convert “$i” -resize 500×500 “x_$i”; done

    This will take every jpg in the current directory resize it to 500 by 500 pixels and then save it as with and x_ prefixing the filename. You can get it to overwrite the current file by making the input and output file names equal (in this case it simple means removing x_ from the above code)

    Categories: Linux, bash Tags: , ,
    // unused langs // // // //