[Beignet] [PATCH 2/5] refine clCreateCommandQueue and clRetainCommandQueue.

junyan.he at inbox.com junyan.he at inbox.com
Thu Oct 13 08:40:54 UTC 2016


From: Junyan He <junyan.he at intel.com>

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_api.c               | 38 ------------------------------------
 src/cl_api_command_queue.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 src/cl_command_queue.c     | 34 ++++++++++++++++++++++----------
 src/cl_command_queue.h     | 11 ++++-------
 src/cl_context.c           | 26 -------------------------
 src/cl_context.h           |  6 ------
 6 files changed, 76 insertions(+), 87 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 03388ec..34242af 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -143,44 +143,6 @@ clReleaseDevice(cl_device_id device)
   return CL_SUCCESS;
 }
 
-cl_command_queue
-clCreateCommandQueue(cl_context                   context,
-                     cl_device_id                 device,
-                     cl_command_queue_properties  properties,
-                     cl_int *                     errcode_ret)
-{
-  cl_command_queue queue = NULL;
-  cl_int err = CL_SUCCESS;
-  CHECK_CONTEXT (context);
-
-  err = cl_devices_list_include_check(context->device_num, context->devices, 1, &device);
-  if (err)
-    goto error;
-
-  INVALID_VALUE_IF (properties & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE));
-
-  if(properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) {/*not supported now.*/
-    err = CL_INVALID_QUEUE_PROPERTIES;
-    goto error;
-  }
-
-  queue = cl_context_create_queue(context, device, properties, &err);
-error:
-  if (errcode_ret)
-    *errcode_ret = err;
-  return queue;
-}
-
-cl_int
-clRetainCommandQueue(cl_command_queue command_queue)
-{
-  cl_int err = CL_SUCCESS;
-  CHECK_QUEUE (command_queue);
-  cl_command_queue_add_ref(command_queue);
-error:
-  return err;
-}
-
 cl_mem
 clCreateBuffer(cl_context    context,
                cl_mem_flags  flags,
diff --git a/src/cl_api_command_queue.c b/src/cl_api_command_queue.c
index 0f458a3..c9403a4 100644
--- a/src/cl_api_command_queue.c
+++ b/src/cl_api_command_queue.c
@@ -16,9 +16,47 @@
  *
  */
 #include "cl_command_queue.h"
+#include "cl_device_id.h"
 #include "CL/cl.h"
 #include <stdio.h>
 
+cl_command_queue
+clCreateCommandQueue(cl_context context,
+                     cl_device_id device,
+                     cl_command_queue_properties properties,
+                     cl_int *errcode_ret)
+{
+  cl_command_queue queue = NULL;
+  cl_int err = CL_SUCCESS;
+
+  do {
+    if (!CL_OBJECT_IS_CONTEXT(context)) {
+      err = CL_INVALID_CONTEXT;
+      break;
+    }
+
+    err = cl_devices_list_include_check(context->device_num, context->devices, 1, &device);
+    if (err)
+      break;
+
+    if (properties & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE)) {
+      err = CL_INVALID_VALUE;
+      break;
+    }
+
+    if (properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) { /*not supported now.*/
+      err = CL_INVALID_QUEUE_PROPERTIES;
+      break;
+    }
+
+    queue = cl_create_command_queue(context, device, properties, &err);
+  } while (0);
+
+  if (errcode_ret)
+    *errcode_ret = err;
+  return queue;
+}
+
 cl_int
 clGetCommandQueueInfo(cl_command_queue command_queue,
                       cl_command_queue_info param_name,
@@ -75,6 +113,16 @@ clFinish(cl_command_queue command_queue)
 }
 
 cl_int
+clRetainCommandQueue(cl_command_queue command_queue)
+{
+  if (!CL_OBJECT_IS_COMMAND_QUEUE(command_queue)) {
+    return CL_INVALID_COMMAND_QUEUE;
+  }
+  cl_command_queue_add_ref(command_queue);
+  return CL_SUCCESS;
+}
+
+cl_int
 clReleaseCommandQueue(cl_command_queue command_queue)
 {
   if (!CL_OBJECT_IS_COMMAND_QUEUE(command_queue)) {
diff --git a/src/cl_command_queue.c b/src/cl_command_queue.c
index 7e7a854..d844af8 100644
--- a/src/cl_command_queue.c
+++ b/src/cl_command_queue.c
@@ -36,27 +36,41 @@
 #include <stdio.h>
 #include <string.h>
 
-LOCAL cl_command_queue
+static cl_command_queue
 cl_command_queue_new(cl_context ctx)
 {
   cl_command_queue queue = NULL;
 
   assert(ctx);
-  TRY_ALLOC_NO_ERR (queue, CALLOC(struct _cl_command_queue));
+  queue = cl_calloc(1, sizeof(_cl_command_queue));
+  if (queue == NULL)
+    return NULL;
+
   CL_OBJECT_INIT_BASE(queue, CL_OBJECT_COMMAND_QUEUE_MAGIC);
-  cl_command_queue_init_enqueue(queue);
+  if (cl_command_queue_init_enqueue(queue) != CL_SUCCESS) {
+    cl_free(queue);
+    return NULL;
+  }
 
   /* Append the command queue in the list */
   cl_context_add_queue(ctx, queue);
-  queue->ctx = ctx;
-  queue->cmrt_event = NULL;
+  return queue;
+}
 
-exit:
+LOCAL cl_command_queue
+cl_create_command_queue(cl_context ctx, cl_device_id device,
+                        cl_command_queue_properties properties, cl_int *errcode_ret)
+{
+  cl_command_queue queue = cl_command_queue_new(ctx);
+  if (queue == NULL) {
+    *errcode_ret = CL_OUT_OF_HOST_MEMORY;
+  }
+
+  queue->props = properties;
+  queue->device = device;
+
+  *errcode_ret = CL_SUCCESS;
   return queue;
-error:
-  cl_command_queue_delete(queue);
-  queue = NULL;
-  goto exit;
 }
 
 LOCAL void
diff --git a/src/cl_command_queue.h b/src/cl_command_queue.h
index 40127d6..830c150 100644
--- a/src/cl_command_queue.h
+++ b/src/cl_command_queue.h
@@ -40,7 +40,7 @@ typedef struct _cl_command_queue_enqueue_worker {
 typedef _cl_command_queue_enqueue_worker *cl_command_queue_enqueue_worker;
 
 /* Basically, this is a (kind-of) batch buffer */
-struct _cl_command_queue {
+typedef struct _cl_command_queue {
   _cl_base_object base;
   _cl_command_queue_enqueue_worker worker;
   cl_context ctx;                      /* Its parent context */
@@ -50,9 +50,7 @@ struct _cl_command_queue {
   cl_int barrier_events_size;          /* The size of array that wait_events point to */
   cl_command_queue_properties props;   /* Queue properties */
   cl_mem perf;                         /* Where to put the perf counters */
-
-  void* cmrt_event;                    /* the latest CmEvent* of the command queue */
-};
+} _cl_command_queue;
 
 #define CL_OBJECT_COMMAND_QUEUE_MAGIC 0x83650a12b79ce4efLL
 #define CL_OBJECT_IS_COMMAND_QUEUE(obj) ((obj &&                           \
@@ -60,9 +58,8 @@ struct _cl_command_queue {
          CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Allocate and initialize a new command queue. Also insert it in the list of
- * command queue in the associated context
- */
-extern cl_command_queue cl_command_queue_new(cl_context);
+ * command queue in the associated context */
+extern cl_command_queue cl_create_command_queue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*);
 
 /* Destroy and deallocate the command queue */
 extern void cl_command_queue_delete(cl_command_queue);
diff --git a/src/cl_context.c b/src/cl_context.c
index 378f4c3..8086231 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -418,32 +418,6 @@ cl_context_add_ref(cl_context ctx)
   CL_OBJECT_INC_REF(ctx);
 }
 
-LOCAL cl_command_queue
-cl_context_create_queue(cl_context ctx,
-                        cl_device_id device,
-                        cl_command_queue_properties properties, /* XXX */
-                        cl_int *errcode_ret)
-{
-  cl_command_queue queue = NULL;
-  cl_int err = CL_SUCCESS;
-
-
-
-  /* We create the command queue and store it in the context list of queues */
-  TRY_ALLOC (queue, cl_command_queue_new(ctx));
-  queue->props = properties;
-  queue->device = device;
-
-exit:
-  if (errcode_ret)
-    *errcode_ret = err;
-  return queue;
-error:
-  cl_command_queue_delete(queue);
-  queue = NULL;
-  goto exit;
-}
-
 cl_buffer_mgr
 cl_context_get_bufmgr(cl_context ctx)
 {
diff --git a/src/cl_context.h b/src/cl_context.h
index 4e7c2e8..d829991 100644
--- a/src/cl_context.h
+++ b/src/cl_context.h
@@ -158,12 +158,6 @@ extern void cl_context_add_ref(cl_context);
 extern cl_int cl_context_properties_process(const cl_context_properties *prop,
                                             struct _cl_context_prop *cl_props, cl_uint * prop_len);
 
-/* Create the command queue from the given context and device */
-extern cl_command_queue cl_context_create_queue(cl_context,
-                                                cl_device_id,
-                                                cl_command_queue_properties,
-                                                cl_int*);
-
 /* Enqueue a ND Range kernel */
 extern cl_int cl_context_ND_kernel(cl_context,
                                    cl_command_queue,
-- 
2.7.4





More information about the Beignet mailing list