ompi
ompi copied to clipboard
configury: enhance short float detection with clang
With clang, short float support requires --rtlib=compiler-rt to be passed to the linker. In order to avoid a false positive, it is necessary have the runtime called in the test program.
The test program was hence updated with the function below that generates a call to the __extendhfsf2() runtime function.
float extend (_Float16 v) { return (float)v; }
Thanks Blaise Bourdin for reporting this.
Refs: #13181
@kawashima-fj Could you please review this PR, especially the working of ompi/mpiext/shortfloat/README.md?
It mentions software emulation for shortfloat on clang 6 and 7.
AOCC 5 (AMD clang 17.0.6 based) or the latest upstream clang 20.1.2 also require --rtlib=compiler-rt, but I do not know if this is still software emulation.
Also, the pthreads test fails with clang++:
$ cat conftest.cpp
#include <pthread.h>
int i = 3;
pthread_t me, newthread;
void cleanup_routine(void *foo);
void *thread_main(void *foo);
void cleanup_routine(void *foo) { i = 4; }
void *thread_main(void *foo) { i = 2; return (void*) &i; }
int main(int argc, char* argv[])
{
pthread_attr_t attr;
me = pthread_self();
pthread_atfork(NULL, NULL, NULL);
pthread_attr_init(&attr);
pthread_cleanup_push(cleanup_routine, 0);
pthread_create(&newthread, &attr, thread_main, 0);
pthread_join(newthread, 0);
pthread_cleanup_pop(0);
return 0;
}
$ clang++ --rtlib=compiler-rt ~/conftest.cpp
/usr/bin/ld: /tmp/conftest-81eb1f.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
/usr/bin/ld: /usr/lib64/libgcc_s.so.1: error adding symbols: DSO missing from command line
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Depending on the clang version, it might be needed to pass --stdlib=libc++ and/or -lunwind to get it working.
Is this something that should be reported upstream?
@ggouaillardet OK, I'll take a look. I'm a bit busy now. I'll take a look this weekend or next week.
@ggouaillardet Sorry for being late.
Regarding __extendhfsf2, which is usually defined in libgcc or compiler-rt, probably this problem occurs under the following conditions:
- x86-64
- Clang version >= 15 (Clang supported
_Float16since version 15 on x86-64) - libgcc version <= 11 (GCC (including libgcc) supported FP16 since version 12 on x86-64)
--rtlib=compiler-rtis not specified (compiler-rt is used instead of libgcc)-march=flag is not specified or specified with an old architecture (software emulation is required only for old architectures)
So your README.md change is not accurate. The current sentences (written by me) may not be accurate either because the support status depends on architectures. Rewriting to something like the following sentences may be better.
In some cases, support of
_Float16is required not only by a compiler but also by a runtime library. When using Clang, you may need the following CLI options ...
Regarding pthread, it's surprising for me. It may be a bug. I couldn't find a report in the LLVM repo. So it's worth reporting that to the LLVM community.
@ggouaillardet Is your --stdlib=libc++/-lunwind part in the README.md related to this shortfloat?