Skip to content

[RPP] Add rocFFT GPU acceleration for audio spectrogram (AICV-283) - #11496

Draft
LakshmiKumar23 wants to merge 17 commits into
developfrom
users/lakshmi/rpp-audio-rocfft
Draft

[RPP] Add rocFFT GPU acceleration for audio spectrogram (AICV-283)#11496
LakshmiKumar23 wants to merge 17 commits into
developfrom
users/lakshmi/rpp-audio-rocfft

Conversation

@LakshmiKumar23

Copy link
Copy Markdown
Contributor

Summary

This PR adds rocFFT library support for GPU-accelerated FFT in the RPP HIP backend audio spectrogram, replacing the O(N²) manual DFT implementation with O(N log N) rocFFT library calls. This is the GPU counterpart to PR #11146's CPU FFT work.

JIRA: AICV-283

Dependencies

⚠️ This PR depends on #11146 merging first. This branch includes the merge of PR #11146 to integrate the build system changes for dual FFT backend support (CPU: FFTS/in-house FFT, GPU: rocFFT/manual DFT).

Background

CPU Side (HOST Backend) - PR #11146

  • Before: Used external FFTS library (required dependency)
  • After: Added in-house CPU FFT algorithm, making FFTS optional

GPU Side (HIP Backend) - This PR

  • Before: Manual DFT implementation (O(N²) brute force using custom GPU kernels)
    • Two kernels: compute_coefficients_hip_tensor + fourier_transform_hip_tensor
    • Completely independent of FFTS library (separate code path)
  • After: rocFFT library acceleration (O(N log N))
    • Single magnitude kernel + rocFFT library call
    • Plan caching optimization for repeated transforms
    • Manual DFT kept as conditional fallback

Key Note: CPU and GPU FFT implementations were always separate - this PR only touches the HIP backend.

Performance Results

Speedup: 1.6x over manual DFT implementation (with plan caching optimization)

Changes Made

1. CMake Infrastructure

  • New: projects/rpp/cmake/FindROCFFT.cmake - CMake finder module for rocFFT
    • Searches TheRock paths and standard ROCm SDK locations
    • Creates imported target rocfft::rocfft
  • Modified: projects/rpp/CMakeLists.txt
    • Dual FFT backend support: CPU (FFTS/in-house) + HIP (rocFFT/manual DFT)
    • Auto-detection with find_package(ROCFFT QUIET)
    • Conditional compilation flag: -DRPP_USE_ROCFFT
    • Conditional linking for HIP backend

2. Code Implementation

  • Modified: projects/rpp/src/modules/tensor/hip/kernel/spectrogram.cpp
    • Added rocFFT execution path with #ifdef RPP_USE_ROCFFT
    • New kernel: compute_magnitude_from_complex_hip_tensor
      • Converts rocFFT complex output to magnitude (power 1 or 2)
      • Optimized transpose path for FT layout using shared memory
    • rocFFT workflow: plan creation → execution → magnitude computation
    • Kept manual DFT as #else fallback (will be removed after validation period)

3. Performance Optimization

  • Modified: projects/rpp/src/include/rpp_handle.hpp
    • Moved rocfft_setup()/cleanup() from per-call to Handle ctor/dtor
    • Added rocFFT plan cache in HandleImpl (keyed by nfft size)
    • Added get_rocfft_plan() helper for plan creation/retrieval
    • Eliminates expensive plan recreation on every spectrogram call

4. Documentation

  • Modified: projects/rpp/CHANGELOG.md
  • Modified: projects/rpp/CMakeLists.txt
    • Version bump: 3.2.0 → 3.3.0
    • Audio support now enabled by default
  • Modified: projects/rpp/README.md and docs/install/rpp-build.rst
    • Documented new FFT backend behavior
    • Updated build instructions

Testing

Test Results

  • HIP Backend: ✅ PASSED
    • All audio tests passed including spectrogram
    • Golden reference validation successful

Test Coverage

  • ✅ nfft sizes: 256, 512, 1024, 2048
  • ✅ Batch sizes: 1, 3, 8, 16
  • ✅ Layouts: TF (time-frequency) and FT (frequency-time)
  • ✅ Parameters: centerWindows ON/OFF, reflectPadding ON/OFF

Build Validation

Works with both rocFFT present and absent:

# With rocFFT (GPU acceleration)
cmake .. -DBACKEND=HIP -DRPP_AUDIO_SUPPORT=ON
ldd librpp.so | grep rocfft  # ✅ Shows librocfft.so.0

# Without rocFFT (fallback to manual DFT)
cmake .. -DBACKEND=HIP -DRPP_AUDIO_SUPPORT=ON # rocFFT not found
# ✅ Builds successfully, uses manual DFT

Future Work

Phase 6: Manual DFT Removal (planned after 1-2 release cycles)

  • Remove compute_coefficients_hip_tensor and fourier_transform_hip_tensor kernels
  • Remove all #ifdef RPP_USE_ROCFFT conditional blocks
  • Make rocFFT a required dependency for HIP audio support
  • Expected: ~150 lines of code removed, simpler maintenance

Files Changed

New Files:

  • projects/rpp/cmake/FindROCFFT.cmake

Modified Files:

  • projects/rpp/CMakeLists.txt - FFT detection, linking, version bump
  • projects/rpp/src/modules/tensor/hip/kernel/spectrogram.cpp - rocFFT implementation
  • projects/rpp/src/include/rpp_handle.hpp - Plan caching
  • projects/rpp/CHANGELOG.md - Release notes
  • projects/rpp/README.md - Build documentation
  • projects/rpp/docs/install/rpp-build.rst - Build documentation

Checklist

levxn and others added 14 commits August 6, 2026 05:34
- Created FindROCFFT.cmake module for rocFFT library detection
- Modified CMakeLists.txt to detect rocFFT for HIP backend
- Enable audio support with either FFTS (CPU) or rocFFT (HIP)
- Link rocFFT only for HIP backend, FFTS only for CPU backend
- Set RPP_USE_ROCFFT_LIB=1 when rocFFT is found

Co-Authored-By: Claude <noreply@anthropic.com>
Combined changes from users/rrawther/rpp_ffts_host_implementation with
our rocFFT GPU implementation:

- CPU backend: FFTS library OR in-house FFT (PR #11146)
- HIP backend: rocFFT library (our addition)
- Both backends now have library-accelerated FFT support
- Resolved merge conflicts in CMakeLists.txt

Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed FindROCFFT.cmake to search for rocfft.h with PATH_SUFFIXES
- Removed 'manual DFT' reference from rocFFT not found message
- Verified: librpp.so successfully links librocfft.so.0

Co-Authored-By: Claude <noreply@anthropic.com>
Implements Phase 2 of rocFFT integration: code implementation in spectrogram.cpp

Changes:
- Add rocFFT header with conditional compilation guard
- New kernel: compute_magnitude_from_complex_hip_tensor
  * Non-vertical: Direct coalesced writes (TF layout)
  * Vertical: 16x16 shared memory transpose (FT layout)
  * Supports power=1 (magnitude) and power=2 (squared)
- Add rocFFT execution path in hip_exec_spectrogram_tensor
  * Real-to-complex 1D batch FFT using rocFFT library
  * Proper resource management and error handling
  * Specific RPP error codes for different failure scenarios
- Preserve manual DFT code as fallback under #else

Performance: rocFFT provides O(N log N) vs O(N^2) manual DFT
Expected speedup: 3-30x depending on nfft size

Build verification:
- Clean compile with no warnings
- librocfft.so.0 successfully linked
- All rocFFT symbols present in librpp.so

Co-Authored-By: Claude <noreply@anthropic.com>
Moves rocfft_setup() and rocfft_cleanup() from per-call (in spectrogram)
to per-handle lifecycle (Handle constructor/destructor).

Before: rocfft_setup/cleanup called on every spectrogram invocation
After: Called once when Handle is created/destroyed

Performance improvement: ~10% reduction in overhead (143ms → 128ms)

Note: rocFFT plan creation/destruction still occurs per-call and is
the main performance bottleneck (36x slower than manual DFT for small
nfft=512). Future work: implement plan caching for better performance.

Co-Authored-By: Claude <noreply@anthropic.com>
Cache rocFFT plans in Handle to avoid expensive plan creation/destruction
on every spectrogram call. Plans are keyed by (nfft, batchCount) composite
key and destroyed when the Handle is released.

Performance improvement: spectrogram now runs 1.6x faster than manual DFT
(2.11ms vs 3.37ms avg per batch).

- Add rocfft_plan_cache map to HandleImpl (keyed by nfft << 32 | batchCount)
- Add get_rocfft_plan() helper to create/retrieve cached plans
- Fix namespace mismatch (declaration now in namespace rpp)
- Fix AUDIO_SUPPORT preprocessor guard

Co-Authored-By: Claude <noreply@anthropic.com>
- Bump version from 3.2.0 to 3.3.0 for rocFFT integration
- Enable RPP_AUDIO_SUPPORT by default (no external FFT dependency)
- Add changelog entry for rocFFT GPU acceleration and in-house CPU FFT
- Update README and build docs to reflect new defaults and FFT backends

Co-Authored-By: Claude <noreply@anthropic.com>
@LakshmiKumar23 LakshmiKumar23 self-assigned this Aug 31, 2026
@LakshmiKumar23 LakshmiKumar23 added test_type:standard If enabled, the PR will run standard tests test:rpp and removed documentation labels Aug 31, 2026
@therock-pr-bot

therock-pr-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rpp/src/include/common/cpu/rpp_cpu_fft.hpp, projects/rpp/src/include/tensor/hip_tensor_executors.hpp, projects/rpp/src/modules/handle_hip.cpp, projects/rpp/src/modules/tensor/cpu/kernel/spectrogram.cpp, projects/rpp/src/modules/tensor/hip/kernel/spectrogram.cpp (+1 more); no test file found
🔎 pre-commit ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled
🤖 therock-pr-bot ✅ Pass

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

Copy link
Copy Markdown

Pre-commit check failed

pre-commit failed

Please run locally:

  • python -m pip install pre-commit
  • pre-commit install
  • pre-commit run --all-files --show-diff-on-failure

This repo uses .pre-commit-config.yaml.

- Reformat function signatures to meet line length requirements
- Add blank line after include directives
- Consolidate single-line if statements

Co-Authored-By: Claude <noreply@anthropic.com>
LakshmiKumar23 and others added 2 commits August 31, 2026 10:40
- Break long comment lines
- Reformat long assignment statements
- Adjust hipMemsetAsync formatting

Co-Authored-By: Claude <noreply@anthropic.com>
Apply clang-format to fix all remaining formatting issues:
- Line length compliance
- Proper indentation alignment
- Consistent spacing

Co-Authored-By: Claude <noreply@anthropic.com>
@therock-pr-bot

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants