From 5534a6e31678de2aa37d6ff4f8c9b9b8229100c9 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 13 Mar 2012 11:25:41 -0400 Subject: Add cluSimpleInit --- get_global_id.c | 18 +----------------- util.c | 23 +++++++++++++++++++++++ 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 */ diff --git a/util.c b/util.c index e85bda1..8989dce 100644 --- a/util.c +++ b/util.c @@ -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) { diff --git a/util.h b/util.h index 9ecad93..5a1d2f5 100644 --- a/util.h +++ b/util.h @@ -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); -- cgit v1.2.3