boofun.core.gpu
GPU acceleration for Boolean function operations.
Provides CuPy-accelerated implementations of computationally intensive operations with automatic fallback to NumPy on CPU.
Accelerated operations: - Walsh-Hadamard Transform (WHT) - Influence computation from Fourier coefficients - Noise stability computation - Spectral weight by degree - Batch truth table / Fourier evaluation
Usage:
from boofun.core.gpu import is_gpu_available, gpu_walsh_hadamard
if is_gpu_available():
fourier = gpu_walsh_hadamard(truth_table_pm)
Install CuPy for GPU support:
pip install cupy-cuda12x # adjust for your CUDA version
Note
This module was consolidated from gpu.py and gpu_acceleration.py
in v1.3.0. The old gpu_acceleration module is removed; all public
names are available here.
Functions
|
Decorator: route to GPU for arrays >= 2^14 elements. |
|
Enable or disable GPU acceleration at runtime. |
|
Get the array module (numpy or cupy) for the given array. |
Return information about available GPU resources. |
|
|
Run a named operation on GPU if available, otherwise raise. |
|
Influence computation: Inf_i[f] = sum_{S containing i} f_hat(S)^2. |
|
Noise stability: Stab_rho[f] = sum_S rho^|S| f_hat(S)^2. |
|
Spectral weight by degree: W^{=k}[f] = sum_{|S|=k} f_hat(S)^2. |
|
Walsh-Hadamard Transform with optional GPU acceleration. |
Check if GPU acceleration is available (CuPy + working CUDA). |
|
Check if GPU acceleration is currently enabled. |
|
|
Heuristic: should we use GPU for this operation? |
|
Move arr to CPU memory. |
|
Move arr to GPU memory if available and enabled. |
Classes
|
GPU-accelerated operations for a single Boolean function. |
- boofun.core.gpu.is_gpu_available() bool[source]
Check if GPU acceleration is available (CuPy + working CUDA).
- boofun.core.gpu.enable_gpu(enable: bool = True) None[source]
Enable or disable GPU acceleration at runtime.
- boofun.core.gpu.get_gpu_info() Dict[str, Any][source]
Return information about available GPU resources.
- boofun.core.gpu.should_use_gpu(operation: str, data_size: int, n_vars: int) bool[source]
Heuristic: should we use GPU for this operation?
- Parameters:
operation – One of ‘truth_table’, ‘fourier’, ‘walsh_hadamard’, ‘wht’, ‘influences’, etc.
data_size – Number of elements in the input.
n_vars – Number of Boolean variables.
- Returns:
True if GPU acceleration is recommended.
- boofun.core.gpu.get_array_module(arr: ndarray | Any) Any[source]
Get the array module (numpy or cupy) for the given array.
- boofun.core.gpu.to_gpu(arr: ndarray) ndarray | Any[source]
Move arr to GPU memory if available and enabled.
- boofun.core.gpu.gpu_walsh_hadamard(values: ndarray, in_place: bool = False) ndarray[source]
Walsh-Hadamard Transform with optional GPU acceleration.
When CuPy is available and enabled the iterative butterfly is run on GPU; otherwise delegates to the CPU
fast_walsh_hadamardin optimizations.- Parameters:
values – Array of 2^n values in +/-1 representation.
in_place – Modify values in place (saves memory on CPU path).
- Returns:
WHT result (normalised, on CPU).
- boofun.core.gpu.gpu_influences(fourier_coeffs: ndarray, n_vars: int | None = None) ndarray[source]
Influence computation: Inf_i[f] = sum_{S containing i} f_hat(S)^2.
Uses GPU when enabled, otherwise falls back to CPU vectorised code.
- boofun.core.gpu.gpu_noise_stability(fourier_coeffs: ndarray, rho: float) float[source]
Noise stability: Stab_rho[f] = sum_S rho^|S| f_hat(S)^2.
Uses GPU when enabled, otherwise falls back to CPU.
- boofun.core.gpu.gpu_spectral_weight_by_degree(fourier_coeffs: ndarray) ndarray[source]
Spectral weight by degree: W^{=k}[f] = sum_{|S|=k} f_hat(S)^2.
Uses GPU when enabled, otherwise falls back to CPU.
- boofun.core.gpu.gpu_accelerate(operation: str, *args: Any, **kwargs: Any) ndarray[source]
Run a named operation on GPU if available, otherwise raise.
Supported operations: -
truth_table_batch: args = (inputs, truth_table) -fourier_batch: args = (inputs, coefficients) -walsh_hadamard: args = (function_values,)