为了学习tvm的源码,想着从最开始的版本v0.1,v0.2等版本开始学习。但是编译的时候总是有问题,然后到github的issue去搜,可以看到大部分的问题都是llvm版本的问题导致的。特别是v0.1~v0.3的版本最好使用 4.0<llvm<6.0,这也是猜测的。我用llvm 5.0.1是可以编译通过的
1. 编译过程
1.1 下载代码
git clone --recursive https://github.com/dmlc/tvm
git checkout v0.2
1.2 下载llvm5.0.1
- 可以从下载预编译好的llvm 5.0.1
- 从我的百度网盘下载. 提取码: bjur
1.3 编译
这里可以采用make或者cmake编译,用make编译会比较方便一点。
- 修改
make/config.mk
,将LLVM_CONFIG
修改为llvm 5.0.1 llvm-config的路径。比如
LLVM_CONFIG=/home/llvm-5.0/bin/llvm-config
-
编译
make -j8 -
结果
编译完成后在lib
目录下有编译好的动态库
1.4 设置python模块路径
Set the environment variable PYTHONPATH
to tell python where to find
the library. For example, assume we cloned tvm
on the home directory~
. then we can added the following line in ~/.bashrc
.
It is recommended for developers who may change the codes.
The changes will be immediately reflected once you pulled the code and rebuild the project (no need to call setup
again)
```bash
export PYTHONPATH=/path/to/tvm/python:/path/to/tvm/topi/python:${PYTHONPATH}
```
2.测试
运行opt_gemm.py
,和numpy的计算做对比
cd tutorials/optimiza
python opt_gemmy.py