Skip to content

Commit 8bbd201

Browse files
authored
Merge pull request #6205 from kawashima-fj/pr/fp16
Add FP16 datatypes
2 parents 8451cd7 + ef4c47d commit 8bbd201

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+974
-105
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ ompi/mpiext/pcollreq/mpif-h/profile/pscan_init_f.c
302302
ompi/mpiext/pcollreq/mpif-h/profile/pscatter_init_f.c
303303
ompi/mpiext/pcollreq/mpif-h/profile/pscatterv_init_f.c
304304

305+
ompi/mpiext/shortfloat/c/mpiext_shortfloat_c.h
306+
ompi/mpiext/shortfloat/mpif-h/mpiext_shortfloat_mpifh.h
307+
ompi/mpiext/shortfloat/use-mpi-f08/mpiext_shortfloat_usempif08.h
308+
305309
ompi/tools/mpisync/mpisync
306310
ompi/tools/mpisync/mpirun_prof
307311
ompi/tools/mpisync/ompi_timing_post

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ Open MPI Extensions
873873
because they are not standardized yet. Future versions of Open MPI
874874
will switch to the MPI_ prefix once the MPI Standard which includes
875875
this feature is published. See their man page for more details.
876+
- shortfloat: Provides MPI datatypes MPIX_C_FLOAT16, MPIX_SHORT_FLOAT,
877+
MPIX_SHORT_FLOAT, and MPIX_CXX_SHORT_FLOAT_COMPLEX if corresponding
878+
language types are available. See ompi/mpiext/shortfloat/README.txt
879+
for details.
876880
- affinity: Provides the OMPI_Affinity_str() routine on retrieving
877881
a string that contains what resources a process is bound to. See
878882
its man page for more details.

config/ompi_fortran_check.m4

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ AC_DEFUN([OMPI_FORTRAN_CHECK], [
129129
long*double) ofc_type_kind=C_LONG_DOUBLE ;;
130130
long*long) ofc_type_kind=C_LONG_LONG ;;
131131
short) ofc_type_kind=C_SHORT ;;
132+
short*float) ofc_type_kind=C_SHORT_FLOAT ;;
133+
short*float*_Complex) ofc_type_kind=C_SHORT_FLOAT_COMPLEX ;;
132134
float*_Complex) ofc_type_kind=C_FLOAT_COMPLEX ;;
133135
double*_Complex) ofc_type_kind=C_DOUBLE_COMPLEX ;;
134136
long*double*_Complex) ofc_type_kind=C_LONG_DOUBLE_COMPLEX ;;
137+
opal_short_float_t) ofc_type_kind=C_SHORT_FLOAT ;;
138+
opal_short_float_complex_t) ofc_type_kind=C_SHORT_FLOAT_COMPLEX ;;
135139
*)
136140
# Skip types like "DOUBLE PRECISION"
137141
;;
@@ -142,8 +146,9 @@ AC_DEFUN([OMPI_FORTRAN_CHECK], [
142146

143147
# See if the value is -1. If so, then just say we don't
144148
# have a match. If the compiler doesn't support
145-
# ISO_C_BINDING, then we'll just fall back to a default
146-
# kind and hope for the best. :-\
149+
# ISO_C_BINDING, C_SHORT_FLOAT, or C_SHORT_FLOAT_COMPLEX,
150+
# then we'll just fall back to a default kind and hope
151+
# for the best. :-\
147152
OMPI_FORTRAN_GET_KIND_VALUE([$ofc_type_kind], 4, [ofc_type_kind_value])
148153
AS_IF([test $ofc_type_kind_value -le 0],
149154
[ofc_have_type=0

config/ompi_setup_mpi_fortran.m4

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1818
dnl Copyright (c) 2014-2017 Research Organization for Information Science
1919
dnl and Technology (RIST). All rights reserved.
2020
dnl Copyright (c) 2016 IBM Corporation. All rights reserved.
21+
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2122
dnl $COPYRIGHT$
2223
dnl
2324
dnl Additional copyrights may follow
@@ -168,25 +169,33 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
168169
[int, int64_t, long long, long], [16], [yes])
169170

170171
OMPI_FORTRAN_CHECK([REAL], [yes],
171-
[float, double, long double], [-1], [yes])
172+
[short float, float, double, long double, opal_short_float_t],
173+
[-1], [yes])
172174
OMPI_FORTRAN_CHECK([REAL*2], [no],
173-
[float, double, long double], [2], [yes])
175+
[short float, float, double, long double, opal_short_float_t],
176+
[2], [yes])
174177
OMPI_FORTRAN_CHECK([REAL*4], [no],
175-
[float, double, long double], [4], [yes])
178+
[short float, float, double, long double, opal_short_float_t],
179+
[4], [yes])
176180
OMPI_FORTRAN_CHECK([REAL*8], [no],
177-
[float, double, long double], [8], [yes])
181+
[short float, float, double, long double, opal_short_float_t],
182+
[8], [yes])
178183
OMPI_FORTRAN_CHECK([REAL*16], [no],
179-
[float, double, long double], [16], [yes])
184+
[short float, float, double, long double, opal_short_float_t],
185+
[16], [yes])
180186

