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 "". (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.

No comments:

Post a comment