Monday 11 June 2012

How to run CUDA in Emulation Mode

Some beginners feel a little bit dejected when they find that their systems do not contain GPUs to learn and work with CUDA. In this blog post, I shall include the step by step process of installing and executing CUDA programs in emulation mode on a system with no GPU installed in it.

It is mentioned here that you will not be able to gain any performance advantage expected out of a GPU (obviously). Instead, the performance will be worse than a CPU implementation. However, emulation mode provides an excellent tool to compile and debug your CUDA codes for more advanced purposes.

Please note that I performed the following steps for a Dell Xeon with Windows 7 (32-bit) system.

1. Acquire and install Microsoft Visual Studio 2008 on your system.

2. Access the CUDA Toolkit Archives  page and select CUDA Toolkit 2.3 (June 2009) version. (It is the last version that came with emulation mode. Emulation mode was discontinued in later versions.)

3. Download and install the following on your machine:-

  • Developer Drivers for WinVista (190.38) - (Select the one as required for your machine.)
  • CUDA Toolkit
  • CUDA SDK Code Samples
  • CUBLAS and CUFFT (If required)
4. The next step is to check whether the sample codes run properly on the system or not. This will ensure that there is nothing missing from the required installations. Browse the nVIDIA GPU Computing SDK using the windows start bar or by using the following path in your My Computer address bar:-
"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\bin\win32\Release"


(Also note that the ProgramData folder is by default set to "Hidden" attribute. It will be good if you unhide theis folder as it will be frequently utilized later on as you progress with your CUDA learning spells.)

5. Run the "deviceQuery" program and it should output something similar as shown in Fig. 1. Upon visual inspection of the output data, it can be seen that "there is no GPU device found" however the test has PASSED. This means that all the required installations for CUDA in emulation mode has been completed and now we can proceed with writing, compiling and executing CUDA programs in emulation mode.

Figure 1. Successful Rxecution of deviceQuery.exe
6. Open Visual Studio and create a new Win32 console project. Let's name it "HelloCUDAEmuWorld". Remember to select the "EMPTY PROJECT" option in Application Settings. Now Right Click on "Source Files" in the project tree and add new C++ code item. Remember to include the extension ".cu" instead of ".cpp". Let's name this item as "HelloCUDAEmuWorld.cu". (If you forget the file extension, it can always be renamed via the project tree on the left).

7. Include the CUDA include, lib and  bin paths to MS Visual Studio. They were located at "C:\CUDA" in my system.

The next steps need to be performed for every new CUDA project when created.

8. Right Click on the project and select Custom Build Rules. Check the Custom Build Rules v2.3.0 option if available. Otherwise, click on Find Existing... and navigate to "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common" and select Cuda.rules. This will add the build rules for CUDA v2.3 to VS 2008.

9. Right click on the project and select Properties. Navigate to Configuration Properties --> Linker --> Input. Type in cudart.lib in the Additional Dependencies text bar and click Okay. Now we are ready to compile and run our first ever CUDA program in emulation mode. But first we need to activate the emulation  mode for .cu files.

10. Once again  Right click on the project and select Properties. Navigate to Configuration Properties --> CUDA Build Rule v2.3.0 --> General. Set Emulation Mode from No to Yes in the right hand column of the opened window. Click Okay.

11. Type in the following in the code editor and build and compile the project. And there it is. Your first ever CUDA program, in Emulation Mode. Something to brag about among friends.

int main(void)
{
return 0;
}


I hope this effort would not go in vain and offer some help to anyone who is tied up regarding this issue. Do contact if there is any query regarding the above procedure.

Sunday 10 June 2012

My Experience with CUDA & GPUs

Like most of You, I started learning GPU programming on my own. I got hold of the book titled "CUDA By Example" from nVIDIA website and started gobbling it page by page. The funny thing was, right in the beginning of Chapter 1, it was mentioned that only three (03) things are needed to learn and write a CUDA program, namely:-
1. Visual Studio 2008
2. CUDA SDK
3. A Graphical Processing Unit (GPU)
I was so glad that I had all these things in my Desktop. However, nothing was mentioned in the book about integrating CUDA in Visual Studio 2008 so the ".cu" file could be compiled and run on the desktop. So I dug in. Searched the Internet for about a week and tried everything I could find. Finally, after long hours and efforts, I managed to run my first ever "HelloCUDAWorld" program.
The motivation of creating this page is to lessen the hardships beginners face while getting acquainted with CUDA and GPU programming. I shall put in best of my efforts to include step by step process to integrate CUDA with Visual Studio and other such related issues. It is intended to be an open ended blog, mainly to encourage youth and researchers from Pakistan to study and take up this hugely important and vast area of research. Let's hope I can do a good job. =)