Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hypre-multiprecision build #850

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
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
55 changes: 52 additions & 3 deletions src/blas/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,67 @@ OBJS = ${BLAS_FILES:.c=.o}
# Targets
##################################################################

all: ${OBJS}
#all: ${OBJS}

all: blas_OBJS

install: all
cp -fR $(srcdir)/_hypre_blas.h $(HYPRE_INC_INSTALL)

clean:
clean: clean_mup
rm -rf *.o

distclean: clean

ifeq (${MP_BUILD}, 1)
clean_mup:
rm -rf ${MuP_OBJDIR}
else
clean_mup:
endif

##################################################################
# Rules
# Build Rules
##################################################################

ifeq (${MP_BUILD}, 1)

MuP_OBJDIR = MuP_obj.dir
MuP_OBJDIR_single = ${MuP_OBJDIR}/${join ${shell basename ${CURDIR}},_flt}
MuP_OBJDIR_double = ${MuP_OBJDIR}/${join ${shell basename ${CURDIR}},_dbl}
MuP_OBJDIR_longdouble = ${MuP_OBJDIR}/${join ${shell basename ${CURDIR}},_ldbl}
#
#MKDIR_P = mkdir -p
#mkmpdir:
# ${MKDIR_P} ${MuP_OBJDIR}
#
ADD_OBJS_single = ${addprefix ${MuP_OBJDIR_single}/, ${notdir ${OBJS}}}
${ADD_OBJS_single}: CFLAGS += -DMP_BUILD_SINGLE=1
${MuP_OBJDIR_single}/%.o: %.c ${BLAS_HEADERS}
# @echo "MuP_OBJDIR is ${ADD_OBJS_single} ... $%"
@echo "processing C object $@ ..."
@mkdir -p ${@D}
${CC} ${CFLAGS} -c -o $@ $<
#
ADD_OBJS_double = ${addprefix ${MuP_OBJDIR_double}/, ${notdir ${OBJS}}}
${ADD_OBJS_double}: CFLAGS += -DMP_BUILD_DOUBLE=1
${MuP_OBJDIR_double}/%.o: %.c ${BLAS_HEADERS}
@echo "processing C object $@ ..."
@mkdir -p ${@D}
${CC} ${CFLAGS} -c -o $@ $<
#
ADD_OBJS_longdouble = ${addprefix ${MuP_OBJDIR_longdouble}/, ${notdir ${OBJS}}}
${ADD_OBJS_longdouble}: CFLAGS += -DMP_BUILD_LONGDOUBLE=1
${MuP_OBJDIR_longdouble}/%.o: %.c ${BLAS_HEADERS}
@echo "processing C object $@ ..."
@mkdir -p ${@D}
${CC} ${CFLAGS} -c -o $@ $<
#
# multiprecision object files
blas_OBJS: ${ADD_OBJS_single} ${ADD_OBJS_double} ${ADD_OBJS_longdouble}
#
else
${OBJS}: ${BLAS_HEADERS}
blas_OBJS: ${OBJS}
endif

4 changes: 4 additions & 0 deletions src/blas/_hypre_blas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include <HYPRE_config.h>

#ifdef HYPRE_MIXED_PRECISION
#include "blas_mup_func.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
41 changes: 41 additions & 0 deletions src/blas/blas_func_header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be merged with the headers script approach we are gradually adopting throughout hypre. That way the internal header file for each subdirectory in hypre is always done in the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rfalgout Yes, I agree we can do that. Not all the subdirectories have this headers script, but perhaps this could force us to head in that direction.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
# Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
# HYPRE Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

# generate header file for transforming multiprecision function names

MUP_HEADER=blas_mup_func.h

cat > $MUP_HEADER <<@
/*** DO NOT EDIT THIS FILE DIRECTLY (use 'blas_func_header' to generate) ***/
@
# Generate copyright header
../config/writeHeader.sh $MUP_HEADER

cat >> $MUP_HEADER <<@

/******************************************************************************
* Header file for transforming multiprecision functions names
*****************************************************************************/

#ifndef BLAS_MUP_FUNC_HEADER
#define BLAS_MUP_FUNC_HEADER

#include "multiprecision.h"

@

FIN=blas_functions.saved
cat>> $MUP_HEADER <<@
$(
cat "$FIN" | while read -r func_name
do
# print dressed-up function
echo "#define $func_name HYPRE_MULTIPRECISION_FUNC ( $func_name )"
done
)

#endif
@
30 changes: 30 additions & 0 deletions src/blas/blas_functions.saved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the comment for script blas_func_header, this file can just be named functions.saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
hypre_dasum
hypre_daxpy
hypre_dcopy
hypre_ddot
hypre_dgemm
hypre_dgemv
hypre_dger
hypre_dnrm2
hypre_drot
hypre_dscal
hypre_dswap
hypre_dsymm
hypre_dsymv
hypre_dsyr2
hypre_dsyr2k
hypre_dsyrk
hypre_dtrmm
hypre_dtrmv
hypre_dtrsm
hypre_dtrsv
hypre_d_lg10
hypre_d_sign
hypre_pow_dd
hypre_pow_di
hypre_s_cat
hypre_s_cmp
hypre_s_copy
hypre_idamax
hypre_blas_lsame
hypre_blas_xerbla
50 changes: 50 additions & 0 deletions src/blas/blas_mup_func.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*** DO NOT EDIT THIS FILE DIRECTLY (use 'blas_func_header' to generate) ***/

