TVM Building on Windows
Preparation
- Visual Studio: Download Link, Community version is enough.
- CMake: Download Link, choose latest release (binary distribution is convenient).
- Anaconda: Download Link, used to manage python enveriment.
- Git: Download Link, used to pull tvm repo.
Compile LLVM
Suppose you want to build TVM in directory E:\tvm\
Download and compile LLVM project: Getting Started with the LLVM System — LLVM 20.0.0git documentation, following the guide of Getting the Source Code and Building LLVM. (I can’t build tvm from pre-built binary LLVM.)
在 CMake 中,-S 参数指定了 CMakeLists.txt 文件所在的目录,-B 参数指定了构建文件的生成目录。
1 |
|
其中:
<source_dir>
:包含 CMakeLists.txt 文件的源代码目录。<build_dir>
:用于存放构建文件的目录。
1 |
|
If build process is successful, you will find build/release/bin/llvm-config.exe
Compile TVM
Following the official guidance: Install from Source — tvm 0.18.dev0 documentation (apache.org)
Get Source from Github
1 |
|
Modify config.cmake file
Modify /cmake/config.cmake
Modify set(USE_LLVM OFF)
to set(USE_LLVM "/path/to/llvm-config --link-static")
, /path/to/llvm-config
is the path of llvm-config.exe
in the last step.
If want to use CUDA: set(USE_CUDA ON)
Build Anaconda Environment
Install all necessary build dependencies.
1 |
|
Build Shared Library
TVM support build via MSVC using cmake.
cmake --build build --config Release -- /m
用于在 build
目录中构建项目,并使用 Release
配置,同时启用多线程构建。
cmake --build build
:告诉 CMake 在build
目录中执行构建操作。--config Release
:指定构建配置为Release
。这通常意味着启用优化选项,以生成更小的可执行文件并提高性能。-- /m
:这是 Windows 平台上的一个参数,用于启用多线程构建。它告诉 CMake 使用多个处理器核心来加速构建过程。
1 |
|
If build process is successful, you will find tvm.dll, tvm_runtime.dll
.etc in tvm/build/Release
.
Import tvm package into python
Open anaconda prompt in tvm/python
.
1 |
|
Verify whether the package is installed or not.
1 |
|