Skip to content

Add int8/uint8 CPU support for SpaceToDepth and int8 for DepthToSpace#29154

Open
ArsalanShakil wants to merge 1 commit into
microsoft:mainfrom
ArsalanShakil:spacedepth-integer-types
Open

Add int8/uint8 CPU support for SpaceToDepth and int8 for DepthToSpace#29154
ArsalanShakil wants to merge 1 commit into
microsoft:mainfrom
ArsalanShakil:spacedepth-integer-types

Conversation

@ArsalanShakil

@ArsalanShakil ArsalanShakil commented Jun 18, 2026

Copy link
Copy Markdown

Description

Add CPU support for 8-bit integer tensor types to the SpaceToDepth and DepthToSpace operators:

  • SpaceToDepth (opsets 1–12 and 13): previously supported only float/double; now also accepts uint8 and int8.
  • DepthToSpace (opsets 11–12 and 13): previously supported float/double/uint8; now also accepts int8.

uint8_t and int8_t are routed through a single template instantiation. These ops only shuffle 8-bit elements around, so the signedness of the data is irrelevant — handling both in one branch avoids the binary-size cost of a second instantiation (per the guidance in #21287). SpaceDepthOpCpuImpl now takes raw pointers so the shared branch can feed it via DataRaw()/MutableDataRaw().

Also adds typed unit tests covering uint8/int8 for SpaceToDepth and int8 for DepthToSpace, and updates docs/OperatorKernels.md.

Motivation and Context

Fixes #21287. The DepthToSpace/SpaceToDepth ONNX operators support integer types, but the ORT CPU kernels did not fully implement them, which is needed for running quantized models. This completes the integer support on CPU (SpaceToDepth had none; DepthToSpace was missing int8).

The CUDA kernels are already generic and could be extended similarly in a follow-up; this PR focuses on the CPU EP.

SpaceToDepth previously supported only float/double on CPU, and
DepthToSpace supported float/double/uint8. Extend the CPU kernels so
both ops also accept 8-bit integer tensors, which is needed for running
quantized models.

uint8_t and int8_t are routed through a single template instantiation:
the ops only shuffle 8-bit elements, so the signedness of the data is
irrelevant and we avoid the binary-size cost of a second instantiation.
SpaceDepthOpCpuImpl now takes raw pointers so the shared branch can feed
it via DataRaw().

Adds typed unit tests covering uint8/int8 for SpaceToDepth and int8 for
DepthToSpace, and updates docs/OperatorKernels.md.

Fixes microsoft#21287
@ArsalanShakil

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] SpaceToDepth & DepthToSpace integer implementations

1 participant