Skip to content
Snippets Groups Projects
hardware.rst 7.78 KiB

Hardware context

Arbor provides two ways for working with hardware resources:

  • Prescribe the hardware resources and their contexts for use in Arbor simulations.
  • Query available hardware resources (e.g. the number of available GPUs), and initializing MPI.

Note that to utilize some hardware features Arbor must be built and installed with the feature enabled, for example MPI or a GPU. Please refer to the :ref:`installation guide <in_build_install>` for information on how to enable hardware support.

Available resources

Helper functions for checking cmake or environment variables, as well as configuring and checking MPI are the following:

Env: Helper functions

The arbor.env module collects helper functions for interacting with the environment.

Prescribed resources

The Python wrapper provides an API for:

  • prescribing which hardware resources are to be used by a simulation using :class:`proc_allocation`.
  • opaque handles to hardware resources used by simulations called :class:`context`.

Enumerates the computational resources on a node to be used for a simulation, specifically the number of threads and identifier of a GPU if available.

Here are some examples of how to create a :class:`proc_allocation`.

import arbor

# default: one thread and no GPU selected
alloc1 = arbor.proc_allocation()

# 8 threads and no GPU
alloc2 = arbor.proc_allocation(8, None)

# reduce alloc2 to 4 threads and use the first available GPU
alloc2.threads = 4
alloc2.gpu_id  = 0

An opaque handle for the hardware resources used in a simulation. A :class:`context` contains a thread pool, and optionally the GPU state and MPI communicator. Users of the library do not directly use the functionality provided by :class:`context`, instead they configure contexts, which are passed to Arbor interfaces for domain decomposition and simulation.

Contexts can be queried for information about which features a context has enabled, whether it has a GPU, how many threads are in its thread pool.

Here are some simple examples of how to create a :class:`context`:

import arbor
import mpi4py.MPI as mpi

# Construct a context that uses 1 thread and no GPU or MPI.
context = arbor.context()

# Construct a context that:
#  * uses 8 threads in its thread pool;
#  * does not use a GPU, reguardless of whether one is available
#  * does not use MPI.
alloc   = arbor.proc_allocation(8, None)
context = arbor.context(alloc)

# Construct a context that uses:
#  * 4 threads and the first GPU;
#  * MPI_COMM_WORLD for distributed computation.
alloc   = arbor.proc_allocation(4, 0)
comm    = arbor.mpi_comm(mpi.COMM_WORLD)
context = arbor.context(alloc, comm)