Skip to content

[mkldnn][20/22] Port ideep's utility helpers, constants and enums into ATen - #204806

Closed
frost-intel wants to merge 49 commits into
pytorch:mainfrom
frost-intel:ideep-removal/20-port-ideep-utils
Closed

frost-intel wants to merge 49 commits into
pytorch:mainfrom
frost-intel:ideep-removal/20-port-ideep-utils

Conversation

@frost-intel

@frost-intel frost-intel commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Linked issue or supporting maintainer

Part of #154444

BC-breaking?

No

Summary (human written only)

Ports the last few ideep helpers into ATen, and switches ATen calls to the new ports. Changes include:

  • Scale constants
  • enums for lowp and rnn attributes
  • Use aliases for ideep::engine and ideep::stream, to be changed to ports in the next PR.

Tests verify no behavior change by checking oneDNN verbose logs before and after, as well as primitive-cache miss counts.

Fake stack

Agent details (if applicable)

Developed with assistance from Claude Opus 5.5.

Part of #154444 (remove the ideep submodule). Depends on #204805.

This ports the remaining small ideep helpers that ATen calls into aten/src/ATen/native/mkldnn/detail/Utils.h, in namespace at::native::mkldnn. The code is copied line-for-line from ideep's abstract_types.hpp, utils.hpp and attributes.hpp, with ideep's comments kept. After this PR, the only ideep types ATen still uses are the tensor, engine and stream, which the next PR ports.

Changes

  • detail/Utils.h gains:
    • constants DEF_SCALE, DEF_ZP, EMPTY_SCALE and EMPTY_ZP (from ideep's IDEEP_DEF_SCALE etc.);
    • enums lowp_kind and rnn_kind;
    • has_bf16_type_support() and has_fp16_type_support();
    • in utils::: fmap, any_le, get_compatible_dilates, group_dims, op_scale_mask, tensor_scale_mask, conv_weight_scale_mask and set_verbose.
  • ideep::post_ops becomes dnnl::post_ops. ideep's class was a thin wrapper that ATen used only through dnnl::post_ops methods.
  • Engine and IStream become aliases of ideep::engine and ideep::stream in detail/Tensor.h. They are ported in the next PR together with the tensor class, because the tensor allocates memory through the engine.
  • Call sites in mkldnn/ and quantized/cpu/ switch to the ATen names (30 files).

Deviations from ideep

  • The four constants are plain namespace-scope const, as in ideep. inline const would avoid one copy per file, but it added about 29 KB of per-file initialization code in libtorch_cpu.so, so I kept ideep's form.
  • utils::set_verbose keeps ideep's return convention: true when oneDNN reports success. Casting dnnl::status directly would invert the result, because success is 0.

Testing

No behavior change:

  • oneDNN verbose primitive logs are identical before and after for test_mkldnn, quantized conv, conv-transpose and linear, and matmul, as are the outputs of targeted probe scripts.
  • Primitive-cache miss counts are identical at the default LRU_CACHE_CAPACITY and at LRU_CACHE_CAPACITY=1.
  • Compiles cleanly with -Wall -Wextra -Wsign-compare -Werror in release and debug builds.

Update: the stream alias is IStream, not Stream. A Stream in at::native::mkldnn would shadow
at::Stream (c10::Stream) for all code in that namespace, the same reason the tensor is ITensor.
Engine has no at:: counterpart and keeps its name.

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01 @gujinghui @PenghuiCheng @jianyuh @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal

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).
@pytorch-bot

pytorch-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 67f6a6e with merge base 30c5b5d (image):
💚 Looks good so far! There are no failures yet. 💚

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

Move the fp32 and int8 prepare_parameters overloads out of Conv.cpp's
anonymous namespace and declare both in Conv.h. The transposed
convolution port reuses them from Deconv.cpp; with only the fp32
overload at namespace scope, the int8 one in the anonymous namespace
hides it and the fp32 calls fail to compile.
…ration-new

# Conflicts:
#	build_variables.bzl
…emoval/integration-new

