Skip to content

[mkldnn][4/N] Port sum, binary, and direct_copy ops from ideep into ATen - #201059

Closed
frost-intel wants to merge 3 commits into
pytorch:mainfrom
frost-intel:ideep-removal/04-port-sum-binary
Closed

frost-intel wants to merge 3 commits into
pytorch:mainfrom
frost-intel:ideep-removal/04-port-sum-binary

Conversation

@frost-intel

@frost-intel frost-intel commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Linked issue or supporting maintainer

Part of #154444

BC-breaking?

No

Summary (human written only)

Ports sum and binary operators from ideep to aten::native::mkldnn::sum/binary. Port is line-for-line. I also copy the direct_copy function in a new file. In order to avoid including all of MKLDNNCommon.h and ideep in aten/src/ATen/native/mkldnn/detail/Utils.h, new files DirectCopy.h/cpp are added. When we port ideep::tensor into ATen, the direct copy function will be moved into that file, so this is temporary.

Fake stack

Agent details (if applicable)

Developed with assistance from Claude Opus 5.5.

What changed (9 files, +144/−8):

  • detail/Binary.{h,cpp}: at::native::mkldnn::sum and binary, ported line for line from ideep's sum.hpp and binary.hpp. They keep the user-managed scratchpad, the output layout choice (from the inputs for sum, "any" for binary), input reorders for binary, and the in-place buffer replacement on dst.

  • detail/DirectCopy.{h,cpp}: direct_copy, ported from ideep's direct_copy.hpp. It keeps the buffer replacement, the reorder and the scale propagation.

  • Call sites: all 8 switched.

    File Ops Calls
    BinaryOps.cpp add_out (×2), add, mul_out 4
    Copy.cpp copy_ 1
    TensorShape.cpp clone 1
    Normalization.cpp batchnorm running-stats update 2

    No ideep::sum, ideep::binary or ideep::direct_copy calls remain outside XPU, and BinaryOps.cpp and Copy.cpp no longer call any ideep operator.

  • build_variables.bzl: 2 entries. CMake and Buck pick up headers from the detail/ setup added in PR 3.

Checks:

  • Same oneDNN calls before and after. I ran all of test_mkldnn.py plus test_freezing.py -k mkldnn with ONEDNN_VERBOSE=1 and compared the logged primitive creations and executions, with timings stripped. I ran the baseline twice first, and it repeats exactly, so any difference would be real.
    • All 6,572 distinct primitive log lines are identical.
    • Those tests exercise the ported code: sum runs 40 times (13 distinct), binary 4 times, and reorder runs 130,755 times, which includes the copies.
  • Tests:
    • test_mkldnn.py: 92 passed, 1 skipped.
    • Freezing tests: 4 passed, 5 skipped.
    • test_mkldnn_fusion.py: OK.
    • test_nn.py -k "batchnorm and cpu": 9 passed.
  • Lint: clean.

(test/jit/test_freezing.py was later deleted upstream by #203621. The final A/B comparison of the whole series against main, described in #204808, re-checks these paths without it.)

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01

@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 1d4f8fa with merge base 780bf8e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added module: cpu CPU specific problem (e.g., perf, algorithm) release notes: quantization release notes category labels Oct 15, 2026
@frost-intel
frost-intel force-pushed the ideep-removal/04-port-sum-binary branch from 61ea8d2 to 4557630 Compare October 29, 2026 16:04
Part of pytorch#154444.

Replace ideep type aliases with the oneDNN (or std) types they name.
Each is a plain `using` in ideep, so this is a pure spelling change
with no effect on generated code. It removes about a third of the
remaining ideep references from ATen CPU code.
Part of pytorch#154444. Move ideep::eltwise_forward/backward into aten.
Switch all CPU callers (relu, sigmoid, tanh, gelu, scalar mul,
dense GELU, JIT frozen scalar mul). Line-for-line port.
Part of pytorch#154444. Depends on pytorch#201055

Move ideep::sum, ideep::binary and ideep::direct_copy into
aten/src/ATen/native/mkldnn/detail/{Binary,DirectCopy}.{h,cpp} and switch
all CPU callers (add/add_/add_out, mul_out, copy_, clone, batch_norm
running-stat update). The port is line-for-line, including destination
reinit when the destination layout differs. It still operates on
ideep::tensor.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
pytorchmergebot pushed a commit that referenced this pull request Nov 19, 2026
…1053)

## Linked issue or supporting maintainer
Part of #154444

## BC-breaking?
No

## Summary (human written only)
See #154444 for ideep removal discussion.
Replace ideep type aliases with the oneDNN or std types they name. Each is a plain `using` in ideep, so this is a pure spelling change with no effect on generated code. It removes about a third of the remaining ideep references from ATen CPU code.

#### Fake Stack
* #201052
* -> #201053
* Port ops:
* #201055
* #201059
* #201062
* #201080
* #201083
* #201126
* #201194
* #201224
* #201229
* #202547
* #202611
* #202622
* #203645
* #204617
* #204615
* Port classes and utils:
* #204801
* #204805
* #204806
* #204807
* Final removal:
* #204808

## Agent details (if applicable)

Developed with assistance from Claude Opus 5.5
Summary:
> Replace ideep type aliases with the oneDNN (or std) types they name:
> data_type, dims, format_tag/tag, prop_kind, algorithm, scale_t,
> zero_point_t and exec_args. Each is a plain `using` in ideep, so this is
> a pure spelling change with no effect on generated code. It removes
> about a third of the remaining ideep references from ATen CPU code
> without touching any ideep-specific behavior.

Pull Request resolved: #201053
Approved by: https://github.com/albanD, https://github.com/malfet
@frost-intel

Copy link
Copy Markdown
Collaborator Author

Moved to ghstack:
#205709

pytorchmergebot pushed a commit that referenced this pull request Nov 20, 2026
…into ATen (#205710)

## Linked issue or supporting maintainer
Part of #154444

## BC-breaking?
No

## Summary (human written only)
Ports `sum` and `binary` operators from ideep to `at::native::mkldnn::sum/binary`. Port is line-for-line. I also copy the `direct_copy` function in a new file. When we port `ideep::tensor` into ATen, the direct copy function will be moved into that file, so this is temporary.

## Agent details (if applicable)
Developed with assistance from Claude Opus 5.5.

> **What changed** (11 files, +167/−8):
>
> - **`detail/Sum.{h,cpp}` and `detail/Binary.{h,cpp}`:** `at::native::mkldnn::sum` and `binary`, ported line for line from ideep's `sum.hpp` and `binary.hpp`, one file each as in ideep. They keep the user-managed scratchpad, the output layout choice (from the inputs for `sum`, "any" for `binary`), input reorders for `binary`, and the in-place buffer replacement on `dst`.
> - **`detail/DirectCopy.{h,cpp}`:** `direct_copy`, ported from ideep's `direct_copy.hpp`. It keeps the buffer replacement, the reorder and the scale propagation.
> - **Call sites:** all 8 switched.
>
>   | File | Ops | Calls |
>   |---|---|---|
>   | `BinaryOps.cpp` | `add_out` (×2), `add`, `mul_out` | 4 |
>   | `Copy.cpp` | `copy_` | 1 |
>   | `TensorShape.cpp` | `clone` | 1 |
>   | `Normalization.cpp` | batchnorm running-stats update | 2 |
>
>   No `ideep::sum`, `ideep::binary` or `ideep::direct_copy` calls remain outside XPU, and `BinaryOps.cpp` and `Copy.cpp` no longer call any ideep operator.
> - **`build_variables.bzl`:** 3 entries. CMake and Buck pick up headers from the `detail/` setup added in PR 3.
>
> **Checks:**
>
> - **Same oneDNN calls before and after.** I ran all of `test_mkldnn.py` plus `test_freezing.py -k mkldnn` with `ONEDNN_VERBOSE=1` and compared the logged primitive creations and executions, with timings stripped. I ran the baseline twice first, and it repeats exactly, so any difference would be real.
>   - All 6,572 distinct primitive log lines are identical.
>   - Those tests exercise the ported code: `sum` runs 40 times (13 distinct), `binary` 4 times, and `reorder` runs 130,755 times, which includes the copies.
> - **Tests:**
>   - `test_mkldnn.py`: 92 passed, 1 skipped.
>   - Freezing tests: 4 passed, 5 skipped.
>   - `test_mkldnn_fusion.py`: OK.
>   - `test_nn.py -k "batchnorm and cpu"`: 9 passed.
> - **Lint:** clean.
>
> (`test/jit/test_freezing.py` and `test/test_mkldnn_fusion.py` were later deleted upstream by #203621. The final A/B comparison of the whole series against `main`, described in #204808, re-checks these paths without it.)
>
> Previously submitted as #201059.

Pull Request resolved: #205710
Approved by: https://github.com/albanD
ghstack dependencies: #205709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: cpu CPU specific problem (e.g., perf, algorithm) open source release notes: quantization release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants