Repository navigation
feat(rpp): added bilateral filter cpu kernel - #13786
sruthi0107 merged 7 commits into
Conversation
✅ All Checks Passed — Ready for Review
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
Pre-commit check failed⛔ pre-commit failed Please run locally:
This repo uses |
|
🎉 All checks passed! This PR is ready for review. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bounds errors, single-channel handling, HIP parameter access, numerical edge cases, and unsupported-backend tests affect correctness and safety.
5 open issues
What changed in this PR
Adds a scalar CPU bilateral filter to RPP’s tensor image operations. The supplied diff also includes API scaffolding and correctness tests, beyond the kernel-only scope described in the PR.
Changes:
- Implements per-image spatial and range weighting for four data types and planar/packed layouts.
- Adds the public API, argument validation, and HOST dispatch; HIP remains unimplemented.
- Adds an independent reference model and parameterized correctness and negative tests.
| File | Description |
|---|---|
| projects/rpp/utilities/test/src/tests/image/filter/bilateral_filter_test.cpp | Adds correctness grids and invalid-argument tests. |
| projects/rpp/utilities/test/src/reference/bilateral_filter_ref.hpp | Adds a double-precision reference model. |
| projects/rpp/src/modules/tensor/rppt_tensor_filter_augmentations.cpp | Adds validation and backend dispatch. |
| projects/rpp/src/modules/tensor/cpu/kernel/bilateral_filter.cpp | Implements scalar HOST filtering and layout handling. |
| projects/rpp/src/include/tensor/host_tensor_executors.hpp | Declares the HOST executor. |
| projects/rpp/api/rppt_tensor_filter_augmentations.h | Declares and documents the public API. |
Review effort: Balanced
Declares rppt_bilateral_filter and wires its HOST path end to end, with the CPU kernel left as a stub (returns RPP_ERROR_NOT_IMPLEMENTED) to be implemented on top. - API: rppt_tensor_filter_augmentations.h. Per-image stdDevSpaceTensor (pixels) and stdDevRangeTensor (stored pixel units), kernelSize 3/5/7/9, REPLICATE border only, per-channel range distance. - Entry point: argument validation (kernelSize, datatypes, layouts, batch size, border type, stdDevs > 0) and U8/F16/F32/I8 HOST dispatch. HIP returns RPP_ERROR_NOT_IMPLEMENTED. - host_tensor_executors.hpp: bilateral_filter_host_tensor declaration. - cpu/kernel/bilateral_filter.cpp: stub with the spec in a comment and the four explicit instantiations.
Reference model and Correctness/Negative tests for the new rppt_bilateral_filter op, in the ROCm#11802 suite layout. - Golden reuses filter_common.hpp's window: square KxK, REPLICATE clamped to the ROI, per-channel range distance, per-image stdDevs, stdDevRangeTensor in the dtype's stored units. - Correctness: 704 cases per backend (gaussian_filter's grid) with identity (sr0p1) and gaussian-limit (sr10000) parameter corners. - Negative: even/out-of-range kernelSize, zero/negative stdDevs and a non-REPLICATE border must not return RPP_SUCCESS. Requires an RPP that declares rppt_bilateral_filter.
ba2b96c to
e71e99f
Compare
AryanSalmanpour
left a comment
There was a problem hiding this comment.
Reviewed the new HOST kernel at e71e99f6. I reimplemented the kernel's float arithmetic against the double reference and ran both over PKD3/PLN3/PLN1, partial ROIs, ROIs smaller than K, K in {3,5,7,9}, U8/I8/F32 and the degenerate-sigma corners: max deviation 0 LSB on U8/I8 and <=1.2e-7 on F32. I found no correctness defect — the I8 +128 / saturate_pixel pairing, the colOffsets bounds and the 256-entry LUT indexing are all exactly in range, and weightSum >= 1 always.
Two defensive/efficiency points below. Copilot's five earlier findings all look resolved by this rewrite (I re-checked the tiny-sigma NaN case numerically), so nothing here repeats them. Separately, this kernel has no intra-image parallelism and no AVX2 path unlike every sibling filter — that needs a coordinated change across the signature and call site, so I have raised it outside the diff rather than as a suggestion.
sruthi0107
left a comment
There was a problem hiding this comment.
All tests pass and the implementation looks good to me
TheRock Submodule Bump ActivityNewest first
|
Resolves conflicts with rppt_bilateral_filter (#13786), which was appended at the same place in rppt_tensor_filter_augmentations.h/.cpp. Both ops are kept, bilateral first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Motivation
Implements the HOST (CPU) kernel for
rppt_bilateral_filter. The API, entry point and executor declaration came in as scaffolding onusers/sruthi0107/rpp-bilateral-filter, where the CPU kernel was a stub that returnedRPP_ERROR_NOT_IMPLEMENTED. This PR replaces that stub with a working scalar implementation that matches the golden model inbilateral_filter_ref.hpp.Technical Details
Only
src/modules/tensor/cpu/kernel/bilateral_filter.cppchanges. The header, entry point, executor declaration and tests are untouched.Algorithm. For each image, channel and output pixel in the ROI, the kernel computes the weighted mean over a square K×K window (K ∈ {3, 5, 7, 9}):
create_bilateral_spatial_kernel_host).|v - v0|. Differences are always whole numbers in [0, 255], so the lookup is exact.exp(-(v - v0)² · rangeMulFactor)is computed directly, withrangeMulFactor = 1 / (2σr²)precomputed per image. Float differences aren't whole numbers, so a table can't be indexed by them.Rpp32ffor every data type.nearbyintf) and then saturate. F16/F32 are not rounded and are clamped to [0, 1]. I8 adds +128 beforesaturate_pixelto offset that helper's −128 shift. σr is used in stored units, with no rescaling.[batchCount].gaussian_filter_host_tensor.Not in this PR:
fast_exp_avxfor the range term) is planned as a follow-up, with these tests as the safety net.RPP_ERROR_NOT_IMPLEMENTEDfrom the scaffold.Test Plan
make rpp(-DBACKEND=HIP -DCMAKE_BUILD_TYPE=Release -DGPU_TARGETS=gfx1100) and installed it to a local prefix.users/sruthi0107/rpp-bilateral-filter-tests(golden model and gtest cases, on top of the gtest suite in feat(rpp): Add a GoogleTest correctness suite for RPP tensor operations #11802) into the working tree without committing them. Builtrpp_testsagainst the local install and confirmed withlddthat it loads the newlibrpp.so../rpp_tests --gtest_filter='*BilateralFilter*/HOST_*'.The test grid covers:
Test Result
All 711 HOST tests pass:
BilateralFilterTest.Correctness: 704/704BilateralFilterNegativeTest.Negative: 7/7HIP cases were not run; that backend is not implemented yet.
Submission Checklist