Skip to content

Create Fortran bindings module#2807

Open
joewallwork wants to merge 5 commits into
mainfrom
2805_fortran-mod
Open

Create Fortran bindings module#2807
joewallwork wants to merge 5 commits into
mainfrom
2805_fortran-mod

Conversation

@joewallwork
Copy link
Copy Markdown
Collaborator

@joewallwork joewallwork commented May 7, 2026

Closes #2805

Thanks to @isaacaka for figuring out how to make use of activity descriptors in Fortran: bind to those that Enzyme picks up in C. To avoid users having to know how to do Fortran-C binding, we thought it would be beneficial to create a Fortran module containing these for convenience. There will likely be other things that come up that we can add to the module later in the project.

To use these descriptors in Fortran, import them with

use enzyme_mod, only: enzyme_const, enzyme_dup

or just

use enzyme_mod

Checklist

  • Add a Fortran module into the repo containing these bindings
  • Hook it up in the build system

@joewallwork joewallwork self-assigned this May 7, 2026
@joewallwork joewallwork added enhancement New feature or request fortran Related to Enzyme's Fortran bindings labels May 7, 2026
@vchuravy
Copy link
Copy Markdown
Member

vchuravy commented May 7, 2026

Is use enzyme_mod common in Fortran? Would it make more sense to just have use enzyme?

Comment thread enzyme/Fortran/enzyme.f90
@joewallwork
Copy link
Copy Markdown
Collaborator Author

Is use enzyme_mod common in Fortran? Would it make more sense to just have use enzyme?

Both are common although I suppose _mod tends to be appended in older codes. I'm happy to use enzyme instead.

@joewallwork
Copy link
Copy Markdown
Collaborator Author

Is use enzyme_mod common in Fortran? Would it make more sense to just have use enzyme?

Both are common although I suppose _mod tends to be appended in older codes. I'm happy to use enzyme instead.

Done in 27b7edc.

Comment thread enzyme/CMakeLists.txt Outdated
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(Enzyme)
project(Enzyme LANGUAGES C CXX Fortran)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without adding Fortran to the languages in the project, I get the CMake error

FortranCInterface requires the Fortran language to be enabled

when building Enzyme. If I remove that from Fortran/CMakeLists.txt then I get

CMake can not determine linker language for target: EnzymeFortran

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0479c37 by enabling Fortran in the subdir rather than globally.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added a CMake option ENZYME_FORTRAN in 827e439 that's defaulted to off like the other Fortran-related options. Turning it on builds the bindings.

@joewallwork joewallwork marked this pull request as ready for review May 11, 2026 16:15
@joewallwork joewallwork requested a review from wsmoses May 11, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fortran Related to Enzyme's Fortran bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Fortran module for bindings

3 participants