Report a clear error instead of crashing on a device-planned copy - #21704
Report a clear error instead of crashing on a device-planned copy#21704shoumikhin wants to merge 1 commit into
Conversation
🔗 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. |
|
Superseded by #21960. Two reasons for reopening this as a standalone change: It did not build. It did not need to be stacked. This change touches #21960 also strengthens the new test. It previously handed one buffer to both the source |
|
Closing in favor of #21960, which is green: the unittest jobs on Linux, macOS and Windows all pass, in CMake, buck and editable installs. Those are the jobs that failed here. |
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.