Skip to content

Commit bb7b43f

Browse files
committed
Add Fortran API
1 parent 1c87794 commit bb7b43f

22 files changed

+2506
-3
lines changed

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
@@ -62,6 +62,40 @@ else()
6262
message( STATUS "GauXC Disabling C API" )
6363
endif()
6464

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

66100
target_include_directories( gauxc
67101
PUBLIC
@@ -141,6 +175,13 @@ configure_file(
141175
${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
142176
)
143177

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

145186
include( GNUInstallDirs )
146187

@@ -157,6 +198,7 @@ set_target_properties( gauxc PROPERTIES EXPORT_NAME gauxc )
157198
set(export_properties
158199
# currently configurable properties
159200
"GAUXC_HAS_C"
201+
"GAUXC_HAS_FORTRAN"
160202
"GAUXC_HAS_HOST"
161203
"GAUXC_HAS_DEVICE"
162204
"GAUXC_HAS_CUDA"
@@ -178,6 +220,7 @@ set(export_properties
178220
set_target_properties(gauxc
179221
PROPERTIES
180222
"GAUXC_HAS_C" ${GAUXC_HAS_C}
223+
"GAUXC_HAS_FORTRAN" ${GAUXC_HAS_FORTRAN}
181224
"GAUXC_HAS_HOST" ${GAUXC_HAS_HOST}
182225
"GAUXC_HAS_DEVICE" ${GAUXC_HAS_DEVICE}
183226
"GAUXC_HAS_CUDA" ${GAUXC_HAS_CUDA}
@@ -214,13 +257,28 @@ install(
214257
FILES_MATCHING PATTERN "*.h"
215258
)
216259

260+
if( GAUXC_HAS_FORTRAN )
261+
# Install Fortran modules
262+
install(
263+
DIRECTORY ${PROJECT_BINARY_DIR}/modules/
264+
DESTINATION include/gauxc/modules
265+
FILES_MATCHING PATTERN "*.mod"
266+
)
267+
endif()
268+
217269
# Install generated headers
218270
install(
219271
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
220272
DESTINATION include/gauxc
221273
)
222-
223-
274+
275+
if( GAUXC_HAS_FORTRAN )
276+
install(
277+
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.f
278+
DESTINATION include/gauxc
279+
)
280+
endif()
281+
224282
# Export target to script
225283
set( INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/gauxc )
226284
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)