Commit 3ef76ba7 authored by Christoph Gerum's avatar Christoph Gerum

Started opencl pi

parent dac7eb52
File added
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h>
char *pi_kernel_source= "\n" \
"__kernel void pi( \n" \
" __global float *buffer, \n" \
" const unsigned int count) \n" \
"{ \n" \
" int i = get_global_id(0); \n" \
" if(i < count){ \n" \
" output[i] = input[i] * input[i]; \n" \
" } \n" \
"} \n" \
"\n";
int main(int argc, char **argv){
cl_uint platform_id_count = 0;
clGetPlatformIDs (0, 0, &platform_id_count);
printf("System has %d opencl Platforms\n", platform_id_count);
cl_platform_id *platform_ids = malloc(platform_id_count *
sizeof(cl_platform_id));
clGetPlatformIDs (platform_id_count, platform_ids, 0);
cl_uint device_id_count = 0;
clGetDeviceIDs (platform_ids [0], CL_DEVICE_TYPE_ALL, 0, 0,
&device_id_count);
cl_device_id *device_ids = malloc(device_id_count
* sizeof(cl_device_id));
clGetDeviceIDs (platform_ids [0], CL_DEVICE_TYPE_ALL, device_id_count,
device_ids, 0);
cl_context context;
context = clCreateContext(0, 1, device_ids, 0, 0, 0);
cl_command_queue commands;
commands = clCreateCommandQueue(context, device_ids[0], 0, 0);
cl_program program;
program = clCreateProgramWithSource(context, 1, (const char **) &pi_kernel_source, 0, 0);
if (!program) {
printf("Error: Failed to create compute program!\n");
return -1;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment