[Beignet] [PATCH] refine the event implementation and fix some bugs.
xionghu.luo at intel.com
xionghu.luo at intel.com
Thu Apr 24 14:37:25 PDT 2014
From: Luo <xionghu.luo at intel.com>
1 remove useless data element;
2 fix some logic bugs;
3 add implementation for clEnqueueMarkerWithWaitList.
---
src/cl_alloc.c | 1 +
src/cl_api.c | 22 +++++++++++++++++---
src/cl_event.c | 65 ++++++++++++++++++++++++++++++++++++----------------------
src/cl_event.h | 4 +++-
4 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/src/cl_alloc.c b/src/cl_alloc.c
index 20d5578..93d2e6a 100644
--- a/src/cl_alloc.c
+++ b/src/cl_alloc.c
@@ -71,6 +71,7 @@ cl_free(void *ptr)
return;
atomic_dec(&cl_alloc_n);
free(ptr);
+ ptr = NULL;
}
LOCAL size_t
diff --git a/src/cl_api.c b/src/cl_api.c
index 1543ff4..a8c4fbe 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -2621,10 +2621,26 @@ clEnqueueNativeKernel(cl_command_queue command_queue,
error:
return err;
}
+clEnqueueMarker(cl_command_queue command_queue,
+ cl_event *event)
+{
+ cl_int err = CL_SUCCESS;
+ CHECK_QUEUE(command_queue);
+ if(event == NULL) {
+ err = CL_INVALID_VALUE;
+ goto error;
+ }
+
+ cl_event_marker_with_wait_list(command_queue, 0, NULL, event);
+error:
+ return err;
+}
cl_int
-clEnqueueMarker(cl_command_queue command_queue,
- cl_event * event)
+clEnqueueMarkerWithWaitList(cl_command_queue command_queue,
+ cl_uint num_events_in_wait_list,
+ const cl_event *event_wait_list,
+ cl_event *event)
{
cl_int err = CL_SUCCESS;
CHECK_QUEUE(command_queue);
@@ -2633,7 +2649,7 @@ clEnqueueMarker(cl_command_queue command_queue,
goto error;
}
- cl_event_marker(command_queue, event);
+ cl_event_marker_with_wait_list(command_queue, num_events_in_wait_list, event_wait_list, event);
error:
return err;
}
diff --git a/src/cl_event.c b/src/cl_event.c
index 727ee1f..203bfc2 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -224,7 +224,7 @@ cl_int cl_event_wait_events(cl_uint num_events_in_wait_list, const cl_event *eve
if((event_wait_list[i]->type == CL_COMMAND_USER) ||
(event_wait_list[i]->enqueue_cb &&
(event_wait_list[i]->enqueue_cb->wait_user_events != NULL))){
- for(j=0; j<num_events_in_wait_list; j++)
+ for(j=0; j<= i; j++)
cl_event_add_ref(event_wait_list[j]); //add defer enqueue's wait event reference
return CL_ENQUEUE_EXECUTE_DEFER;
}
@@ -244,7 +244,7 @@ cl_int cl_event_wait_events(cl_uint num_events_in_wait_list, const cl_event *eve
return CL_ENQUEUE_EXECUTE_DEFER;
if(event_wait_list[i]->gpgpu_event)
cl_gpgpu_event_update_status(event_wait_list[i]->gpgpu_event, 1);
- cl_event_set_status(event_wait_list[i], CL_COMPLETE); //Execute user's callback
+ //// cl_event_set_status(event_wait_list[i], CL_COMPLETE); //Execute user's callback
}
return CL_ENQUEUE_EXECUTE_IMM;
}
@@ -260,12 +260,14 @@ void cl_event_new_enqueue_callback(cl_event event,
cl_int i;
GET_QUEUE_THREAD_GPGPU(data->queue);
- /* Allocate and inialize the structure itself */
+ /* Allocate and initialize the structure itself */
TRY_ALLOC_NO_ERR (cb, CALLOC(enqueue_callback));
+#if 0
cb->num_events = num_events_in_wait_list;
TRY_ALLOC_NO_ERR (cb->wait_list, CALLOC_ARRAY(cl_event, num_events_in_wait_list));
for(i=0; i<num_events_in_wait_list; i++)
cb->wait_list[i] = event_wait_list[i];
+#endif
cb->event = event;
cb->next = NULL;
cb->wait_user_events = NULL;
@@ -276,12 +278,13 @@ void cl_event_new_enqueue_callback(cl_event event,
node = queue->wait_events[i]->waits_head;
if(node == NULL)
queue->wait_events[i]->waits_head = cb;
- else
- while((node != cb) && node->next)
- node = node->next;
- if(node == cb) //wait on dup user event
- continue;
- node->next = cb;
+ else{
+ while((node != cb) && node->next)
+ node = node->next;
+ if(node == cb) //wait on dup user event
+ continue;
+ node->next = cb;
+ }
/* Insert the user event to enqueue_callback's wait_user_events */
TRY_ALLOC_NO_ERR (u_ev, CALLOC(user_event));
@@ -291,7 +294,7 @@ void cl_event_new_enqueue_callback(cl_event event,
}
}
- /* Find out all user events that events in event_wait_list wait */
+ /* Find out all user events that in event_wait_list wait */
for(i=0; i<num_events_in_wait_list; i++) {
if(event_wait_list[i]->status <= CL_COMPLETE)
continue;
@@ -319,21 +322,25 @@ void cl_event_new_enqueue_callback(cl_event event,
while(user_events != NULL) {
/* Insert the enqueue_callback to user event's waits_tail */
node = user_events->event->waits_head;
- while((node != cb) && node->next)
- node = node->next;
- if(node == cb) { //wait on dup user event
- user_events = user_events->next;
- continue;
+ if(node == NULL)
+ event_wait_list[i]->waits_head = cb;
+ else{
+ while((node != cb) && node->next)
+ node = node->next;
+ if(node == cb) { //wait on dup user event
+ user_events = user_events->next;
+ continue;
+ }
+ node->next = cb;
}
- node->next = cb;
/* Insert the user event to enqueue_callback's wait_user_events */
TRY_ALLOC_NO_ERR (u_ev, CALLOC(user_event));
u_ev->event = user_events->event;
u_ev->next = cb->wait_user_events;
cb->wait_user_events = u_ev;
+ cl_command_queue_insert_event(event->queue, user_events->event);
user_events = user_events->next;
- cl_command_queue_insert_event(event->queue, event_wait_list[i]);
}
}
}
@@ -353,8 +360,10 @@ error:
cb->wait_user_events = cb->wait_user_events->next;
cl_free(u_ev);
}
+#if 0
if(cb->wait_list)
cl_free(cb->wait_list);
+#endif
cl_free(cb);
}
goto exit;
@@ -363,8 +372,9 @@ error:
void cl_event_set_status(cl_event event, cl_int status)
{
user_callback *user_cb;
- user_event *u_ev, *u_ev_next;
- cl_int ret, i;
+ user_event *u_ev;
+ //user_event *u_ev_next;
+ //cl_int ret, i;
cl_event evt;
pthread_mutex_lock(&event->ctx->event_lock);
@@ -385,6 +395,7 @@ void cl_event_set_status(cl_event event, cl_int status)
cl_gpgpu_event_update_status(event->gpgpu_event, 1); //now set complet, need refine
event->status = status; //Change the event status after enqueue and befor unlock
+#if 0
pthread_mutex_unlock(&event->ctx->event_lock);
for(i=0; i<event->enqueue_cb->num_events; i++)
cl_event_delete(event->enqueue_cb->wait_list[i]);
@@ -392,6 +403,8 @@ void cl_event_set_status(cl_event event, cl_int status)
if(event->enqueue_cb->wait_list)
cl_free(event->enqueue_cb->wait_list);
+#endif
+
cl_free(event->enqueue_cb);
event->enqueue_cb = NULL;
}
@@ -426,7 +439,7 @@ void cl_event_set_status(cl_event event, cl_int status)
enqueue_cb->wait_user_events = enqueue_cb->wait_user_events->next;
cl_free(u_ev);
}
-
+#if 0
u_ev = enqueue_cb->wait_user_events;
while(u_ev) {
u_ev_next = u_ev->next;
@@ -436,7 +449,7 @@ void cl_event_set_status(cl_event event, cl_int status)
} else
u_ev->next = u_ev_next;
}
-
+#endif
/* Still wait on other user events */
if(enqueue_cb->wait_user_events != NULL) {
enqueue_cb = enqueue_cb->next;
@@ -447,11 +460,12 @@ void cl_event_set_status(cl_event event, cl_int status)
cl_command_queue_remove_event(enqueue_cb->event->queue, event);
/* All user events complete, now wait enqueue events */
+#if 0
ret = cl_event_wait_events(enqueue_cb->num_events, enqueue_cb->wait_list,
enqueue_cb->event->queue);
- ret = ret;
+// ret = ret;
assert(ret != CL_ENQUEUE_EXECUTE_DEFER);
-
+#endif
cb = enqueue_cb;
enqueue_cb = enqueue_cb->next;
@@ -474,7 +488,10 @@ void cl_event_update_status(cl_event event)
cl_event_set_status(event, CL_COMPLETE);
}
-cl_int cl_event_marker(cl_command_queue queue, cl_event* event)
+cl_int cl_event_marker_with_wait_list(cl_command_queue queue,
+ cl_uint num_events_in_wait_list,
+ const cl_event *event_wait_list,
+ cl_event* event)
{
enqueue_data data;
diff --git a/src/cl_event.h b/src/cl_event.h
index 3c61110..a1c10fc 100644
--- a/src/cl_event.h
+++ b/src/cl_event.h
@@ -38,8 +38,10 @@ typedef struct _user_event {
typedef struct _enqueue_callback {
cl_event event; /* The event relative this enqueue callback */
enqueue_data data; /* Hold all enqueue callback's infomation */
+#if 0
cl_uint num_events; /* num events in wait list */
cl_event* wait_list; /* All event wait list this callback wait on */
+#endif
user_event* wait_user_events; /* The head of user event list the callback wait on */
struct _enqueue_callback* next; /* The next enqueue callback in wait list */
} enqueue_callback;
@@ -90,7 +92,7 @@ void cl_event_set_status(cl_event, cl_int);
/* Check and update event status */
void cl_event_update_status(cl_event);
/* Create the marker event */
-cl_int cl_event_marker(cl_command_queue, cl_event*);
+cl_int cl_event_marker_with_wait_list(cl_command_queue, cl_uint, const cl_event *, cl_event*);
/* Do the event profiling */
cl_int cl_event_get_timestamp(cl_event event, cl_profiling_info param_name);
#endif /* __CL_EVENT_H__ */
--
1.8.1.2
More information about the Beignet
mailing list