# Conflicts:
#	aten/src/ATen/native/mkldnn/Normalization.cpp
#	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
…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
…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.
Mechanical rename of ideep::tensor to at::native::mkldnn::ITensor (an alias in
detail/Tensor.h) so the tensor port can swap in a ported class without touching
call sites again. Generated code is unchanged. Part of pytorch#154444.
Port the ideep helpers ATen still calls into detail/Utils.h: the default and
empty scale/zero-point constants, lowp_kind, rnn_kind, has_bf16/fp16_type_support,
and utils:: (scale/zero-point masks, group_dims, get_compatible_dilates,
set_verbose). ideep::post_ops uses become dnnl::post_ops. Engine and Stream
become aliases in detail/Tensor.h; they are ported together with the tensor
class, which allocates through the engine. Part of pytorch#154444.
at::Stream (c10::Stream) is visible inside at::native::mkldnn, and an
unqualified Stream there would silently pick the oneDNN stream. Use
IStream, matching the ITensor naming.
@frost-intel
frost-intel force-pushed the ideep-removal/20-port-ideep-utils branch from 71a62dc to 67f6a6e Compare November 19, 2026 16:43
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 added a commit that referenced this pull request Nov 21, 2026
… ATen

Part of #154444

No

Ports the last few ideep helpers into ATen, and switches ATen calls to the new ports. Changes include:
* Scale constants
* enums for lowp and rnn attributes
* Use aliases for `ideep::engine` and `ideep::stream`, to be changed to ports in the next PR.

Tests verify no behavior change by checking oneDNN verbose logs before and after, as well as primitive-cache miss counts.

Developed with assistance from Claude Opus 5.5.

>
> This ports the remaining small ideep helpers that ATen calls into the new `aten/src/ATen/native/mkldnn/detail/IdeepUtils.h`, in namespace `at::native::mkldnn`. The code is copied line-for-line from ideep's `abstract_types.hpp`, `utils.hpp` and `attributes.hpp`, with ideep's comments kept. After this PR, the only ideep types ATen still uses are the tensor, engine and stream, which 21/N ports, plus `ideep::attr_t` inside `Attr`'s conversion operator, which those tensor reorders need until then.
>
> ### Changes
> - `detail/IdeepUtils.h` (new) contains:
>   - constants `DEF_SCALE`, `DEF_ZP`, `EMPTY_SCALE` and `EMPTY_ZP` (from ideep's `IDEEP_DEF_SCALE` etc.);
>   - enums `lowp_kind` and `rnn_kind`;
>   - `has_bf16_type_support()` and `has_fp16_type_support()`;
>   - in `utils::`: `fmap`, `any_le`, `get_compatible_dilates`, `group_dims`, `op_scale_mask`, `tensor_scale_mask`, `tensor_zp_mask`, `conv_weight_scale_mask` and `set_verbose`;
>   - `one_of` and `is_avx2_vnni_2`, moved unchanged from `mkldnn/Utils.h`, where the earlier ports had added them.
> - Nine ported `detail/` files that included `mkldnn/Utils.h` for these helpers include `detail/IdeepUtils.h` instead. `mkldnn/Utils.h` and `MKLDNNCommon.h` include `detail/IdeepUtils.h`, so their other users still see these helpers.
> - `ideep::post_ops` becomes `dnnl::post_ops`. ideep's class was a thin wrapper that ATen used only through `dnnl::post_ops` methods.
> - `Engine` and `IStream` become aliases of `ideep::engine` and `ideep::stream` in `detail/Tensor.h`. They are ported in 21/N together with the tensor class, because the tensor allocates memory through the engine.
> - Call sites in `mkldnn/` and `quantized/cpu/` switch to the ATen names.
>
> ### Deviations from ideep
> None in behavior. Kept as in ideep, although they could be written differently:
> - The four constants are plain namespace-scope `const`, as in ideep. `inline const` would avoid one copy per file, but it added about 29 KB of per-file initialization code in `libtorch_cpu.so`, so I kept ideep's form.
> - `lowp_kind` and `rnn_kind` stay unscoped enums, as in ideep.
> - `utils::set_verbose` keeps ideep's return convention: `true` when oneDNN reports success. Casting `dnnl::status` directly would invert the result, because `success` is 0.
>
> The stream alias is `IStream`, not `Stream`. A `Stream` in `at::native::mkldnn` would shadow `at::Stream` (`c10::Stream`) for all code in that namespace, the same reason the tensor is `ITensor`. `Engine` has no `at::` counterpart and keeps its name.
>
> ### Testing
> No behavior change:
> - oneDNN verbose primitive logs are identical before and after for `test_mkldnn`, quantized conv, conv-transpose and linear, and matmul, as are the outputs of targeted probe scripts.
> - Primitive-cache miss counts are identical at the default `LRU_CACHE_CAPACITY` and at `LRU_CACHE_CAPACITY=1`.
> - Compiles cleanly with `-Wall -Wextra -Wsign-compare -Werror` in release and debug builds.
>
> Previously submitted as #204806.

cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 aditew01 gujinghui PenghuiCheng jianyuh min-jean-cho yanbing-j Guobing-Chen Xia-Weiwen snadampal

ghstack-source-id: 29bbb64
Pull-Request: #205980
frost-intel added a commit that referenced this pull request Nov 22, 2026
… ATen

Part of #154444

No

Ports the last few ideep helpers into ATen, and switches ATen calls to the new ports. Changes include:
* Scale constants
* enums for lowp and rnn attributes
* Use aliases for `ideep::engine` and `ideep::stream`, to be changed to ports in the next PR.

Tests verify no behavior change by checking oneDNN verbose logs before and after, as well as primitive-cache miss counts.

Developed with assistance from Claude Opus 5.5.

>
> This ports the remaining small ideep helpers that ATen calls into the new `aten/src/ATen/native/mkldnn/detail/IdeepUtils.h`, in namespace `at::native::mkldnn`. The code is copied line-for-line from ideep's `abstract_types.hpp`, `utils.hpp` and `attributes.hpp`, with ideep's comments kept. After this PR, the only ideep types ATen still uses are the tensor, engine and stream, which 21/N ports, plus `ideep::attr_t` inside `Attr`'s conversion operator, which those tensor reorders need until then.
>
> ### Changes
> - `detail/IdeepUtils.h` (new) contains:
>   - constants `DEF_SCALE`, `DEF_ZP`, `EMPTY_SCALE` and `EMPTY_ZP` (from ideep's `IDEEP_DEF_SCALE` etc.);
>   - enums `lowp_kind` and `rnn_kind`;
>   - `has_bf16_type_support()` and `has_fp16_type_support()`;
>   - in `utils::`: `fmap`, `any_le`, `get_compatible_dilates`, `group_dims`, `op_scale_mask`, `tensor_scale_mask`, `tensor_zp_mask`, `conv_weight_scale_mask` and `set_verbose`;
>   - `one_of` and `is_avx2_vnni_2`, moved unchanged from `mkldnn/Utils.h`, where the earlier ports had added them.
> - Nine ported `detail/` files that included `mkldnn/Utils.h` for these helpers include `detail/IdeepUtils.h` instead. `mkldnn/Utils.h` and `MKLDNNCommon.h` include `detail/IdeepUtils.h`, so their other users still see these helpers.
> - `ideep::post_ops` becomes `dnnl::post_ops`. ideep's class was a thin wrapper that ATen used only through `dnnl::post_ops` methods.
> - `Engine` and `IStream` become aliases of `ideep::engine` and `ideep::stream` in `detail/Tensor.h`. They are ported in 21/N together with the tensor class, because the tensor allocates memory through the engine.
> - Call sites in `mkldnn/` and `quantized/cpu/` switch to the ATen names.
>
> ### Deviations from ideep
> None in behavior. Kept as in ideep, although they could be written differently:
> - The four constants are plain namespace-scope `const`, as in ideep. `inline const` would avoid one copy per file, but it added about 29 KB of per-file initialization code in `libtorch_cpu.so`, so I kept ideep's form.
> - `lowp_kind` and `rnn_kind` stay unscoped enums, as in ideep.
> - `utils::set_verbose` keeps ideep's return convention: `true` when oneDNN reports success. Casting `dnnl::status` directly would invert the result, because `success` is 0.
>
> The stream alias is `IStream`, not `Stream`. A `Stream` in `at::native::mkldnn` would shadow `at::Stream` (`c10::Stream`) for all code in that namespace, the same reason the tensor is `ITensor`. `Engine` has no `at::` counterpart and keeps its name.
>
> ### Testing
> No behavior change:
> - oneDNN verbose primitive logs are identical before and after for `test_mkldnn`, quantized conv, conv-transpose and linear, and matmul, as are the outputs of targeted probe scripts.
> - Primitive-cache miss counts are identical at the default `LRU_CACHE_CAPACITY` and at `LRU_CACHE_CAPACITY=1`.
> - Compiles cleanly with `-Wall -Wextra -Wsign-compare -Werror` in release and debug builds.
>
> Previously submitted as #204806.

cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 aditew01 gujinghui PenghuiCheng jianyuh min-jean-cho yanbing-j Guobing-Chen Xia-Weiwen snadampal

ghstack-source-id: 77f72a8
Pull-Request: #205980
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
… ATen (#205980)

## Linked issue or supporting maintainer
Part of #154444
Supported by @albanD

## BC-breaking?
No

## Summary (human written only)
Ports the last few ideep helpers into ATen, and switches ATen calls to the new ports. Changes include:
* Scale constants
* enums for lowp and rnn attributes
* Use aliases for `ideep::engine` and `ideep::stream`, to be changed to ports in the next PR.

Tests verify no behavior change by checking oneDNN verbose logs before and after, as well as primitive-cache miss counts.

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

>
> This ports the remaining small ideep helpers that ATen calls into the new `aten/src/ATen/native/mkldnn/detail/IdeepUtils.h`, in namespace `at::native::mkldnn`. The code is copied line-for-line from ideep's `abstract_types.hpp`, `utils.hpp` and `attributes.hpp`, with ideep's comments kept. After this PR, the only ideep types ATen still uses are the tensor, engine and stream, which 21/N ports, plus `ideep::attr_t` inside `Attr`'s conversion operator, which those tensor reorders need until then.
>
> ### Changes
> - `detail/IdeepUtils.h` (new) contains:
>   - constants `DEF_SCALE`, `DEF_ZP`, `EMPTY_SCALE` and `EMPTY_ZP` (from ideep's `IDEEP_DEF_SCALE` etc.);
>   - enums `lowp_kind` and `rnn_kind`;
>   - `has_bf16_type_support()` and `has_fp16_type_support()`;
>   - in `utils::`: `fmap`, `any_le`, `get_compatible_dilates`, `group_dims`, `op_scale_mask`, `tensor_scale_mask`, `tensor_zp_mask`, `conv_weight_scale_mask` and `set_verbose`;
>   - `one_of` and `is_avx2_vnni_2`, moved unchanged from `mkldnn/Utils.h`, where the earlier ports had added them.
> - Nine ported `detail/` files that included `mkldnn/Utils.h` for these helpers include `detail/IdeepUtils.h` instead. `mkldnn/Utils.h` and `MKLDNNCommon.h` include `detail/IdeepUtils.h`, so their other users still see these helpers.
> - `ideep::post_ops` becomes `dnnl::post_ops`. ideep's class was a thin wrapper that ATen used only through `dnnl::post_ops` methods.
> - `Engine` and `IStream` become aliases of `ideep::engine` and `ideep::stream` in `detail/Memory.h`. They are ported in 21/N together with the tensor class, because the tensor allocates memory through the engine.
> - Call sites in `mkldnn/` and `quantized/cpu/` switch to the ATen names.
>
> ### Deviations from ideep
> None in behavior. Kept as in ideep, although they could be written differently:
> - The four constants are plain namespace-scope `const`, as in ideep. `inline const` would avoid one copy per file, but it added about 29 KB of per-file initialization code in `libtorch_cpu.so`, so I kept ideep's form.
> - `lowp_kind` and `rnn_kind` stay unscoped enums, as in ideep.
> - `utils::set_verbose` keeps ideep's return convention: `true` when oneDNN reports success. Casting `dnnl::status` directly would invert the result, because `success` is 0.
>
> The stream alias is `IStream`, not `Stream`. A `Stream` in `at::native::mkldnn` would shadow `at::Stream` (`c10::Stream`) for all code in that namespace, the same reason the memory class is not named is `Tensor`. `Engine` has no `at::` counterpart and keeps its name.
>
> ### Testing
> No behavior change:
> - oneDNN verbose primitive logs are identical before and after for `test_mkldnn`, quantized conv, conv-transpose and linear, and matmul, as are the outputs of targeted probe scripts.
> - Primitive-cache miss counts are identical at the default `LRU_CACHE_CAPACITY` and at `LRU_CACHE_CAPACITY=1`.
> - Compiles cleanly with `-Wall -Wextra -Wsign-compare -Werror` in release and debug builds.
>
> Previously submitted as #204806.

Pull Request resolved: #205980
Approved by: https://github.com/albanD
ghstack dependencies: #205978, #205979
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) module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration open source release notes: quantization release notes category release notes: releng release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants