Skip to content

Register et_copy device-copy ops for ATen-mode runtimes#20902

Open
shoumikhin wants to merge 1 commit into
pytorch:mainfrom
shoumikhin:export-D111752990
Open

Register et_copy device-copy ops for ATen-mode runtimes#20902
shoumikhin wants to merge 1 commit into
pytorch:mainfrom
shoumikhin:export-D111752990

Conversation

@shoumikhin

Copy link
Copy Markdown
Contributor

Summary:
The device-placement pass inserts et_copy::_h2d_copy.out / _d2h_copy.out at
CPU<->accelerator boundaries (e.g. CUDA-delegated subgraphs). These portable ops
are registered for the portable runtime via functions.yaml, but ATen-mode
consumers hit "Missing operator: et_copy::_h2d_copy.out" at runtime: ATen-mode
codegen only registers ATen native_functions.yaml ops, so generated_lib_aten
never emits these custom ops and no op__device_copy_aten target existed.

This adds an ATen-mode registration path:

  • et_copy_ops.yaml custom-ops schema + device_copy_ops_aten_lib (+_static)
    that registers the ops for ATen-mode runtimes, reusing the op__device_copy
    _aten kernel.
  • op__device_copy moved into CUSTOM_OPS to produce the _aten target; it
    stays registered for the portable runtime via functions.yaml.
  • op__device_copy.cpp gains an ATen-mode kernel branch: the planned at::Tensor
    carries no device metadata in ATen mode, so direction comes from op identity
    (_h2d/_d2h) and the copy uses the registered CUDA DeviceAllocator on the
    current device. The portable branch is factored to share device-accessor
    helpers but keeps its existing behavior.

Scope/limitations:

  • ATen-mode device copy is CUDA-only and single-GPU (current device): the
    planned device type/index are not recoverable from the at::Tensor, so the
    kernel targets the registered CUDA allocator's current device. Multi-GPU /
    non-CUDA support is a follow-up (see the TODO in op__device_copy.cpp).

fbcode and xplat copies are kept identical.

Differential Revision: D111752990

Copilot AI review requested due to automatic review settings July 14, 2026 01:36
@pytorch-bot

pytorch-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20902

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:

❌ 34 Pending, 1 Unclassified Failure

As of commit 7fc0c28 with merge base ae754e9 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@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 Jul 14, 2026
@meta-codesync

meta-codesync Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@shoumikhin has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111752990.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ATen-mode runtime failures for et_copy::_h2d_copy.out / et_copy::_d2h_copy.out by adding an ATen-mode registration path (custom-op schema + generated registration lib) and extending op__device_copy with an ATen-mode kernel implementation.

Changes:

  • Add et_copy_ops.yaml plus device_copy_ops_aten_lib to register the device-copy ops in ATen-mode runtimes.
  • Adjust operator target wiring so op__device_copy_aten is produced and can be linked by the ATen-mode registration library.
  • Implement and test an ATen-mode kernel branch for device copies (direction determined by op identity; uses registered CUDA allocator on current device).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl Moves op__device_copy into the list that produces an _aten target as well.
kernels/test/targets.bzl Adds a dedicated ATen-mode device-copy unit test target.
kernels/test/op__device_copy_aten_test.cpp New ATen-mode tests validating direction selection, resize behavior, and guardrails.
kernels/portable/targets.bzl Exports et_copy_ops.yaml, adds an operator library for it, and adds device_copy_ops_aten_lib for ATen-mode registration.
kernels/portable/et_copy_ops.yaml Defines custom-op schemas for et_copy device-copy ops for ATen-mode codegen/registration.
kernels/portable/cpu/op__device_copy.cpp Adds ATen-mode kernel path and refactors device metadata access helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kernels/portable/cpu/op__device_copy.cpp Outdated
Comment thread kernels/test/targets.bzl Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 02:18
shoumikhin added a commit to shoumikhin/executorch that referenced this pull request Jul 14, 2026
Summary:

