summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--get_global_id.c11
-rw-r--r--util.c17
-rw-r--r--util.h2
3 files changed, 20 insertions, 10 deletions
diff --git a/get_global_id.c b/get_global_id.c
index 65e20d4..34fd753 100644
--- a/get_global_id.c
+++ b/get_global_id.c
@@ -29,19 +29,10 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
- command_queue = clCreateCommandQueue(context,
- device_id,
- 0, /* Command queue properties */
- &error); /* Error code */
-
- if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateCommandQueue() failed: %s\n",
- cluErrorString(error));
+ if (!cluCreateCommandQueue(&command_queue, context, device_id)) {
return EXIT_FAILURE;
}
- fprintf(stderr, "clCreateCommandQueue() succeeded.\n");
-
if (!cluCreateKernel(context, device_id, &kernel, "global_id")) {
return EXIT_FAILURE;
}
diff --git a/util.c b/util.c
index 3c0339d..e85bda1 100644
--- a/util.c
+++ b/util.c
@@ -106,6 +106,23 @@ unsigned cluCreateContext(cl_context * context, cl_device_id device_id)
return 1;
}
+unsigned cluCreateCommandQueue(cl_command_queue * command_queue,
+ cl_context context, cl_device_id device_id)
+{
+ cl_int error;
+ *command_queue = clCreateCommandQueue(context,
+ device_id,
+ 0, /* Command queue properties */
+ &error); /* Error code */
+
+ if (error != CL_SUCCESS) {
+ fprintf(stderr, "clCreateCommandQueue() failed: %s\n",
+ cluErrorString(error));
+ return 0;
+ }
+ return 1;
+}
+
#define CODE_CHUNK 64
unsigned cluCreateKernel(cl_context context, cl_device_id device_id,
diff --git a/util.h b/util.h
index 4fa074f..7589655 100644
--- a/util.h
+++ b/util.h
@@ -2,6 +2,8 @@
const char * cluErrorString(cl_int error);
unsigned cluInitGpuDevice(cl_device_id * device_id);
unsigned cluCreateContext(cl_context * context, cl_device_id device_id);
+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 cluKernelSetArg(cl_kernel kernel, cl_uint index, size_t size,