Float16-related build failure on FreeBSD
I'm encountering the following Float16-related build failure when targeting FreeBSD:
ninja: job failed: /opt/bin/x86_64-unknown-freebsd13.2-libgfortran5-cxx11-llvm_version+19.asserts/x86_64-unknown-freebsd13.2-clang --sysroot=/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/ -DCL_HPP_TARGET_OPENCL_VERSION=300 -DCL_TARGET_OPENCL_VERSION=300 -DCL_USE_DEPRECATED_OPENCL_1_0_APIS -DCL_USE_DEPRECATED_OPENCL_1_1_APIS -DCL_USE_DEPRECATED_OPENCL_1_2_APIS -DCL_USE_DEPRECATED_OPENCL_2_0_APIS -DCL_USE_DEPRECATED_OPENCL_2_1_APIS -DCL_USE_DEPRECATED_OPENCL_2_2_APIS -I/workspace/srcdir/pocl/build -I/workspace/srcdir/pocl/include -I/workspace/srcdir/pocl/include/hpp -I/workspace/srcdir/pocl/lib/CL/devices -I/workspace/srcdir/pocl/lib/CL/. -O3 -DNDEBUG -fPIC -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Wno-ignored-attributes -Werror=return-type -Werror=vla -fvisibility=hidden -std=gnu99 -MD -MT lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o -MF lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o.d -o lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o -c /workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:143:1: error: controlling expression type '_Float16' not compatible with any generic association type
143 | DEFINE_PRINT_FLOATS (_Float16)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:121:13: note: expanded from macro 'DEFINE_PRINT_FLOATS'
121 | if (isnan (val)) \
| ^~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:104:2: note: expanded from macro 'isnan'
104 | __fp_type_select(x, __inline_isnanf, __inline_isnan, __inline_isnanl)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:81:62: note: expanded from macro '__fp_type_select'
81 | #define __fp_type_select(x, f, d, ld) __extension__ _Generic((x), \
| ^~~
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:143:1: error: controlling expression type '_Float16' not compatible with any generic association type
143 | DEFINE_PRINT_FLOATS (_Float16)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:123:13: note: expanded from macro 'DEFINE_PRINT_FLOATS'
123 | if (isinf (val)) \
| ^~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:102:18: note: expanded from macro 'isinf'
102 | #define isinf(x) __fp_type_select(x, __isinff, __isinf, __isinfl)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:81:62: note: expanded from macro '__fp_type_select'
81 | #define __fp_type_select(x, f, d, ld) __extension__ _Generic((x), \
| ^~~
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:143:1: error: controlling expression type '_Float16' not compatible with any generic association type
143 | DEFINE_PRINT_FLOATS (_Float16)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:125:29: note: expanded from macro 'DEFINE_PRINT_FLOATS'
125 | p->flags.sign = signbit (val) ? 1 : 0; \
| ^~~~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:124:20: note: expanded from macro 'signbit'
124 | #define signbit(x) __fp_type_select(x, __signbitf, __signbit, __signbitl)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:81:62: note: expanded from macro '__fp_type_select'
81 | #define __fp_type_select(x, f, d, ld) __extension__ _Generic((x), \
| ^~~
3 errors generated.
In file included from /workspace/srcdir/pocl/lib/CL/pocl_llvm_metadata.cc:47:
/workspace/srcdir/pocl/lib/CL/../llvmopencl/LLVMUtils.h:28:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
28 | IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:32:3: note: expanded from macro 'IGNORE_COMPILER_WARNING'
32 | DO_PRAGMA(clang diagnostic ignored X)
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:26:22: note: expanded from macro 'DO_PRAGMA'
26 | #define DO_PRAGMA(x) _Pragma(#x)
| ^
<scratch space>:74:27: note: expanded from here
74 | clang diagnostic ignored "-Wmaybe-uninitialized"
| ^
1 warning generated.
/workspace/srcdir/pocl/lib/CL/pocl_llvm_utils.cc:27:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
27 | IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:32:3: note: expanded from macro 'IGNORE_COMPILER_WARNING'
32 | DO_PRAGMA(clang diagnostic ignored X)
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:26:22: note: expanded from macro 'DO_PRAGMA'
26 | #define DO_PRAGMA(x) _Pragma(#x)
| ^
<scratch space>:6:27: note: expanded from here
6 | clang diagnostic ignored "-Wmaybe-uninitialized"
| ^
/workspace/srcdir/pocl/lib/CL/pocl_llvm_utils.cc:290:19: warning: format specifies type 'char *' but the argument has type 'StringRef' [-Wformat]
289 | POCL_MSG_WARN("Can't find a kernellib supported by the host CPU (%s)\n",
| ~~
290 | llvm::sys::getHostCPUName());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/pocl_debug.h:255:52: note: expanded from macro 'POCL_MSG_WARN'
255 | #define POCL_MSG_WARN(...) POCL_MSG_WARN2("", __VA_ARGS__)
| ^~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/pocl_debug.h:254:56: note: expanded from macro 'POCL_MSG_WARN2'
254 | POCL_MSG_PRINT_F(WARNING, WARN, errcode, __VA_ARGS__)
| ^~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/pocl_debug.h:236:30: note: expanded from macro 'POCL_MSG_PRINT_F'
236 | log_printf ( __VA_ARGS__); \
| ^~~~~~~~~~~
/workspace/srcdir/pocl/lib/CL/pocl_debug.h:61:42: note: expanded from macro 'log_printf'
61 | #define log_printf(...) fprintf (stderr, __VA_ARGS__)
| ^~~~~~~~~~~
2 warnings generated.
/workspace/srcdir/pocl/lib/CL/pocl_llvm_wg.cc:30:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
30 | IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:32:3: note: expanded from macro 'IGNORE_COMPILER_WARNING'
32 | DO_PRAGMA(clang diagnostic ignored X)
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:26:22: note: expanded from macro 'DO_PRAGMA'
26 | #define DO_PRAGMA(x) _Pragma(#x)
| ^
<scratch space>:6:27: note: expanded from here
6 | clang diagnostic ignored "-Wmaybe-uninitialized"
| ^
In file included from /workspace/srcdir/pocl/lib/CL/pocl_llvm_wg.cc:70:
/workspace/srcdir/pocl/lib/CL/../llvmopencl/LLVMUtils.h:28:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
28 | IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:32:3: note: expanded from macro 'IGNORE_COMPILER_WARNING'
32 | DO_PRAGMA(clang diagnostic ignored X)
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:26:22: note: expanded from macro 'DO_PRAGMA'
26 | #define DO_PRAGMA(x) _Pragma(#x)
| ^
<scratch space>:397:27: note: expanded from here
397 | clang diagnostic ignored "-Wmaybe-uninitialized"
| ^
2 warnings generated.
In file included from /workspace/srcdir/pocl/lib/CL/pocl_llvm_build.cc:73:
/workspace/srcdir/pocl/lib/CL/../llvmopencl/LLVMUtils.h:28:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
28 | IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:32:3: note: expanded from macro 'IGNORE_COMPILER_WARNING'
32 | DO_PRAGMA(clang diagnostic ignored X)
| ^
/workspace/srcdir/pocl/lib/CL/../llvmopencl/CompilerWarnings.h:26:22: note: expanded from macro 'DO_PRAGMA'
26 | #define DO_PRAGMA(x) _Pragma(#x)
| ^
<scratch space>:38:27: note: expanded from here
38 | clang diagnostic ignored "-Wmaybe-uninitialized"
| ^
1 warning generated.
ninja: subcommand failed
I guess https://github.com/franz/pocl/commit/515c792be7bf620a9c9defb2bfd7fab2fd82fb49 needs to be extended some more? @franz
Is there someone actively fixing FreeBSD issues and it's more of a "best effort". @maleadt are you interested in maintaining the FreeBSD port? If so, we shall setup a CI for it.
Not really, this is just one of the many platforms we provide Julia for, but I don't have FreeBSD experience myself. Maybe @ararslan (one of the Julia FreeBSD maintainers) has experience with _Float16 on FreeBSD. If not, I'd just suggest to additionally exclude that platform from using _Float16.
Apologies for the delayed response. _Float16 is defined on FreeBSD but isnan doesn't support it when compiling as C (with Clang or GCC), though it does when compiling as C++ (Clang only). I'm not sure why that's the case. Unfortunately I don't have any experience with _Float16 so I suspect I can't be of much help here other than to assist in investigating if anyone has ideas. In the meantime, @maleadt's suggestion seems reasonable to me.
For what it's worth, there is a FreeBSD port of PoCL 4.0 and it has a few patches, but I don't know enough about PoCL to know whether those have since been incorporated here, nor whether the _Float16-related things were introduced since 4.0.
Yes, in my experience, the standard C++ functions such as isnan or std::numeric_limits are not available for _Float16. You would need to define them yourself, probably via bool isnan(_Float16 f) { using std::isnan; return isnan(float(f)); } or similar.
As chance has it I'm currently working on https://github.com/eschnett/gdal/blob/eschnett/float16-implementation/port/cpl_float.h which provides such work-arounds for GDAL.
This should be fixed in main
I'm still seeing this. Cross-compiling f21ef2ade1f4c0b2e9767d8e27e5878131351e7c for FreeBSD against LLVM 17:
[15:01:20] ninja: job failed: /opt/bin/x86_64-unknown-freebsd13.2-libgfortran5-cxx11-llvm_version+17/x86_64-unknown-freebsd13.2-clang --sysroot=/opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/ -DCL_HPP_TARGET_OPENCL_VERSION=300 -DCL_TARGET_OPENCL_VERSION=300 -DCL_USE_DEPRECATED_OPENCL_1_0_APIS -DCL_USE_DEPRECATED_OPENCL_1_1_APIS -DCL_USE_DEPRECATED_OPENCL_1_2_APIS -DCL_USE_DEPRECATED_OPENCL_2_0_APIS -DCL_USE_DEPRECATED_OPENCL_2_1_APIS -DCL_USE_DEPRECATED_OPENCL_2_2_APIS -I/workspace/srcdir/pocl/build -I/workspace/srcdir/pocl/include -I/workspace/srcdir/pocl/include/hpp -I/workspace/srcdir/pocl/lib/CL/devices -I/workspace/srcdir/pocl/lib/CL/. -O3 -DNDEBUG -fPIC -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Wno-ignored-attributes -Werror=return-type -Werror=vla -fvisibility=hidden -std=gnu99 -MD -MT lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o -MF lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o.d -o lib/CL/devices/CMakeFiles/pocl-devices.dir/printf_buffer.c.o -c /workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c
[15:01:20] /workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:143:1: error: controlling expression type '_Float16' not compatible with any generic association type
[15:01:20] 143 | DEFINE_PRINT_FLOATS (_Float16)
[15:01:20] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[15:01:20] /workspace/srcdir/pocl/lib/CL/devices/printf_buffer.c:121:13: note: expanded from macro 'DEFINE_PRINT_FLOATS'
[15:01:20] 121 | if (isnan (val)) \
[15:01:20] | ^~~~~~~~~~~
[15:01:20] /opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:104:2: note: expanded from macro 'isnan'
[15:01:20] 104 | __fp_type_select(x, __inline_isnanf, __inline_isnan, __inline_isnanl)
[15:01:20] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[15:01:20] /opt/x86_64-unknown-freebsd13.2/x86_64-unknown-freebsd13.2/sys-root/usr/include/math.h:81:62: note: expanded from macro '__fp_type_select'
[15:01:20] 81 | #define __fp_type_select(x, f, d, ld) __extension__ _Generic((x), \
[15:01:20] | ^~~
Relevant bits from the configuration:
[15:01:12] -- Checking Device-side (Clang/LLVM) support for _Float16 type
[15:01:12] -- Clang supports _Float16 type on CPU
[15:01:13] -- Performing Test HOST_COMPILER_SUPPORTS_FLOAT16
[15:01:13] -- Performing Test HOST_COMPILER_SUPPORTS_FLOAT16 - Success
[15:01:13] -- Host side compiler support for _Float16: 1
[15:01:14] -- HOST_CLANG_FLAGS: --target=x86_64-unknown-freebsd13.2 -D_HAS_FLOAT16_TYPE
[15:01:14] -- HOST_COMPILER_SUPPORTS_FLOAT16: 1
[15:01:14] -- CLANG_SUPPORTS_FLOAT16_ON_CPU: 1
Building with HOST_COMPILER_SUPPORTS_FLOAT16:BOOL=OFF works around the issue.