part3.c 1.1 KB
#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: