Repository navigation
Add GPU-accelerated TCRdist distance calculation - #754
felixpetschko wants to merge 57 commits into
Conversation
…lt blocks within Hamming kernel itself
# Conflicts: # src/scirpy/tests/test_ir_dist_metrics.py
|
@grst Could you please add the run-gpu-ci label? I don't have permission to set it myself. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #754 +/- ##
==========================================
- Coverage 76.78% 74.29% -2.50%
==========================================
Files 52 52
Lines 4851 5045 +194
==========================================
+ Hits 3725 3748 +23
- Misses 1126 1297 +171
🚀 New features to boost your workflow:
|
|
added, also sent you an invitation to give you the permissions. |
grst
left a comment
There was a problem hiding this comment.
This is stacked on #753, so let's wrap it up after that one is merged.
Some comments here.
Another one found by Claude that I think is legit:
Output dtype differs: the GPU returns int32, while the CPU returns float64. Worse, the GPU result silently becomes float64 when n_blocks > len(seqs). That happens because the base class’s empty-block path returns a float CSR, and vstack then upcasts everything. The test even works around this (if n_blocks <= len(...)). I’d fix the empty-block path rather than encode the inconsistency in a test.
| for name, value in ( | ||
| ("dist_weight", dist_weight), | ||
| ("gap_penalty", gap_penalty), | ||
| ("ntrim", ntrim), | ||
| ("ctrim", ctrim), | ||
| ): | ||
| if not isinstance(value, (int, np.integer)) or not 0 <= value <= np.iinfo(np.int32).max: | ||
| raise ValueError(f"`{name}` must be a non-negative 32-bit integer.") |
There was a problem hiding this comment.
I think these validation would also make sense for the CPU version. How about moving them to the parent class?
| d_seqs_mat2_transposed = cp.transpose(cp.asarray(seqs_mat2_block.astype(np.int8, copy=False))).copy() | ||
|
|
||
| def run_tcrdist_kernel(buffer_width): | ||
| d_data_matrix = cp.empty((seqs_mat1_rows, buffer_width), dtype=cp.int32) |
| seqs = np.load(TESTDATA / "tcrdist_test_data/tcrdist_WU3k_seqs.npy") | ||
| reference_result = scipy.sparse.load_npz(TESTDATA / "tcrdist_test_data/tcrdist_WU3k_csr_result.npz") | ||
|
|
||
| gpu_tcrdist_calculator = GPUTCRdistDistanceCalculator(cutoff=15, gap_penalty=4, **kwargs) |
There was a problem hiding this comment.
Maybe also worth also testing TCRBLOSUM and potentially more parameters here?
Summary
This PR adds GPU support for the CDR3 TCRdist metric, following the general structure of the GPU Hamming implementation and matching the updated CPU TCRdist behavior. It substantially improves execution time on large datasets.
Adds metric="gpu_tcrdist" for GPU-accelerated CDR3 TCRdist calculations, supporting
BLOSUM62 and TCRBLOSUM matrices.
Follows the GPU Hamming implementation with configurable row/column tiling, adaptive
result buffers, symmetry-based tile skipping, ...
Supports fixed_gappos=True only; dynamic gap positioning is not yet implemented.
Matches the updated CPU defaults and trimming behavior: gap_penalty=12, cutoff=24, trim-
aware fixed gap positioning, and exclusion of fully trimmed sequences. -> depends on PR Update CPU TCRdist defaults and fix trimming behavior #753.
Enables processing of the Omniscope COVID dataset with approximately 8 million cells in about ~5
minutes on a single NVIDIA A30, compared with approximately ~2 hours with 64 CPU
cores with the CPU implementation.
Updates API documentation, the large-datasets tutorial, and the changelog.