LLVM error when using opt-level 3 with half precision: __gnu_h2f_ieee

I ran into the following error when run ResNet-18 using opt-level 3 with float16.

“LLVM ERROR: Program used external function ‘__gnu_h2f_ieee’ which could not be resolved!”

Note that opt-level 3 with float32 works fine, and opt-level 1 with float16 also works fine.

Anyone knows how to fix this error?

Thanks
Long

There is an optimization pass which precomputes the computation graph to prune the nodes that can be calculated in advance. So you should be able to run float16 on your building environment. For your problem,

@tqchen says:

This is because the native x86 do not have fp16 support. We need to link a fallback library from compiler-rt. I do not know however, how to do this properly. So here is one hack that works.

clone https://github.com/llvm-mirror/compiler-rt to local folder.

Add a file src/runtime/fp16_f2h.cc to your tvm code, with the following line

extern "C" {
#include "/path/to/compiler-rt/lib/builtins/truncsfhf2.c"
}

Add another file src/runtime/fp16_h2f.cc, with the following line

extern "C" {
#include "/path/to/compiler-rt/lib/builtins/extendhfsf2.c"
}

That specific file contains a fallback implementation that can be used in x86. A better way to solve this problem would be figure out how to link compiler-rt’s builtin properly. Which I am not able to do so far.

1 Like

how can I reproduce it locally? I see similar error in mxnet CI http://jenkins.mxnet-ci.amazon-ml.com/blue/organizations/jenkins/mxnet-validation%2Funix-cpu/detail/PR-16660/2/pipeline/