Skip to content

Commit 47df607

Browse files
committed
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 <jsquyres@cisco.com> Signed-off-by: KAWASHIMA Takahiro <t-kawashima@fujitsu.com>
1 parent 9af19ab commit 47df607

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

config/opal_check_alt_short_float.m4

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dnl -*- shell-script -*-
22
dnl
3-
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
3+
dnl Copyright (c) 2018-2020 FUJITSU LIMITED. All rights reserved.
4+
dnl Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
45
dnl $COPYRIGHT$
56
dnl
67
dnl Additional copyrights may follow
@@ -35,7 +36,34 @@ AC_DEFUN([OPAL_CHECK_ALT_SHORT_FLOAT], [
3536
fi
3637
if test "$opal_short_float_type" != ""; then
3738
AC_MSG_RESULT([yes ($opal_short_float_type)])
38-
AC_CHECK_TYPES($opal_short_float_type, [opal_enable_short_float=1], [opal_enable_short_float=0])
39+
AC_CHECK_TYPES($opal_short_float_type, [opal_alt_short_float_exists=1], [opal_alt_short_float_exists=0])
40+
41+
# Even if the alternate short float type exists, make sure
42+
# that the compiler can actually compile/link when
43+
# mathematical operations are performed on variables of that
44+
# type. Case in point: clang 6.0.x and 7.0.x need an
45+
# additional CLI flag added (--rtlib=compiler-rt) to enable
46+
# software emulation of _Float16. Open MPI will *not*
47+
# automagically add that flag -- we'll just emit a warning and
48+
# point the user to a README where more information is
49+
# available.
50+
AC_MSG_CHECKING([if compiler supports arithmetic operations on $opal_short_float_type])
51+
AS_IF([test $opal_alt_short_float_exists -eq 1],
52+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
53+
static $opal_short_float_type a = 2.5, b = 3.8;
54+
a += b;]])],
55+
[AC_MSG_RESULT([yes])
56+
opal_enable_short_float=1],
57+
[AC_MSG_RESULT([no])
58+
AS_IF([test `basename $CC` = "clang"],
59+
[AC_MSG_WARN([if you are using the Clang 6.0.x or 7.0.x compilers and want])
60+
AC_MSG_WARN([to enable software emulation of half-precision floating point])
61+
AC_MSG_WARN([in conjunction with the "shortfloat" Open MPI extension,])
62+
AC_MSG_WARN([see the ompi/mpiext/shortfloat/README.txt file for details.])
63+
])
64+
opal_enable_short_float=0])
65+
])
66+
3967
if test "$opal_enable_short_float" = 1; then
4068
AC_DEFINE_UNQUOTED(opal_short_float_t, [[$opal_short_float_type]],
4169
[User-selected alternate C type of short float])

ompi/mpiext/shortfloat/README.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ that of MPICH.
2323
This extension is enabled only if the C compiler supports 'short float'
2424
or '_Float16', or the '--enable-alt-short-float=TYPE' option is passed
2525
to the configure script.
26+
27+
NOTE: The Clang 6.0.x and 7.0.x compilers support the "_Float16" type
28+
(via software emulation), but require an additional linker flag to
29+
function properly. If you wish to enable Clang 6.0.x or 7.0.x's
30+
software emulation of _Float16, use the following CLI options to Open
31+
MPI configure script:
32+
33+
./configure \
34+
LDFLAGS=--rtlib=compiler-rt \
35+
--with-wrapper-ldflags=--rtlib=compiler-rt ...

0 commit comments

Comments
 (0)