From bce47e769d8df61167a1a1649b5d2c25166736db Mon Sep 17 00:00:00 2001 From: "Delaney, Hugh" Date: Mon, 7 Sep 2026 16:27:11 +0100 Subject: [PATCH] fix: strip host-write-only flag and cover all capture-replay allocations Capture/replay needs to read buffer and image contents back on the host to dump and replay kernels, so CL_MEM_HOST_WRITE_ONLY must be cleared alongside CL_MEM_HOST_NO_ACCESS. Also apply the same flag masking to clCreateBufferWithProperties, clCreateImage, and clCreateImageWithProperties, which were previously missing it. --- intercept/src/dispatch.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/intercept/src/dispatch.cpp b/intercept/src/dispatch.cpp index bfc28b59..d068b3d5 100644 --- a/intercept/src/dispatch.cpp +++ b/intercept/src/dispatch.cpp @@ -992,9 +992,10 @@ CL_API_ENTRY cl_mem CL_API_CALL CLIRN(clCreateBuffer)( if( pIntercept->config().CaptureReplay ) { - // Make sure that there are no device only buffers - // Since we need them to replay the kernel - flags &= ~CL_MEM_HOST_NO_ACCESS; + // Make sure that there are no device only or host write only + // buffers, since we need to read buffer contents back on the + // host to dump and replay the kernel. + flags &= ~( CL_MEM_HOST_NO_ACCESS | CL_MEM_HOST_WRITE_ONLY ); } INITIALIZE_BUFFER_CONTENTS_INIT( flags, size, host_ptr ); CHECK_ERROR_INIT( errcode_ret ); @@ -1052,6 +1053,13 @@ CL_API_ENTRY cl_mem CL_API_CALL CLIRN(clCreateBufferWithProperties)( flags, size, host_ptr ); + if( pIntercept->config().CaptureReplay ) + { + // Make sure that there are no device only or host write only + // buffers, since we need to read buffer contents back on the + // host to dump and replay the kernel. + flags &= ~( CL_MEM_HOST_NO_ACCESS | CL_MEM_HOST_WRITE_ONLY ); + } INITIALIZE_BUFFER_CONTENTS_INIT( flags, size, host_ptr ); CHECK_ERROR_INIT( errcode_ret ); HOST_PERFORMANCE_TIMING_START(); @@ -1305,6 +1313,14 @@ CL_API_ENTRY cl_mem CL_API_CALL CLIRN(clCreateImage)( CHECK_ERROR_INIT( errcode_ret ); HOST_PERFORMANCE_TIMING_START(); + if( pIntercept->config().CaptureReplay ) + { + // Make sure that there are no device only or host write only + // images, since we need to read image contents back on the + // host to dump and replay the kernel. + flags &= ~( CL_MEM_HOST_NO_ACCESS | CL_MEM_HOST_WRITE_ONLY ); + } + cl_mem retVal = pIntercept->dispatch().clCreateImage( context, flags, @@ -1395,6 +1411,14 @@ CL_API_ENTRY cl_mem CL_API_CALL CLIRN(clCreateImageWithProperties)( CHECK_ERROR_INIT( errcode_ret ); HOST_PERFORMANCE_TIMING_START(); + if( pIntercept->config().CaptureReplay ) + { + // Make sure that there are no device only or host write only + // images, since we need to read image contents back on the + // host to dump and replay the kernel. + flags &= ~( CL_MEM_HOST_NO_ACCESS | CL_MEM_HOST_WRITE_ONLY ); + } + cl_mem retVal = pIntercept->dispatch().clCreateImageWithProperties( context, properties,