Would you like to tell me how to build TVM binaries corresponding to
TVM For Fun and Profit Tutorial, at FCRC 2019 ?
I was wondering if it would be possible to use full TVM function on local environment.
I utilized ‘tvmai/ci-gpu’ (Docker image used in GPU CI) and build TVM as follows.
FROM tvmai/ci-gpu
MAINTAINER Shintaro Takemura;
LABEL Description="Docker image for TVM built with OpenGL support"
# Reference
# https://github.com/dmlc/tvm/blob/master/docker/Dockerfile.demo_opencl
RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \
lxde xrdp xvfb ibus x11-utils \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
# Configure Desktop
RUN echo "startlxde" > /etc/skel/.xsession
# Cloning TVM source & submodules
RUN git clone --depth=1 https://github.com/dmlc/tvm --recursive
# Building TVM
ENV TVM_HOME="/tvm"
ENV TVM_BUILD_DIR="${TVM_HOME}/build"
RUN mkdir -p ${TVM_BUILD_DIR} && \
cd ${TVM_BUILD_DIR} && \
cmake .. -DUSE_BLAS=openblas -DUSE_LLVM=ON -DUSE_OPENGL=ON -DUSE_OPENCL=ON -DUSE_VULKAN=ON && \
make -j6
# Building Python package
ENV PYTHONPATH=${TVM_HOME}/python:${TVM_HOME}/topi/python:${TVM_HOME}/nnvm/python:${PYTHONPATH}
RUN cd ${TVM_HOME}/python && python3 setup.py install --user
RUN cd ${TVM_HOME}/topi/python && python3 setup.py install --user
RUN cd ${TVM_HOME}/nnvm/python && python3 setup.py install --user
I tried to export OpenGL kernel code using tvm.relay as follows.
import tvm
from tvm import relay
import numpy as np
data = relay.var("data", shape=(1, 1, 16, 16), dtype="float32")
weight = relay.const(np.random.uniform(size=(1, 1, 1, 1)))
conv = relay.nn.conv2d(data, weight)
model = relay.nn.relu(conv)
args = relay.ir_pass.free_vars(model)
func = relay.Function(args, model)
target = tvm.target.opengl()
context = tvm.gpu(0)
graph, lib, params = relay.build(func, target=target)
print(lib.imported_modules[0].get_source(fmt="gl"))
However, I couldn’t import tvm.relay correctly as follows.
nvidia-docker run --rm -it -u $(id -u):$(id -g) -v $(pwd):$(pwd) -e HOME=$(pwd) -w $(pwd) -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY ***my-docker-tag*** python3 $(pwd)/test_tvm_opengl.py
Traceback (most recent call last):
File "/home/stakemura/test_tvm_opengl.py", line 11, in <module>
args = relay.ir_pass.free_vars(model)
AttributeError: module 'tvm.relay' has no attribute 'ir_pass'
As shown as this successful test case, FCRC 2019 binaries can import tvm.relay correctly on google colab.