/******************************************************************************
* Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
* HYPRE Project Developers. See the top-level COPYRIGHT file for details.
*
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
******************************************************************************/

/******************************************************************************
* Header file for transforming multiprecision functions names
*****************************************************************************/

#ifndef BLAS_MUP_FUNC_HEADER
#define BLAS_MUP_FUNC_HEADER

#include "multiprecision.h"

#define hypre_dasum HYPRE_MULTIPRECISION_FUNC ( hypre_dasum )
#define hypre_daxpy HYPRE_MULTIPRECISION_FUNC ( hypre_daxpy )
#define hypre_dcopy HYPRE_MULTIPRECISION_FUNC ( hypre_dcopy )
#define hypre_ddot HYPRE_MULTIPRECISION_FUNC ( hypre_ddot )
#define hypre_dgemm HYPRE_MULTIPRECISION_FUNC ( hypre_dgemm )
#define hypre_dgemv HYPRE_MULTIPRECISION_FUNC ( hypre_dgemv )
#define hypre_dger HYPRE_MULTIPRECISION_FUNC ( hypre_dger )
#define hypre_dnrm2 HYPRE_MULTIPRECISION_FUNC ( hypre_dnrm2 )
#define hypre_drot HYPRE_MULTIPRECISION_FUNC ( hypre_drot )
#define hypre_dscal HYPRE_MULTIPRECISION_FUNC ( hypre_dscal )
#define hypre_dswap HYPRE_MULTIPRECISION_FUNC ( hypre_dswap )
#define hypre_dsymm HYPRE_MULTIPRECISION_FUNC ( hypre_dsymm )
#define hypre_dsymv HYPRE_MULTIPRECISION_FUNC ( hypre_dsymv )
#define hypre_dsyr2 HYPRE_MULTIPRECISION_FUNC ( hypre_dsyr2 )
#define hypre_dsyr2k HYPRE_MULTIPRECISION_FUNC ( hypre_dsyr2k )
#define hypre_dsyrk HYPRE_MULTIPRECISION_FUNC ( hypre_dsyrk )
#define hypre_dtrmm HYPRE_MULTIPRECISION_FUNC ( hypre_dtrmm )
#define hypre_dtrmv HYPRE_MULTIPRECISION_FUNC ( hypre_dtrmv )
#define hypre_dtrsm HYPRE_MULTIPRECISION_FUNC ( hypre_dtrsm )
#define hypre_dtrsv HYPRE_MULTIPRECISION_FUNC ( hypre_dtrsv )
#define hypre_d_lg10 HYPRE_MULTIPRECISION_FUNC ( hypre_d_lg10 )
#define hypre_d_sign HYPRE_MULTIPRECISION_FUNC ( hypre_d_sign )
#define hypre_pow_dd HYPRE_MULTIPRECISION_FUNC ( hypre_pow_dd )
#define hypre_pow_di HYPRE_MULTIPRECISION_FUNC ( hypre_pow_di )
#define hypre_s_cat HYPRE_MULTIPRECISION_FUNC ( hypre_s_cat )
#define hypre_s_cmp HYPRE_MULTIPRECISION_FUNC ( hypre_s_cmp )
#define hypre_s_copy HYPRE_MULTIPRECISION_FUNC ( hypre_s_copy )
#define hypre_idamax HYPRE_MULTIPRECISION_FUNC ( hypre_idamax )
#define hypre_blas_lsame HYPRE_MULTIPRECISION_FUNC ( hypre_blas_lsame )
#define hypre_blas_xerbla HYPRE_MULTIPRECISION_FUNC ( hypre_blas_xerbla )

#endif
5 changes: 5 additions & 0 deletions src/blas/hypre_blas.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
* This header renames the functions in BLAS to avoid conflicts
*--------------------------------------------------------------------------*/

#ifdef HYPRE_MIXED_PRECISION
#include "blas_mup_func.h"
#endif


/* blas */
#define dasum_ hypre_dasum
#define daxpy_ hypre_daxpy
Expand Down
3 changes: 3 additions & 0 deletions src/config/HYPRE_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
/* Define to 1 if using long long int for HYPRE_BigInt */
#undef HYPRE_MIXEDINT

/* Define to 1 if using mixed-precision for HYPRE_Real type */
#undef HYPRE_MIXED_PRECISION

/* Print HYPRE errors */
#undef HYPRE_PRINT_ERRORS

