Skip to content
szaghiPublic

About

Fortran UNified Device Acceleration Library

Topics

Resources

Contributing

Stars

18 stars

Watchers

5 watching

Forks

Repository files navigation

FUNDAL

FUNDAL

Fortran UNified Device Acceleration Library

a pure Fortran library providing a unified API for GPU/device memory management over OpenACC and OpenMP backends.

GitHub tag GitHub issues CI Coverage License

🔀 One API, three builds
OpenACC, OpenMP offload or the compile-time CPU mode, chosen by a macro: the same dev_* calls
🧱 Structured memory
Device arrays as Fortran pointers: dev_alloc, dev_free, dev_memcpy_*, custom bounds
📦 Unstructured memory
Host allocatables mapped to the device: dev_alloc_unstr, dev_memcpy_*_unstr
🔄 Allocate and copy
dev_assign_to/from_device, transposed copies, dev_alloc_replace
🧩 Portable kernels
fundal.H macros: one loop, an OpenACC and an OpenMP directive
🛑 No silent host fallback
dev_init(require_device=.true.), dev_is_host_fallback
🔎 Allocation registry
Frees on the right device, catches double frees, dev_alloc_report finds leaks
🌐 MPI multi-device
One device per rank with any MPI: split the node, dev_init(local_rank=node_rank)

The FUNDAL website has a tutorial, a cookbook and the reference of every procedure; every code sample there is compiled and run.


Quick start

#include "fundal.H"

program quickstart
!< A first FUNDAL program: device memory, copies, a kernel.
use, intrinsic :: iso_fortran_env, only : I4P=>int32, R8P=>real64
use            :: fundal
implicit none
integer(I4P), parameter :: n=8              ! array size
real(R8P), pointer      :: a_dev(:)=>null() ! device memory
real(R8P)               :: a(n)             ! host memory
integer(I4P)            :: i                ! counter
integer(I4P)            :: ierr             ! error status

call dev_init                                          ! select the device
call dev_alloc(fptr_dev=a_dev, ubounds=[n], ierr=ierr) ! allocate on the device
if (ierr /= 0) error stop 'device allocation failed'
a = [(real(i, R8P), i=1, n)]
call dev_memcpy_to_device(dst=a_dev, src=a)            ! host -> device

!$acc parallel loop DEVICEVAR(a_dev)
!$omp OMPLOOP DEVICEPTR(a_dev)
do i=1, n                                              ! a kernel, on the device
   a_dev(i) = 2._R8P * a_dev(i)
enddo

call dev_memcpy_from_device(dst=a, src=a_dev)          ! device -> host
call dev_free(a_dev)                                   ! release the device memory
print '(A,*(F5.1))', 'a:', a
print '(A,L1)', 'doubled on the device: ', all(a == [(2._R8P * i, i=1, n)])
endprogram quickstart

DEVICEVAR, DEVICEPTR and OMPLOOP come from fundal.H: the compiler reads the directive of the backend it builds for. Build FUNDAL and the program with the same macros (here gfortran and OpenACC):

make COMPILER=gnu BACKEND=oac
gfortran -cpp -DCOMPILER_GNU -DDEV_OAC -fopenacc -I src/lib -I build/gnu-oac/mod \
         quickstart.F90 build/gnu-oac/libfundal.a -o quickstart
./quickstart

Install

FoBiS

git clone https://github.com/szaghi/FUNDAL && cd FUNDAL
fobis build --lmodes                       # list the modes
fobis build --mode fundal-test-oac-nvf     # NVIDIA nvfortran + OpenACC
fobis build --mode fundal-test-omp-ifx     # Intel ifx + OpenMP offload
fobis build --mode fundal-test-oac-gnu     # GNU gfortran + OpenACC
fobis build --mode fundal-test-omp-amd     # AMD amdflang + OpenMP offload
bash scripts/run_tests.sh                  # run the tests built into exe/

make

make COMPILER=nvf BACKEND=oac GPU=cc89     # build/nvf-oac/libfundal.a and build/nvf-oac/mod/

COMPILER=gnu|nvf|ifx|amd, BACKEND=none|oac|omp.

CMake

cmake -B build -DFUNDAL_BACKEND=oac        # none|oac|omp; -DCMAKE_Fortran_COMPILER=nvfortran|ifx|amdflang; MPI test: -DFUNDAL_MPI=ON
cmake --build build && ctest --test-dir build
cmake --install build --prefix <prefix>    # then find_package(FUNDAL) and link FUNDAL::fundal

fpm

fpm build                                              # compile-time CPU mode
fpm build --flag "-DDEV_OAC -DCOMPILER_GNU -fopenacc"  # gfortran + OpenACC

See the installation guide for every option and for using FUNDAL in your project.

One-line install

curl -fsSL https://github.com/szaghi/FUNDAL/releases/latest/download/install.sh | bash

It installs the latest release into ~/.local with the build system you choose among those FUNDAL ships (--build fobis|fpm|cmake|make: a menu asks when you do not say), one install per compiler (lib/fundal/<compiler>-<version>/, include/fundal/<compiler>-<version>/, with fundal.H next to the modules), and makes it usable through pkg-config (pkg-config --cflags --libs fundal, with PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig). It builds the compile-time CPU mode with gfortran (no device backend): for a device build or another compiler, build FUNDAL as below. Pass options after bash -s --, e.g. ... | bash -s -- --build cmake --prefix /opt/fundal; --help lists them all, --uninstall removes the install. The installer is FoBiS's (One-line installer).


Authors

Contributions are welcome — see the Contributing page.

Copyrights

This project is distributed under a multi-licensing system:

Anyone interested in using, developing, or contributing to FUNDAL is welcome — pick the license that best fits your needs.

About

Fortran UNified Device Acceleration Library

Topics

Resources

Contributing

Stars

18 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages