brainevent.config.set_backend#
- brainevent.config.set_backend(platform, backend)[source]#
Set the global default backend for a platform across all primitives.
After this call, every primitive that has a kernel registered for backend on platform will use it by default, unless overridden by an explicit
backend=keyword argument at call time.- Parameters:
- Raises:
ValueError – If platform is not
'cpu','gpu'or'tpu', or if backend is an empty string.
See also
get_backendQuery the current global backend for a platform.
clear_backendsClear all global backend defaults.
Notes
Backend selection is resolved inside each primitive’s MLIR lowering function, and JAX caches lowered/compiled executables (both the eager dispatch cache and the
jitcompilation cache) keyed on primitive + abstract values, not on the global backend setting. If this call actually changes the effective value for platform, it therefore callsjax.clear_caches()so that already-compiled call sites pick up the new backend on their next invocation (at the cost of forcing recompilation everywhere on next use). Callingset_backendwith the value it already has is a no-op and does not clear caches.This makes
set_backenda setup-time, single-threaded control: it is intended to be called before the hot loop / before other threads start compiling, not toggled concurrently from multiple threads while other work is in flight (jax.clear_caches()is process-global). For per-call, thread-safe backend selection, passbackend=<name>directly to the primitive call instead – it is a bind parameter and therefore part of the cache key, so it composes safely with concurrent dispatch.Determinism on GPU. The default GPU kernels (
cuda_raw) accumulate with float atomics, so their results can differ in the last bits from one call to the next. WhenXLA_FLAGSsets--xla_gpu_deterministic_ops(read when a primitive is lowered), every primitive without an explicit choice lowers with'jax_raw'on GPU, whose XLA scatters and reductions follow the flag; a primitive without a'jax_raw'GPU kernel warns once. An explicit choice (backend=on the call, or this function) is kept.Examples
>>> import brainevent >>> brainevent.config.set_backend('gpu', 'cuda_raw') >>> brainevent.config.get_backend('gpu') 'cuda_raw' >>> brainevent.config.set_backend('gpu', None) # clear >>> brainevent.config.get_backend('gpu') is None True