Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041
Codegen: emit EValue::tryTo<T>() in boxed kernel wrappers#19041
Conversation
|
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. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 New Failure, 1 Cancelled Job, 2 Unrelated FailuresAs of commit 3b23d98 with merge base de8ce55 ( 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. |
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
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
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
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
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
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
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
This PR needs a
|
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