Uses
"Console"
#INCLUDE "%APP_INCLUDEPATH%/cl/cl.tBasicU"
Function
TBMain
()
/* Host/device data structures */
tcl_platform_id platform
tcl_device_id device
tcl_context context
tcl_int ErrCl
tcl_uint ref_count
/* Access the first installed platform */
ErrCl = clGetPlatformIDs(1, platform,
Byval
Null
)
if
(ErrCl < 0)
Then
pError(
"Couldn't find any platforms"
)
APP_SetReturnCode(1) :
WaitKey
:
Exit
Function
End
If
/* Access the first available device */
ErrCl = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, device,
ByVal
NULL
)
If
(ErrCl = CL_DEVICE_NOT_FOUND)
Then
ErrCl = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, device,
ByVal
NULL
)
End
If
if
(ErrCl < 0)
Then
pError(
"Couldn't find any devices"
)
APP_SetReturnCode(1) :
WaitKey
:
Exit
Function
End
If
/* Create the context */
context = clCreateContext(
ByVal
NULL
, 1, device,
ByVal
NULL
,
ByVal
NULL
, ErrCl)
if
(ErrCl < 0)
Then
pError(
"Couldn't create a context"
)
APP_SetReturnCode(1) :
WaitKey
:
Exit
Function
End
If
/* Determine the reference count */
ErrCl = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
SizeOf
(ref_count),
VarPtr
(ref_count),
ByVal
NULL
)
If
(ErrCl < 0)
Then
pError(
"Couldn't read the reference count."
)
APP_SetReturnCode(1) :
WaitKey
:
Exit
Function
End
If
PrintL
StrFormat
$(
"Initial reference count: {1}"
, ref_count)
/* Update
and
display the reference count */
clRetainContext(context)
clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
SizeOf
(ref_count),
VarPtr
(ref_count),
ByVal
NULL
)
PrintL
StrFormat
$(
"Reference count: {1}"
, ref_count)
clReleaseContext(context)
clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
SizeOf
(ref_count),
VarPtr
(ref_count),
ByVal
NULL
)
PrintL
StrFormat
$(
"Reference count: {1}"
, ref_count)
clReleaseContext(context)
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