1
0
Fork
You've already forked gpaufp
0
GPU accelerated fork of audfprint
  • Python 99.3%
  • Shell 0.7%
Troed Sångberg d493a90b2f feat: add stft_auto convenience function, gpu_table parameter, CPU-optimized get_hits
- Add stft_auto() to stft.py with automatic GPU/CPU fallback
- Use stft_auto() in audfprint_analyze.py for cleaner code
- Add gpu_table parameter to HashTable.__init__() to disable GPU storage
- Replace GPU get_hits() with CPU path (24x faster for sequential access)
- Add copy_to_gpu() and copy_to_cpu() methods for memory conversion
2026年07月06日 12:52:56 +02:00
audfprint_gpu feat: add stft_auto convenience function, gpu_table parameter, CPU-optimized get_hits 2026年07月06日 12:52:56 +02:00
benchmarks First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00
tests First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00
.gitignore First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00
pyproject.toml First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00
README.md First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00
run_tests.sh First commit of this GPU-accelerated audfprint fork 2026年07月06日 12:44:20 +02:00

audfprint_gpu - GPU-Accelerated AudFPrint

This package provides CUDA-accelerated versions of AudFPrint's core fingerprinting functions using CuPy and cuSignal.

Quick Start

# Use GPU-accelerated STFT
from audfprint_gpu.stft import stft, stft_auto, stft_cpu
import numpy as np
signal = np.random.randn(11025) # Audio signal
n_fft = 512
# GPU version (raises ImportError if GPU libs not available)
spectrogram_gpu = stft(signal, n_fft)
# CPU version (always available)
spectrogram_cpu = stft_cpu(signal, n_fft)
# Auto version (uses GPU if available, falls back to CPU)
spectrogram = stft_auto(signal, n_fft)
# Use GPU-accelerated Analyzer
from audfprint_gpu.audfprint_analyze import Analyzer
analyzer = Analyzer()
peaks = analyzer.find_peaks(signal, 11025)
landmarks = analyzer.peaks2landmarks(peaks)
hashes = analyzer.wavfile2hashes("audio.mp3")

Installation

This project uses UV for package management with a virtual environment:

# Create virtual environment (Python 3.12.12 by default)
uv venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install dependencies (CUDA 13)
uv pip install numpy scipy cupy-cuda13x
# For CUDA 12.x
uv pip install numpy scipy cupy-cuda12x cusignal
# For CPU-only fallback
uv pip install numpy scipy

Environment Variables

  • AUDFPRINT_USE_GPU=1: Enable GPU mode globally (default: 0)

Running Tests

# Activate virtual environment
source .venv/bin/activate
# Set PYTHONPATH
export PYTHONPATH=/home/troed/dev/gpaufp:$PYTHONPATH
# Run STFT tests
python test_stft.py
# Run Analyzer tests
python test_analyze.py
# Or use the convenience script
../run_tests.sh
# Run benchmarks
python ../benchmarks/benchmark_stft.py --signal-lengths 11025 44100 110250 661500

Performance

Verified Benchmark Results (2026年06月02日):

Signal Length FFT Size CPU Time GPU Time Speedup
11,025 512 0.09ms 0.31ms 0.3x
44,100 512 0.24ms 0.31ms 0.8x
110,250 512 0.56ms 0.48ms 1.2x
661,500 512 4.21ms 2.15ms 2.0x
661,500 1024 5.19ms 2.25ms 2.3x
661,500 2048 5.75ms 2.60ms 2.2x

Performance Observations:

  • GPU acceleration provides minimal benefit for small signals (<44K samples) due to CPU→GPU transfer overhead
  • Significant speedup (2.0-2.3x) for large signals where computation dominates transfer
  • Batch processing would benefit from keeping data on GPU between operations
  • Break-even point: signals >44K samples with FFT size 2048 show GPU advantage

Expected speedups for full pipeline:

  • STFT: 2-3x faster on GPU for typical audio
  • Peak Detection: 5-20x faster (when fully ported)
  • Matching: 10-100x faster (when fully ported)

API Compatibility

All functions maintain API compatibility with the original audfprint library:

STFT Functions

Function GPU Version CPU Version Description
stft() GPU-accelerated STFT
stft_cpu() Original CPU STFT
stft_auto() Auto-select based on availability
periodic_hann() CPU Hann window
periodic_hann_gpu() GPU Hann window

Analyzer Functions

Function GPU Version CPU Version Description
Analyzer.find_peaks() Peak detection with GPU STFT
locmax() Local maxima detection
locmax_gpu() GPU-accelerated local maxima
spreadpeaks() Peak spreading (CPU)
spreadpeaks_gpu() GPU-accelerated peak spreading
landmarks2hashes() Landmark to hash conversion
landmarks2hashes_gpu() GPU-accelerated conversion

Test Status

All tests verified to pass as of 2026年06月02日:

  • STFT correctness (GPU vs CPU difference: 1.63e-14)
  • STFT performance (2.3x speedup on large signals)
  • STFT auto-fallback mechanism
  • Analyzer peak detection
  • Analyzer landmark generation
  • Analyzer comparison with original AudFPrint
  • Matcher initialization
  • Matcher hash table integration
  • Matcher match_hashes function
  • Matcher full pipeline
  • Matcher comparison with original audfprint_match

References