Skip to content

Commit 27cbcc4

Browse files
committed
Add Fortran API
1 parent b7eb770 commit 27cbcc4

22 files changed

Lines changed: 1133 additions & 5 deletions

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ endif()
2828

2929
# GauXC Options
3030
option( GAUXC_ENABLE_C "Enable C API" ON )
31+
option( GAUXC_ENABLE_FORTRAN "Enable Fortran API" OFF )
3132
option( GAUXC_ENABLE_HOST "Enable Host Integrator" ON )
3233
option( GAUXC_ENABLE_CUDA "Enable CUDA Bindings" OFF )
3334
option( GAUXC_ENABLE_HIP "Enable HIP Bindings" OFF )
@@ -56,6 +57,7 @@ cmake_dependent_option( GAUXC_ENABLE_CUTLASS
5657

5758
# Default the feature variables
5859
set( GAUXC_HAS_C FALSE CACHE BOOL "" FORCE )
60+
set( GAUXC_HAS_FORTRAN FALSE CACHE BOOL "" FORCE )
5961
set( GAUXC_HAS_HOST FALSE CACHE BOOL "" FORCE )
6062
set( GAUXC_HAS_CUDA FALSE CACHE BOOL "" FORCE )
6163
set( GAUXC_HAS_HIP FALSE CACHE BOOL "" FORCE )
@@ -70,6 +72,7 @@ set( GAUXC_BLAS_IS_LP64 FALSE CACHE BOOL "" FORCE )
7072

7173
mark_as_advanced( FORCE
7274
GAUXC_HAS_C
75+
GAUXC_HAS_FORTRAN
7376
GAUXC_HAS_HOST
7477
GAUXC_HAS_CUDA
7578
GAUXC_HAS_HIP

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: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ add_library( gauxc
4242
atomic_radii.cxx
4343
)
4444

45-
if( GAUXC_ENABLE_C )
45+
if( GAUXC_ENABLE_C OR GAUXC_ENABLE_FORTRAN )
4646
target_sources( gauxc PRIVATE
4747
c_types.cxx
4848
c_molecule.cxx
@@ -58,6 +58,37 @@ if( GAUXC_ENABLE_C )
5858
set(GAUXC_HAS_C TRUE CACHE BOOL "GauXC Has C API" FORCE)
5959
endif()
6060

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

6293
target_include_directories( gauxc
6394
PUBLIC
@@ -137,6 +168,13 @@ configure_file(
137168
${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
138169
)
139170

171+
if( GAUXC_HAS_FORTRAN )
172+
# Generate config file
173+
configure_file(
174+
${PROJECT_SOURCE_DIR}/include/gauxc/gauxc_config.f.in
175+
${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.f
176+
)
177+
endif()
140178

141179
include( GNUInstallDirs )
142180

@@ -153,6 +191,7 @@ set_target_properties( gauxc PROPERTIES EXPORT_NAME gauxc )
153191
set(export_properties
154192
# currently configurable properties
155193
"GAUXC_HAS_C"
194+
"GAUXC_HAS_FORTRAN"
156195
"GAUXC_HAS_HOST"
157196
"GAUXC_HAS_DEVICE"
158197
"GAUXC_HAS_CUDA"
@@ -174,6 +213,7 @@ set(export_properties
174213
set_target_properties(gauxc
175214
PROPERTIES
176215
"GAUXC_HAS_C" ${GAUXC_HAS_C}
216+
"GAUXC_HAS_FORTRAN" ${GAUXC_HAS_FORTRAN}
177217
"GAUXC_HAS_HOST" ${GAUXC_HAS_HOST}
178218
"GAUXC_HAS_DEVICE" ${GAUXC_HAS_DEVICE}
179219
"GAUXC_HAS_CUDA" ${GAUXC_HAS_CUDA}
@@ -210,13 +250,28 @@ install(
210250
FILES_MATCHING PATTERN "*.h"
211251
)
212252

253+
if( GAUXC_HAS_FORTRAN )
254+
# Install Fortran modules
255+
install(
256+
DIRECTORY ${PROJECT_BINARY_DIR}/modules/
257+
DESTINATION include/gauxc/modules
258+
FILES_MATCHING PATTERN "*.mod"
259+
)
260+
endif()
261+
213262
# Install generated headers
214263
install(
215264
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.h
216265
DESTINATION include/gauxc
217266
)
218-
219-
267+
268+
if( GAUXC_HAS_FORTRAN )
269+
install(
270+
FILES ${PROJECT_BINARY_DIR}/include/gauxc/gauxc_config.f
271+
DESTINATION include/gauxc/modules
272+
)
273+
endif()
274+
220275
# Export target to script
221276
set( INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/gauxc )
222277
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
!> @brief C interoperable basis set type
26+
type, bind(c), public :: gauxc_basisset_type
27+
!> Header containing type information
28+
type(gauxc_header_type) :: header = gauxc_header_type(gauxc_type_basisset)
29+
!> Pointer to the internal basis set object
30+
type(c_ptr) :: ptr = c_null_ptr
31+
end type gauxc_basisset_type
32+
33+
interface
34+
!> @brief Create new basis set object
35+
function gauxc_basisset_new(status) result(basis) bind(c)
36+
import :: gauxc_basisset_type, gauxc_status_type
37+
implicit none
38+
!> @param status Status of the operation
39+
type(gauxc_status_type), intent(out) :: status
40+
!> @return Pointer to the newly created basis set object
41+
type(gauxc_basisset_type) :: basis
42+
end function gauxc_basisset_new
43+
44+
!> @brief Create a new BasisSet instance from an array of Shells
45+
function gauxc_basisset_new_from_shells(status, shells, nshells) result(basis) bind(c)
46+
import :: c_size_t, gauxc_status_type, gauxc_shell_type, gauxc_basisset_type
47+
implicit none
48+
!> @param status Status of the operation
49+
type(gauxc_status_type), intent(out) :: status
50+
!> @param shells Pointer to an array of Shell objects
51+
type(gauxc_shell_type), intent(in) :: shells(*)
52+
!> @param nshells Number of shells in the array
53+
integer(c_size_t), value :: nshells
54+
!> @return Pointer to the newly created basis set object
55+
type(gauxc_basisset_type) :: basis
56+
end function gauxc_basisset_new_from_shells
57+
58+
!> @brief Delete a GauXC basis set object
59+
subroutine gauxc_basisset_delete(status, basis) bind(c)
60+
import :: gauxc_status_type, gauxc_basisset_type
61+
implicit none
62+
!> @param status Status of the operation
63+
type(gauxc_status_type), intent(out) :: status
64+
!> @param basis Pointer to the basis set object to delete
65+
type(gauxc_basisset_type), intent(inout) :: basis
66+
end subroutine gauxc_basisset_delete
67+
end interface
68+
69+
contains
70+
71+
end module gauxc_basisset

0 commit comments

Comments
 (0)