Skip to content

Commit

Permalink
Merge pull request #282 from mlee03/fregrid_acc_compile
Browse files Browse the repository at this point in the history
Add OpenACC compile option to autotools
  • Loading branch information
rem1776 authored May 9, 2024
2 parents b90bd1b + 5d123f4 commit f886213
Show file tree
Hide file tree
Showing 12 changed files with 3,495 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ SUBDIRS = postprocessing/combine_restarts \
if WITH_CHECK_PROGS
SUBDIRS += t
endif

if ENABLE_ACC
SUBDIRS += tools/libfrencutils_acc
SUBDIRS += tools/fregrid_acc
endif
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ make install
The option `--with-mpi` to the `configure` command will configure for building
parallel running versions of certain FRE-NCtools applications.

### OpenACC-enabled NCTools applications
The option `--enable-acc=yes` to the `configure` command will configure for building
the fregrid_acc executable that is capable of offloading computation to GPUs. Currently, only
NVDIA compilers are supported to enable OpenACC directives in fregrid_acc and libfrencutils_acc.
Please ensure that `FC=nvfortran` and `CC=nvc`.

## Building on a GFDL-managed system
The recommended environment with the recommended autoconf defaults can be loaded by running
Expand Down
21 changes: 17 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ AC_ARG_ENABLE([quad-precision],
[],
[enable_quad_precision=no])

AC_PROG_CC([icc gcc])
AC_PROG_CC([icc gcc nvc])
AM_PROG_CC_C_O
## When autoconf v2.70 is more available, this can be replaced with:
##AC_C__GENERIC
Expand All @@ -62,7 +62,7 @@ AS_IF([test $gx_cv_c__Generic = no],
AC_MSG_ERROR([The C compiler does not support the generic selection C-11 standard. Please use a C-11 compliant compiler.])
)

AC_PROG_FC([ifort gfortran])
AC_PROG_FC([ifort gfortran nvfortran])
AC_PROG_FC_C_O
AC_FC_SRCEXT([f90])
AC_FC_SRCEXT([F90])
Expand All @@ -85,12 +85,17 @@ AS_IF([test x"$with_mpi" = x"yes"],
AM_CONDITIONAL([WITH_MPI], [test x"$build_mpi" = x"yes"])
AM_CONDITIONAL([WITH_MPI_TESTS], [test x"$build_mpi" = x"yes" -a -z "$SKIP_MPI_TEST"])

#Build with OpenACC suport. Default is 'no'
AC_ARG_ENABLE([acc],
[AS_HELP_STRING([--enable-acc], [Build with OpenACC support. Defaults to 'no'])] )
AS_IF([test ${enable_acc:no} = "yes"], [enable_acc=yes], [enable_acc=no])
AM_CONDITIONAL([ENABLE_ACC], [test $enable_acc = "yes"])

AC_CHECK_FUNCS(gettid, [], [])

# Check if Fortran compiler has Cray pointer support
GX_FC_CRAY_POINTER_FLAG()


# Add Cray Pointer support flag
if test ! -z "$FC_CRAY_POINTER_FLAG"; then
FCFLAGS="$FCFLAGS $FC_CRAY_POINTER_FLAG"
Expand All @@ -117,6 +122,12 @@ AC_CHECK_PROGS(PROVE, [prove])

AM_CONDITIONAL([WITH_CHECK_PROGS], [test -n "$PROVE" -a -n "$BATS"])

# Check if openacc.h exists
if test $enable_acc = yes ; then
AC_CHECK_HEADERS([openacc.h], [], [AC_MSG_ERROR(["Cannot find OpenACC header file"])] )
AC_MSG_WARN(Currently only NVIDIA compilers are supported to compile with OpenACC in FRE-NCTOOLS)
fi

# Check for library
AX_LIB_NETCDF()
if test "$with_netcdf" = "no"; then
Expand Down Expand Up @@ -174,7 +185,6 @@ if test x$ac_compiler_gnu = xyes; then
AC_SUBST(RPATH_FLAGS)
fi


# Output files
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
Expand All @@ -187,9 +197,11 @@ AC_CONFIG_FILES([Makefile
postprocessing/split_ncvars/Makefile
postprocessing/timavg/Makefile
tools/libfrencutils/Makefile
tools/libfrencutils_acc/Makefile
tools/check_mask/Makefile
tools/cubic_utils/Makefile
tools/fregrid/Makefile
tools/fregrid_acc/Makefile
tools/make_coupler_mosaic/Makefile
tools/make_hgrid/Makefile
tools/make_land_domain/Makefile
Expand All @@ -212,4 +224,5 @@ AC_CONFIG_FILES([Makefile
tools/simple_hydrog/rmvpr/Makefile
tools/simple_hydrog/libfmslite/Makefile
])

AC_OUTPUT
3 changes: 1 addition & 2 deletions tools/fregrid/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ if WITH_MPI
bin_PROGRAMS += fregrid_parallel
endif

AM_CFLAGS = -I$(top_srcdir)/tools/libfrencutils \
$(NETCDF_CFLAGS)
AM_CFLAGS = -I$(top_srcdir)/tools/libfrencutils $(NETCDF_CFLAGS)
LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS) $(RPATH_FLAGS)

fregrid_SOURCES = bilinear_interp.c \
Expand Down
36 changes: 36 additions & 0 deletions tools/fregrid_acc/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#***********************************************************************
# GNU Lesser General Public License
#
# This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools).
#
# FRE-NCTools is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# FRE-NCTools is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with FRE-NCTools. If not, see
# <http://www.gnu.org/licenses/>.
#***********************************************************************
bin_PROGRAMS = fregrid_acc

AM_CFLAGS = -I$(top_srcdir)/tools/libfrencutils $(NETCDF_CFLAGS) \
-I$(top_srcdir)/tools/libfrencutils_acc \
-I$(top_srcdir)/tools/fregrid -acc
LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS) $(RPATH_FLAGS)

fregrid_acc_SOURCES = conserve_interp_acc.c \
conserve_interp_acc.h \
fregrid_acc.c

fregrid_acc_LDADD = $(top_builddir)/tools/fregrid/fregrid_util.o \
$(top_builddir)/tools/fregrid/conserve_interp.o \
$(top_builddir)/tools/fregrid/bilinear_interp.o \
$(top_builddir)/tools/libfrencutils/libfrencutils.a \
$(top_builddir)/tools/libfrencutils_acc/libfrencutils_acc.a \
$(LDADD)
Loading

0 comments on commit f886213

Please sign in to comment.