[READ-ONLY] Mirror of https://github.com/jmrplens/phonometry. Standards-conformant acoustics library for Python: measurement and metrology, docs.jmrp.io/phonometry
phonometry docs simulation compute.md
26 kB · 499 lines
Markdown
at main

← [Documentation index](../README.md) # Where a simulation runs: NumPy, CuPy and torch An FDTD run is a handful of array operations repeated thousands of times over fields of a fixed size, which is the kind of work a GPU is built for. The two engines of `phonometry.simulation`, the acoustic `FDTD2D` behind `fdtd_simulation` and the elastic `ElasticFDTD2D` behind `elastic_fdtd_simulation`, step on NumPy by default, and on an NVIDIA GPU through CuPy or on PyTorch (on a CPU, an NVIDIA GPU or Apple's MPS) when you ask. It is one stepping code for all of them: each engine builds its maps in NumPy float64, in this process, when it is constructed, hands them to the device once, and from then on touches its fields only with operations of the Python array API standard, which the three libraries implement. This page says how to ask for a device, what each one needs installed, how a whole script or a worker picks its device, what happens when the device is not there, how a result records where it ran, and what the library promises about the numbers on each device. The physics, the sources and the boundaries are the same everywhere; they are explained in [2D FDTD wave simulation](fdtd-simulation.md) and [Elastic waves and fluid-solid coupling](elastic-waves.md). [Where heavy work runs](where-it-runs.md) maps the devices, the nodes and the encoders in one place. ## 1. Asking for a device: `Compute` A `Compute` record says where the fields step, in which dtype, and whether the run may fall back to NumPy: | Field | Values | Default | |---|---|---| | `device` | `"cpu"` (NumPy), `"cupy"` (an NVIDIA GPU through CuPy), `"torch:cpu"`, `"torch:cuda"`, `"torch:mps"` (Apple silicon) | `"cpu"` | | `device_index` | which GPU, for `"cupy"` and `"torch:cuda"` | `0` | | `dtype` | `"float64"` or `"float32"` | `"float64"` | | `fallback` | step on NumPy with a warning when the device is not available, instead of raising | `False` | | `host` | the node the run goes to, by its name in the hosts file; see [Sending a simulation to a remote n…