torchvision.roi_align performance optimization with openMP
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🚀 The feature
Looking at the implementation of roi_align_kernel, it seems as if this can be further optimized using openmp parallelization
Here's what can be done to get performance boost:
- Added
#pragma omp parallel forto the kernel (line 27) - Added -fopenmp as CFLAG to the compilation
- Set torch.set_num_threads() to desired num of OMP threads (on test/WL side).
Motivation, pitch
I did some experimentation locally in which:
- I've added this optimization
- Built a small test case that calls roi_align
- Profiled
torchvision.ops.roi_align()and measured time using current implementation vs. 18 threads on simple CLX machine.
On my humble experiments it shows 10X performance boost!
Alternatives
There can be other libraries/tooling that can do optimization to this CPU kernel. One can think of oneTBB or something alike.
Nevertheless, the current implementation is a really naive and can easily be much performant.
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with torchvision/csrc/ops/cpu/roi_align_kernel.cpp at the linked roi_align_kernel implementation and review how the CPU extension is compiled. Reproduce the reported comparison with a small roi_align test case, then evaluate OpenMP compilation and thread-setting behavior. Done means a validated performance improvement without regressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-vision, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100