Skip to content

cuda: serialise constant-memory uploads with their kernel launches - #3725

Draft
melonakos wants to merge 2 commits into
masterfrom
fix/3711-convolve-constant-race
Draft

cuda: serialise constant-memory uploads with their kernel launches#3725
melonakos wants to merge 2 commits into
masterfrom
fix/3711-convolve-constant-race

Conversation

@melonakos

@melonakos melonakos commented Sep 11, 2026

Copy link
Copy Markdown
Member

Calling af::convolve from several host threads on the CUDA backend can silently return results computed with another thread's filter (#3711). convolve, morph and transform stage per-call data through a constant symbol of a cached module, and the upload and the launch are both asynchronous on the single stream every host thread shares, so two threads can interleave upload, upload, launch, launch. A lock is now held from the upload through the launch enqueue at all seven sites and released before the post-launch check, which synchronises the stream in debug builds and with synchronous calls enabled. Adds a threading test with a distinct filter per thread at the file's usual 32 threads and 1000 iterations.

Draft because there is no NVIDIA GPU here: the backend compiles under CUDA 13 apart from the master breakages #3715 fixes, and the test passes on the CPU backend, but it has not been seen to fail on the unfixed CUDA code. canny and floodFill keep a per-call flag in a device variable and have the same class of bug; not covered here, noted in the mutex comment, and to be filed separately.

convolve, morph and transform stage per-call data through a __constant__ symbol of a cached module, and both the upload and the launch are asynchronous on the one stream shared by every host thread. Two threads could interleave upload, upload, launch, launch and the first launch ran with the second thread's filter, silently. Hold a lock from the upload through the launch enqueue at all seven sites, and add a threading test that runs a distinct filter per thread. Fixes #3711.
POST_LAUNCH_CHECK synchronises the stream in debug builds and whenever
synchronous calls are enabled, so the guard now ends before it. The
threading test uses the file's THREAD_COUNT and ITERATION_COUNT, the kernel
headers include platform.hpp for the declaration, and the mutex comment says
that the per-call flags in canny and flood_fill are not covered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant