summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2012-03-13 11:25:41 -0400
committerTom Stellard <thomas.stellard@amd.com>2012-03-13 11:25:41 -0400
commit5534a6e31678de2aa37d6ff4f8c9b9b8229100c9 (patch)
tree6130448573e53d1b6e2a5118beb39c05795f9163
parentd2b31e6b570e2cc3b4fd0237037d93129e9422bc (diff)
Add cluSimpleInit
-rw-r--r--get_global_id.c18
-rw-r--r--util.c23
-rw-r--r--util.h1
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);