Metadata-Version: 2.4
Name: fp-arena
Version: 0.1.0
Summary: A rapid-prototyping environment for custom floating-point types in DaCe
Author: ETH Zurich and the FP-Arena authors
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/spcl/FP-Arena
Project-URL: Repository, https://github.com/spcl/FP-Arena
Project-URL: Issues, https://github.com/spcl/FP-Arena/issues
Project-URL: Changelog, https://github.com/spcl/FP-Arena/blob/main/CHANGELOG.md
Keywords: dace,floating-point,stochastic-rounding,reduced-precision,prototyping
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: ordered-set
Requires-Dist: scipy
Requires-Dist: tqdm
Provides-Extra: extended
Requires-Dist: dace-extended>=1.0.0; extra == "extended"
Provides-Extra: dace
Requires-Dist: dace>=2.0.0b2; extra == "dace"
Provides-Extra: testing
Requires-Dist: pytest; extra == "testing"
Requires-Dist: pytest-xdist; extra == "testing"
Provides-Extra: corpus
Requires-Dist: h5py; extra == "corpus"
Provides-Extra: dev
Requires-Dist: fp-arena[extended,testing]; extra == "dev"
Dynamic: license-file

# FP-Arena

A rapid-prototyping environment for testing custom floating-point types in
[DaCe](https://github.com/spcl/dace). FP-Arena adds new FP types (and the C++
that implements them) as a **plugin** that registers itself into DaCe at import
time — no fork, no DaCe source changes.


## Install

Pick the DaCe FP-Arena runs on with an extra; both install the `dace` package, so take exactly one:

```bash
pip install "fp-arena[extended]"   # DaCe extended (PyPI dace-extended): all of FP-Arena
pip install "fp-arena[dace]"       # spcl's dace: the types and change_and_propagate_fp_types; not fp_arena.search
```

`fp_arena.search` uses DaCe extended's vectorization passes.

The benchmark kernels the examples and tests use (heat3d, hdiff, vadv, CLOUDSC) live in `fp_arena.corpus`; their
reference data (`.h5`, `.sdfg`) ships only with a checkout.

Already have a DaCe checkout (any `extended`-based branch) you want to use? Install without an extra, which pulls no
DaCe:

```bash
pip install fp-arena   # or, from a checkout: pip install -e .
```

## Quick start

Importing `fp_arena` registers the types *and* auto-enables any SDFG that uses
them, so there is nothing else to call:

```python
import numpy as np
import dace
import fp_arena                       # registers types + auto-enables on compile

@dace.program
def axpy(a: fp_arena.float32sr[1024], b: fp_arena.float32sr[1024],
         c: fp_arena.float32sr[1024]):
    for i in dace.map[0:1024]:
        c[i] = a[i] * b[i] + c[i]     # arithmetic rounds stochastically

sdfg = axpy.to_sdfg()
a = np.full(1024, 1.0, np.float32)
b = np.full(1024, 1.0, np.float32)
c = np.zeros(1024, np.float32)
sdfg(a=a, b=b, c=c)                    # headers injected + fast-math stripped automatically
```


## Notes

- Auto-enable wraps `SDFG.compile` (installed on import) and only touches SDFGs
  that actually use an FP-Arena type. Turn it off with
  `fp_arena.disable_auto_extensions()`; enable a single SDFG explicitly with
  `sdfg.enable_fp_arena_extensions()`.
- The SR types are header-only, allocation-free, and `__host__`/`__device__`
  capable (GPU codegen works; the device RNG is clock-seeded).
- Stochastic rounding needs exact IEEE rounding, so enabling removes
  `-ffast-math` / `/fp:fast` / `--use_fast_math` from DaCe's compiler flags
  (otherwise on by default). Auto-enable scopes this to the SR compile; the
  explicit `enable_fp_arena_extensions` makes it a persistent default.
- Both types capture each operation's result exactly (error-free), which is what
  matters for error analysis. `float32sr` evaluates each op in `double` (exact
  for +/−/×) and rounds by perturbing the dropped mantissa bits; `float64sr`
  uses error-free transforms (TwoSum, FMA TwoProd) since there is no wider native
  type, then rounds against the exact residual (`ulp` is a power of two, so the
  probability compare is exact too).
