Report a clear error instead of crashing on a device-planned copy - #21704
Open
shoumikhin wants to merge 1 commit into
Open
Report a clear error instead of crashing on a device-planned copy#21704shoumikhin wants to merge 1 commit into
shoumikhin wants to merge 1 commit into
Conversation
Contributor
Author
shoumikhin
requested review from
JacobSzwejbka,
kirklandsign and
larryliu0820
as code owners
August 9, 2026 23:16
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21704
Note: Links to docs will display an error until the docs builds have been completed. ❌ 8 New Failures, 2 Unrelated FailuresAs of commit cbcf910 with merge base 730b77a ( NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
The problem
When the runtime fills a memory-planned tensor, it copies the caller's data into the
buffer it reserved, using a plain host copy:
std::memcpy(t_dst.mutable_data_ptr(), t_src.const_data_ptr(), t_src.nbytes());That is correct for main memory. If the destination lives on an accelerator, a host copy
into it is undefined and the process dies with a segmentation fault and no message. The
last thing a user sees is unrelated:
Nothing points at the cause, which is a program whose activations live on a device being
exported so the runtime also reserves its own buffer for them.
The change
Check the assumption the copy makes, and return an error naming the fix instead of
crashing:
This does not make that copy work, on purpose. A caller who hands over device memory
asked for no copying, so the right answer is to export the program so the runtime shares
that memory rather than duplicating it. The message says how.
Host to host copying is unchanged, which is every existing caller.
Test plan
Added
copy_tensor_data_device_test.cpp, covering three cases with no GPU needed, sincea tensor only has to be labelled as device memory for the check to apply:
Verified the error text is produced rather than a crash. Built and ran the runtime tests
on Linux x86_64.