[build] how to choose the llvm version used to build tvm

// 原代码
#include "llvm/Support/TargetRegistry.h"
// 修改为(仅LLVM >= 16)
#include "llvm/MC/TargetRegistry.h"

So when i get a tvm code , does I only check the related code, and choose a matched llvm version ?

After I install them, I find both llvm14 and llvm15 put the TargetRegistry.h under MC ( eg: apt install llvm-15-dev ), it looks inconsistent with deepseek’s description

(tvm0.18_py310_zyd_Dietcode) (DietCode) root@j00595921debug2-cc95c9977-q752v:/home/zhongyunde/source/DietCode# find /usr/include/ -name TargetRegistry.h
/usr/include/llvm-15/llvm/MC/TargetRegistry.h
/usr/include/llvm-11/llvm/Support/TargetRegistry.h
/usr/include/llvm-14/llvm/MC/TargetRegistry.h

But after I appoint the llvm-11 to build tvm 0.8, there are many mismatched API used, so it I still don’t get the right llvm version ?

/home/zhongyunde/source/DietCode/tvm/src/target/llvm/codegen_amdgpu.cc: In member function 'virtual void tvm::codegen::CodeGenAMDGPU::VisitStmt_(const tvm::tir::AllocateNode*)':
/home/zhongyunde/source/DietCode/tvm/src/target/llvm/codegen_amdgpu.cc:99:21: error: 'class llvm::AllocaInst' has no member named 'getAlignment'; did you mean 'setAlignment'?

Oh, I think it maybe the code is not imcomplete , such as there is no config.cmake under tvm/cmake compare to the https://github.com/apache/tvm:v0.7

DietCode/README.md at MLSys2022_AE · UofT-EcoSystem/DietCode · GitHub

  • After copy the config.cmake, the project can also be compiled, and I don’t have idea why now it can find the head file TargetRegistry.h and match the API ?

cmake -DUSE_CUDA=/usr/local/cuda -DCMAKE_POLICY_VERSION_MINIMUM=4.0 -DUSE_CUBLAS=1 -DUSE_CUDNN=1 ..

Hi @vfdff

The minimum required version currently is set to 6.0 .

LLVM is a fast changing library and TVM is trying to keep pace with it’s frequent API changes, and tries to mantain a backword compatibility from the latest available one down to older 6.0 (currently).

TVM currently uses LLVM versions 10 & 17 in it’s CI build systems.

It is encouraged to use latest LLVM , like they currently are 19 or 20, e.g. on personal side I use 20.

If you have multiple concurrent LLVM installations on your system, make sure none of their headers is within the main system path (like i.e. /usr/include/llvm/, but on something more private to each other) then you can just pick the desired version for TVM compilation by e.g. -DUSE_LLVM=llvm-config-19


I give an example of a multi LLVM installation:

$ rpm -qa | grep llvm | grep devel
llvm21-devel-21.0.0-20250506.0.gitc6c2e210.fc43.x86_64
llvm18-devel-18.1.8-6.fc42.x86_64
llvm17-devel-17.0.6-9.fc41.x86_64
llvm-devel-20.1.3-1.fc43.x86_64
$ dirname `rpm -ql llvm21-devel | grep include | head -1`
/usr/lib64/llvm21/include/
$ dirname `rpm -ql llvm18-devel | grep include | head -1`
/usr/lib64/llvm18/include/
$ dirname `rpm -ql llvm17-devel | grep include | head -1`
/usr/lib64/llvm17/include/
$ dirname `rpm -ql llvm-devel | grep include | head -1`
/usr/include <-- WILL interfere

The llvm-devel package is not good here, it will interfere with the others and should be removed (e.g. rpm -e llvm-devel) or replaced from this generic edition to a privatized variant.

As you can see headers are /usr/lib64/llvm{XX}/include/ which is has no system wide availability , thus the -DUSE_LLVM=llvm-config-XX will select and work properly without interfering with other versions.

Example here is on a Fedora system, same should be followed either by manual compiling own versions of LLVMs (but with proper flags for changing the default header paths), or other mainstream distribution packages.

1 Like

thanks @cbalint13 very much

Do you mean the newest tvm can be built with LLVM versions 10 & 17 , or the old tvm 0.7 is also supported ?

PS: some checking on my local machine

  • Now I figure out the tvm is built wih set(USE_LLVM OFF) when I use the config.cmake, so it don’t report the mismatch between tvm v0.7 and llvm.
(tvm0.18_py310_zyd_Dietcode) root@j00595921debug2-cc95c9977-q752v:/home/zhongyunde/source/DietCode# python
Python 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tvm
>>> print(tvm.support.libinfo()["USE_LLVM"])
OFF
>>> print(tvm.__version__)
0.8.dev0
  • The config -DUSE_LLVM=OFF doesn’t take active without the above config.cmake. ··· cmake -DUSE_CUDA=/usr/local/cuda -DCMAKE_POLICY_VERSION_MINIMUM=4.0 -DUSE_CUBLAS=1 -DUSE_CUDNN=1 -DUSE_LLVM=OFF .. ···

Do you mean the newest tvm can be built with LLVM versions 10 & 17 , or the old tvm 0.7 is also >supported ?

  • It means version 10 and 17 are very well tested, but I was reffering to latest version of today.

PS: some checking on my local machine

(tvm0.18_py310_zyd_Dietcode) root@j00595921debug2-cc95c9977->q752v:/home/zhongyunde/source/DietCode# python
Python 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tvm
>>> print(tvm.support.libinfo()["USE_LLVM"])
OFF
>>> print(tvm.__version__)
0.8.dev0
  • Looks like a quite old TVM version, 4 years old, you should match it with what was the latest LLVM available at that time.
  • The config -DUSE_LLVM=OFF doesn’t take active without the above config.cmake. ··· cmake ->DUSE_CUDA=/usr/local/cuda -DCMAKE_POLICY_VERSION_MINIMUM=4.0 -DUSE_CUBLAS=1 ->DUSE_CUDNN=1 -DUSE_LLVM=OFF … ··· [/quote]
  • Of course disabling LLVM backend would skip all your LLVM issues, by looking back in time LLVM would be at maximum version 12.x for your TVM version 0.8
1 Like

Thanks, llvm version 12 matches the old tvm version 0.8, it works fine.

set(USE_LLVM “llvm-config-12 --link-static”)

PS: It may report missing /usr/lib/llvm-12/lib/libPolly.a and -lz, they can be workaroud by

apt-get install libclang-common-12-dev

apt install zlib1g=1:1.2.11.dfsg-2ubuntu1.5 zlib1g-dev