Skip to content

Conversation

@lgeiger
Copy link
Contributor

@lgeiger lgeiger commented Jun 19, 2025

index_put with a boolean mask (target[mask] = src) causes a cudaStreamSynchronize. When both mask and target tensors are on GPU this is expected.

However, the sync can be prevented if the mask is a CPU tensor.
Internally a new index tensor is created with mask.nonzero() so we can use a non-blocking copy to transfer it to the GPU since it cannot be accidentally mutated by the user between its creation and the device copy. @ngimel Let me know if I'm missing something.

I think this is useful since users can't prevent a sync simply by making sure all tensors are on the same device as with other ops. Instead one would need to do something like this which is much less readable

indices = mask.nonzero().squeeze(1).to("cuda", non_blocking=True)
target[indices] = src

Fixes #12461

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 19, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/156384

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit c172e4e with merge base 6b7767f (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 19, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@lgeiger
Copy link
Contributor Author

lgeiger commented Jun 19, 2025

@pytorchbot label "release notes: cuda"

@pytorch-bot pytorch-bot bot added the release notes: cuda release notes category label Jun 19, 2025
@lgeiger lgeiger requested a review from ngimel June 19, 2025 17:14
@mikaylagawarecki mikaylagawarecki added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 20, 2025
@lgeiger
Copy link
Contributor Author

lgeiger commented Jun 24, 2025

@pytorchmergebot merge

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 24, 2025

Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra.

@lgeiger lgeiger requested a review from ngimel June 24, 2025 23:50
@lgeiger
Copy link
Contributor Author

lgeiger commented Jun 25, 2025

dfdf9bd should fix the build failure on CI

@lgeiger
Copy link
Contributor Author

lgeiger commented Jun 27, 2025

@ngimel any chance you could trigger CI to verify that this PR is good to go?

@cyyever
Copy link
Collaborator

cyyever commented Jun 28, 2025

@pytorchmergebot merge -r

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 28, 2025
@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased index-put-no-sync onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout index-put-no-sync && git pull --rebase)

@pytorch-bot pytorch-bot bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Jun 28, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged open source release notes: cuda release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Certain operations cause implicity sync-points

6 participants