[RUNTIME][LLVM] _cc.create_shared error while run tune_simple_template

Hi I face a error while runing the tutorials/autotvm/tune_simple_template.py script. as following:

No: 1 GFLOPS: 0.00/0.00 result: MeasureResult(costs=(RuntimeError(‘Except caught from RPC call: TVMCall CFunc Error:\nTraceback (most recent call last):\n File “/home/dladmin/Repositoir/Pub/tvm/python/tvm/_ffi/_ctypes/function.py”, line 56, in cfun\n rv = local_pyfunc(*pyargs)\n File “/home/dladmin/Repositoir/Pub/tvm/python/tvm/rpc/server.py”, line 51, in load_module\n m = _load_module(path)\n File “/home/dladmin/Repositoir/Pub/tvm/python/tvm/module.py”, line 223, in load\n _cc.create_shared(path + “.so”, files)\n File “/home/dladmin/Repositoir/Pub/tvm/python/tvm/contrib/cc.py”, line 33, in create_shared\n _linux_shared(output, objects, options, cc)\n File “/home/dladmin/Repositoir/Pub/tvm/python/tvm/contrib/cc.py”, line 59, in _linux_shared\n raise RuntimeError(msg)\nRuntimeError: Compilation error:\n/usr/bin/ld: /tmp/tmpah3cflh5/lib.o: relocation R_X86_64_32S against `.rodata.cst16’ can not be used when making a shared object; recompile with -fPIC\n/tmp/tmpah3cflh5/lib.o: error adding symbols: Bad value\ncollect2: error: ld returned 1 exit status\n\n’,),), error_no=4, all_cost=0.3922765254974365, timestamp=1540458625.9476259) [(‘tile_y’, [64, 8]), (‘tile_x’, [32, 16])],None,43

My tvm is builld from source and with llvm manually set to llvm-7.0 (ubuntu 16.04), and also change the gcc to 7.3.0 with

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7 g+±7

it seems that /usr/bin/ld complains about relocation R_X86_64_32S against .rodata.cst16 and suggest add the -fPIC flag.
is it because g++ not compatible with object file created by llvm? or any other ideas about this situation?

(from https://github.com/dmlc/tvm/issues/1985 thread)

What part of your setup is built with gcc?

Hi

I change my ubuntu default gcc/g++ to gcc-7, so everything build with gcc is with gcc-7. for tvm, it should be that every library(libnnvm_compiler.so/libtvm_runtime.so/libtvm.so/libtvm_topi.so/libvta.so) is build with gcc-7.

This is because I need a higher version of llvm(llvm-7) to generate AMDGPU code. and if I continue to use the gcc-5.4(default version of ubuntu-16.04), the ABI is different hence i can not do “import tvm”

Same problem, have you found the solution?

If you use llvm 7.0, then this problem will happen. Try to use llvm 4.0

Hi.

Yes you’re right. I tested on llvm 6.0.1 and everything goes OK. It seemd other people also faced with this problem. Maybe the LLVM-7.0 create object file breaks some compatibility in PIC reloc mode.

Building ROCm support
Currently, ROCm is supported only on linux, so all the instructions are written with linux in mind.

Set set(USE_ROCM ON), set ROCM_PATH to the correct path.
You need to first install HIP runtime from ROCm. Make sure the installation system has ROCm installed in it.
Install latest stable version of LLVM (v6.0.1), and LLD, make sure ld.lld is available via command line.

@tqchen sorry for the delay, but I think I figure out the root cause.

ubuntu + LLVM 7.0(official binary download) + gcc-7.3(manually install), will cause this problem, because of the gcc/llvm compatbility issue. For tvm use gcc to compile, and need link to LLVM library for codegen, hence must use a proper version of gcc to compile the entire tvm source.
In my case, the gcc-7.3 compiled tvm with llvm-7.0.0 may result in llvm::TargetMachine created without PIC enabled (getRelocationModel() of this target may return an unknow Reloc::Model type, which is very strange)

I didn’t find the exact gcc version to compile the LLVM-7.0.0, but I install gcc 7.3, which should be a relatively new gcc version.(used in ubuntu 18.04)

Here I propose a solution, to build tvm with clang

e.g. after download LLVM release and modify USE_LLVM as below

set(USE_LLVM /opt/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-config)

do cmake like:

mkdir build ; cd build
cmake -DCMAKE_C_COMPILER=/opt/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang
  -DCMAKE_CXX_COMPILER=/opt/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++
   ../
make
1 Like

Thanks @carlushuang for figuring out the problem. We can add a trouble shooting section to the installation to make the suggestions