From 47df60717c10cb4843e50708e518476796f64afb Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 16 Jun 2020 06:56:37 -0700 Subject: [PATCH 1/2] check_alt_short_float: ensure compiler supports math Even if the compiler supports an "alternate" short float type (e.g., _Float16), check to make sure that the compiler will correctly link applications that perform mathematical operations on that type. Carefully choose the mathematical test in the configure check to ensure the mathematical operation is not removed by compiler optimization (when setting CFLAGS=-O1 or higher). Out of the box, clang 6.0.x and 7.0.x will fail to link applications that try to perform addition (and other mathematical operations) on _Float16 variables (an additional CLI flag is required to enable software emulation of _Float16). If we detect a situation where the type is supported by a sample program fails to link and the basename of $CC is "clang", emit a warning and point the user to a relevant README. Signed-off-by: Jeff Squyres Signed-off-by: KAWASHIMA Takahiro --- config/opal_check_alt_short_float.m4 | 32 ++++++++++++++++++++++++++-- ompi/mpiext/shortfloat/README.txt | 10 +++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/config/opal_check_alt_short_float.m4 b/config/opal_check_alt_short_float.m4 index 1df8b228b3..31a720d094 100644 --- a/config/opal_check_alt_short_float.m4 +++ b/config/opal_check_alt_short_float.m4 @@ -1,6 +1,7 @@ dnl -*- shell-script -*- dnl -dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +dnl Copyright (c) 2018-2020 FUJITSU LIMITED. All rights reserved. +dnl Copyright (c) 2020 Cisco Systems, Inc. All rights reserved. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow @@ -35,7 +36,34 @@ AC_DEFUN([OPAL_CHECK_ALT_SHORT_FLOAT], [ fi if test "$opal_short_float_type" != ""; then AC_MSG_RESULT([yes ($opal_short_float_type)]) - AC_CHECK_TYPES($opal_short_float_type, [opal_enable_short_float=1], [opal_enable_short_float=0]) + AC_CHECK_TYPES($opal_short_float_type, [opal_alt_short_float_exists=1], [opal_alt_short_float_exists=0]) + + # Even if the alternate short float type exists, make sure + # that the compiler can actually compile/link when + # mathematical operations are performed on variables of that + # type. Case in point: clang 6.0.x and 7.0.x need an + # additional CLI flag added (--rtlib=compiler-rt) to enable + # software emulation of _Float16. Open MPI will *not* + # automagically add that flag -- we'll just emit a warning and + # point the user to a README where more information is + # available. + AC_MSG_CHECKING([if compiler supports arithmetic operations on $opal_short_float_type]) + AS_IF([test $opal_alt_short_float_exists -eq 1], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[ +static $opal_short_float_type a = 2.5, b = 3.8; +a += b;]])], + [AC_MSG_RESULT([yes]) + opal_enable_short_float=1], + [AC_MSG_RESULT([no]) + AS_IF([test `basename $CC` = "clang"], + [AC_MSG_WARN([if you are using the Clang 6.0.x or 7.0.x compilers and want]) + AC_MSG_WARN([to enable software emulation of half-precision floating point]) + AC_MSG_WARN([in conjunction with the "shortfloat" Open MPI extension,]) + AC_MSG_WARN([see the ompi/mpiext/shortfloat/README.txt file for details.]) + ]) + opal_enable_short_float=0]) + ]) + if test "$opal_enable_short_float" = 1; then AC_DEFINE_UNQUOTED(opal_short_float_t, [[$opal_short_float_type]], [User-selected alternate C type of short float]) diff --git a/ompi/mpiext/shortfloat/README.txt b/ompi/mpiext/shortfloat/README.txt index 6e39fafaf0..3406fc5d1b 100644 --- a/ompi/mpiext/shortfloat/README.txt +++ b/ompi/mpiext/shortfloat/README.txt @@ -23,3 +23,13 @@ that of MPICH. This extension is enabled only if the C compiler supports 'short float' or '_Float16', or the '--enable-alt-short-float=TYPE' option is passed to the configure script. + +NOTE: The Clang 6.0.x and 7.0.x compilers support the "_Float16" type +(via software emulation), but require an additional linker flag to +function properly. If you wish to enable Clang 6.0.x or 7.0.x's +software emulation of _Float16, use the following CLI options to Open +MPI configure script: + + ./configure \ + LDFLAGS=--rtlib=compiler-rt \ + --with-wrapper-ldflags=--rtlib=compiler-rt ... From 2c171718ae96f300643ab53b2a3dc5c14caaacc7 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 16 Jun 2020 07:02:51 -0700 Subject: [PATCH 2/2] check_alt_short_float: minor formatting tweak Prevent spurious #-style comments from appearing in the generated configure script. Signed-off-by: Jeff Squyres --- config/opal_check_alt_short_float.m4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/opal_check_alt_short_float.m4 b/config/opal_check_alt_short_float.m4 index 31a720d094..ac285eed9e 100644 --- a/config/opal_check_alt_short_float.m4 +++ b/config/opal_check_alt_short_float.m4 @@ -9,10 +9,10 @@ dnl dnl $HEADER$ dnl -# Check whether the user wants to use an alternate type of C 'short float'. +dnl Check whether the user wants to use an alternate type of C 'short float'. -# OPAL_CHECK_ALT_SHORT_FLOAT -# ------------------------------------------------------------ +dnl OPAL_CHECK_ALT_SHORT_FLOAT +dnl ------------------------------------------------------------ AC_DEFUN([OPAL_CHECK_ALT_SHORT_FLOAT], [ AC_CHECK_TYPES(_Float16) AC_MSG_CHECKING([if want alternate C type of short float])