181187
# In some compilers, the bit representation of REAL*16 is not the same
182188
# as the C counterpart that we found. If this is the case, then we
183189
# want to disable reduction support for MPI_REAL16 (per ticket #1603).
184190
OMPI_FORTRAN_CHECK_REAL16_C_EQUIV
185191

186192
OMPI_FORTRAN_CHECK([DOUBLE PRECISION], [yes],
187-
[float, double, long double], [-1], [yes])
193+
[short float, float, double, long double, opal_short_float_t],
194+
[-1], [yes])
188195

189-
OMPI_FORTRAN_CHECK([COMPLEX], [yes], [float _Complex, double _Complex], [-1], [no])
196+
OMPI_FORTRAN_CHECK([COMPLEX], [yes],
197+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
198+
[-1], [no])
190199

191200
# The complex*N tests are a bit different (note: the complex tests are
192201
# the same as all the rest, because complex is a composite of two
@@ -199,21 +208,23 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
199208
# have a back-end C type for it)
200209
# b) compiler supports complex*N
201210

202-
OMPI_FORTRAN_CHECK([COMPLEX*4], [no], [float _Complex], [4], [no])
211+
OMPI_FORTRAN_CHECK([COMPLEX*4], [no],
212+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
213+
[4], [no])
203214
OMPI_FORTRAN_CHECK([COMPLEX*8], [no],
204-
[float _Complex, double _Complex, long double _Complex],
215+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
205216
[8], [no])
206217
OMPI_FORTRAN_CHECK([COMPLEX*16], [no],
207-
[float _Complex, double _Complex, long double _Complex],
218+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
208219
[16], [no])
209220
OMPI_FORTRAN_CHECK([COMPLEX*32], [no],
210-
[float _Complex, double _Complex, long double _Complex],
221+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
211222
[32], [no])
212223
# Double precision complex types are not standard, but many
213224
# compilers support it. Code should be wrapped with #ifdef
214225
# OMPI_HAVE_FORTRAN_DOUBLE_COMPLEX
215226
OMPI_FORTRAN_CHECK([DOUBLE COMPLEX], [no],
216-
[float _Complex, double _Complex, long double _Complex],
227+
[short float _Complex, float _Complex, double _Complex, long double _Complex, opal_short_float_complex_t],
217228
[-1], [no])
218229

219230
# Regardless of whether we have fortran bindings, or even a

