Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041
Open
lucylq wants to merge 3 commits intogh/lucylq/152/headfrom
Open
Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041lucylq wants to merge 3 commits intogh/lucylq/152/headfrom
lucylq wants to merge 3 commits intogh/lucylq/152/headfrom
Conversation
Contributor
Author
|
Stack from ghstack (oldest at bottom): |
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19041
Note: Links to docs will display an error until the docs builds have been completed. ❌ 10 New Failures, 1 Unrelated FailureAs of commit ccca70a with merge base 273888f ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
lucylq
pushed a commit
that referenced
this pull request
Apr 22, 2026
Before this change, every generated boxed kernel wrapper unpacked its
EValue stack args via the abort-on-mismatch accessors (.to<T>(),
.toOptional<T>(), .toTensorList(), .toIntList(), .toDoubleList(),
.toBoolList(), .toListOptionalTensor()). A malformed PTE whose
KernelCall arg_indices point at wrong-tagged EValues would therefore
crash the runtime with ET_CHECK_MSG inside the generated wrapper,
before the underlying native kernel sees the inputs.
Emit the Result-returning tryTo* counterparts instead, with a single
shared error-propagation pattern:
auto x_res = ev.tryTo<T>();
if (!x_res.ok()) { context.fail(x_res.error()); return; }
T x = x_res.get();
The kernel entry function is already void-returning and takes a
KernelRuntimeContext&, which has a documented fail() channel for
precisely this case — no ABI change, no signature change, no impact
on hand-written kernels registered directly against OpFunction.
Coverage: _gen_code_base_type, _gen_code_optional_type, and each
typed branch of _gen_code_list_type (Tensor, int/SymInt, float, bool
with ATen/lean variants, and ListOptional<Tensor> with ATen/lean
variants).
Depends on the EValue::tryTo<T>() API added earlier in the stack.
Authored-with: Claude
ghstack-source-id: 6a3c6c4
ghstack-comment-id: 4292676210
Pull-Request: #19041
lucylq
pushed a commit
that referenced
this pull request
Apr 22, 2026
Before this change, every generated boxed kernel wrapper unpacked its
EValue stack args via the abort-on-mismatch accessors (.to<T>(),
.toOptional<T>(), .toTensorList(), .toIntList(), .toDoubleList(),
.toBoolList(), .toListOptionalTensor()). A malformed PTE whose
KernelCall arg_indices point at wrong-tagged EValues would therefore
crash the runtime with ET_CHECK_MSG inside the generated wrapper,
before the underlying native kernel sees the inputs.
Emit the Result-returning tryTo* counterparts instead, with a single
shared error-propagation pattern:
auto x_res = ev.tryTo<T>();
if (!x_res.ok()) { context.fail(x_res.error()); return; }
T x = x_res.get();
The kernel entry function is already void-returning and takes a
KernelRuntimeContext&, which has a documented fail() channel for
precisely this case — no ABI change, no signature change, no impact
on hand-written kernels registered directly against OpFunction.
Coverage: _gen_code_base_type, _gen_code_optional_type, and each
typed branch of _gen_code_list_type (Tensor, int/SymInt, float, bool
with ATen/lean variants, and ListOptional<Tensor> with ATen/lean
variants).
Depends on the EValue::tryTo<T>() API added earlier in the stack.
Authored-with: Claude
ghstack-source-id: e93ad8d
ghstack-comment-id: 4292676210
Pull-Request: #19041
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.
Let codegen generate the new tryTo evalue accessors that return Result, instead of the old .to()
Depends on the EValue::tryTo() API added earlier in the stack.
Authored-with: Claude