scirpy.ir_dist.metrics.GPUHammingDistanceCalculator

scirpy.ir_dist.metrics.GPUHammingDistanceCalculator#

class scirpy.ir_dist.metrics.GPUHammingDistanceCalculator(*, cutoff=2, n_blocks=1, gpu_tile_rows=100000, gpu_tile_cols=100000, gpu_tile_buffer_cols=1000, gpu_n_blocks=None, gpu_block_width=None)#

Computes pairwise distances between gene sequences based on the “hamming” distance metric with GPU support.

The code of this class is based on pwseqdist. Reused under MIT license, Copyright (c) 2020 Andrew Fiore-Gartland.

For performance reasons, the rows and columns of the final result matrix are grouped into tiles for GPU computation. gpu_tile_rows and gpu_tile_cols control how many matrix rows and columns are grouped into each tile. Each tile is computed on the GPU and converted to a sparse CSR matrix before the tiles are combined again.

gpu_tile_buffer_cols controls how many buffer columns are initially reserved for sparse result entries in each row of a tile. Because only distances at or below the cutoff are retained, the number of entries that need to be stored is usually considerably smaller than the number of columns in the tile. If necessary, the buffer is enlarged and the calculation is retried.

Smaller tiles reduce per-tile memory pressure but add tile-management overhead. Larger values for gpu_tile_buffer_cols can avoid retries but require more GPU memory.

Parameters:
  • cutoff (int (default: 2)) – Will eleminate distances > cutoff to make efficient use of sparse matrices.

  • n_blocks (int (default: 1)) – Number of outer row partitions submitted through joblib. This can be used with a distributed joblib backend to distribute the calculation across multiple GPU workers.

  • gpu_tile_rows (int (default: 100000)) – Number of result matrix rows per GPU tile.

  • gpu_tile_cols (int (default: 100000)) – Number of result matrix columns per GPU tile.

  • gpu_tile_buffer_cols (int (default: 1000)) – Initial number of retained sparse entries reserved per row of each tile. Higher values can avoid retries for denser results but require more GPU memory.

  • gpu_n_blocks (int | None (default: None)) – Deprecated since v0.26.0 and ignored. Use gpu_tile_cols to set the number of columns per GPU tile.

  • gpu_block_width (int | None (default: None)) – Deprecated since v0.26.0 and ignored. Use gpu_tile_buffer_cols to set the initial result buffer width.

Methods table#

calc_dist_mat(seqs[, seqs2])

Calculates the pairwise distances between two vectors of gene sequences based on the distance metric of the derived class and returns a CSR distance matrix.

Methods#

GPUHammingDistanceCalculator.calc_dist_mat(seqs, seqs2=None)#

Calculates the pairwise distances between two vectors of gene sequences based on the distance metric of the derived class and returns a CSR distance matrix. Also creates a histogram based on the minimum value per row of the distance matrix if histogram is set to True.

Return type:

csr_matrix