config/opal_check_alt_short_float.m4

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
dnl
8+
dnl $HEADER$
9+
dnl
10+
11+
# Check whether the user wants to use an alternate type of C 'short float'.
12+
13+
# OPAL_CHECK_ALT_SHORT_FLOAT
14+
# ------------------------------------------------------------
15+
AC_DEFUN([OPAL_CHECK_ALT_SHORT_FLOAT], [
16+
AC_CHECK_TYPES(_Float16)
17+
AC_MSG_CHECKING([if want alternate C type of short float])
18+
AC_ARG_ENABLE(alt-short-float,
19+
AC_HELP_STRING([--enable-alt-short-float=TYPE],
20+
[Use an alternate C type TYPE of 'short float' if 'short float' is not available on the C compiler. 'short float' is a new C type proposed for the next C language standard in ISO/IEC JTC 1/SC 22 WG 14 (C WG). (default: "_Float16" if available, disabled otherwise)]))
21+
if test "$enable_alt_short_float" = "yes"; then
22+
AC_MSG_ERROR([--enable-alt-short-float must have an argument.])
23+
elif test "$enable_alt_short_float" = "no"; then
24+
:
25+
elif test "$enable_alt_short_float" != ""; then
26+
opal_short_float_type="$enable_alt_short_float"
27+
opal_short_float_complex_type="$enable_alt_short_float [[2]]"
28+
elif test "$ac_cv_type_short_float" = "yes" && \
29+
test "$ac_cv_type_short_float__Complex" = "yes"; then
30+
opal_short_float_type="short float"
31+
opal_short_float_complex_type="short float _Complex"
32+
elif test "$ac_cv_type__Float16" = "yes"; then
33+
opal_short_float_type="_Float16"
34+
opal_short_float_complex_type="_Float16 [[2]]"
35+
fi
36+
if test "$opal_short_float_type" != ""; then
37+
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+
if test "$opal_enable_short_float" = 1; then
40+
AC_DEFINE_UNQUOTED(opal_short_float_t, [[$opal_short_float_type]],
41+
[User-selected alternate C type of short float])
42+
AC_DEFINE_UNQUOTED(opal_short_float_complex_t, [[$opal_short_float_complex_type]],
43+
[User-selected alternate C type of short float _Complex])
44+
AC_CHECK_TYPES(opal_short_float_t)
45+
AC_CHECK_TYPES(opal_short_float_complex_t)
46+
AC_CHECK_SIZEOF(opal_short_float_t)
47+
AC_CHECK_SIZEOF(opal_short_float_complex_t)
48+
OPAL_C_GET_ALIGNMENT(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T)
49+
elif test "$enable_alt_short_float" != ""; then
50+
AC_MSG_ERROR([Alternate C type of short float $opal_short_float_type requested but not available. Aborting])
51+
fi
52+
else
53+
AC_MSG_RESULT([no])
54+
fi
55+
])

configure.ac

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
2626
# Copyright (c) 2018 Amazon.com, Inc. or its affiliates.
2727
# All Rights reserved.
28+
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2829
# $COPYRIGHT$
2930
#
3031
# Additional copyrights may follow
@@ -371,6 +372,27 @@ OPAL_CHECK_IDENT([CC], [CFLAGS], [c], [C])
371372
# Check for some types
372373
#
373374

375+
# 'short float' support of the Intel C++ Compiler (group of C and C++
376+
# compilers), at least versions 18.0 and 19.0, is half-baked. It can
377+
# compile declarations of 'short float' variables and expressions of
378+
# 'sizeof(short float)' but cannot compile casts and operations of
379+
# 'short float' variables. In this situation, 'AC_CHECK_TYPES(short float)'
380+
# defines 'HAVE_SHORT_FLOAT' as 1 and compilation errors occur in
381+
# ompi/mca/op/base/op_base_functions.c. To avoid this error, check it
382+
# using 'AC_COMPILE_IFELSE' and set Autoconf cache variables before
383+
# 'AC_CHECK_TYPES(short float)'. This check can be removed when all
384+
# OMPI-supported Intel C++ Compilers support 'short float' completely
385+
# (or drop it completely).
386+
if test "$opal_cv_c_compiler_vendor" = "intel"; then
387+
AC_MSG_CHECKING([if Intel compiler supports "short float" properly])
388+
AC_COMPILE_IFELSE(
389+
[AC_LANG_SOURCE([float f(short float a, short float b) { return (float)(a + b); }])],
390+
[AC_MSG_RESULT([yes])],
391+
[ac_cv_type_short_float="no"
392+
ac_cv_type_short_float__Complex="no"]
393+
AC_MSG_RESULT([no]))
394+
fi
395+
374396
AC_CHECK_TYPES(int8_t)
375397
AC_CHECK_TYPES(uint8_t)
376398
AC_CHECK_TYPES(int16_t)
@@ -385,10 +407,12 @@ AC_CHECK_TYPES(uint128_t)
385407
AC_CHECK_TYPES(long long)
386408

387409
AC_CHECK_TYPES(__float128)
410+
AC_CHECK_TYPES(short float)
388411
AC_CHECK_TYPES(long double)
389412
# We only need these types if we're building the OMPI project, but
390413
# OPAL currently doesn't protect for their lack of presence well.
391414
AC_CHECK_HEADERS(complex.h)
415+
AC_CHECK_TYPES(short float _Complex)
392416
AC_CHECK_TYPES(float _Complex)
393417
AC_CHECK_TYPES(double _Complex)
394418
AC_CHECK_TYPES(long double _Complex)
@@ -409,6 +433,9 @@ AC_CHECK_SIZEOF(short)
409433
AC_CHECK_SIZEOF(int)
410434
AC_CHECK_SIZEOF(long)
411435
AC_CHECK_SIZEOF(long long)
436+
if test "$ac_cv_type_short_float" = yes; then
437+
AC_CHECK_SIZEOF(short float)
438+
fi
412439
AC_CHECK_SIZEOF(float)
413440
AC_CHECK_SIZEOF(double)
414441
AC_CHECK_SIZEOF(long double)
@@ -417,6 +444,9 @@ if test "$ac_cv_type___float128" = yes; then
417444
fi
418445
# We only need these types if we're building the OMPI project, but
419446
# OPAL currently doesn't protect for their lack of presence well.
447+
if test "$ac_cv_type_short_float__Complex" = yes; then
448+
AC_CHECK_SIZEOF(short float _Complex)
449+
fi
420450
AC_CHECK_SIZEOF(float _Complex)
421451
AC_CHECK_SIZEOF(double _Complex)
422452
AC_CHECK_SIZEOF(long double _Complex)
@@ -459,6 +489,9 @@ OPAL_C_GET_ALIGNMENT(wchar_t, OPAL_ALIGNMENT_WCHAR)
459489
OPAL_C_GET_ALIGNMENT(int, OPAL_ALIGNMENT_INT)
460490
OPAL_C_GET_ALIGNMENT(long, OPAL_ALIGNMENT_LONG)
461491
OPAL_C_GET_ALIGNMENT(long long, OPAL_ALIGNMENT_LONG_LONG)
492+
if test "$ac_cv_type_short_float" = yes; then
493+
OPAL_C_GET_ALIGNMENT(short float, OPAL_ALIGNMENT_SHORT_FLOAT)
494+
fi
462495
OPAL_C_GET_ALIGNMENT(float, OPAL_ALIGNMENT_FLOAT)
463496
OPAL_C_GET_ALIGNMENT(double, OPAL_ALIGNMENT_DOUBLE)
464497
OPAL_C_GET_ALIGNMENT(long double, OPAL_ALIGNMENT_LONG_DOUBLE)
@@ -469,13 +502,22 @@ fi
469502

470503
# We only need these types if we're building the OMPI project, but
471504
# OPAL currently doesn't protect for their lack of presence well.
505+
if test "$ac_cv_type_short_float__Complex" = yes; then
506+
OPAL_C_GET_ALIGNMENT(short float _Complex, OPAL_ALIGNMENT_SHORT_FLOAT_COMPLEX)
507+
fi
472508
OPAL_C_GET_ALIGNMENT(float _Complex, OPAL_ALIGNMENT_FLOAT_COMPLEX)
473509
OPAL_C_GET_ALIGNMENT(double _Complex, OPAL_ALIGNMENT_DOUBLE_COMPLEX)
474510
OPAL_C_GET_ALIGNMENT(long double _Complex, OPAL_ALIGNMENT_LONG_DOUBLE_COMPLEX)
475511

476512
OPAL_C_GET_ALIGNMENT(void *, OPAL_ALIGNMENT_VOID_P)
477513
OPAL_C_GET_ALIGNMENT(size_t, OPAL_ALIGNMENT_SIZE_T)
478514

515+
#
516+
# Check for an alternate type of C 'short float'
517+
#
518+
519+
OPAL_CHECK_ALT_SHORT_FLOAT
520+
479521
#
480522
# Check for other compiler characteristics
481523
#

ompi/datatype/ompi_datatype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* reserved.
1010
* Copyright (c) 2015-2018 Research Organization for Information Science
1111
* and Technology (RIST). All rights reserved.
12+
* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
1213
* $COPYRIGHT$
1314
*
1415
* Additional copyrights may follow
@@ -57,7 +58,7 @@ BEGIN_C_DECLS
5758
#define OMPI_DATATYPE_FLAG_DATA_FORTRAN 0xC000
5859
#define OMPI_DATATYPE_FLAG_DATA_LANGUAGE 0xC000
5960

60-
#define OMPI_DATATYPE_MAX_PREDEFINED 47
61+
#define OMPI_DATATYPE_MAX_PREDEFINED 50
6162

6263
#if OMPI_DATATYPE_MAX_PREDEFINED > OPAL_DATATYPE_MAX_SUPPORTED
6364
#error Need to increase the number of supported dataypes by OPAL (value OPAL_DATATYPE_MAX_SUPPORTED).

0 commit comments

Comments
 (0)