Repository navigation
Optimize bicubic resize with OpenMP - #1143
Open
AhmedDusuki wants to merge 1 commit into
Open
AhmedDusuki wants to merge 1 commit into
AhmedDusuki wants to merge 1 commit into
Conversation
Parallelize independent rows in the horizontal and vertical float-domain bicubic passes for large workloads, while retaining the scalar path for small images and builds without OpenMP. Add optional CMake discovery and linkage for supported C API vision targets, with exact scalar/OpenMP regression coverage.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Independent row writes preserve scalar accumulation order, and no blocking issues were identified in build integration or regression coverage.
No open issues 🎉
What changed in this PR
Adds optional OpenMP acceleration to vision C API bicubic resizing, addressing the parallelism portion of #1057 while retaining scalar execution for small workloads and unsupported builds.
Changes:
- Parallelizes independent rows above a work threshold.
- Adds conditional OpenMP discovery and linking.
- Tests exact equality between scalar and parallel resize helpers.
| File | Description |
|---|---|
| test/pp_api_test/test_processor.cc | Adds scalar/OpenMP equality regression coverage. |
| shared/api/image_resample_float.h | Adds row-parallel helpers and threshold-based dispatch. |
| CMakeLists.txt | Enables optional OpenMP for eligible vision C API builds. |
| cmake/ext_python.cmake | Links OpenMP into eligible Python extension builds. |
Review effort: Balanced
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.
Addresses #1057.
Summary
This adds optional OpenMP row parallelism to the float-domain bicubic resize used by the vision C API.
Both the horizontal and vertical passes operate on independent rows. The existing scalar helpers remain unchanged and are used for small workloads and builds without OpenMP. The implementation does not set a thread count, so applications retain control through their normal OpenMP runtime configuration.
OpenMP discovery is limited to eligible C API vision builds. Android, iOS, and Emscripten retain the scalar path because enabling OpenMP on those targets would change their runtime and deployment requirements.
Performance
Fresh local measurements were taken on an AMD Ryzen 5 2600X using GCC 14.4.0 in a release build. The TorchVision reference used PyTorch 2.14.1+cpu and TorchVision 0.29.1+cpu.
No thread count was configured for the original scalar path, this PR, or the default TorchVision column. On this machine, the OpenMP runtime selected 12 threads while PyTorch selected 6 intra-op threads by default. A separate TorchVision run explicitly used 12 intra-op threads for a matched thread-count reference.
Each configuration was launched three times. Every run used three warm-ups followed by 40, 30, 20, 15, or 10 timed samples from the smallest to largest case. Each table entry is the median of the three run medians.
The two smallest cases remain on the scalar path because they are below the parallel-work threshold. Their small timing differences are normal run-to-run variation.
The original and OpenMP paths produced identical output hashes in every run. TorchVision float is included as a familiar performance reference, but it is not an exact implementation comparison because it has slightly different floating-point results.
Correctness
Parallelism changes only which independent rows execute concurrently. The tap order and floating-point accumulation within each output pixel are unchanged.
The new regression test compares the scalar and OpenMP horizontal and vertical helpers using deterministic input and uneven dimensions. Both passes produce exactly equal output.
Validation
pp_api_test: 204 passed, 2 disabledlibgompgit diff --checkpassedThis PR focuses on the OpenMP portion of #1057. Explicit SIMD remains a possible follow-up if further optimization is needed.