The device-placement pass inserts `et_copy::_h2d_copy.out` / `_d2h_copy.out` at
CPU<->accelerator boundaries (e.g. CUDA-delegated subgraphs). These portable ops
are registered for the portable runtime via `functions.yaml`, but ATen-mode
consumers hit "Missing operator: et_copy::_h2d_copy.out" at runtime: ATen-mode
codegen only registers ATen `native_functions.yaml` ops, so `generated_lib_aten`
never emits these custom ops and no `op__device_copy_aten` target existed.

This adds an ATen-mode registration path:
- `et_copy_ops.yaml` custom-ops schema + `device_copy_ops_aten_lib` (+`_static`)
  that registers the ops for ATen-mode runtimes, reusing the `op__device_copy`
  `_aten` kernel.
- `op__device_copy` moved into `CUSTOM_OPS` to produce the `_aten` target; it
  stays registered for the portable runtime via `functions.yaml`.
- `op__device_copy.cpp` gains an ATen-mode kernel branch: the planned `at::Tensor`
  carries no device metadata in ATen mode, so direction comes from op identity
  (_h2d/_d2h) and the copy uses the registered CUDA DeviceAllocator on the
  current device. The portable branch is factored to share device-accessor
  helpers but keeps its existing behavior.

Scope/limitations:
- ATen-mode device copy is CUDA-only and single-GPU (current device): the
  planned device type/index are not recoverable from the at::Tensor, so the
  kernel targets the registered CUDA allocator's current device. Multi-GPU /
  non-CUDA support is a follow-up (see the TODO in op__device_copy.cpp).

fbcode and xplat copies are kept identical.

Reviewed By: digantdesai

Differential Revision: D111752990

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread kernels/portable/cpu/op__device_copy.cpp Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 02:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment thread kernels/test/op__device_copy_aten_test.cpp
Comment thread kernels/portable/cpu/op__device_copy.cpp Outdated
Comment thread kernels/portable/cpu/op__device_copy.cpp
Comment thread kernels/portable/cpu/op__device_copy.cpp
Comment thread kernels/portable/cpu/op__device_copy.cpp
Copilot AI review requested due to automatic review settings July 14, 2026 02:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread kernels/test/op__device_copy_aten_test.cpp
Copilot AI review requested due to automatic review settings July 14, 2026 14:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Summary:

The device-placement pass inserts `et_copy::_h2d_copy.out` / `_d2h_copy.out` at
CPU<->accelerator boundaries (e.g. CUDA-delegated subgraphs). These portable ops
are registered for the portable runtime via `functions.yaml`, but ATen-mode
consumers hit "Missing operator: et_copy::_h2d_copy.out" at runtime: ATen-mode
codegen only registers ATen `native_functions.yaml` ops, so `generated_lib_aten`
never emits these custom ops and no `op__device_copy_aten` target existed.

This adds an ATen-mode registration path:
- `et_copy_ops.yaml` custom-ops schema + `device_copy_ops_aten_lib` (+`_static`)
  that registers the ops for ATen-mode runtimes, reusing the `op__device_copy`
  `_aten` kernel.
- `op__device_copy` moved into `CUSTOM_OPS` to produce the `_aten` target; it
  stays registered for the portable runtime via `functions.yaml`.
- `op__device_copy.cpp` gains an ATen-mode kernel branch: the planned `at::Tensor`
  carries no device metadata in ATen mode, so direction comes from op identity
  (_h2d/_d2h) and the copy uses the registered CUDA DeviceAllocator on the
  current device. The portable branch is factored to share device-accessor
  helpers but keeps its existing behavior.

Scope/limitations:
- ATen-mode device copy is CUDA-only and single-GPU (current device): the
  planned device type/index are not recoverable from the at::Tensor, so the
  kernel targets the registered CUDA allocator's current device. Multi-GPU /
  non-CUDA support is a follow-up (see the TODO in op__device_copy.cpp).

fbcode and xplat copies are kept identical.

Reviewed By: digantdesai

Differential Revision: D111752990

@digantdesai digantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need any CMake changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/cuda ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants