Repository navigation
[mkldnn][18/N] Port ideep's primitive cache and attr_t into ATen - #204801
Closed
frost-intel wants to merge 46 commits into
Closed
frost-intel wants to merge 46 commits into
frost-intel wants to merge 46 commits into
Conversation
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::softmax_forward, ideep::prelu_forward and ideep::prelu_backward into aten/src/ATen/native/mkldnn/detail/ {Softmax,Prelu}.{h,cpp} and switch the callers in SoftMax.cpp and Prelu.cpp. The port is line-for-line; prelu_backward drops ideep's unused prop_kind parameter. ideep::softmax_backward has no ATen callers and is not ported. 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.
Replace the weight_with_src_rank helper with ideep's inline code in prelu_forward and prelu_backward so the port reads line-for-line against ideep's prelu.hpp. No behavior change; ONEDNN_VERBOSE logs are unchanged.
Part of pytorch#154444. Depends on pytorch#201055. Move ideep::pooling_forward and ideep::pooling_backward into aten/src/ATen/native/mkldnn/detail/Pooling.{h,cpp} and switch the callers in Pooling.cpp. The port is line-for-line, including storing max-pool indices as a workspace on the output tensor for use by the backward pass. ideep::pooling_v2_* (dilated pooling) has no ATen callers and is not ported. 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.
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.
Part of pytorch#154444. Depends on pytorch#201055. Move the ideep batch_normalization_forward_inference/forward_training/ backward and layer_normalization_forward operators used by ATen into aten/src/ATen/native/mkldnn/detail/{BatchNorm,LayerNorm}.{h,cpp} and switch the callers in Normalization.cpp. The port is line-for-line for the code paths ATen uses; flags are fixed to ideep's defaults (the only values ATen ever passed), so ideep's unused fused-relu/workspace branches and the ignored momentum parameter are dropped. Verified with ONEDNN_VERBOSE=1: the primitive create/exec log of test_mkldnn.py and the mkldnn freezing tests is identical before and after. A new test_mkldnn_layer_norm in test_freezing.py is added, since not previously covered by tests.
Replace the kScaleShift constant with ideep's per-function pd_flags in the batchnorm forward inference, forward training and backward ports so they read line-for-line against ideep's batchnorm.hpp. No behavior change; ONEDNN_VERBOSE logs are unchanged.
Part of pytorch#154444. Depends on pytorch#201055. Move the ideep lstm_forward_inference (compute and expected_weights_desc), lstm_forward_training (prepare and compute) and lstm_backward operators used by ATen into aten/src/ATen/native/mkldnn/detail/Lstm.{h,cpp} and switch the callers in RNN.cpp and MKLDNNConversions.cpp. The port is line-for-line for the code paths ATen uses, including ideep's u8 branch; parameters that ATen never passed or ideep ignored are dropped. Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing tests (all primitive create/exec lines identical before and after), and by comparing the output of mkldnn._reorder_mkldnn_rnn_layer_weight across 24 configurations (byte-identical packed layouts and values).
Part of pytorch#154444. Depends on pytorch#201055 (only the top commit is new). Move the ideep inner_product_forward (compute, compute_binary, expected_weights_desc), inner_product_backward_data and inner_product_backward_weights code paths used by ATen into aten/src/ATen/native/mkldnn/detail/InnerProduct.{h,cpp} and switch the callers in Linear.cpp and MKLDNNConversions.cpp. The port is line-for-line; ideep's private helpers keep their names. Primitive descriptors still come from ideep's computation_cache with the same keys, so the cache is shared with ideep until it is ported separately. Verified with ONEDNN_VERBOSE=1: the primitive create/exec logs of test_mkldnn.py, the mkldnn freezing tests, test_mkldnn_fusion.py and the Inductor mkldnn linear pattern tests are identical before and after.
Cast weights.ndims() to size_t when comparing with diff_src_dims.size(). The comparison is copied from ideep, where it is hidden by the system-header include; WERROR builds reject it here.
Part of pytorch#154444. Depends on pytorch#201055. Port the floating-point convolution forward, backward-data and backward-weights operators ATen uses from ideep into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}. The port is line-for-line, still takes ideep::tensor/attr_t, and shares ideep's primitive cache, so behavior is unchanged. Switch the call sites in mkldnn/Conv.cpp, ConvPrepack.cpp, MKLDNNConversions.cpp and quantized/cpu/qconv_prepack.cpp (expected_weights_desc only). Quantized prepare/compute and transposed convolution remain on ideep for now. Drop code ATen never reaches: use_gemm, unused overloads/parameters, backward_weights' diff_weight_type, and the fixed algorithm parameter on backward. Remove an unused variable and fix sign-compare loop indices that surface outside ideep's system-header include.
Keep only the fp32 forward port (compute_v3, compute_binary, expected_weights_desc and their helpers) to stay under the PR size limit. Backward data/weights and compute_v2 with its int8 prepare_parameters / compute_dispatch path move to separate PRs; their call sites in mkldnn/Conv.cpp and ConvPrepack.cpp go back to ideep until those land.
Part of pytorch#154444. Depends on pytorch#201055. Port the floating-point matmul path ATen uses (ideep's deprecated no-bias matmul_forward::compute) into aten/src/ATen/native/mkldnn/detail/Matmul.{h,cpp}. The port is line-for-line, still takes ideep::tensor/attr_t, and shares ideep's primitive cache, so behavior is unchanged. Switch the three call sites in mkldnn/Matmul.cpp. Quantized linear remains on ideep for now. Drop code ATen never reaches: compute_impl's int8 branches (callers always pass empty scales and unscaled weights), the scale, bin_post_params, dst_type, lowp_kind and engine parameters, and the unused zero-point, bias-attr and dynamic-quant fields.
Part of pytorch#154444. Depends on pytorch#201055. Port convolution_backward_data::compute_v2 and convolution_backward_weights::compute_v2 (with its compute_impl) into aten/src/ATen/native/mkldnn/detail/ConvBackward.{h,cpp}. The port is line-for-line and still takes ideep::tensor/attr_t. As in ideep, the forward hint comes from ideep::convolution_forward::get_primitive_desc. Switch the backward call sites in mkldnn/Conv.cpp. Drop the fixed algorithm parameter, the engine parameters, and backward_weights' unused diff_weight_type branch.
…rimitive_desc Base this PR on the conv forward port (pytorch#201224) instead of PR 3. The backward data/weights port now lives in detail/Conv.{h,cpp} next to the forward code, as in ideep's conv.hpp, and its forward hint calls the ported get_primitive_desc instead of ideep::convolution_forward:: get_primitive_desc. detail/ConvBackward.{h,cpp} are removed.
Part of pytorch#154444. Depends on pytorch#201224. Port ideep's deprecated convolution_forward::compute_v2 (with and without bias) and the code it routes through, the scale/zero-point compute_dispatch and the int8 conv_deconv_utils::prepare_parameters, into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}. The port is line-for-line, still takes ideep::tensor/attr_t, and shares ideep's primitive cache, so behavior is unchanged. Switch the two compute_v2 calls in mkldnn/ConvPrepack.cpp. Drop the algorithm, prop_kind, lowp_kind and engine parameters ATen never passes, and an unused weights_zero_point local.
Port the int8 paths of ideep::matmul_forward used by quantized linear into
detail/Matmul.{h,cpp}. Part of pytorch#154444.
- TensorFactories: drop the int32_t-dims note; dnnl::memory::dims is int64_t. - qconv: the dst-scale comments named a nonexistent `scale_size`; describe what the code actually passes (1/output_scale and dst_zero_points).
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204801
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 42d257d with merge base 30c5b5d ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Nov 13, 2026
Part of pytorch#154444. Ports the int8 paths of `ideep::convolution_transpose_forward` that quantized `conv_transpose` uses into `aten/src/ATen/native/mkldnn/detail/Deconv.{h,cpp}`. The port is line for line, with no behavior change, and still uses ideep's primitive cache. - `deconv_forward_params` moves into `Deconv.h`; `DeconvParams` in `OnednnUtils.h` now points at it. - Ported: int8 `prepare`, `compute` with prepared params, and int8 2-in-1 `compute`, plus the int8 `do_prepare` and `compute_impl` behind them. Call sites in `qconv.cpp` are switched over. - The int8 `conv_deconv_utils::prepare_parameters` from 14/N is now declared in `Conv.h`, and its definition moves out of `Conv.cpp`'s anonymous namespace. That move also fixes a build error when 14/N and 15/N are combined: with the int8 overload left in the anonymous namespace, it hides 15/N's fp32 overload. Not ported, because ATen never reaches them: `compute_v2`, `prepare_v3`, and the no-bias int8 overloads. The only change from ideep is dropping the `engine` parameter. With this, every ideep operator ATen uses is ported. The remaining non-type ideep use is the primitive cache clear in `IDeepRegistration.cpp`. Testing: A/B oneDNN verbose logs (before vs. after) are identical for: - the quantized conv/deconv tests, with fixed random seeds - `test_mkldnn` - a probe that reuses packed deconv weights with new input scales and shapes to reach the cache-miss path; its outputs are also bitwise equal
This test was added to test/jit/test_freezing.py earlier in this PR, but pytorch#203621 deleted that file together with the public torch.jit.script and torch.jit.freeze. The MKLDNN layer norm port is only reachable through the frozen-graph pass (prim::MKLDNNLayerNorm), so move the test here and drive the pass through the private entry points that remain.
frost-intel
force-pushed
the
ideep-removal/18-port-primitive-cache
branch
from
November 13, 2026 20:13
5d00f5b to
c5e7e97
Compare
…ration-new # Conflicts: # build_variables.bzl
…emoval/integration-new # Conflicts: # aten/src/ATen/native/mkldnn/Normalization.cpp # build_variables.bzl
…ion-new # Conflicts: # build_variables.bzl
…/integration-new # Conflicts: # aten/src/ATen/native/mkldnn/MKLDNNConversions.cpp # build_variables.bzl
…ion-new # Conflicts: # aten/src/ATen/native/mkldnn/MKLDNNConversions.cpp # build_variables.bzl
…al/integration-new
…l/integration-new # Conflicts: # aten/src/ATen/native/mkldnn/detail/Conv.cpp # aten/src/ATen/native/mkldnn/detail/Conv.h
…ation-new # Conflicts: # aten/src/ATen/native/mkldnn/MKLDNNConversions.cpp # build_variables.bzl
…val/integration-new
…ation-new # Conflicts: # build_variables.bzl
…val/integration-new # Conflicts: # aten/src/ATen/native/quantized/cpu/OnednnUtils.h
Port ideep::utils::{lru_cache,computation_cache,create_key,to_bytes} into
detail/PrimitiveCache.h (namespace at::native::mkldnn::utils) and switch the
ported conv, deconv, inner product and matmul ops to it. clear_computation_cache
now clears the ported convolution store. Same capacity (1024; 1 on aarch64),
LRU_CACHE_CAPACITY override, per-thread stores and key bytes as ideep.
Part of pytorch#154444.
Mechanical rename of ideep::attr_t to at::native::mkldnn::Attr (an alias in detail/Attr.h) so the following commit can swap in a ported class without touching call sites again. Part of pytorch#154444.
Replace the Attr alias with a port of ideep::attr_t in detail/Attr.h: the constructors, deep-copy assignment, scale/zero-point storage, has_op_kind, non_negitive_output, to_bytes (cache key) and the factory helpers ATen uses. Unused helpers are not ported. A conversion to ideep::attr_t, carrying the scale and zero-point maps, remains until ideep::tensor is ported, since its reorders still take ideep::attr_t. Part of pytorch#154444.
frost-intel
force-pushed
the
ideep-removal/18-port-primitive-cache
branch
from
November 19, 2026 16:43
c5e7e97 to
42d257d
Compare
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
pytorchmergebot
pushed a commit
that referenced
this pull request
Nov 25, 2026
…5977) ## Linked issue or supporting maintainer Part of #154444 Supported by @albanD ## BC-breaking? No ## Summary (human written only) This PR ports oneDNN primitive cache and attr_t from ideep to ATen, as well as renames for uses within ATen. Tests verified the same number of cache-misses for a fixed workload with A/B testing. ## Agent details (if applicable) Developed with assistance from Claude Opus 5.5. > > Three parts, each line-for-line with no behavior change: > > 1. **Primitive cache.** `detail/PrimitiveCache.h` ports `ideep::utils::lru_cache`, `computation_cache` and the `to_bytes`/`create_key` key builders. Behavior is unchanged: one thread-local store per descriptor type, capacity 1024 (1 on aarch64), overridable with `LRU_CACHE_CAPACITY`, and byte-identical keys. The conv, deconv, inner-product and matmul ports, plus `clear_computation_cache`, now use it. The ideep store is no longer used by ATen. > 2. **`Attr` alias.** Mechanical rename of `ideep::attr_t` to `at::native::mkldnn::Attr` (233 uses). > 3. **`Attr` class.** `detail/Attr.h` ports `ideep::attr_t`: the constructors ATen uses, deep-copy assignment, scale/zero-point storage, `has_op_kind`, `non_negative_output` (ideep spells it `non_negitive_output`), `to_bytes`, and the 15 factory helpers ATen uses. Unused helpers and constructors are not ported. ideep's note in `to_bytes` saying scales and zero points are not encoded is out of date (they are), so it is rewritten to list what is actually left out. A conversion to `ideep::attr_t` that carries the scale and zero-point maps remains until `ideep::tensor` is ported (21/N), because its reorders still take `ideep::attr_t`. > > Testing: > - oneDNN verbose logs before vs. after are identical for `test_mkldnn`, quantized conv/deconv/linear, and the fp matmul tests. The cache-miss probes for quantized linear/deconv and the fp32 matmul probe also give bitwise-equal outputs. > - Per-op primitive-descriptor cache-miss counts are identical before vs. after, at the default capacity and with `LRU_CACHE_CAPACITY=1`. > - A standalone probe checks that `Attr` and `ideep::attr_t` produce byte-identical cache keys for every factory and constructor ATen uses, and that copying and conversion keep scales and zero points. > > Previously submitted as #204801. Pull Request resolved: #205977 Approved by: https://github.com/albanD ghstack dependencies: #205972, #205973, #205974, #205975, #205976
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue or supporting maintainer
Part of #154444
BC-breaking?
No
Summary (human written only)
This PR ports oneDNN primitive cache and attr_t from ideep to ATen, as well as renames for uses within ATen.
Tests verified the same number of cache-misses for a fixed workload with A/B testing.
Depends on 2/N-17/N.
Fake stack
sum,binary, anddirect_copyops from ideep into ATen #201059compute_v2op into ATen #202611Agent details (if applicable)
Developed with assistance from Claude Opus 5.5.