Skip to content

Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041

Open
lucylq wants to merge 3 commits intogh/lucylq/152/headfrom
gh/lucylq/153/head
Open

Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041
lucylq wants to merge 3 commits intogh/lucylq/152/headfrom
gh/lucylq/153/head

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Apr 22, 2026

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

[ghstack-poisoned]
@lucylq
Copy link
Copy Markdown
Contributor Author

lucylq commented Apr 22, 2026

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 22, 2026

🔗 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 Failure

As of commit ccca70a with merge base 273888f (image):

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 lucylq mentioned this pull request Apr 22, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 22, 2026
[ghstack-poisoned]
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
[ghstack-poisoned]
@lucylq lucylq requested a review from JacobSzwejbka as a code owner April 22, 2026 02:23
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant