part3.c
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
int main() {
cl_platform_id platform;
cl_device_id device;
cl_context context;
cl_uint refCount;
// get first available platform
clGetPlatformIDs(1, &platform, NULL);
// get first available gpu device
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
// create context
context = clCreateContext(NULL, 1, &device, NULL, NULL, NULL);
// get context reference count
clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
sizeof(refCount), &refCount, NULL);
printf("Ref count: %u ", refCount);
// increment reference count
clRetainContext(context);
clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
sizeof(refCount), &refCount, NULL);
printf(">> %u ", refCount);
// decrement reference count
clReleaseContext(context);
clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT,
sizeof(refCount), &refCount, NULL);
printf(">> %u ", refCount);
// finally release context
clReleaseContext(context);
printf(">> 0\n");
return 0;
}
// vim: set ft=c ts=4 sw=4: