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 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.Examples
>>> import brainevent >>> brainevent.set_backend('gpu', 'warp') >>> brainevent.get_backend('gpu') 'warp' >>> brainevent.set_backend('gpu', None) # clear >>> brainevent.get_backend('gpu') is None True