diff options
-rw-r--r-- | get_global_id.c | 18 | ||||
-rw-r--r-- | util.c | 23 | ||||
-rw-r--r-- | util.h | 1 |
3 files changed, 25 insertions, 17 deletions
diff --git a/get_global_id.c b/get_global_id.c index 2f6f266..1b41809 100644 --- a/get_global_id.c +++ b/get_global_id.c @@ -17,23 +17,7 @@ int main(int argc, char ** argv) int out_data[10]; size_t global_work_size = 10; - if (!cluInitGpuDevice(&context.device_id)) { - return EXIT_FAILURE; - } - - if (!cluCreateContext(&context.cl_ctx, context.device_id)) { - return EXIT_FAILURE; - } - - if (!cluCreateCommandQueue(&context.command_queue, context.cl_ctx, - context.device_id)) { - return EXIT_FAILURE; - } - - if (!cluCreateKernel(context.cl_ctx, context.device_id, &context.kernel, - "global_id")) { - return EXIT_FAILURE; - } + cluSimpleInit(&context, "global_id"); out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, /* Flags */ @@ -232,6 +232,29 @@ unsigned cluCreateKernel(cl_context context, cl_device_id device_id, return 1; } +unsigned cluSimpleInit(struct clu_context * context, const char * kernel_name) +{ + if (!cluInitGpuDevice(&context->device_id)) { + return 0; + } + + if (!cluCreateContext(&context->cl_ctx, context->device_id)) { + return 0; + } + + if (!cluCreateCommandQueue(&context->command_queue, context->cl_ctx, + context->device_id)) { + return 0; + } + + if (!cluCreateKernel(context->cl_ctx, context->device_id, &context->kernel, + kernel_name)) { + return 0; + } + + return 1; +} + unsigned cluKernelSetArg(cl_kernel kernel, cl_uint index, size_t size, const void * value) { @@ -13,5 +13,6 @@ unsigned cluCreateCommandQueue(cl_command_queue * command_queue, cl_context context, cl_device_id device_id); unsigned cluCreateKernel(cl_context context, cl_device_id device_id, cl_kernel * kernel, const char * kernel_name); +unsigned cluSimpleInit(struct clu_context * context, const char * kernel_name); unsigned cluKernelSetArg(cl_kernel kernel, cl_uint index, size_t size, const void * value); |