Repository navigation
fix: Do not create a GPU stream on :cpu workers to synchronize them - #164
Merged
polvalente merged 2 commits intoNov 27, 2026
Merged
polvalente merged 2 commits into
polvalente merged 2 commits into
Conversation
…ime call synchronize_thread_streams() called default_stream(gpu) on every worker thread. On a :cpu worker, this call created a GPU stream with no work on it. Each sync then committed an empty command buffer and waited for it. The function now peeks the default GPU stream of the thread and syncs it only when it exists. An op that a thread puts on its default GPU stream creates this stream first, so the sync still covers all the GPU work of the thread. A compiled while with 1 iteration on an M2 Pro: the :cpu worker went from 124 µs to 102-108 µs per call. The :gpu worker did not change, at about 440 µs per call.
Member
|
@georgeguimaraes I don't thing there's measureable differences here. Could you provide a benchmarking script in which these changes matter? 20us difference could be explained by host os scheduling differences even. |
Member
Author
|
@polvalente You are right that the time difference alone does not justify this change. The main point is that |
polvalente
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #155,
synchronize_thread_streams()callsdefault_stream(gpu)on every worker thread before a compiledwhileor aruntime_call. On a:cpuworker, this call creates a GPU stream that the thread never uses. The function then commits an empty command buffer on that stream and waits for it.The function now peeks the default GPU stream of the thread and syncs it only when it exists. An op that a thread puts on its default GPU stream creates this stream first, so the sync still covers all the GPU work of the thread. Thus the function waits only for the streams that the thread used, and it creates no stream. The CPU sync, which fixed #154, does not change.
The time per call on a
:cpuworker also goes down a little. A compiledwhilewith 1 iteration, median of 5 batches of 2000 calls on an M2 Pro:main:cpu:gpuChecks on this branch:
:cpu, 400 runs on:gpu, 0 failures.:cpupassed (2739 of 2739). A 3rd run had 1 failure in "allocating a tensor increases active memory". That test passed when run alone and with its file.EMLX_TEST_DEFAULT_GPU=true: 12 failures.mainfails the same 12 tests (triangular_solve, runtime_call graph split and ownership, quantized matmul).