Sunday, 18 November 2012

First thoughts on Windows 8

So windows 8 has been released and I have been faced with the dilemma of whether to upgrade my Windows 7 machine to Windows 8 or skip this release. Like many developers I have learned to be skeptical of new releases of Windows, I live in fear that another Vista may be inflicted on the world. I decided to have a little look at it and thought it would be the perfect subject for my next article, so I hopped on the Microsoft Developers Network Academic Alliance and downloaded myself a copy. Then I fired up VMware and installed, the boot time was very reasonable… things were looking good at this point.

So the tiles appeared just like I had seen in the television ads, the first thing that popped into my head upon seeing the home screen was "This would be brilliant on a tablet PC", this would be the recurring theme during my time with Windows 8. So the interface doesn't do anything for me, I expected as much since I'm hopelessly tied to my desktop interface. Upon opening the desktop "app"… hold on… WHERE IS MY START BUTTON!!! That's right, they've taken one of my most used features out of the desktop version. Needless to say I was horrified, at this point they had successfully alienated me (and a lot of other people too I think), but I owed it to Microsoft to soldier on and look for some redeeming points. So the desktop has changed quite a bit, it no longer has a start button, the default window decorator has taken on a more metro feel but apart from that it's more or less business as usual.

The main changes have come in the form of apps. The introduction of the Windows Store has wrought great changes in the Windows interface, no longer is the desktop the main place to access your favourite programs, no longer is the internet the first port of call to find programs. In principle I like the app store but it provides so little information per screen and doesn't have the volume of apps that Apple store has. It also feels like they have tried to shoehorn the xbox 360 store into the operating system, oh dear, this had such potential.

The final nail in the Windows 8 coffin came when I tried to install some of my favourite programs from Windows 7 only to find that some of them no longer work. So I sat back in my chair thinking how good Windows 8 could have been and feeling thoroughly disappointed, how could Microsoft have done this to me. Who knows, future changes may make Windows 8 a useable system, but for now I think I'll have to stick with 7 as the thought of trying to develop on Windows 8 gives me a sore stomach.

Sunday, 11 November 2012

How To Become A Programmer!

I know that this is a topic that has been covered in quite a few blogs, forums, books etc. etc. but it's a topic that I have been repeatedly asked this question via message on my youtube channel and I've decided that I'm sick of rewriting my answer every time. Wouldn't it be nice to have a list of recommendations on how to start programming? I know that I was very unsure when I started programming, in terms of what language, what IDE, should I learn from a book or the internet and so on. I've been programming for around 9 years now and I like to think that I'm pretty decent at it. I'm also a teaching assistant at QUB so I have some experience with helping beginning programmers. This is a set of recommendations about how to become a competent programmer. Enjoy!!

Pick a language

This is easier said than done and sometimes depends on what you hope to accomplish. The most common languages that are used in the software development industry are C# and Java. In QUB they use Java as a teaching language, I don't personally think that this is the best way to become a good programmer. The problem  with Java (and C# for that matter) as a learning language is that it comes with a huge standard library, when you start programming you do not need these libraries as they are essentially non-transferable skills, they are specific to that language. I always follow the tenant that structure is the most important part of learning programming not the syntax of a specific language. For these reasons I think the best language to learn in is C, since many modern programming languages are based on C the syntax is transferable. Since C is a language with a very basic standard library it forces you to learn more about the implementation of very useful algorithms (searching, sorting, etc.).

In my opinion the best book for learning C is:
The C Programming Language by Brian W. Kernighan and Dennis Ritchie - This is not a book that will teach you programming methodology but it is the definitive guide for the C language syntax

Pick a development environment (IDE)

Integrated development environments (IDEs) are the easiest way to begin programming, they're generally composed of a text editor and a set of tools for developing programs. The IDE that you will use is really dependent on what language you want to learn but I've included a list of common and popular IDEs and the languages they are used for.
  • Netbeans - Free IDE that can be used for a variety of languages but mainly for Java but I've also used it for C and C++. This is available for all popular operating systems.
  • Eclipse - Probably the most popular Java IDE freely available, can also be used for other languages. Includes very good refactoring tools. Available on all popular operating systems.
  • Visual Studio - This is Microsoft's IDE, it's pretty much the best choice if you plan to do any C# development. Although its a commercial package there is a free option available i.e. Visual C# Express Edition. This is only available on Windows operating systems.
  • Xcode - Apples IDE for C/C++/Objective C programming. It is freely available but can only be used on Mac OS X.
  • Code::Blocks - Good cross-platform IDE for C and C++ development. It lacks some features of the other IDEs but is still a very good option.

Join a development forum

I think it is very important for starting programmers to have a place that they can go to if they get stuck. Lots of people get discouraged from programming because they get up to a point and get stuck. One of the best communities around is on http://stackoverflow.com/, they have a huge amount of information and very experienced developers that are always willing to help out.

Start Programming Now!!!

If you want to be a good programmer there is no substitute for experience, you need to immerse yourself in programming. Pick a project that you think would be interesting or useful, e.g. calculator, text editor, pong game… then begin working, you need something that you are interested in or you will most likely lose motivation. I've done very well at university in my computer science course and this is not because of any particular advantage over the other students, but since I started programming I have thrown myself into the subject. Once you do this you will find that you pick up programming very quickly and will have a good time doing it!!

Sunday, 4 November 2012

Installing CUDA 5 on Kubuntu

Introduction

So today I decided to install the CUDA 5 toolkit on my linux machine so that I can test my OpenCL applications on it. This turned out to be much more of a pain than I had originally thought as there is no definitive guide on how to install CUDA under linux and also the installer is quite finicky and really needs a rethink. So I'm posting some tips on how to install the toolkit so that other people don't make the same mistakes I did. Just so you guys know the linux version that I use is Kubuntu 12.10. The main issue with installing the toolkit is that the driver they package with it requires you to have gcc version 4.7 but the toolkit installation requires that you have version 4.4, I'm sure you can all see why this would be an issue. Before reading this guide I advise watching these videos:


So the first piece of advice I have for you guys is to install the driver FIRST and then the toolkit/samples after.

DISCLAIMER: This guide is offered without any guarantees, I am not responsible if you end up bricking your install. You have been warned!

1. Installing the Driver

First install the following libraries & Tools:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

Next we will blacklist some modules(drivers), in terminal enter:
sudo kate /etc/modprobe.d/blacklist.conf

Add the following to the end of the file(one per line like so):
blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv

Save the file and close the editor.
Now we want to get rid of any nvidia residuals, in terminal:
sudo apt-get remove --purge nvidia*

Next you need to restart your machine (sudo reboot). At this point, if you log back it to your machine you may find that the window manager isn't working correctly (window borders are missing etc.). Before worrying about that I advise installing the driver portion of the toolkit

0) Press Ctrl+Alt+F1 at login screen(you don't have to login, we'll have to restart later anyway), then log in.
1) sudo service lightdm stop
2) cd Downloads
3) chmod +x <cuda>.run (your toolkit filename)
4) sudo ./<cuda>.run

When asked if you wish to install the driver enter y, but do NOT install the toolkit or samples. After the installation execute “sudo service lightdm start” to restart the x server. Log in to the machine, if your window manager is still screwed I solved this by running “sudo apt-get install kubuntu-desktop”. If you are running another version of linux this command will differ from mine.

Round about here you've installed the driver and (hopefully) your system is running fine. Now for the easy bit, installing the toolkit and samples.

2. Making GCC 4.4 the default version

In this section we are going to use update-alternatives to make gcc-4.4 the default version on your system. In the terminal execute the following commands

sudo apt-get install gcc-4.4
sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --config gcc

Choose gcc-4.4

gcc --version

You should have gotten some output saying your version number is 4.4.x

3. Installing the Toolkit/Samples

Now you are ready to install the toolkit. All you need to do is navigate to your downloads folder(from the terminal of course) and run “sudo ./<cuda>.run” the same as before but this time when it asks if you want to install the driver select no and install the toolkit and samples instead. This installation worked for me first time but I have heard of some people getting error messages about missing glut libraries (and possibly others), if this happens you will need to find out where the glut library is on your computer and make a symbolic link to /usr/lib using ln (the link tool). Anywhoooo... assuming your install was a success you have very little else to do apart from set up your environment variables and test the install.

Add Environmental variables:
export PATH=/usr/local/cuda/bin:$PATH

#for 64-bit machines:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH

#for 32-bit machines:
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH

Now we want to test did the toolkit install properly:
nvcc --version

