今天玩了一下tvm的安装
我要安装v0.14.0的版本
所以按照官网的方法
https://tvm.apache.org/docs/install/from_source.html#python-package-installation
git clone --recursive https://github.com/apache/tvm tvm
git checkout v0.14.0
recursive是很重要的
这一步可以替换成gitee的网址
然后我修改了.gitsubmodule文件
大家可以参考
[submodule "dmlc-core"]
path = 3rdparty/dmlc-core
url = https://github.com/dmlc/dmlc-core.git
[submodule "dlpack"]
path = 3rdparty/dlpack
url = https://github.com/dmlc/dlpack.git
[submodule "3rdparty/rang"]
path = 3rdparty/rang
url = https://github.com/agauniyal/rang.git
[submodule "3rdparty/vta-hw"]
path = 3rdparty/vta-hw
url = https://github.com/apache/tvm-vta.git
[submodule "3rdparty/libbacktrace"]
path = 3rdparty/libbacktrace
url = https://github.com/tlc-pack/libbacktrace.git
[submodule "3rdparty/cutlass"]
path = 3rdparty/cutlass
url = https://github.com/NVIDIA/cutlass.git
[submodule "3rdparty/OpenCL-Headers"]
path = 3rdparty/OpenCL-Headers
url = https://github.com/KhronosGroup/OpenCL-Headers.git
[submodule "3rdparty/cnpy"]
path = 3rdparty/cnpy
url = https://github.com/rogersce/cnpy.git
[submodule "3rdparty/cutlass_fpA_intB_gemm"]
path = 3rdparty/cutlass_fpA_intB_gemm
url = https://github.com/tlc-pack/cutlass_fpA_intB_gemm
[submodule "3rdparty/libflash_attn"]
path = 3rdparty/libflash_attn
url = https://github.com/tlc-pack/libflash_attn
这些第三方库下载完毕之后
开始build
首先要cp cmake的config.cmake到build文件夹下
修改里面的配置
我反正是都上齐活了
然后.bashrc上面加上这一句
之后直接cmake…
make -j4开始构建
构建成功
参考下面的method1
export TVM_HOME=/path/to/tvm
export PYTHONPATH=$TVM_HOME/python:${PYTHONPATH}
把这两段放bashrc
调出python
import tvm就好啦
这时候你会发现有一些日志
如果你不喜欢这些日志
echo 'export TVM_LOG_DEBUG=0' >> ~/.bashrc
echo 'export TVM_LOG_INFO=0' >> ~/.bashrc
echo 'export TVM_LOG_WARNING=0' >> ~/.bashrc
source ~/.bashrc
尝试使用一下tvm
首先下载resnet50-v2-7.onnx
然后编译它
import onnx
import tvm
from tvm import relay
# Load the ONNX model
onnx_model = onnx.load("resnet50-v2-7.onnx")
# Convert ONNX model to Relay IR
shape_dict = {"data": (1, 3, 224, 224)}
mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)
# Target configuration
target = tvm.target.cuda()
# Compile the model
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(mod, target, params=params)
# Export the compiled model as a shared library
lib.export_library("resnet50.so")
这样获得了resnet50.so
尝试读取
import tvm
tvm.runtime.Module = tvm.runtime.load_module("resnet50.so")
成功
fmlab
~/tvm1/test/resnet50Trans.py