Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fortran interface #341

Merged
merged 9 commits into from
May 22, 2020
Merged

Add Fortran interface #341

merged 9 commits into from
May 22, 2020

Conversation

awehrfritz
Copy link
Contributor

Description

This add a Fortran interface for OCCA and respective tests and examples.

The implementation utilises the Fortran 2003 ISO_C_BINDING module. Thus a Fortran 2003 compliant compiler is required. The interface relies on OCCA's C interface and is sthus limited to the functionality exposed via the C interface. The Fortran implementation is in most cases a simple interface to the C functions, thus simply providing a standardised way for the compiler to call the C functions from a Fortran program.

The Fortran interface is compiled into a shared library libocca_fortran.so, which can be simply linked to an application intending to use OCCA. Alternatively, the Fortran modules can be directly included in a statically compiled program, as demonstrated in examples/fortran/03_static_compilation.

This resolves issue #104.

Future work

While this initial implementation is fully functional, a subsequent revision could include additional wrapper/convenience functions to make the interface more "Fortran-like".
The following lists a few examples in this regard:

  1. The Fortran-to-C string conversion could be hidden by implementing a small shim layer around the interface in order to hide the F_C_str function in:
device = occaCreateDeviceFromString(F_C_str(info))
  1. Another example would be the Fortran pointer assignment for UVA memory, which could be wrapped in a single function call. Currently this requires the following:
  type(C_void_ptr)       :: a 
  real(C_float), pointer :: a_ptr(:)

  a  = occaTypedUMalloc(entries, occaDtypeFloat, C_NULL_ptr, occaDefault)

  if (C_associated(a)) then
    call C_F_pointer(a,a_ptr,[entries])
  end if
  1. The call to C_loc in
call occaCopyPtrToMem(o_b, C_loc(b), occaAllBytes   , 0_occaUDim_t, occaDefault)

could be hidden in a convenience function/wrapper analog to the proposed shim layer in 1.

@awehrfritz awehrfritz changed the title Fortran interface Add Fortran interface May 10, 2020
@dmed256
Copy link
Member

dmed256 commented May 12, 2020

🔥 🔥 🔥 This is pretty amazing, I'll take some time this week to check it out. Thank you!!

@dmed256
Copy link
Member

dmed256 commented May 22, 2020

Sorry it took a while. I have a few changes I would like to make but nothing blocking.

Thanks again for all your hard work!

@dmed256 dmed256 merged commit d7fa75a into libocca:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants