Archives for 8 Jul,2010

You are browsing the site archives by date.

Installing PyCuda on ubuntu 10.04

Using graphics cards to hand massively parallel tasks can now be realised in python, thanks to PyCuda a module for python which allows interaction with the CUDA libaries/binaries provided by Nvidia. To get this working in ubuntu 10.04 lucid lynx I followed this guide

Prep / Installation:

First install CUDA, most places will tell you that CUDA is incompatible with gcc-4.3 but this is not true if you make a few small changes to the file, please see this post about installing CUDA in ubuntu

Install the required packages (or use package manager):

sudo apt-get install python-numpy -y
sudo apt-get install build-essential python-dev python-setuptools libboost-python-dev -y

Download pycuda from:

Untar the achive:

tar xzvf pycuda-0.94rc.tar.gz

Configure, make and install:

cd pycuda-0.94rc
./ –cuda-root=/usr/local/cuda –cudadrv-lib-dir=/usr/lib –boost-inc-dir=/usr/include –boost-lib-dir=/usr/lib –boost-python-libname=boost_python-mt –boost-thread-libname=boost_thread-mt
make -j 4
sudo python install


I had some problems with the compliation because it was complaining about pytools missing, this was resolved by removing and reinstalling python-setuptools:

sudo apt-get remove python-setuptools
sudo apt-get install python-setuptools

Running the example

You should now be able to run the demo in the examples folder and use the to download further demos from the pycuda wiki.

I plan to learn how to use PyCuda and aim to make a MD5 cracker as discussed previously (here and here)

Read More

Changing the battery percentage in an AVD (android virtual device) emulator

First I will briefly show how to react to the battery percentage change in your application, and then show how to change the battery level in the android emulator (AVD).

Reacting to the battery level change in your program

We need to register our application to receive the intent when the battery level information is changed, we do this by adding the following line into our onCreate method of our activity (or some other instance):

		new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

This will run mBatInfoReceiver when the battery level is changed, so we now need to create this method in our activity (or some other instance). The function creates a broadcast receiver to handle the information when the intent is sent for the battery status changing.

		private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){

			public void onReceive(Context arg0, Intent intent) {
			      int level = intent.getIntExtra("level", 0);
			      // TODO: Preform action based upon battery level


Changing the battery level in AVD

First we need to find the port so that we can address the emulator, this will be shown in the titlebar of the AVD.

Froyo running in an AVD (android emulator)

Froyo running in an AVD (android emulator)

Zooming in:

AVD title shows the port "5554:froyo"

Using the port from the AVD found above we can use telnet to control certain aspects of the avd see this android reference for a full reference.

telnet localhost 5554
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
Android console command help:

    help|h|?         print a list of commands
    event            simulate hardware events
    geo              Geo-location commands
    gsm              GSM related commands
    kill             kill the emulator instance
    network          manage network settings
    power            power related commands
    quit|exit        quit control session
    redir            manage port redirections
    sms              SMS related commands
    avd              manager virtual device state
    window           manage emulator window

try 'help ' for command-specific help

Some more information on the power commands:

help power
allows to change battery and AC power status

available sub-commands:
    display          display battery and charger state
    ac               set AC charging state
    status           set battery status
    present          set battery present state
    health           set battery health state
    capacity         set battery capacity state

So now you can change the battery level in the avd using power capacity percentage

power capacity 100
power capacity 99
power capacity 60
power capacity 20
power capacity 0

As you change the battery capacity you should notice that your AVD is responding, just by looking at the battery indicator in the status bar, and your program will react if you have replaced the //TODO: code with something that reacts when the onReceive is called.

Read More