Hi,
I've decided to create this short tutorial to help programmers to setup Visual Studio 2008 as an OpenCL developement environment.
Notice that I'm using the NVIDIA version of OpenCL (CUDA SDK 3.0), installed in the default path (C:\Documents and Settings\All Users\Dados de aplicativos\NVIDIA Corporation\, which from now on will be referenced as ~\NVIDIA Corporation). If you are using ATI drivers, other NVIDIA driver or other Windows version (I'm using XP) you may have to update the paths.

1. Configuring Appearance:

1.1. OpenCL files as C++ files:
In VS2008,
- Go Tools->Options->Text Editor->File Extension, add a new extension "cl" and select Microsoft Visual C++ as Editor. This will enable C++ syntax highlighting on OpenCL files;
- If you wish, you can also add "cu" extensions for CUDA

1.2. Syntax highlighting (for OpenCL reserved words)
- This should be done using a file called "usertype.dat", located at ~\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL\doc, which contains all OpenCL reserved words
- Copy this file to ~\Program Files\Microsoft Visual Studio 9.0\Common7\IDE (again, it may change depending on your OS version)
- This can be done also for CUDA reserved words. CUDA configuration file is at ~\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\doc\syntaxhighlighting\visualstudio_8 (its also called "usertype.dat"
- IMPORTANT NOTE: if there is already an "usertype.dat" on your VS folder (what should happen when adding CUDA and OpenCL files), you should merge both (copying the content of one and pasting at the end of the other)

2. Setting Up a Project

All you must do to use VS and OpenCL is configure correctly the dependencies. After creating a new VC project, right click on the project->properties (also available up in the menu or with the shortcut ALT+F7
1. At Configuration Properties->C++->General->Additional Include Directories add:
  • "~\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL\common\inc";
  • "~\NVIDIA Corporation\NVIDIA GPU Computing SDK\shared\inc";

2. At Linker->General->Additional Library Directories add:
  • "~\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL\common\lib";
  • "~\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL\common\lib\Win32"; (if you are using Windows)
  • "~\NVIDIA Corporation\NVIDIA GPU Computing SDK\shared\lib";

3. At Linker->Input->Additional Dependencies add
  • shrUtils32D.lib
  • oclUtils32D.lib
  • OpenCL.lib

3. Configuring Code Generation Properties

We're almost ready to use OpenCL now. The final step you need to do is clicking on Project->Properties, and then Configuration Properties->C/C++->Code Generation. You must assert the property "Runtime Library" is set to "Multi-threaded Debug (/MTd)". This property specifies wheter the Runtime Library will be statically or dynamically linked to your project. If your project and the libraries it uses are compiled and linked with different runtime libraries, some weird linker errors will happen. Since the '.libs' we just added uses the static runtime library, our project needs to use it as well. More information about this can be found in http://www.cs.unc.edu/~lhp/personal/how2CompileInVC.html.

It's ready. You may now be able to create and compile successfully an OpenCL project using VS2008

Feel free to contact us if you have any doubts.

Leonardo, Bruno

Last edited Jul 30, 2010 at 5:50 PM by bjurkovski, version 7

Comments

heba11 Jan 27, 2013 at 2:26 PM 
Hi
i have followed all the steps you mentioned ,but i still can not create a new opencl project in VC++,
Please can you help me .
i have nvidia GT 630m GPU and VC++ 2008 and CUDA toolkit 4.