Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions enzyme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ENZYME_ENABLE_PLUGINS "Enable Clang/LLD/Opt plugins" ON)
option(ENZYME_ENABLE_BENCHMARKS "Enable benchmarks" OFF)
option(ENZYME_BC_LOADER "Enable bitcode loader" ON)
option(ENZYME_FORTRAN "Build Enzyme Fortran bindings" OFF)
option(ENZYME_CLANG "Build enzyme clang plugin" ON)
option(ENZYME_FLANG "Build enzyme flang symlink" OFF)
option(ENZYME_MLIR "Build enzyme mlir plugin" OFF)
option(ENZYME_IFX "Enable enzyme support for the Intel Fortran compiler IFX" OFF)
option(ENZYME_IFX "Enable enzyme support for the Intel Fortran compiler IFX" OFF)
option(ENZYME_EXTERNAL_SHARED_LIB "Build external shared library" OFF)
option(ENZYME_APPLE_DYNAMIC_LOOKUP
"On Apple, link Enzyme shared library with -flat_namespace/-undefined,dynamic_lookup instead of linking LLVM"
Expand Down Expand Up @@ -299,6 +301,9 @@ endif()
if (ENZYME_ENABLE_PLUGINS)
add_subdirectory(test)
endif()
if (ENZYME_FORTRAN)
add_subdirectory(Fortran)
endif()

# The benchmarks data are not in git-exported source archives to minimize size.
# Only add the benchmarks if the directory exists.
Expand Down
26 changes: 26 additions & 0 deletions enzyme/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
enable_language(Fortran)
include(FortranCInterface)
FortranCInterface_VERIFY(QUIET)

add_library(EnzymeFortran enzyme.f90)

# Install library, create target file
install(
TARGETS EnzymeFortran
EXPORT EnzymeFortranTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/EnzymeFortran)

# Install Fortran module file
if(NOT DEFINED CMAKE_INSTALL_MODULEDIR)
set(
CMAKE_INSTALL_MODULEDIR
"${CMAKE_INSTALL_INCLUDEDIR}/EnzymeFortran"
CACHE STRING "Directory in prefix to install generated module files"
)
endif()
install(FILES "${CMAKE_Fortran_MODULE_DIRECTORY}/enzyme.mod"
DESTINATION "${CMAKE_INSTALL_MODULEDIR}")
36 changes: 36 additions & 0 deletions enzyme/Fortran/enzyme.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
! ===- enzyme.f90 - Fortran bindings for Enzyme ---------------------------=== !
!
! Enzyme Project
!
! Part of the Enzyme Project, under the Apache License v2.0 with LLVM
! Exceptions. See https://llvm.org/LICENSE.txt for license information.
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
!
! If using this code in an academic setting, please cite the following:
! @misc{enzymeGithub,
! author = {William S. Moses and Valentin Churavy},
! title = {Enzyme: High Performance Automatic Differentiation of LLVM},
! year = {2020},
! howpublished = {\url{https://github.com/wsmoses/Enzyme}},
! note = {commit xxxxxxx}
! }
!
! ===----------------------------------------------------------------------=== !
!
! This file provides Fortran bindings for Enzyme.
!
! ===----------------------------------------------------------------------=== !
module enzyme
use iso_c_binding, only: c_int
implicit none
private

! Bindings for activity descriptors
integer(c_int), public, bind(C, name="enzyme_const") :: enzyme_const
integer(c_int), public, bind(C, name="enzyme_dup") :: enzyme_dup
integer(c_int), public, bind(C, name="enzyme_dupnoneed") :: enzyme_dupnoneed
integer(c_int), public, bind(C, name="enzyme_out") :: enzyme_out
integer(c_int), public, bind(C, name="enzyme_scalar") :: enzyme_scalar
integer(c_int), public, bind(C, name="enzyme_width") :: enzyme_width
integer(c_int), public, bind(C, name="enzyme_vector") :: enzyme_vector
Comment thread
vchuravy marked this conversation as resolved.
end module enzyme
Loading