Skip to main content

Enabling Event-driven Computation in CPU/GPU/TPU.

Project description

Enabling Event-driven Computation in CPU/GPU/TPU

Header image of brainevent.

Supported Python Version LICENSE Documentation Status PyPI version Continuous Integration Daily CI Tests Code Coverage PyPI Downloads DOI

Brain is characterized by the discrete spiking events, which are the fundamental units of computation in the brain.

BrainEvent provides a set of data structures and algorithms for such event-driven computation on CPUs, GPUs, TPUs, and maybe more, which can be used to model the brain dynamics in an efficient and biologically plausible way.

Particularly, it provides the following classes to represent binary (spiking) events in the brain:

  • BinaryArray: an array wrapping a vector/matrix of binary events (spikes).
  • BitPackedBinary: a memory-efficient representation that packs binary events into bits (see also the bitpack helper).
  • CompactBinary: a compact representation that stores only the indices of the active (non-zero) events.

Furthermore, it implements the following commonly used data structures for event-driven computation of the above classes. Most structures come in row-oriented (R) and column-oriented (C) variants:

  • CSR / CSC: sparse matrices in CSR / CSC format for sparse and event-driven computation.
  • JITCScalarR / JITCScalarC: a just-in-time connectivity matrix with homogeneous (scalar) weight for sparse and event-driven computation.
  • JITCNormalR / JITCNormalC: a just-in-time connectivity matrix with normal-distribution weights for sparse and event-driven computation.
  • JITCUniformR / JITCUniformC: a just-in-time connectivity matrix with uniform-distribution weights for sparse and event-driven computation.
  • FixedNumConn / FixedNumPerPre / FixedNumPerPost: fixed-number connectivity matrices, where each neuron has a fixed number of synaptic connections.
  • ...

BrainEvent is fully compatible with physical units and unit-aware computations provided in BrainUnit.

Usage

If you want to take advantage of event-driven computations, you must warp your data with brainevent.BinaryArray:

import brainevent

# wrap your array with BinaryArray
event_array = brainevent.BinaryArray(your_array)

Then, the matrix multiplication with the following data structures, $\mathrm{event\ array} @ \mathrm{data}$, will take advantage of event-driven computations:

  • Sparse data structures provided by brainevent, like:
    • brainevent.CSR
    • brainevent.JITCScalarR
    • brainevent.FixedNumPerPre
    • ...
  • Dense data structures provided by JAX/NumPy, like:
    • jax.numpy.ndarray
    • numpy.ndarray
data = jax.random.rand(...)  # normal dense array
data = brainevent.CSR(...)  # CSR structure
data = brainevent.JITCScalarR(...)  # JIT connectivity
data = brainevent.FixedNumPerPre(...)  # fixed number of post-synaptic connections per pre-neuron

# event-driven matrix multiplication
r = event_array @ data
r = data @ event_array

Installation

You can install brainevent via pip:

pip install brainevent -U

Alternatively, you can install BrainX, which bundles brainevent with other compatible packages for a comprehensive brain modeling ecosystem:

pip install BrainX -U

GPU compile dependencies

The first time a kernel runs on a GPU, brainevent compiles its CUDA source on the fly. This needs three things:

  1. NVIDIA driver (provides libcuda and nvidia-smi) — a system-level requirement for any approach.
  2. jax[cuda12] or jax[cuda13] — installing it pulls in the nvidia-* pip packages, which already bundle nvcc/ptxas/CUDA runtime/headers. A separate system CUDA Toolkit is therefore not required.
  3. A host C++ compiler (g++/clang++) — pip does not provide one. Install it via conda install -c conda-forge gxx, sudo apt-get install g++, or sudo dnf install gcc-c++.

Optional configuration:

  • brainevent.config.prefer_system_nvcc() — prefer the system PATH nvcc instead of the pip-bundled one (pip is the default).
  • Environment variables: BRAINEVENT_NVCC_PREFER=pip|system, BRAINEVENT_NVCC_PATH, CUDA_HOME, CXX.
  • BRAINEVENT_ALLOW_UNSUPPORTED_COMPILER=1 — force compilation when the host gcc is newer than nvcc supports.
  • BRAINEVENT_COMPUTE_CAPABILITIES=8.6,8.0 — skip nvidia-smi auto-detection.
  • BRAINEVENT_TOOLCHAIN_DEBUG=1 — append a "toolchain snapshot" to every toolchain error for easier debugging.

Documentation

The official documentation is hosted on Read the Docs: https://brainx.chaobrain.com/brainevent/

See also the ecosystem

brainevent is one part of our brain modeling ecosystem: https://brainx.chaobrain.com/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainevent-0.1.1.tar.gz (656.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brainevent-0.1.1-py3-none-any.whl (807.5 kB view details)

Uploaded Python 3

File details

Details for the file brainevent-0.1.1.tar.gz.

File metadata

  • Download URL: brainevent-0.1.1.tar.gz
  • Upload date:
  • Size: 656.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brainevent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9d4b4f676790c7a4296450a2c7bcea7b256501ce393630d2ea8d59e492948980
MD5 ffae616540fbca2df7c4128ecb238d46
BLAKE2b-256 8fbf84f0ad54a2d4694cc1e4c26b7ad977f18db5698d768a04325665bf23bf42

See more details on using hashes here.

File details

Details for the file brainevent-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: brainevent-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 807.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brainevent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1c56579455e9af341ce5c50795ca986a91123e562a06b2a6b3dca6c33e4224f
MD5 587093d589d72d757a5109d200f36572
BLAKE2b-256 edbaa6501c12d7342b13f09d47f274322c8cba2011708a36bbb82b89a80bc1a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page