Expand Down
2 changes: 2 additions & 0 deletions src/config/Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ SHARED_BUILD_FLAG = @SHARED_BUILD_FLAG@
SHARED_SET_SONAME = @SHARED_SET_SONAME@
SHARED_OPTIONS = @SHARED_OPTIONS@

MP_BUILD = @MP_BUILD@

BUILD_PYTHON = @BUILD_PYTHON@
PYTHON = @PYTHON@

Expand Down
24 changes: 24 additions & 0 deletions src/config/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ then
AC_DEFINE(HYPRE_COMPLEX, 1, [Define to 1 if using complex values])
fi

dnl *** Mixed-precision support build option
AC_ARG_ENABLE(mixed-precision,
AS_HELP_STRING([--enable-mixed-precision],
[Enable mixed-precision build (default is NO).]),
[case "${enableval}" in
yes) hypre_using_fei=no
hypre_using_mixed_precision=yes ;;
no) hypre_using_mixed_precision=no ;;
*) AC_MSG_ERROR([Bad value ${enableval} for --enable-mixed-precision]) ;;
esac],
[hypre_using_mixed_precision=no]
)
MP_BUILD=0
if test "$hypre_using_mixed_precision" = "yes"
then
AC_DEFINE(HYPRE_MIXED_PRECISION, 1, [Define to 1 if using mixed-precision for HYPRE_Real type])
MP_BUILD=1
fi

AC_ARG_ENABLE(maxdim,
AS_HELP_STRING([--enable-maxdim=MAXDIM],
[Change max dimension size to MAXDIM (default is 3).
Expand Down Expand Up @@ -2915,6 +2934,11 @@ dnl *********************************************************************
AC_SUBST(DSUPERLU_INCLUDE)
AC_SUBST(DSUPERLU_LIBS)

dnl *********************************************************************
dnl * Mixed precision build
dnl *********************************************************************
AC_SUBST(MP_BUILD)

dnl *********************************************************************
dnl * ar & ranlib substitution
dnl *********************************************************************
Expand Down
21 changes: 21 additions & 0 deletions src/config/generate_function_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
# HYPRE Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

# generate file containing function names in current folder.
# This will be used to generate a header file for transforming
# multiprecision function names. It will also be useful for
# regression testing for the multiprecision build.
#
# NOTE: It must be run on symbols generated from the
# non-multiprecision build of hypre.

rootdir=$PWD
rootdir="${rootdir%/}"
rootname="${rootdir##*/}"

## extract function names and remove leading and trailing underscores, if any
## To include local functions (static functions) test on $2=="t" as well
nm -A --defined-only *.o* | awk -F'[ ]' '$2=="T"{print $3}' | sed 's/_*//;s/_*$//' > ${rootname}_functions.out
17 changes: 17 additions & 0 deletions src/config/writeHeader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
# HYPRE Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

FNAME=$1
cat >> $FNAME <<@

/******************************************************************************
* Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
* HYPRE Project Developers. See the top-level COPYRIGHT file for details.
*
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
******************************************************************************/
@

29 changes: 29 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ ac_header_c_list=
ac_subst_vars='LTLIBOBJS
LIBOBJS
AR
MP_BUILD
DSUPERLU_LIBS
DSUPERLU_INCLUDE
SUPERLU_LIBS
Expand Down Expand Up @@ -805,6 +806,7 @@ enable_bigint
enable_single
enable_longdouble
enable_complex
enable_mixed_precision
enable_maxdim
enable_persistent
enable_hopscotch
Expand Down Expand Up @@ -1548,6 +1550,8 @@ Optional Features:
--enable-single Use single precision values (default is NO).
--enable-longdouble Use long double precision values (default is NO).
--enable-complex Use complex values (default is NO).
--enable-mixed-precision
Enable mixed-precision build (default is NO).
--enable-maxdim=MAXDIM Change max dimension size to MAXDIM (default is 3).
Currently must be at least 3.
--enable-persistent Uses persistent communication (default is NO).
Expand Down Expand Up @@ -3588,6 +3592,29 @@ printf "%s\n" "#define HYPRE_COMPLEX 1" >>confdefs.h

fi

# Check whether --enable-mixed-precision was given.
if test ${enable_mixed_precision+y}
then :
enableval=$enable_mixed_precision; case "${enableval}" in
yes) hypre_using_fei=no
hypre_using_mixed_precision=yes ;;
no) hypre_using_mixed_precision=no ;;
*) as_fn_error $? "Bad value ${enableval} for --enable-mixed-precision" "$LINENO" 5 ;;
esac
else $as_nop
hypre_using_mixed_precision=no

fi

MP_BUILD=0
if test "$hypre_using_mixed_precision" = "yes"
then

printf "%s\n" "#define HYPRE_MIXED_PRECISION 1" >>confdefs.h

MP_BUILD=1
fi

# Check whether --enable-maxdim was given.
if test ${enable_maxdim+y}
then :
Expand Down Expand Up @@ -11164,6 +11191,8 @@ printf "%s\n" "#define HYPRE_LINUX 1" >>confdefs.h








Expand Down
Loading