opencl-template/main.c

54 lines
1.3 KiB
C
Raw Normal View History

2018-04-23 09:09:14 +02:00
#include <stdio.h>
#include <CL/cl.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
cl_int error;
cl_platform_id *platform_ids = NULL;
cl_device_id *device_ids = NULL;
cl_uint platform_id_count = 0;
cl_uint device_id_count = 0;
cl_context_properties context_properties[4];
cl_context context;
clGetPlatformIDs (0, NULL, &platform_id_count);
if (platform_id_count == 0)
return -1;
platform_ids = (cl_platform_id*) malloc(platform_id_count *
sizeof(cl_platform_id));
if (platform_ids == NULL)
return -1;
clGetPlatformIDs (platform_id_count, platform_ids, NULL);
printf("Platforms available: %u\n", (unsigned int)platform_id_count);
clGetDeviceIDs (platform_ids[0], CL_DEVICE_TYPE_ALL, 0, NULL,
&device_id_count);
printf("Device in Platform 0 count: %u\n", (unsigned int)device_id_count);
if (device_id_count == 0)
return -1;
device_ids = (cl_device_id*) malloc(sizeof(cl_device_id)*device_id_count);
clGetDeviceIDs (platform_ids[0], CL_DEVICE_TYPE_ALL, device_id_count,
device_ids, NULL);
context_properties[0] = CL_CONTEXT_PLATFORM;
context_properties[1] = (cl_context_properties)platform_ids[0];
context_properties[2] = context_properties[3] = 0;
context = clCreateContext (context_properties, device_id_count,
device_ids, NULL,
NULL, &error);
return 0;
}