linumpy.gpu#

GPU acceleration module for linumpy.

This module provides GPU-accelerated versions of compute-intensive operations using CuPy. All functions have automatic fallback to CPU (NumPy) if: - CuPy is not installed - No CUDA-capable GPU is available - GPU memory is insufficient

Usage:

from linumpy.gpu import GPU_AVAILABLE, get_array_module

# Check if GPU is available
if GPU_AVAILABLE:
    print("GPU acceleration enabled")

# Get appropriate array module (cupy or numpy)
xp = get_array_module(use_gpu=True)

# Use GPU-accelerated functions
from linumpy.gpu.fft_ops import gpu_phase_correlation
from linumpy.gpu.interpolation import gpu_affine_transform
from linumpy.gpu.registration import GPUAcceleratedRegistration
Configuration:

Set USE_GPU=false environment variable to disable GPU globally.

Submodules#

Attributes#

Functions#

get_array_module([use_gpu])

Get the appropriate array module (cupy or numpy).

to_gpu(array)

Transfer array to GPU if available.

to_cpu(array)

Transfer array to CPU (numpy).

gpu_info()

Get information about GPU availability and configuration.

print_gpu_info()

Print GPU availability information.

list_gpus()

List all available GPUs with memory information.

select_best_gpu([verbose])

Select the GPU with the most free memory.

select_gpu(device_id[, verbose])

Select a specific GPU by device ID.

print_gpu_status()

Print detailed status of all available GPUs.

Package Contents#

linumpy.gpu.GPU_AVAILABLE = False[source]#
linumpy.gpu.CUPY_AVAILABLE = False[source]#
linumpy.gpu.GPU_DEVICE_NAME = 'N/A'[source]#
linumpy.gpu.GPU_MEMORY_GB = 0[source]#
linumpy.gpu.get_array_module(use_gpu=True)[source]#

Get the appropriate array module (cupy or numpy).

Parameters:

use_gpu (bool) – Whether to use GPU if available.

Returns:

cupy if GPU available and use_gpu=True, else numpy

Return type:

module

linumpy.gpu.to_gpu(array)[source]#

Transfer array to GPU if available.

Parameters:

array (np.ndarray) – Input array

Returns:

CuPy array if GPU available, else original numpy array

Return type:

array

linumpy.gpu.to_cpu(array)[source]#

Transfer array to CPU (numpy).

Parameters:

array (array-like) – Input array (numpy or cupy)

Returns:

NumPy array

Return type:

np.ndarray

linumpy.gpu.gpu_info()[source]#

Get information about GPU availability and configuration.

Returns:

Dictionary with GPU information

Return type:

dict

linumpy.gpu.print_gpu_info()[source]#

Print GPU availability information.

Return type:

None

linumpy.gpu.list_gpus()[source]#

List all available GPUs with memory information.

Returns:

List of GPU info dictionaries with keys: - id: Device ID - name: Device name - total_gb: Total memory in GB - free_gb: Free memory in GB - used_gb: Used memory in GB - utilization: Memory utilization (0-1)

Return type:

list of dict

linumpy.gpu.select_best_gpu(verbose=True)[source]#

Select the GPU with the most free memory.

This function queries all available GPUs and switches to the one with the most free memory. Useful when running on multi-GPU systems where one GPU may already be in use.

Parameters:

verbose (bool) – Print selection information

Returns:

Selected GPU ID, or None if no GPU available

Return type:

int or None

Examples

>>> from linumpy.gpu import select_best_gpu
>>> select_best_gpu()
Selected GPU 1: NVIDIA RTX A6000 (45.2 GB free / 48.0 GB total)
1
linumpy.gpu.select_gpu(device_id, verbose=True)[source]#

Select a specific GPU by device ID.

Parameters:
  • device_id (int) – GPU device ID (0, 1, 2, …)

  • verbose (bool) – Print selection information

Returns:

Selected GPU ID, or None if invalid

Return type:

int or None

Examples

>>> from linumpy.gpu import select_gpu
>>> select_gpu(1)
Selected GPU 1: NVIDIA RTX A6000 (48.0 GB total)
1
linumpy.gpu.print_gpu_status()[source]#

Print detailed status of all available GPUs.

Shows memory usage for each GPU, highlighting the currently selected one.

Return type:

None