diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2012-03-13 11:22:09 -0400 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2012-03-13 11:22:09 -0400 |
commit | d2b31e6b570e2cc3b4fd0237037d93129e9422bc (patch) | |
tree | 614b16da6e2bf1f51c203796f2b87b35867a40e4 | |
parent | d290aedf15294fc815746fe9c2931fe153c708b1 (diff) |
Add struct clu_context
-rw-r--r-- | get_global_id.c | 28 | ||||
-rw-r--r-- | util.h | 7 |
2 files changed, 20 insertions, 15 deletions
diff --git a/get_global_id.c b/get_global_id.c index 34fd753..2f6f266 100644 --- a/get_global_id.c +++ b/get_global_id.c @@ -3,17 +3,13 @@ #include <CL/cl.h> +#include "util.h" int main(int argc, char ** argv) { cl_int error; - cl_device_id device_id; - cl_context context; - - cl_command_queue command_queue; - - cl_kernel kernel; + struct clu_context context; cl_mem out_buffer; @@ -21,23 +17,25 @@ int main(int argc, char ** argv) int out_data[10]; size_t global_work_size = 10; - if (!cluInitGpuDevice(&device_id)) { + if (!cluInitGpuDevice(&context.device_id)) { return EXIT_FAILURE; } - if (!cluCreateContext(&context, device_id)) { + if (!cluCreateContext(&context.cl_ctx, context.device_id)) { return EXIT_FAILURE; } - if (!cluCreateCommandQueue(&command_queue, context, device_id)) { + if (!cluCreateCommandQueue(&context.command_queue, context.cl_ctx, + context.device_id)) { return EXIT_FAILURE; } - if (!cluCreateKernel(context, device_id, &kernel, "global_id")) { + if (!cluCreateKernel(context.cl_ctx, context.device_id, &context.kernel, + "global_id")) { return EXIT_FAILURE; } - out_buffer = clCreateBuffer(context, + out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, /* Flags */ sizeof(out_data), /* Size of buffer */ NULL, /* Pointer to the data */ @@ -50,12 +48,12 @@ int main(int argc, char ** argv) fprintf(stderr, "clCreateBuffer() succeeded.\n"); - if ( !cluKernelSetArg(kernel, 0, sizeof(cl_mem), &out_buffer)) { + if ( !cluKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) { return EXIT_FAILURE; } - error = clEnqueueNDRangeKernel(command_queue, - kernel, + error = clEnqueueNDRangeKernel(context.command_queue, + context.kernel, 1, /* Number of dimensions */ NULL, /* Global work offset */ &global_work_size, @@ -72,7 +70,7 @@ int main(int argc, char ** argv) fprintf(stderr, "clEnqueueNDRangeKernel() suceeded.\n"); - error = clEnqueueReadBuffer(command_queue, + error = clEnqueueReadBuffer(context.command_queue, out_buffer, CL_TRUE, /* TRUE means it is a blocking read. */ 0, /* Buffer offset to read from. */ @@ -1,4 +1,11 @@ +struct clu_context { + cl_device_id device_id; + cl_context cl_ctx; + cl_command_queue command_queue; + cl_kernel kernel; +}; + const char * cluErrorString(cl_int error); unsigned cluInitGpuDevice(cl_device_id * device_id); unsigned cluCreateContext(cl_context * context, cl_device_id device_id); |