Skip to content

fix(async): settle mapAsync without blocking on older futures - #654

Open
mvanhorn wants to merge 1 commit into
wcandillon:mainfrom
mvanhorn:fix/637-mapasync-waiter
Open

mvanhorn wants to merge 1 commit into
wcandillon:mainfrom
mvanhorn:fix/637-mapasync-waiter

Conversation

@mvanhorn

Copy link
Copy Markdown

Description

Reading back a ready buffer could stall until unrelated GPU work finished if the caller requested a queue completion notification before mapping the buffer. The waiter took the oldest future from the queue and blocked in WaitAny on that future alone. While onSubmittedWorkDone was pending, the waiter could not process a later mapAsync future even if the buffer was ready.

The waiter now calls WaitAny on up to 64 futures at a time with a 1 ms timeout. Between calls it rotates unfinished futures to the back of the queue and picks up new arrivals. It retries unfinished futures in smaller batches if a multi-future wait fails. The new regression tests cover both call orders, multiple independent maps, and readback of data written by the pending submission.

The transcript records three invocations of repo_lint and gives no exit status for any of them.
The transcript records yarn lint with no output or exit status.
The transcript records npm run cpplint with no output or exit status.
No test was run with the react-native-webgpu change reverted, because no test runs for the changed files, so none is shown to catch this bug.
The new spec packages/webgpu/src/__tests__/MapAsyncWaitOrder.spec.ts did not run here: no test runner for it was available.

Fixes #637

Agent-written content

Not applicable to this change.

The waiter now calls WaitAny on up to 64 futures at a time with a 1 ms
timeout. Between calls it rotates unfinished futures to the back of the
queue and picks up new arrivals. It retries unfinished futures in
smaller batches if a multi-future wait fails. The new regression tests
cover both call orders, multiple independent maps, and readback of data
written by the pending submission.

Fixes wcandillon#637

This branch has not been deployed

No deployments
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.

mapAsync resolves late because the waiter thread blocks on the oldest future

1 participant