[Beignet] [PATCH V2] Fix a bug for event error status.

junyan.he at inbox.com junyan.he at inbox.com
Thu Sep 29 10:04:32 UTC 2016


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

V2:
  Move the event list status check to clWaitForEvents API.

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_api.c       |  5 +++--
 src/cl_api_event.c |  8 ++++++++
 src/cl_event.c     | 18 ++++++++++--------
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index f8c48de..1d4c5a1 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1280,6 +1280,7 @@ clGetEventInfo(cl_event      event,
                size_t *      param_value_size_ret)
 {
   cl_int err = CL_SUCCESS;
+  cl_int status;
   CHECK_EVENT(event);
 
   if (param_name == CL_EVENT_COMMAND_QUEUE) {
@@ -1289,8 +1290,8 @@ clGetEventInfo(cl_event      event,
   } else if (param_name == CL_EVENT_COMMAND_TYPE) {
     FILL_GETINFO_RET (cl_command_type, 1, &event->event_type, CL_SUCCESS);
   } else if (param_name == CL_EVENT_COMMAND_EXECUTION_STATUS) {
-    cl_event_get_status(event);
-    FILL_GETINFO_RET (cl_int, 1, &event->status, CL_SUCCESS);
+    status = cl_event_get_status(event);
+    FILL_GETINFO_RET (cl_int, 1, &status, CL_SUCCESS);
   } else if (param_name == CL_EVENT_REFERENCE_COUNT) {
     cl_uint ref = CL_OBJECT_GET_REF(event);
     FILL_GETINFO_RET (cl_int, 1, &ref, CL_SUCCESS);
diff --git a/src/cl_api_event.c b/src/cl_api_event.c
index aec2cdf..63bccf2 100644
--- a/src/cl_api_event.c
+++ b/src/cl_api_event.c
@@ -190,6 +190,7 @@ clWaitForEvents(cl_uint num_events,
                 const cl_event *event_list)
 {
   cl_int err = CL_SUCCESS;
+  cl_uint i;
 
   if (num_events == 0 || event_list == NULL) {
     return CL_INVALID_VALUE;
@@ -200,6 +201,13 @@ clWaitForEvents(cl_uint num_events,
     return err;
   }
 
+  for (i = 0; i < num_events; i++) {
+    if (cl_event_get_status(event_list[i]) < CL_COMPLETE) {
+      err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
+      return err;
+    }
+  }
+
   err = cl_event_wait_for_events_list(num_events, event_list);
   return err;
 }
diff --git a/src/cl_event.c b/src/cl_event.c
index 4acd619..0804dbd 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -436,6 +436,8 @@ cl_event_wait_for_events_list(cl_uint num_events, const cl_event *event_list)
     while (e->status > CL_COMPLETE) {
       CL_OBJECT_WAIT_ON_COND(e);
     }
+
+    assert(e->status <= CL_COMPLETE);
     /* Iff some error happened, return the error. */
     if (e->status < CL_COMPLETE) {
       ret = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
@@ -467,16 +469,11 @@ cl_event_check_waitlist(cl_uint num_events_in_wait_list, const cl_event *event_w
 
     /* check the event and context */
     for (i = 0; i < num_events_in_wait_list; i++) {
-      if (event_wait_list[i] == NULL || !CL_OBJECT_IS_EVENT(event_wait_list[i])) {
+      if (!CL_OBJECT_IS_EVENT(event_wait_list[i])) {
         err = CL_INVALID_EVENT;
         break;
       }
 
-      if (cl_event_get_status(event_wait_list[i]) < CL_COMPLETE) {
-        err = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
-        break;
-      }
-
       if (event == event_wait_list + i) { /* Pointer of element of the wait list */
         err = CL_INVALID_EVENT_WAIT_LIST;
         break;
@@ -541,16 +538,21 @@ cl_event_is_ready(cl_event event)
 {
   int i;
   int status;
+  int ret_status = CL_COMPLETE;
 
   for (i = 0; i < event->depend_event_num; i++) {
     status = cl_event_get_status(event->depend_events[i]);
 
-    if (status != CL_COMPLETE) {
+    if (status > CL_COMPLETE) { // Find some not ready, just OK
       return status;
     }
+
+    if (status < CL_COMPLETE) { // Record some error.
+      ret_status = status;
+    }
   }
 
-  return CL_COMPLETE;
+  return ret_status;
 }
 
 LOCAL cl_event
-- 
2.7.4





More information about the Beignet mailing list