[CUDA] Implement update_event to fix timer race condition
@@ -142,6 +142,7 @@ pocl_cuda_init_device_ops (struct pocl_device_ops *ops)
ops->submit = pocl_cuda_submit;
ops->notify = pocl_cuda_notify;
ops->wait_event = pocl_cuda_wait_event;
+ ops->update_event = pocl_cuda_update_event;
ops->free_event_data = pocl_cuda_free_event_data;
ops->join = pocl_cuda_join;
ops->flush = pocl_cuda_flush;
@@ -158,7 +159,6 @@ pocl_cuda_init_device_ops (struct pocl_device_ops *ops)
/* TODO: implement remaining ops functions if needed: */
/* broadcast */
/* get_timer_value */
- /* update_event */
}
cl_int
@@ -1327,14 +1327,31 @@ pocl_cuda_finalize_command (cl_device_id device, cl_event event)
return;
}
- /* Retain this event temporarily, otherwise the call to
- * POCL_UPDATE_EVENT_COMPLETE might release the event before we've
- * dealt with the timing.
- * TODO: Maybe better to handle update_event so we don't have to do this? */
- POname (clRetainEvent) (event);
-
POCL_UPDATE_EVENT_RUNNING (&event);
POCL_UPDATE_EVENT_COMPLETE (&event);
+}
+
+void
+pocl_cuda_update_event (cl_device_id device, cl_event event, cl_int status)
+{
+ switch (status)
+ {
+ case CL_QUEUED:
+ if (event->queue->properties & CL_QUEUE_PROFILING_ENABLE)
+ event->time_queue = device->ops->get_timer_value (device->data);
+ event->status = status;
+ break;
+ case CL_SUBMITTED:
+ if (event->queue->properties & CL_QUEUE_PROFILING_ENABLE)
+ event->time_submit = device->ops->get_timer_value (device->data);
+ event->status = status;
+ break;
+ case CL_RUNNING:
+ /* Wait until complete to get the timing from the CUDA events */
+ event->status = status;
+ break;
+ case CL_COMPLETE:
+ pocl_mem_objs_cleanup (event);
/* Update timing info with CUDA event timers if profiling enabled */
if (event->queue->properties & CL_QUEUE_PROFILING_ENABLE)
@@ -1350,6 +1367,9 @@ pocl_cuda_finalize_command (cl_device_id device, cl_event event)
* sane. */
float diff;
+ CUresult result;
+ pocl_cuda_event_data_t *event_data
+ = (pocl_cuda_event_data_t *)event->data;
cl_ulong epoch = ((pocl_cuda_device_data_t *)device->data)->epoch;
result = cuEventElapsedTime (
@@ -1367,7 +1387,18 @@ pocl_cuda_finalize_command (cl_device_id device, cl_event event)
event->time_end = max (event->time_end, event->time_start + 1);
}
- POname (clReleaseEvent) (event);
+ POCL_LOCK_OBJ (event);
+ event->status = CL_COMPLETE;
+ device->ops->broadcast (event);
+ POCL_UNLOCK_OBJ (event);
+
+ pocl_update_command_queue (event);
+
+ break;
+ default:
+ assert ("Invalid event status\n");
+ break;
+ }
}
void
