Skip to content

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

Open
lucylq wants to merge 21 commits intomainfrom
gh/lucylq/153/head
Open

Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041
lucylq wants to merge 21 commits intomainfrom
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

Github Executorch added 3 commits April 21, 2026 17:15
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@lucylq
Copy link
Copy Markdown
Contributor Author

lucylq commented Apr 22, 2026

Stack from ghstack (oldest at bottom):

@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.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 1 Cancelled Job, 2 Unrelated Failures

As of commit 3b23d98 with merge base de8ce55 (image):

NEW FAILURE - The following job has failed:

CANCELLED JOB - The following job was cancelled. Please retry:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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
Github Executorch added 3 commits April 21, 2026 18:52
[ghstack-poisoned]
[ghstack-poisoned]
[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
Github Executorch added 3 commits April 21, 2026 19:23
[ghstack-poisoned]
[ghstack-poisoned]
[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
Github Executorch added 3 commits April 22, 2026 10:51
[ghstack-poisoned]
[ghstack-poisoned]
[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: 1b6d5a0
ghstack-comment-id: 4292676210
Pull-Request: #19041
Github Executorch added 3 commits April 22, 2026 11:01
[ghstack-poisoned]
[ghstack-poisoned]
[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: 7c4f2f4
ghstack-comment-id: 4292676210
Pull-Request: #19041
Github Executorch added 3 commits April 22, 2026 11:11
[ghstack-poisoned]
[ghstack-poisoned]
[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: 2cec11b
ghstack-comment-id: 4292676210
Pull-Request: #19041
Github Executorch added 2 commits April 23, 2026 17:30
[ghstack-poisoned]
[ghstack-poisoned]
lucylq pushed a commit that referenced this pull request Apr 24, 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: d68bbc3
ghstack-comment-id: 4292676210
Pull-Request: #19041
Base automatically changed from gh/lucylq/152/head to main April 24, 2026 16:30
[ghstack-poisoned]
lucylq pushed a commit that referenced this pull request Apr 24, 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: 4b20a4f
ghstack-comment-id: 4292676210
Pull-Request: #19041
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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