PDA

View Full Version : Chapter 2, example 1: Testing platform extensions



Petr Schreiber
19-09-2012, 08:42
The first strange new word from OpenCL world is "platform".

Platform is set of OpenCL runtimes provided by each hardware vendor.

For example, on my PC I have installed NVIDIA GeForce card and Intel Core 2 Duo CPU. Both NVIDIA and Intel support OpenCL, so after installing drivers for GPU and SDK for CPU I have two platforms on my PC.

When doing calculation, you are free to choose which platform to use for your computations. The first step is to get to know, what is installed, and that is what the following example gives you info about.

OpenCL has strictly defined functionality, but each hardware vendor can provide extensions to it. The example lists names of extensions as well, what they are good for you don't need to worry as of now, we will look into that later.

Comparing to the book original, I added platform name retrieving routines to the example, to make it more clear "what is what"

So what I learn?
How to enumerate OpenCL platforms on your PC.

So what I need to run it?
You will need the latest ThinBASIC and OpenCL headers (http://www.thinbasic.com/community/showthread.php?10159-OpenCL-Headers-Updated-Sep-15-2011) to run it + of course modern GPU or CPU (http://www.thinbasic.com/community/showthread.php?10161-OpenCL-Supported-hardware).

Code listing (full code in attachement!)


' -- NOTE: Enhanced to list the info for all installed platforms, which have name info added

Uses "Console"

#INCLUDE "%APP_INCLUDEPATH%/cl/cl.tBasicU"

Function TBMain()

/* Host data structures */
tcl_platform_id platforms()
tcl_uint num_platforms
tcl_int i, ErrCL, platform_index = -1

/* Extension data */
String ext_data
tSize ext_size
String icd_ext = "cl_khr_icd"

/* Find number of platforms */
ErrCL = clGetPlatformIDs(1, ByVal NULL, num_platforms)
If (ErrCL < 0) Then
pError("Couldn't find any platforms.")
APP_SetReturnCode(1) : WaitKey : Exit Function
End If

/* Access all installed platforms */
ReDim platforms(num_platforms)
clGetPlatformIDs(num_platforms, platforms, ByVal NULL)

/* Platform name */
Dim szName As Asciiz * 512

/* Find extensions of all platforms */
For i = 1 To num_platforms

clGetPlatformInfo(platforms(i),
CL_PLATFORM_NAME, 512, ByVal VarPtr(szName), ByVal NULL)
PrintL "Platform #"+Format$(i) + ": " + szName

/* Find size of extension data */
ErrCL = clGetPlatformInfo(platforms(i),
CL_PLATFORM_EXTENSIONS, 0, ByVal NULL, ext_size)
If (ErrCL < 0) Then
pError("Couldn't read extension data.")
''APP_SetReturnCode(1) : WaitKey : Exit Function
Else

/* Access extension data */
ext_data = Repeat$(ext_size, $NUL)
clGetPlatformInfo(platforms(i), CL_PLATFORM_EXTENSIONS,
ext_size, ByVal StrPtr(ext_data), ByVal NULL)
PrintL StrFormat$("Supported extensions: {1}", $CRLF+Replace$(ext_data, " ", $CRLF))

ext_data = ""
End If
Next

PrintL
PrintL "Press any key to continue..."
WaitKey
APP_SetReturnCode(0)

End Function

Function pError( sError As String )

Console_SetTextAttribute(%CONSOLE_FOREGROUND_RED | %CONSOLE_FOREGROUND_INTENSITY)
PrintL sError
Console_SetTextAttribute(%CONSOLE_FOREGROUND_RED | %CONSOLE_FOREGROUND_GREEN | %CONSOLE_FOREGROUND_BLUE)

End Function

kryton9
20-09-2012, 03:05
Thanks for program 2 Petr. As you know, in my notebook I have nVidia optimus. That is both an nVidia video card and intel video card. Optimus switches automatically when higher video power is needed. The CPU is Intel Core i7-2670QM.
I expected to see something like your results but this is all I got.

Petr Schreiber
20-09-2012, 09:27
Hi Kent,

I think it is correct - that is what you get by default. To make Intel CPU operable, you need to install Intel OpenCL SDK (32 bit version) from here: http://software.intel.com/en-us/vcsource/tools/opencl-sdk


Petr

kryton9
21-09-2012, 08:20
Thanks Petr, never thought about needing special drivers.

Petr Schreiber
21-09-2012, 08:31
Yes, it is a bit strange :) Can you see the Intel platform now?


Petr