' -- NOTE: Enhanced to list the info for all installed platforms, with name + types of devices
Uses "Console"
#INCLUDE "%APP_INCLUDEPATH%/cl/cl.tBasicU"
Function TBMain()
/* Host/device data structures */
tcl_platform_id platforms()
tcl_platform_id platform
tcl_uint num_platforms
tcl_device_id devices()
tcl_uint num_devices, addr_data
tcl_int i, ErrCl, p
tcl_device_type deviceType
/* Extension data */
String name_data = Repeat$(48, " ")
String ext_data = Repeat$(4096, " ")
String deviceTypeDescriptor
/* 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
Dim versionCL As Asciiz * 64
For p = 1 To num_platforms
platform = platforms(p)
clGetPlatformInfo(platform,
CL_PLATFORM_NAME, sizeof(szName), ByVal VarPtr(szName), ByVal NULL)
PrintL "List of devices for platform #"+Format$(p) + ": " + szName
/* Determine number of connected devices */
ErrCl = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, ByVal NULL, num_devices)
If (ErrCl < 0) Or num_devices = 0 Then
pError("Couldn't find any devices")
Else
/* Access connected devices */
ReDim devices(num_devices)
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL,
num_devices, devices, ByVal NULL)
/* Obtain data for each connected device */
For i = 1 To num_devices
ErrCl = clGetDeviceInfo(devices(i), CL_DEVICE_NAME,
Len(name_data), ByVal StrPtr(name_data), ByVal NULL)
If (ErrCl < 0) Then
pError("Couldn't read extension data")
APP_SetReturnCode(1) : WaitKey : Exit Function
End If
ErrCl = clGetDeviceInfo(devices(i), CL_DEVICE_VERSION,
SizeOf(versionCL), ByVal StrPtr(versionCL), ByVal NULL)
clGetDeviceInfo(devices(i), CL_DEVICE_ADDRESS_BITS,
SizeOf(ext_data), addr_data, ByVal NULL)
clGetDeviceInfo(devices(i), CL_DEVICE_TYPE,
SizeOf(deviceType), ByVal VarPtr(deviceType), ByVal NULL)
deviceTypeDescriptor = ""
If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_DEFAULT)) Then deviceTypeDescriptor += "DEFAULT "
If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_CPU)) Then deviceTypeDescriptor += "CPU "
If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_GPU)) Then deviceTypeDescriptor += "GPU "
If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_ACCELERATOR)) Then deviceTypeDescriptor += "ACCELERATOR "
clGetDeviceInfo(devices(i), CL_DEVICE_EXTENSIONS,
Len(ext_data), ByVal StrPtr(ext_data), ByVal NULL)
PrintL StrFormat$("NAME: {1}"+$CRLF+"TYPE: {2} ({3})"+$CRLF+"ADDRESS_WIDTH: {4}"+$CRLF+"EXTENSIONS: {5}",
Trim$(name_data), deviceTypeDescriptor, versionCL, Trim$(addr_data), $CRLF+Replace$(TrimFull$(ext_data), " ", $CRLF))
PrintL
Next
End If
PrintL
Next
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
Bookmarks