]> granicus.if.org Git - imagemagick/commitdiff
Check if all events are completed before starting the async call.
authorDirk Lemstra <dirk@git.imagemagick.org>
Mon, 27 Feb 2017 21:06:33 +0000 (22:06 +0100)
committerDirk Lemstra <dirk@git.imagemagick.org>
Mon, 27 Feb 2017 21:06:33 +0000 (22:06 +0100)
MagickCore/opencl-private.h
MagickCore/opencl.c

index c7c5461293b9d9ad8ec5aa9f8be6aca6669929ce..2bfd971b0ad465303837931865d23b0833e23a04 100644 (file)
@@ -206,6 +206,11 @@ typedef CL_API_ENTRY cl_int
 
 
 /* Events APIs */
+typedef CL_API_ENTRY cl_int
+  (CL_API_CALL *MAGICKpfn_clGetEventInfo)(cl_event event,
+    cl_profiling_info param_name,size_t param_value_size,void *param_value,
+    size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0;
+
 typedef CL_API_ENTRY cl_int
   (CL_API_CALL *MAGICKpfn_clWaitForEvents)(cl_uint num_events,
     const cl_event *event_list) CL_API_SUFFIX__VERSION_1_0;
@@ -270,6 +275,7 @@ struct MagickLibraryRec
   MAGICKpfn_clEnqueueUnmapMemObject   clEnqueueUnmapMemObject;
   MAGICKpfn_clEnqueueNDRangeKernel    clEnqueueNDRangeKernel;
 
+  MAGICKpfn_clGetEventInfo            clGetEventInfo;
   MAGICKpfn_clWaitForEvents           clWaitForEvents;
   MAGICKpfn_clReleaseEvent            clReleaseEvent;
   MAGICKpfn_clRetainEvent             clRetainEvent;
index d1bdf892cc15897bf0b09919d1f0957cf1571396..908575b566674c7f6dcf65c4b7ec5e9d5e13df36 100644 (file)
@@ -2415,6 +2415,7 @@ static MagickBooleanType BindOpenCLFunctions()
   BIND(clEnqueueUnmapMemObject);
   BIND(clEnqueueNDRangeKernel);
 
+  BIND(clGetEventInfo);
   BIND(clWaitForEvents);
   BIND(clReleaseEvent);
   BIND(clRetainEvent);
@@ -2817,7 +2818,30 @@ MagickPrivate MagickCLCacheInfo RelinquishMagickCLCacheInfo(
     return((MagickCLCacheInfo) NULL);
   if (relinquish_pixels != MagickFalse)
     {
-      if (info->event_count > 0)
+      MagickBooleanType
+        events_completed;
+
+      ssize_t
+        i;
+
+      events_completed=MagickTrue;
+      for (i=0; i < (ssize_t)info->event_count; i++)
+      {
+        cl_int
+          event_status;
+
+        cl_uint
+          status;
+
+        status=openCL_library->clGetEventInfo(info->events[i],
+          CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof(cl_int),&event_status,NULL);
+        if ((status == CL_SUCCESS) && (event_status != CL_COMPLETE))
+          {
+            events_completed=MagickFalse;
+            break;
+          }
+      }
+      if (events_completed == MagickFalse)
         openCL_library->clSetEventCallback(info->events[info->event_count-1],
           CL_COMPLETE,&DestroyMagickCLCacheInfoAndPixels,info);
       else