Runtime configuration#

The runtime behaviour of strongcoca can be tuned through set_compute_config(), which updates a global ComputeConfig:

import strongcoca

strongcoca.set_compute_config(backend='torch', precision='float32')

Any argument left unset keeps its current value, so individual fields can be updated independently:

strongcoca.set_compute_config(max_solve_mem=200)

Configuration fields#

backend

GPU backend for the O(N³) linear-algebra operations in PolarizabilityCalculator.

'none'

CPU-only path (default).

'torch'

PyTorch / CUDA.

'cupy'

CuPy / CUDA.

precision

Floating-point precision used for GPU operations.

'float32'

Cast to complex64 before the GPU kernel and back to complex128 afterwards (default). Roughly 10x faster on consumer GPUs where FP64 throughput is restricted.

'float64'

Keep complex128 throughout.

max_solve_mem

Maximum memory budget in MiB for intermediate matrices in the linear solve step of PolarizabilityCalculator. The code will chunk the frequency axis so that the A matrix stays below this limit.

Default: 80.

gpu_batched_max

Maximum value of N3 = 3 x N_particles for which the cuBLAS batched solver is used. Above this threshold strongcoca loops over the batch dimension to invoke the non-batched cuSOLVER path, which is faster for large matrices on consumer GPUs. Increase this value (e.g. to 1024 or higher) on A100/H100/H200 cards where the batched path performs well at large N.

Default: 32.

Python API#

class strongcoca.compute_config.ComputeConfig(backend, precision, max_solve_mem, gpu_batched_max)[source]#

Global runtime configuration for the O(N³) linear-algebra operations in PolarizabilityCalculator.

Parameters:
  • backend (str) – 'none' (CPU only), 'torch' (PyTorch/CUDA), or 'cupy' (CuPy/CUDA).

  • precision (str) – Floating-point precision for GPU operations. 'float32' casts to complex64 before the GPU kernel and back to complex128 afterwards (roughly 10x faster on consumer GPUs where FP64 throughput is restricted); 'float64' keeps complex128 throughout.

  • max_solve_mem (float) – Memory budget in MiB for intermediate matrices in the CPU linear solve step. The frequency axis is chunked so that the A matrix stays below this limit.

  • gpu_batched_max (int) – Maximum value of N3 = 3 x N_particles for which the cuBLAS batched solver is used in GPU kernels. Above this threshold, the code loops over the batch dimension to invoke the non-batched cuSOLVER path, which is faster for large matrices on consumer GPUs. Increase this value (e.g. to 1024 or higher) on A100/H100/H200 cards, where the batched cuSOLVER path performs well at large N.

strongcoca.compute_config.set_compute_config(backend=None, precision=None, max_solve_mem=None, gpu_batched_max=None)[source]#

Update one or more fields of the global compute configuration.

Any argument left as None keeps its current value. All arguments are validated before anything is written, so an invalid call leaves the configuration completely unchanged.

Parameters:
Return type:

None

Examples

>>> from strongcoca import set_compute_config, get_compute_config
>>> set_compute_config(max_solve_mem=200)
>>> get_compute_config().max_solve_mem
200.0
>>> set_compute_config(max_solve_mem=80)  # reset to the default
strongcoca.compute_config.get_compute_config()[source]#

Return the current global compute configuration.

Return type:

ComputeConfig