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

auto_accelerate(func)

Decorator: route to GPU for arrays >= 2^14 elements.

enable_gpu([enable])

Enable or disable GPU acceleration at runtime.

get_array_module(arr)

Get the array module (numpy or cupy) for the given array.

get_gpu_info()

Return information about available GPU resources.

gpu_accelerate(operation, *args, **kwargs)

Run a named operation on GPU if available, otherwise raise.

gpu_influences(fourier_coeffs[, n_vars])

Influence computation: Inf_i[f] = sum_{S containing i} f_hat(S)^2.

gpu_noise_stability(fourier_coeffs, rho)

Noise stability: Stab_rho[f] = sum_S rho^|S| f_hat(S)^2.

gpu_spectral_weight_by_degree(fourier_coeffs)

Spectral weight by degree: W^{=k}[f] = sum_{|S|=k} f_hat(S)^2.

gpu_walsh_hadamard(values[, in_place])

Walsh-Hadamard Transform with optional GPU acceleration.

is_gpu_available()

Check if GPU acceleration is available (CuPy + working CUDA).

is_gpu_enabled()

Check if GPU acceleration is currently enabled.

should_use_gpu(operation, data_size, n_vars)

Heuristic: should we use GPU for this operation?

to_cpu(arr)

Move arr to CPU memory.

to_gpu(arr)

Move arr to GPU memory if available and enabled.

Classes

GPUBooleanFunctionOps(truth_table)

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.is_gpu_enabled() bool[source]

Check if GPU acceleration is currently enabled.

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.to_cpu(arr: ndarray | Any) ndarray[source]

Move arr to CPU memory.

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_hadamard in 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,)

class boofun.core.gpu.GPUBooleanFunctionOps(truth_table: ndarray)[source]

GPU-accelerated operations for a single Boolean function.

Wraps a truth table and caches the Fourier transform.

__init__(truth_table: ndarray) None[source]
property pm_values: ndarray

0->+1, 1->-1).

Type:

±1 representation (O’Donnell convention

fourier() ndarray[source]
influences() ndarray[source]
total_influence() float[source]
noise_stability(rho: float) float[source]
spectral_weights() ndarray[source]
boofun.core.gpu.auto_accelerate(func)[source]

Decorator: route to GPU for arrays >= 2^14 elements.