Skip to content

Commit 9a2614a

Browse files
authored
Doc: More Implementation Details (#195)
Add documentation pages that describe implementation specifics in greater detail: - Python module generation with pybind11 - zero-copy data interfaces
1 parent a719df9 commit 9a2614a

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

docs/source/acknowledge_us.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Further pyAMReX References
3333

3434
Works using pyAMReX:
3535

36+
- Huebl A et al.,
37+
**Exascale and ML Models for Accelerator Simulations**.
38+
presentation at the 6th European Advanced Accelerator Concepts workshop (EAAC23), Isola d'Elba, Italy, Sep 17 – 23, 2023.
39+
`DOI:10.5281/zenodo.8362549 <https://doi.org/10.5281/zenodo.8362549>`__
40+
3641
- Sandberg R T, Lehe R, Mitchell C E, Garten M, Qiang J, Vay J-L and Huebl A.
3742
**Hybrid Beamline Element ML-Training for Surrogates in the ImpactX Beam-Dynamics Code**.
3843
14th International Particle Accelerator Conference (IPAC'23), WEPA101, *in print*, 2023.

docs/source/developers/implementation.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@
33
Implementation Details
44
======================
55

6-
.. note::
6+
For now, please see these presentations:
77

8-
TODO :-)
9-
Link Dec 2022 slides from Axel or similar...
8+
- `A. Huebl et al., NREL virtual seminar, December 2022 <https://docs.google.com/presentation/d/1X3_OERbFcZEd-awNEEEoOd98VT-gmB1UDEfK7A4NgGc/edit?usp=sharing>`__
9+
- `A. Huebl et al., "Exascale and ML Models for Accelerator Simulations", 6th European Advanced Accelerator Concepts workshop (EAAC23), Isola d'Elba, Italy, Sep 17 – 23, 2023 DOI:10.5281/zenodo.8362549 <https://doi.org/10.5281/zenodo.8362549>`__
10+
11+
12+
Zero-Copy Data APIs
13+
-------------------
14+
15+
pyAMReX implements the following `standardized data APIs <https://data-apis.org>`__:
16+
17+
- ``__array_interface__`` (CPU)
18+
- ``__cuda_array_interface__`` (CUDA GPU)
19+
- ``DLPack`` (`coming soon <https://github.com/AMReX-Codes/pyamrex/issues/9#issuecomment-1644288546>`__)
20+
21+
These APIs are automatically used when creating "views" (non-copy) numpy arrays, cupy arrays, PyTorch tensors, etc. from AMReX objects such as ``Array4`` and particle arrays.

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The `pyAMReX GitHub repo <https://github.com/AMReX-Codes/pyamrex>`__ is the main
2020
Have a look at the action icons on the top right of the web page: feel free to watch the repo if you want to receive updates, or to star the repo to support the project.
2121
For bug reports or to request new features, you can also open a new `issue <https://github.com/AMReX-Codes/pyamrex/issues>`__.
2222

23-
ON our `discussion page <https://github.com/ECP-WarpX/impactx/discussions>`__, you can find already answered questions, add new questions, get help with installation procedures, discuss ideas or share comments.
23+
On our `discussion page <https://github.com/AMReX-Codes/pyamrex/discussions>`__, you can find already answered questions, add new questions, get help with installation procedures, discuss ideas or share comments.
2424

2525
.. raw:: html
2626

@@ -65,6 +65,7 @@ Usage
6565

6666
usage/how_to_run
6767
usage/api
68+
usage/zerocopy
6869
usage/workflows
6970
.. usage/tests
7071

docs/source/usage/zerocopy.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. _usage-zerocopy:
2+
3+
Zero-Copy
4+
=========
5+
6+
pyAMReX is designed to bridge the worlds of block-structured codes and data science.
7+
As such, it includes zero-copy GPU data access for AI/ML, in situ analysis, application coupling by implementing :ref:`standardized data interfaces <developers-implementation`.
8+
9+
10+
CPU: numpy
11+
----------
12+
13+
zero-copy read and write access.
14+
CPU as well as managed memory CPU/GPU.
15+
16+
Call ``.to_numpy()`` on data objects of pyAMReX.
17+
See the optional arguments of this API.
18+
19+
Writing to the created numpy array will also modify the underlying AMReX memory.
20+
21+
22+
GPU: cupy
23+
---------
24+
25+
GPU zero-copy read and write access.
26+
27+
Call ``.to_cupy()`` on data objects of pyAMReX.
28+
See the optional arguments of this API.
29+
30+
Writing to the created cupy array will also modify the underlying AMReX memory.
31+
32+
33+
GPU: numba
34+
----------
35+
36+
GPU zero-copy read and write access.
37+
38+
After ``from numba import cuda``, create a zero-copy tensor on a GPU array via ``marr_numba = cuda.as_cuda_array(marr)``.
39+
40+
Writing to the created numba array will also modify the underlying AMReX memory.
41+
42+
43+
AI/ML: pyTorch
44+
--------------
45+
46+
CPU and GPU zero-copy read and write access.
47+
48+
Create a zero-copy tensor on a GPU array via ``torch.as_tensor(amrex_array_here, device="cuda")``.
49+
50+
Writing to the created PyTorch tensor will also modify the underlying AMReX memory.

0 commit comments

Comments
 (0)