If you get some output telling you the version number of nvcc then congrats! You are now ready to develop for CUDA and OpenCL!!!

Thursday, 1 November 2012

Setting up OpenCL in Visual Studio

Introduction

As a relatively new OpenCL user I was looking online for a guide to setting up OpenCL in visual studio. I have about 9 years development experience, so I thought this wouldn’t be much of an issue but I did have a little trouble due to a few details of the setup not being common knowledge. In this article I’m going to provide step by step instructions on setting up OpenCL for both nVidia and ATI graphics cards in Visual Studio 2010. I assume that you have an OpenCL capable graphics card, if you are unsure please check your manufacturers website or leave a comment and I’ll check for you. In this tutorial I will be using an nVidia card but I will provide text instructions for AMD cards.

1.       Installing OpenCL

For nVidia graphics cards you need to install the CUDA toolkit and development drivers. As of the time of writing the current CUDA toolkit version was 5.0, this version includes the development drivers in the toolkit. It can be downloaded here:

For ATI graphics cards you will need to install the AMD APP SDK (formerly the AMD Stream SDK). This can be downloaded from:

2.       Setting up the Project

First thing to do is set up an empty VS project by choosing
  • ‘New Project->Visual C++->Win32 Console Application'
  • Enter a name for the project and choose OK
  • In the application creation wizard choose ‘Next’
  • Under ‘Additional options’ check the ‘Empty project’ box and click ‘Finish’

3.       Including OpenCL in the Project

The first step in including OpenCL is to create a C++ file, this enables the configuration options we will need.
  • Right click on the ‘Source Files’ folder in the solution explorer and select ‘Add-> New Item’
  • Select C++ File and give the file a name
  • Click the ‘Add’ button in the bottom right hand corner of the dialog box
  • Now we are ready to point the project to the include directories for OpenCL
  • Right click on the project name in the solution explorer and select ‘Properties’
  • From the ‘Configuration’ drop down box choose ‘All Configurations’
  • Navigate to ‘Configuration Properties-> C/C++ -> General’
  •  In the ‘Additional Include Directories’ field add the following information depending on your graphics card
    •  nVidia   -“$(CUDA_INC_PATH)”
    • AMD    -“$(AMDAPPSDKROOT)\include”

include path image

4.       Linking OpenCL

Now we are going to tell the project where to find the actual library file which contains OpenCL. This is where the actual implementation of OpenCL is contained.

Without closing the dialog box used above:
  • Choose ‘Linker-> General’
  • In  the ‘Additional Dependencies’ field enter the following, again this is based on your card vendor
    •  nVidia   - “$(CUDA_LIB_PATH)”
    • AMD      - “$(AMDAPPSDKROOT)\lib\x86” (for 64 bit users you may need to change the x86 to x86_64, I have no machine to test this on)

library path image
  • Still in the ‘Linker’ submenu, select ‘Input’
  • In the ‘Additional Dependencies’ field click on the arrow that appears at the end of the field and choose Edit…
  • In the dialog that appears enter “OpenCL.lib” (without the quotes obviously J)

library link image

  • Click OK in the dialog box
  • Click OK in the Properties dialog to bring you back to the main IDE
If you are a 32-bit user then your project is now set up for OpenCL (skip to the” Test Your Project” section), if you’re a 64-bit user then continue on to the next section.

5.       A Note for 64-Bit users

If you are using a 64-bit machine then you will need to add an x64 target to your project to be able to build it.
  • Again open the properties page of your project by right clicking on it and selecting ‘Properties’
  • Select ‘Configuration Manager…’ from the top right hand corner of the dialog (if it is greyed out expand ‘Configuration Properties’ on the left hand side to enable it)
  • Under ‘Active solution platforms’ select New...
  • Under ‘Type or select the new platform’ select x64 and click OK
  • Click Close
  • Click OK to get back to the main IDE


Your project should now be set up for OpenCL!! Wasn’t that a breeze ;)

6.       Testing your project

Below is the simplest OpenCL application to test that the install and configuration have worked. Copy this code into the C++ class that you created at the start of the tutorial:

Click the run button. If you get a console window that opens and then closes again, then congratulations!!! You have just taken the first step on your OpenCL/world domination journey. Happy coding guys! If I have made any errors please leave me a comment and I will correct it ASAP.