Implementation Details
For now, please see these presentations:
Zero-Copy Data APIs
pyAMReX implements the following standardized data APIs:
__array_interface__(CPU)__cuda_array_interface__(CUDA GPU)DLPack v1.1 via
__dlpack__and__dlpack_device__(CPU and CUDA, ROCm & SYCL GPUs)
These APIs are automatically used when creating “views” (non-copy) numpy arrays, cupy arrays, dpnp arrays, PyTorch tensors, etc. from AMReX objects such as Array4 and particle arrays.
DLPack is implemented once in src/dlpack/DLPackHelpers.H (kwarg protocol, capsule creation, producer keep-alive, copy & stream synchronization) and bound per container class (Array4, BaseFab, PODVector, Vector, SmallMatrix) with a small adapter describing the exported tensor.
An exception is ArrayOfStructs: DLPack cannot describe record (struct) element types, so it only implements the structured array interfaces above.