Skip to content

core: copy constant padding directly into the output tensor - #3018

Draft
Reza2kn wants to merge 1 commit into
sonos:mainfrom
Reza2kn:codex/perf-constant-pad
Draft

Reza2kn wants to merge 1 commit into
sonos:mainfrom
Reza2kn:codex/perf-constant-pad

Conversation

@Reza2kn

@Reza2kn Reza2kn commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Constant Pad builds an ndarray and then copies the whole result into a tract tensor. Allocate the final tensor directly and copy contiguous input runs through the current executor, preserving signed zero and quantized metadata.

Related to #2739 and #2899. The broader OCR/ORT performance gap remains open.

M2, Criterion estimates for f32 [1,3,640,640] with one cell of H/W padding:

Executor main this change
1 worker 321 µs 151 µs
4 workers 304 µs 110 µs

Reproduce with cargo bench -p tract-core --profile opt-no-lto --bench pad, saving/comparing Criterion baselines. These timings include allocation and output construction.

Validation: cargo fmt --all, cargo clippy --workspace, cargo test -p test-unit-core pad --profile opt-no-lto, and exact-output NNEF checks in serial and with four workers on M2 and x86. Tests include empty dimensions, asymmetric/all-axis padding, multiple numeric types, signed zero, and quantized metadata.

🍍

…t tensor. Allocate the final tensor directly and copy contiguous rows through the executor.

This branch has not been deployed

No deployments
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.

1 participant