OpenCL book PDF

3.2 Developing Environment Setup

This section will walk through the setup process of FOXC, Apple, and NVIDIA OpenCL.

FOXC Setup

This setup procedure assumes the installation of FOXC in a 64-bit Linux environment, under the directory "/usr/local". FOXC can be downloaded for free from the Fixstars website: open_in_new.

The install package can be uncompressed as follows.

>tar -zxf foxc-install-linux64.tar.gz -C /usr/local

The following environmental variables must be set.

List 3.1: CShell

setenv PATH /usr/local/foxc-install/bin:${PATH}
setenv LD_LIBRARY_PATH /usr/local/foxc-install/lib

List 3.2: Bourne Shell

export PATH=/usr/local/foxc-install/bin:${PATH}
export LD_LIBRARY_PATH=/usr/local/foxc-install/lib:${LD_LIBRARY_PATH}

This completes the installation of FOXC.

Apple OpenCL Setup

Mac OS X 10.6 (Snow Leopard) is required to use the Apple OpenCL. Also, since OS X does not have the necessary development toolkits (e.g. GCC) at default, these kits must first be downloaded from Apple's developer site.

Download the latest version of "Xcode" at open_in_new (Figure 3.1). Xcode is a free IDE distributed by Apple, and this includes every tools required to start developing an OpenCL application. As of this writing (March 2010), the latest Xcode version is 3.2.1. You will need an ADC (Apple Developer Connection) account to download this file. The ADC Online account can be created for free.

Figure 3.1: Apple Developer Connection: open_in_new

Double click the downloaded .dmg file, which automatically mounts the archive under /Volumes. The archive can be viewed from the Finder. You should see a file called "Xcode.mpkg" (the name can vary depending on the Xcode version, however) (Figure 3.2).

Figure 3.2: Xcode Archive Content

This file is the installation package for Xcode. Double click this file to start the installer. Most of the installation procedure is self-explanatory, but there is one important step. On the screen shown in Figure 3.3, make sure that the box for "UNIX Dev Support" is checked.

Figure 3.3: Custom Installation Screen

Continue onward after making sure that the above box is checked. When you reach the screen shown in Figure 3.4, the installation has finished successfully. You may now use OpenCL on Mac OS X.

Figure 3.4: Successful Xcode installation


NVIDIA OpenCL is supported in multiple platforms. The installation procedure will be split up into that for Linux, and for Windows.

Install NVIDIA OpenCL on Linux

This section will walk through the installation procedure for 64-bit CentOs 5.3. First, you should make sure that your GPU is CUDA-enabled. Type the following on the command line to get the GPU type (# means run as root).

# lspci | grep -i nVidia

The list of CUDA-Enabled GPUs can be found online at the NVIDIA CUDA Zone: open_in_new.

NVIDIA OpenCL uses GCC as the compiler. Make sure GCC is installed, and that its version is 3.4 or 4.x prior to 4.2. Type the following on the command line.

> gcc --version

If you get an error message such as "command not found: gcc", then GCC is not installed. If the version is not supported for CUDA, an upgrade or a downgrade is required.

Next, go to the NVIDIA OpenCL download page: open_in_new (Figure 3.5). Downloading from this site requires user registration. Download the following 2 files.

  • NVIDIA Drivers for Linux (64-bit):
  • GPU Computing SDK code samples and more:

The following is optional, but will prove to be useful.

  • OpenCL Visual Profiler v1.0 Beta (64-bit): openclprof_1.0-beta_linux_64.tar.gz

Figure 3.5: NVIDIA OpenCL download page

First install the driver. This requires the X Window System to be stopped. If you are using a display manager, this must be stopped, since it automatically restarts the X Window System. Type the following command as root if using gdb.

# service gdm stop

Type the following to run Linux in command-line mode.

# init 3

Execute the downloaded file using shell.

# sh

You will get numerous prompts, which you can answer "OK" unless you are running in a special environment. Restart the X Window System after a successful installation.

# startx

At this point, log off as root, and log back in as a user, as this is required to install the "GPU Computing SDK code samples and more" package. Type the following on the command line.

> sh

You will be prompted for an install directory, which is $HOME by default. This completes the installation procedure for Linux.

Install NVIDIA OpenCL on Windows

This section will walk through the installation on 32-bit Windows Vista.

The GPU type can be verified on the "Device Manager", under "Display Adapter". Go to the CUDA-Enabled GPU list (link given in the Linux section) to make sure your GPU is supported.

Building of the SDK samples requires either Microsoft Visual Studio 8 (2005) or Visual Studio 9 (2008) (Express Edition and above). Make sure this is installed.

Next, go to the NVIDIA OpenCL download page: open_in_new (Figure 3.5). Downloading from this site requires user registration. Download the following 2 files.

  • NVIDIA Drivers for WinVista and Win7 (190.89): nvdrivers_2.3_winvista_32_190.89_general.exe
  • GPU Computing SDK code samples and more: gpucomputingsdk_2.3b_win_32.exe

The following is optional, but will prove to be useful.

  • OpenCL Visual Profiler v1.0 Beta (64-bit):

Double click the download executable for the NVIDIA driver in order to start the installation procedure. Restart your PC when prompted, after the NVIDIA driver is installed.

Next, install the GPU Computing SDK. Installation of the SDK requires user registration. After installation is completed successfully, the SDK will be installed in the following directories:

  • Windows XP
    C:\Documents an Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL
  • Windows Vista / Windows 7
    C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\OpenCL

Restart your system after the SDK installation.

You should now be able to run the OpenCL sample program inside the SDK. To do so, double click on the “ NVIDIA GPU Computing SDK Browser” icon which should have been created on your desktop. You will see a list of all the sample programs in the SDK. Open the “OpenCL Samples ” tab to see all the sample code written in OpenCL. The sample code is listed in increasing level of difficulty. Some samples include a “Whitepaper ”, which is a detailed technical reference for that sample.

Syntax highlighting of OpenCL code on Visual Studio is not supported by default. The following procedure will enable syntax highlighting.

1. Copy usertype.dat

Under the “doc” folder found inside the SDK installation directory, you should see a file called “usertype.dat.” Copy this file to the following directory.

If running on 32-bit Windows

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE (VC8)
C:\Program Files\Microsoft Visual Studio 9\Common7\IDE (VC9)

If running on 64-bit Windows

C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE (VC8)
C:\Program Files (x86)\Microsoft Visual Studio 9\Common7\IDE (VC9)

If “usertype.dat” already exists in the directory, use an editor to append the content of NVIDIA SDK's “usertype.dat” to the existing file.

2. Visual Studio Setup

Start Visual Studio, go to the "Tool" Menu Bar, and then click on "Option". On the left panel, select "Text Editor", then "File Extension". On the right panel, type ".cl" to the box labeled "Extension". Select "Microsoft Visual C++" on the drop-down menu, and then click the "Add" button.

Visual Studio will now perform syntax highlighting on .cl files.

When developing an OpenCL program, the required files for building are located as follows.

  • Header File (Default: "NVIDIA GPU Computing SDK\OpenCL\common\inc\CL")
    cl.h, cl_gl.h, cl_platform.h, clext.h
  • Library (Default: "NVIDIA GPU Computing SDK\OpenCL\common\lib\[Win32|x64]"
    OpenCL.lib (32-bit version and 64-bit versions exist)
  • Dynamic Link Library (Default: "\Windows\system32")

If an application explicitly specifies the link to OpenCL.dll, OpenCL.lib is not required at runtime.


Fixstars  Solutions

Social Links