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 the appropriate array module (cupy or numpy). |
|
Transfer array to GPU if available. |
|
Transfer array to CPU (numpy). |
|
Get information about GPU availability and configuration. |
Print GPU availability information. |
|
List all available GPUs with memory information. |
|
|
Select the GPU with the most free memory. |
|
Select a specific GPU by device ID. |
Print detailed status of all available GPUs. |
Package Contents#
- 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:
- 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