Skip to content

Add GPU support for compute_autocorrelations and compute_local_correlations#56

Merged
deto merged 7 commits intoYosefLab:masterfrom
justjhong:jhong/hotspotgpu
Mar 20, 2026
Merged

Add GPU support for compute_autocorrelations and compute_local_correlations#56
deto merged 7 commits intoYosefLab:masterfrom
justjhong:jhong/hotspotgpu

Conversation

@justjhong
Copy link
Copy Markdown
Contributor

@justjhong justjhong commented Mar 16, 2026

  • Add GPU support via CuPy for compute_autocorrelations() and compute_local_correlations(), enabled with Hotspot(..., use_gpu=True)
  • GPU paths are integrated directly into local_stats.py and local_stats_pairs.py alongside their CPU counterparts
  • CuPy is an optional dependency (pip install hotspotsc[gpu]); existing CPU paths are unchange

Particularly with local correlations, the speed seems to be substantial once we get to scales applicable to realistic scenarios (hundreds of thousands of cells, thousands of genes).

Benchmark results comparing CPU vs GPU:
image

Equivalence results between CPU and GPU:
image

GPU support via CuPy for compute_autocorrelations and
compute_local_correlations, enabled with use_gpu=True.
GPU support via CuPy for compute_autocorrelations and
compute_local_correlations, enabled with use_gpu=True.
Remove section-header comments from GPU functions to match the
bare style of their CPU counterparts. Remove benchmark image,
add GPU/CPU equivalence scatter plot.
- Unify _build_sparse_weight_matrix with square parameter
- Remove cp module parameter from GPU helpers (import locally)
- Skip all_mu/all_x2 allocation when centered=True
- Densify sparse counts once upfront instead of per-gene
- Extract _postprocess_results to share between CPU and GPU paths
- Fix pre-existing bug: none model branch in _compute_hs_pairs_inner
  fitted vals_x into mu_x instead of vals_y into mu_y
- Replace inline model dispatch in _compute_hs_pairs_inner with _fit_gene
@deto
Copy link
Copy Markdown
Member

deto commented Mar 20, 2026

This is great, Justin! Datasets have been growing much larger in recent years so the GPU acceleration is a welcome addition.

@deto deto merged commit f985599 into YosefLab:master Mar 20, 2026
3 of 4 checks passed
@justjhong
Copy link
Copy Markdown
Contributor Author

Thanks @deto! I found Hotspot useful for my thesis so I thought I'd contribute to the package :)

@justjhong justjhong deleted the jhong/hotspotgpu branch March 20, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants