Skip to content

[mkldnn][19/22] Use an ITensor alias for ideep::tensor - #204805

Closed
frost-intel wants to merge 47 commits into
pytorch:mainfrom
frost-intel:ideep-removal/19-itensor-alias
Closed

frost-intel wants to merge 47 commits into
pytorch:mainfrom
frost-intel:ideep-removal/19-itensor-alias

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)

Rename ideep::tensor to at::native::mkldnn::ITensor. For now, this is an alias for ideep::tensor, and will replace it with the ported class in the next PR.

We use ITensor instead of Tensor to avoid conflict with at::Tensor in files which use both.

Fake stack

Agent details (if applicable)

Developed with assistance from Claude Opus 5.5.

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

This is a mechanical rename. Every use of ideep::tensor in ATen becomes at::native::mkldnn::ITensor, which for now is just an alias:

namespace at::native::mkldnn {
using ITensor = ideep::tensor;
}

The alias lives in the new aten/src/ATen/native/mkldnn/detail/Tensor.h. A later PR in this series replaces it with a ported class. Doing the rename first means that PR doesn't touch every call site again, and it keeps this large diff purely mechanical.

The name is ITensor rather than Tensor because Tensor would shadow at::Tensor in five files that use both.

Changes

  • detail/Tensor.h (new): defines the ITensor alias. It includes <cassert> before the ideep header, because ideep relies on its includer for assert.
  • Common.h and MKLDNNCommon.h include detail/Tensor.h.
  • 58 files: ideep::tensor -> ITensor, including the nested ideep::tensor::desc -> ITensor::desc, across aten/src/ATen/native/mkldnn/, native/quantized/cpu/ (including the aarch64-only ACLUtils) and torch/csrc/jit/passes/frozen_ops_to_mkldnn.cpp.
  • Three functions that declared using ideep::tensor; now declare using tensor = at::native::mkldnn::ITensor;, so their bodies stay unchanged.
  • quantized/cpu/OnednnUtils.h had one such declaration that nothing used. It is deleted rather than converted, because the converted form trips -Wunused-local-typedefs under -Werror.

Testing

No behavior change: this is a type alias, so the generated code is unchanged.

  • libtorch_cpu.so and libtorch_python.so have the same symbols and byte-identical .text before and after.
  • Compiles cleanly with -Wall -Wextra -Wsign-compare -Werror in release and debug builds.

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/204805

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

✅ No Failures

As of commit 799a125 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.

…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.
@frost-intel
frost-intel force-pushed the ideep-removal/19-itensor-alias branch from 7a8eb8e to 799a125 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
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
…205978)

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

## BC-breaking?
No

## Summary (human written only)
Rename `ideep::tensor` to `at::native::mkldnn::MkldnnMemory`. For now, this is an alias for `ideep::tensor`, and will replace it with the ported class in the next PR.

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

>
> This is a mechanical rename, split in two PRs for size; this is part 1 and 19/N is part 2. Every use of `ideep::tensor` in ATen becomes `at::native::mkldnn::MkldnnMemory`, which for now is just an alias:
>
>     namespace at::native::mkldnn {
>     using MkldnnMemory = ideep::tensor;
>     }
>
> The alias lives in the new `aten/src/ATen/native/mkldnn/detail/Memory.h`. 21/N replaces it with a ported class. Doing the rename first means that PR doesn't touch every call site again, and it keeps this large diff purely mechanical.
>
> ### Changes
> - `detail/Memory.h` (new): defines the `MkldnnMemory` alias. It includes `<cassert>` before the ideep header, because ideep relies on its includer for `assert`.
> - `Common.h` and `MKLDNNCommon.h` include `detail/Memory.h`, and their `ideep::tensor` uses become `MkldnnMemory`.
> - The ported `detail/` files other than `Conv` and `Deconv` (24 files): `ideep::tensor` -> `MkldnnMemory`, including the nested `ideep::tensor::desc` -> `MkldnnMemoryr::desc`.
>
> 19/N renames the rest: `detail/Conv` and `detail/Deconv`, the other files in `mkldnn/` and `quantized/cpu/`, and `torch/csrc/jit/passes/frozen_ops_to_mkldnn.cpp`. Comments that mention `ideep::tensor` are left as they are and updated in a later PR.
>
> ### Testing
> No behavior change: this is a type alias, so the generated code is unchanged.
> - For the whole rename (both parts, as previously submitted), `libtorch_cpu.so` and `libtorch_python.so` have the same symbols and byte-identical `.text` before and after.
> - Compiles cleanly with `-Wall -Wextra -Wsign-compare -Werror` in release and debug builds.
>
> Previously submitted, together with 19/N, as #204805.

Pull Request resolved: #205978
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
…205979)

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

## BC-breaking?
No

## Summary (human written only)
Rename `ideep::tensor` to `at::native::mkldnn::MkldnnMemory`. For now, this is an alias for `ideep::tensor`, and will replace it with the ported class in the next PR.

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

>
> Part 2 of the mechanical `ideep::tensor` -> `at::native::mkldnn::MkldnnMemory` rename. 18/N added the alias in `detail/Memory.h` and renamed `Common.h`, `MKLDNNCommon.h` and the non-conv `detail/` files; this PR renames the rest. 21/N replaces the alias with a ported class.
>
> ### Changes
> - 33 files: `ideep::tensor` -> `MkldnnMemory`, including the nested `ideep::tensor::desc` -> `MkldnnMemory::desc`, across `detail/Conv` and `detail/Deconv`, the rest of `aten/src/ATen/native/mkldnn/`, `native/Activation.cpp`, `native/quantized/cpu/` (including the aarch64-only `ACLUtils`) and `torch/csrc/jit/passes/frozen_ops_to_mkldnn.cpp`.
> - Three functions that declared `using ideep::tensor;` now declare `using tensor = at::native::mkldnn::MkldnnMemory;`, so their bodies stay unchanged.
> - `quantized/cpu/OnednnUtils.h` had one such declaration that nothing used. It is deleted rather than converted, because the converted form trips `-Wunused-local-typedefs` under `-Werror`.
>
> Comments that mention `ideep::tensor` are left as they are and updated in a later PR.
>
> ### Testing
> No behavior change: this is a type alias, so the generated code is unchanged.
> - For the whole rename (both parts, as previously submitted), `libtorch_cpu.so` and `libtorch_python.so` have the same symbols and byte-identical `.text` before and after.
> - Compiles cleanly with `-Wall -Wextra -Wsign-compare -Werror` in release and debug builds.
>
> Previously submitted, together with 18/N, as #204805.

Pull Request resolved: #205979
Approved by: https://github.com/albanD
ghstack dependencies: #205978
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