From e602a2e4ede50ca6036afcd3f99a74a24545870c Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Sat, 29 Mar 2025 12:40:01 -0700 Subject: [PATCH] fix the device performance timing checks for clReleaseContext The device performance timing checks were only supposed to happen when the context reference count went to zero, but because the reference count was only queried when call logging was enabled, it was happening much more often. Fix by querying (and updating) the context reference count unconditionally. --- intercept/src/dispatch.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/intercept/src/dispatch.cpp b/intercept/src/dispatch.cpp index 5fa1652e..0cebbb3c 100644 --- a/intercept/src/dispatch.cpp +++ b/intercept/src/dispatch.cpp @@ -625,9 +625,9 @@ CL_API_ENTRY cl_int CL_API_CALL CLIRN(clReleaseContext)( { GET_ENQUEUE_COUNTER(); - cl_uint ref_count = - pIntercept->config().CallLogging ? - pIntercept->getRefCount( context ) : 0; + // Note: we use the ref count to for device performance timing checks, + // so get it unconditionally. + cl_uint ref_count = pIntercept->getRefCount( context ); CALL_LOGGING_ENTER( "[ ref count = %d ] context = %p", ref_count, context ); @@ -639,7 +639,8 @@ CL_API_ENTRY cl_int CL_API_CALL CLIRN(clReleaseContext)( HOST_PERFORMANCE_TIMING_END(); CHECK_ERROR( retVal ); ADD_OBJECT_RELEASE( context ); - CALL_LOGGING_EXIT( retVal, "[ ref count = %d ]", --ref_count ); + --ref_count; + CALL_LOGGING_EXIT( retVal, "[ ref count = %d ]", ref_count ); DEVICE_PERFORMANCE_TIMING_CHECK_CONDITIONAL( ref_count == 0 ); FLUSH_CHROME_TRACE_BUFFERING_CONDITIONAL( ref_count == 0 );