Skip to content

FUNDALFortran UNified Device Acceleration Library

A pure Fortran library providing a unified API for GPU/device memory management over OpenACC and OpenMP backends — one interface, any accelerator.

Quick start

A minimal FUNDAL program: allocate device memory, copy data to the GPU, run a kernel, copy back.

fortran
program fundal_taste
use, intrinsic :: iso_fortran_env, only : I4P=>int32, R8P=>real64
use            :: fundal

implicit none
real(R8P), pointer :: a_dev(:,:,:)=>null()  ! device memory
real(R8P), pointer :: b_hos(:,:,:)=>null()  ! host   memory
integer(I4P)       :: ierr
integer(I4P)       :: i, j, k

! initialise environment global variables
myhos   = dev_get_host_num()
devtype = dev_get_device_type()
call dev_set_device_num(0)
mydev   = dev_get_device_num()

! allocate device memory
call dev_alloc(fptr_dev=a_dev, lbounds=[-1,-2,-3], ubounds=[1,2,3], ierr=ierr, dev_id=mydev)

! allocate and set host memory
allocate(b_hos(-1:1,-2:2,-3:3))
b_hos = -3._R8P

! copy to device, work on device, copy back
call dev_memcpy_to_device(dst=a_dev, src=b_hos)

!$acc parallel loop independent deviceptr(a_dev) collapse(3)
!$omp target teams distribute parallel do collapse(3) has_device_addr(a_dev)
do k=-3,3; do j=-2,2; do i=-1,1
  a_dev(i,j,k) = a_dev(i,j,k) / 2._R8P
enddo; enddo; enddo

call dev_memcpy_from_device(dst=b_hos, src=a_dev)
print*, b_hos
endprogram fundal_taste

Device memory is declared as pointer; host memory can be pointer or allocatable. OpenACC and OpenMP pragmas coexist safely — unrecognised directives are ignored by the compiler.

Authors

Copyrights

FUNDAL is distributed under a multi-licensing system:

Use caseLicense
FOSS projectsGPL v3
Closed source / commercialBSD 2-Clause
Closed source / commercialBSD 3-Clause
Closed source / commercialMIT

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