From: Dirk Lemstra Date: Mon, 27 Feb 2017 21:06:33 +0000 (+0100) Subject: Check if all events are completed before starting the async call. X-Git-Tag: 7.0.5-1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27b44900e4e99703726b8f7a621d157e6db24664;p=imagemagick Check if all events are completed before starting the async call. --- diff --git a/MagickCore/opencl-private.h b/MagickCore/opencl-private.h index c7c546129..2bfd971b0 100644 --- a/MagickCore/opencl-private.h +++ b/MagickCore/opencl-private.h @@ -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; diff --git a/MagickCore/opencl.c b/MagickCore/opencl.c index d1bdf892c..908575b56 100644 --- a/MagickCore/opencl.c +++ b/MagickCore/opencl.c @@ -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