Skip to content

Commit fcaf2e3

Browse files
committed
Add Fortran API
1 parent 16abe8f commit fcaf2e3

22 files changed

Lines changed: 2506 additions & 3 deletions

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ cmake_dependent_option( GAUXC_ENABLE_CUTLASS
5353
"Enable CUTLASS Linear Algebra" OFF
5454
"GAUXC_ENABLE_CUDA" OFF
5555
)
56+
cmake_dependent_option( GAUXC_ENABLE_FORTRAN
57+
"Enable Fortran API" OFF
58+
"GAUXC_ENABLE_C" ON
59+
)
5660

5761
# Default the feature variables
5862
set( GAUXC_HAS_C FALSE CACHE BOOL "" FORCE )
63+
set( GAUXC_HAS_FORTRAN FALSE CACHE BOOL "" FORCE )
5964
set( GAUXC_HAS_HOST FALSE CACHE BOOL "" FORCE )
6065
set( GAUXC_HAS_CUDA FALSE CACHE BOOL "" FORCE )
6166
set( GAUXC_HAS_HIP FALSE CACHE BOOL "" FORCE )
@@ -70,6 +75,7 @@ set( GAUXC_BLAS_IS_LP64 FALSE CACHE BOOL "" FORCE )
7075

7176
mark_as_advanced( FORCE
7277
GAUXC_HAS_C
78+
GAUXC_HAS_FORTRAN
7379
GAUXC_HAS_HOST
7480
GAUXC_HAS_CUDA
7581
GAUXC_HAS_HIP
@@ -89,6 +95,10 @@ if( NOT GAUXC_ENABLE_GAU2GRID )
8995
will be made optional in a future release of GauXC [WIP]" )
9096
endif()
9197

98+
if( GAUXC_ENABLE_FORTRAN )
99+
enable_language( Fortran )
100+
set( GAUXC_HAS_FORTRAN TRUE CACHE BOOL "GauXC has Fortran API" FORCE )
101+
endif()
92102

93103
if( GAUXC_ENABLE_HOST )
94104
set(GAUXC_HAS_HOST TRUE CACHE BOOL "GauXC has Host Bindings" FORCE)

cmake/gauxc-config.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ find_dependency( ExchCXX )
1111
find_dependency( IntegratorXX )
1212

1313
set( GAUXC_HAS_C @GAUXC_HAS_C@ )
14+
set( GAUXC_HAS_FORTRAN @GAUXC_HAS_FORTRAN@ )
1415
set( GAUXC_HAS_HOST @GAUXC_HAS_HOST@ )
1516
set( GAUXC_HAS_CUDA @GAUXC_HAS_CUDA@ )
1617
set( GAUXC_HAS_HIP @GAUXC_HAS_HIP@ )
@@ -26,6 +27,9 @@ set( GAUXC_BLAS_IS_LP64 @GAUXC_BLAS_IS_LP64@ )
2627
# Make sure C / CXX are enabled (former for BLAS discovery)
2728
enable_language(C)
2829
enable_language(CXX)
30+
if(GAUXC_HAS_FORTRAN)
31+
enable_language(Fortran)
32+
endif()
2933

3034
if(GAUXC_HAS_OPENMP)
3135
find_dependency( OpenMP )

include/gauxc/gauxc_config.f.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#cmakedefine GAUXC_HAS_C
2+
#cmakedefine GAUXC_HAS_FORTRAN
3+
#cmakedefine GAUXC_HAS_HOST
4+
#cmakedefine GAUXC_HAS_CUDA
5+
#cmakedefine GAUXC_HAS_HIP
6+
#cmakedefine GAUXC_HAS_MPI
7+
#cmakedefine GAUXC_HAS_MAGMA
8+
#cmakedefine GAUXC_HAS_NCCL
9+
#cmakedefine GAUXC_HAS_CUTLASS
10+
#cmakedefine GAUXC_HAS_GAU2GRID
11+
#cmakedefine GAUXC_HAS_HDF5
12+
#cmakedefine GAUXC_USE_FAST_RSQRT
13+
14+
#ifdef GAUXC_HAS_HOST
15+
#cmakedefine GAUXC_CPU_XC_MAX_AM @GAUXC_CPU_XC_MAX_AM@
16+
#cmakedefine GAUXC_CPU_SNLINK_MAX_AM @GAUXC_CPU_SNLINK_MAX_AM@
17+
#endif
18+
19+
#cmakedefine GAUXC_HAS_DEVICE
20+
#ifdef GAUXC_HAS_DEVICE
21+
#cmakedefine GAUXC_GPU_XC_MAX_AM @GAUXC_GPU_XC_MAX_AM@
22+
#cmakedefine GAUXC_GPU_SNLINK_MAX_AM @GAUXC_GPU_SNLINK_MAX_AM@
23+
#endif

include/gauxc/gauxc_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
#pragma once
1313

14-
#cmakedefine GAUXC_HAS_C
14+
#cmakedefine GAUXC_HAS_FORTRAN
1515
#cmakedefine GAUXC_HAS_HOST
1616
#cmakedefine GAUXC_HAS_CUDA
1717
#cmakedefine GAUXC_HAS_HIP

src/CMakeLists.txt

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ else()
6161
message( STATUS "GauXC Disabling C API" )
6262
endif()
6363

64+
if( GAUXC_ENABLE_FORTRAN )
65+
message( STATUS "GauXC Enabling Fortran API" )
66+
target_sources( gauxc PRIVATE
67+
status.f90
68+
types.f90
69+
enums.f90
70+
atom.f90
71+
molecule.f90
72+
shell.f90
73+
basisset.f90
74+
molgrid.f90
75+
runtime_environment.F90
76+
load_balancer.f90
77+
molecular_weights.f90
78+
matrix.f90
79+
functional.f90
80+
xc_integrator.f90
81+
)
82+
set(GAUXC_HAS_FORTRAN TRUE CACHE BOOL "GauXC Has Fortran API" FORCE)
83+
set_target_properties( gauxc PROPERTIES
84+
Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modules
85+
)
86+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/modules)
87+
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/modules)
88+
endif()
89+
target_include_directories(
90+
gauxc
91+
PUBLIC
92+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/modules>
93+
$<INSTALL_INTERFACE:include/gauxc/modules>
94+
)
95+
else()
96+
message( STATUS "GauXC Disabling Fortran API" )
97+
endif()
6498

6599
target_include_directories( gauxc
66100
PUBLIC
@@ -140,6 +174,13 @@ configure_file(
140174
${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
141175
)
142176

177+
if( GAUXC_HAS_FORTRAN )
178+
# Generate config file
179+
configure_file(
180+
${PROJECT_SOURCE_DIR}/include/gauxc/gauxc_config.f.in
181+
${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.f
182+
)
183+
endif()
143184

144185
include( GNUInstallDirs )
145186

@@ -156,6 +197,7 @@ set_target_properties( gauxc PROPERTIES EXPORT_NAME gauxc )
156197
set(export_properties
157198
# currently configurable properties
158199
"GAUXC_HAS_C"
200+
"GAUXC_HAS_FORTRAN"
159201
"GAUXC_HAS_HOST"
160202
"GAUXC_HAS_DEVICE"
161203
"GAUXC_HAS_CUDA"
@@ -177,6 +219,7 @@ set(export_properties
177219
set_target_properties(gauxc
178220
PROPERTIES
179221
"GAUXC_HAS_C" ${GAUXC_HAS_C}
222+
"GAUXC_HAS_FORTRAN" ${GAUXC_HAS_FORTRAN}
180223
"GAUXC_HAS_HOST" ${GAUXC_HAS_HOST}
181224
"GAUXC_HAS_DEVICE" ${GAUXC_HAS_DEVICE}
182225
"GAUXC_HAS_CUDA" ${GAUXC_HAS_CUDA}
@@ -213,13 +256,28 @@ install(
213256
FILES_MATCHING PATTERN "*.h"
214257
)
215258

259+
if( GAUXC_HAS_FORTRAN )
260+
# Install Fortran modules
261+
install(
262+
DIRECTORY ${PROJECT_BINARY_DIR}/modules/
263+
DESTINATION include/gauxc/modules
264+
FILES_MATCHING PATTERN "*.mod"
265+
)
266+
endif()
267+
216268
# Install generated headers
217269
install(
218270
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
219271
DESTINATION include/gauxc
220272
)
221-
222-
273+
274+
if( GAUXC_HAS_FORTRAN )
275+
install(
276+
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.f
277+
DESTINATION include/gauxc/modules
278+
)
279+
endif()
280+
223281
# Export target to script
224282
set( INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/gauxc )
225283
install( EXPORT gauxc-targets

src/atom.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! GauXC Copyright (c) 2020-2024, The Regents of the University of California,
2+
! through Lawrence Berkeley National Laboratory (subject to receipt of
3+
! any required approvals from the U.S. Dept. of Energy).
4+
!
5+
! (c) 2024-2025, Microsoft Corporation
6+
!
7+
! All rights reserved.
8+
!
9+
! See LICENSE.txt for details
10+
11+
!> @brief Module defining atomic data structures and routines for GauXC
12+
module gauxc_atom
13+
use iso_c_binding, only : c_int64_t, c_double
14+
implicit none
15+
private
16+
17+
!> @brief Data structure representing an atom
18+
type, bind(c), public :: gauxc_atom_type
19+
!> Atomic number
20+
integer(c_int64_t) :: atomic_number
21+
!> Cartesian x coordinate
22+
real(c_double) :: x
23+
!> Cartesian y coordinate
24+
real(c_double) :: y
25+
!> Cartesian z coordinate
26+
real(c_double) :: z
27+
end type gauxc_atom_type
28+
29+
contains
30+
31+
end module gauxc_atom

src/basisset.f90

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
! GauXC Copyright (c) 2020-2024, The Regents of the University of California,
2+
! through Lawrence Berkeley National Laboratory (subject to receipt of
3+
! any required approvals from the U.S. Dept. of Energy).
4+
!
5+
! (c) 2024-2025, Microsoft Corporation
6+
!
7+
! All rights reserved.
8+
!
9+
! See LICENSE.txt for details
10+
11+
!> @brief Module defining basis set functionality for GauXC
12+
module gauxc_basisset
13+
use iso_c_binding, only : c_ptr, c_null_ptr, c_size_t
14+
use gauxc_status, only : gauxc_status_type
15+
use gauxc_types, only : gauxc_header_type, gauxc_type_basisset
16+
use gauxc_shell, only : gauxc_shell_type
17+
implicit none
18+
private
19+
20+
public :: &
21+
& gauxc_basisset_new, &
22+
& gauxc_basisset_new_from_shells, &
23+
& gauxc_basisset_delete
24+
25+
public :: &
26+
& gauxc_delete
27+
28+
!> @brief C interoperable basis set type
29+
type, bind(c), public :: gauxc_basisset_type
30+
!> Header containing type information
31+
type(gauxc_header_type) :: header = gauxc_header_type(gauxc_type_basisset)
32+
!> Pointer to the internal basis set object
33+
type(c_ptr) :: ptr = c_null_ptr
34+
end type gauxc_basisset_type
35+
36+
interface
37+
!> @brief Create new basis set object
38+
function gauxc_basisset_new(status) result(basis) bind(c)
39+
import :: gauxc_basisset_type, gauxc_status_type
40+
implicit none
41+
!> @param status Status of the operation
42+
type(gauxc_status_type), intent(out) :: status
43+
!> @return Pointer to the newly created basis set object
44+
type(gauxc_basisset_type) :: basis
45+
end function gauxc_basisset_new
46+
47+
!> @brief Create a new BasisSet instance from an array of Shells
48+
function gauxc_basisset_new_from_shells(status, shells, nshells) result(basis) bind(c)
49+
import :: c_size_t, gauxc_status_type, gauxc_shell_type, gauxc_basisset_type
50+
implicit none
51+
!> @param status Status of the operation
52+
type(gauxc_status_type), intent(out) :: status
53+
!> @param shells Pointer to an array of Shell objects
54+
type(gauxc_shell_type), intent(in) :: shells(*)
55+
!> @param nshells Number of shells in the array
56+
integer(c_size_t), value :: nshells
57+
!> @return Pointer to the newly created basis set object
58+
type(gauxc_basisset_type) :: basis
59+
end function gauxc_basisset_new_from_shells
60+
end interface
61+
62+
interface gauxc_delete
63+
!> @brief Delete a GauXC basis set object
64+
subroutine gauxc_basisset_delete(status, basis) bind(c)
65+
import :: gauxc_status_type, gauxc_basisset_type
66+
implicit none
67+
!> @param status Status of the operation
68+
type(gauxc_status_type), intent(out) :: status
69+
!> @param basis Pointer to the basis set object to delete
70+
type(gauxc_basisset_type), intent(inout) :: basis
71+
end subroutine gauxc_basisset_delete
72+
end interface gauxc_delete
73+
74+
contains
75+
76+
end module gauxc_basisset

0 commit comments

Comments
 (0)