AMD's ROCm RPP Proposal Speeds Up CPU Image Filtering With AVX2 and Multithreading
On December 1, a draft pull request in AMD's ROCm development repository proposed speeding up the CPU implementation of the bilateral filter.
ROCm Performance Primitives (RPP) is a library for processing images, audio, and volumetric data used in deep learning. It supports both a HOST backend for AMD CPUs and a HIP backend for GPUs.
A bilateral filter smooths an image using neighboring pixels, weighting them by both distance and the difference in pixel values. Giving less weight to pixels with very different values lets the filter reduce noise while preserving edges.
The initial CPU implementation, merged on October 29 UTC, processed pixels with scalar operations. The goal was to match the reference implementation first and optimize with AVX2 later.
The new proposal follows through on that plan. The existing implementation uses one thread per image, so the draft reworks both the computation and the way work is split across threads.
AMD ROCm RPP CPU bilateral filter
| Item | Existing implementation | Proposal |
|---|---|---|
| Layout | Calculate pixel positions based on layout | Common planar layout 32-bit floating point |
| Boundaries | Check during computation | Replicate edge pixels first |
| Computation | Process pixels individually | Process 8 pixels at once with AVX2 |
| Weights | 8-bit integers: lookup table Floating point: evaluate exponential | Combine both weights with base-2 exponential (AVX2, no division) |
| One image | 1 thread | Split rows among multiple threads |
| Multiple images | Divide work by image | 1 thread per image Thread count capped at image count |
Standardizing pixel layout to reduce computation
RGB data can store the red, green, and blue values together for each pixel or group them by color channel. The previous filter calculated pixel positions based on the layout of the image.
The proposed implementation separates loading, filtering, and writing. When loading, it converts each channel value to 32-bit floating point and stores it in a common planar layout. Supported combinations of input and output layouts can then use the same filter implementation.
The loader pads both ends of each row by replicating pixels at the edges of the region of interest. That removes repeated boundary checks from the filter itself. Each thread keeps converted rows and reuses them when processing adjacent rows.
The filter uses AVX2, which operates on several values per instruction, to process eight pixels in parallel. The AVX2 implementation uses F16C to convert between 16-bit and 32-bit floating point. The scalar path handles non-AVX2 builds and pixels at the end of a row that do not fill a vector.
Weight calculation also changes for floating-point images. The older implementation used a precalculated table for 8-bit integer pixel differences and evaluated the exponential directly for floating-point values.
The new AVX2 implementation combines the spatial and pixel-value weights into a single base-2 exponential. It splits the exponent into the nearest integer and the remainder. The integer power of two is encoded in the floating-point exponent field, and a sixth-degree polynomial approximates the power of two for the remainder. This avoids division in the exponential and prevents tiny weights from becoming slower-to-process subnormal values.
The contributor said unrolling the loop exhausted the CPU registers available for intermediate values, spilling some to the stack and slowing parts of the computation. The new version limits unrolling.
The changes that make vectorization work extend to the steps before and after the calculation. A common layout frees the filter from computing pixel positions separately for each input format.
Using multiple threads for one image
The proposal also changes how the filter uses CPU threads. Previously, threads could share the work across several images, but one thread processed each image.
The draft splits a single image into row groups, assigning consecutive rows to each thread. Each thread starts by loading rows above its assigned region, so the filter still has the neighboring pixels it needs at the boundaries.
In a batch, work remains divided by image, with at most one thread per image. The contributor said extra threads waiting for work to finish can slow the CPU cores that are doing the computation.
If splitting the work would leave fewer than four rows per thread, the existing logic falls back to one thread. Image size and batch size determine where parallelism is used.
Timing tests on a Ryzen 9 7900X
The contributor tested the draft using an AMD Ryzen 9 7900X with 12 cores and 24 threads and ROCm 10.0. The measurements compare the median of five runs after warm-up on full HD (1920 × 1080) RGB images. The spatial standard deviation was set to 1, and the pixel-value standard deviation was set to 25 in the 8-bit range. For floating-point images, the latter was divided by 255 to match the range.
AMD ROCm RPP CPU filter benchmarks
| Bilateral filter (CPU) Ryzen 9 7900X・ROCm 10.0 1920 × 1080 RGB, median of 5 runs December 1, 2026 update. Speedups vs. original. | ||||
|---|---|---|---|---|
| Threads Old → new | Original (ms) | Initial draft (ms) | Latest draft (ms) | Speedup in latest draft |
| 1 image: unsigned 8-bit, 3 × 3 (interleaved) | ||||
| 1→1 | 67.8 | 19.75 | 16.02 | 4.2× |
| 1→24 | 67.8 | 1.61 | 1.27 | 53× |
| 1 image: 16-bit float, 5 × 5 (interleaved → planar) | ||||
| 1→1 | 896.6 | 51.10 | 31.90 | 28× |
| 1→24 | 896.6 | 4.15 | 2.92 | 307× |
| 1 image: 32-bit float, 9 × 9 (interleaved) | ||||
| 1→1 | 2466.9 | 149.72 | 100.58 | 24.5× |
| 1→24 | 2466.9 | 12.73 | 9.48 | 260× |
| 8 images: 32-bit float, 9 × 9 (interleaved) | ||||
| 8→8 | 2951.0 | 209.5 | 106.9 | 27.6× |
In the contributor's December 1 update, a 3 × 3 filter on one unsigned 8-bit image took 67.8 ms with the old single-threaded implementation. The new implementation took 16.02 ms with one thread and 1.27 ms with 24. With 24 threads it was about 53 times as fast as the original.
In a test filtering a 16-bit floating-point image with a 5 × 5 window and converting interleaved RGB to planar RGB, time fell from 896.6 ms to 31.90 ms with one thread and 2.92 ms with 24. The latter was about 307 times as fast in this comparison.
A 9 × 9 filter on a 32-bit floating-point image fell from 2,466.9 ms to 100.58 ms with one thread and 9.48 ms with 24, a roughly 260-fold speedup. In a batch test with eight 32-bit floating-point images and a 9 × 9 filter, processing with eight threads dropped from 2,951.0 ms to 106.9 ms, about 27.6 times as fast.
The updated results also compare the initial draft with the latest revision. The initial draft introduced layout conversion, AVX2 computation, and threading within one image. The latest revision improves the exponential approximation and conversion of 16-bit floating-point values, among other changes. In the 16-bit layout-conversion test, the initial draft had already reduced the time to 51.10 ms with one thread and 4.15 ms with 24.
The single-threaded gains are worth noting. Layout and computation changes reduced processing time even before work within an image was spread across threads. Multithreading builds on those gains.
The figures apply to a particular filter, CPU, image size, and format. Gains in an application will depend on how much of its time is spent in the filter and on its processing conditions.
Tests to protect correctness
When threads share an image, each region still needs the correct neighboring pixels at the edges. The contributor added tests specifically for splitting images.
According to the contributor, deliberately breaking initialization at a split boundary left the old tests passing but caused all 80 of the new CPU tests to fail. The new tests caught the boundary error.
The contributor reported that all 2,167 bilateral-filter tests passed on each of CPU and GPU, and all 176 comparisons with the reference implementation stayed within tolerance. The one-thread and 24-thread results also matched bit for bit.
Rethinking how one image is processed produced very different runtimes in the contributor's tests. It shows how much work can go into getting more from a CPU. From the order of pixels in memory to how calculations run and how threads divide the work, software design changes how the hardware is used.
KioskNews shows a cleaned-up reading view extracted from the publisher’s page — the original always lives on their site, not ours.
