How to build TVM corresponding to FCRC 2019 binaries?


#1

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.


#2

Try replacing relay.ir_pass.free_vars with relay.analysis.free_vars. There are some recent changes on ir_pass api


#3

Thank you for your quick reply.
I confirmed that relay.analysis.free_vars is available.
But I faced the different issue as follows.
I guess my build script is not correct.
Would you like to tell me how to build TVM like the FCRC 2019 binaries?

Traceback (most recent call last):
  File "/home/stakemura/tvm-opengl/test_tvm_opengl.py", line 18, in <module>
    graph, lib, params = relay.build(func, target=target)
  File "/tvm/python/tvm/relay/build_module.py", line 207, in build
    graph_json, mod, params = bld_mod.build(func, target, target_host, params)
  File "/tvm/python/tvm/relay/build_module.py", line 108, in build
    self._build(func, target, target_host)
  File "/tvm/python/tvm/_ffi/_ctypes/function.py", line 209, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) /tvm/build/libtvm.so(tvm::codegen::BuildOpenGL(tvm::Array<tvm::LoweredFunc, void>)+0x1c0) [0x7f12efe22940]
  [bt] (7) /tvm/build/libtvm.so(tvm::runtime::OpenGLModuleCreate(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::OpenGLShader, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::OpenGLShader> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::FunctionInfo, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::FunctionInfo> > >)+0xeb) [0x7f12f05053bb]
  [bt] (6) /tvm/build/libtvm.so(tvm::runtime::OpenGLModuleNode::OpenGLModuleNode(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::OpenGLShader, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::OpenGLShader> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::FunctionInfo, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::FunctionInfo> > >)+0x92) [0x7f12f0504bc2]
  [bt] (5) /tvm/build/libtvm.so(tvm::runtime::gl::OpenGLWorkspace::Global()+0x55) [0x7f12f0512795]
  [bt] (4) /tvm/build/libtvm.so(tvm::runtime::gl::OpenGLWorkspace::OpenGLWorkspace()+0x4e) [0x7f12f050fd4e]
  [bt] (3) /usr/lib/x86_64-linux-gnu/libglfw.so.3(glfwInit+0x2d) [0x7f12ec52c9bd]
  [bt] (2) /usr/lib/x86_64-linux-gnu/libglfw.so.3(+0x906e) [0x7f12ec53006e]
  [bt] (1) /usr/lib/x86_64-linux-gnu/libglfw.so.3(+0x5887) [0x7f12ec52c887]
  [bt] (0) /tvm/build/libtvm.so(tvm::runtime::gl::GlfwErrorCallback(int, char const*)+0x309) [0x7f12f050c159]
  File "/tvm/src/runtime/opengl/opengl_device_api.cc", line 82
Error: [65544] X11: RandR gamma ramp support seems broken

#4

Seems there are some issue with glfw_init. Please check if there is anything wrong with your environment (OpenGL version, driver, etc…)


#5

I think it would be nice to have these binaries built in a daily fashion so people can try tutorials on Colab on the newest build. Who here thinks it’d be a good/bad idea?


#6

Currently we have to update the notebooks to match the huge number of changes happening in TVM each week.

We fixed a relatively recent version of TVM for the tutorial that you can find here: https://github.com/uwsampl/tvm.

We hope to get the tutorials better integrated into our CI so they stay up to date, we will follow up with more details.


#7

As you advised, I guess our environment have X11-related issue.
In fact, I tried to build TVM on google colab, but it failed to export OpenGL kernel code as this notebook.

---------------------------------------------------------------------------
TVMError                                  Traceback (most recent call last)
<ipython-input-1-c718136d5a9e> in <module>()
     15 context = tvm.gpu(0)
     16 
---> 17 graph, lib, params = relay.build(func, target=target)
     18 print(lib.imported_modules[0].get_source(fmt="gl"))

5 frames
/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/_ffi/_cython/base.pxi in tvm._ffi._cy3.core.CALL()

TVMError: Traceback (most recent call last):
  [bt] (8) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::codegen::BuildOpenGL(tvm::Array<tvm::LoweredFunc, void>)+0x1c3) [0x7ff209188703]
  [bt] (7) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::OpenGLModuleCreate(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::OpenGLShader, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::OpenGLShader> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::FunctionInfo, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::FunctionInfo> > >)+0xeb) [0x7ff20981d99b]
  [bt] (6) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::OpenGLModuleNode::OpenGLModuleNode(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::OpenGLShader, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::OpenGLShader> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::FunctionInfo, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::FunctionInfo> > >)+0x92) [0x7ff20981d372]
  [bt] (5) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::gl::OpenGLWorkspace::Global()+0x55) [0x7ff209815a75]
  [bt] (4) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::gl::OpenGLWorkspace::OpenGLWorkspace()+0x4d) [0x7ff209812d1d]
  [bt] (3) /usr/lib/x86_64-linux-gnu/libglfw.so.3(glfwInit+0x2d) [0x7ff20262bb3d]
  [bt] (2) /usr/lib/x86_64-linux-gnu/libglfw.so.3(+0xbdc5) [0x7ff202631dc5]
  [bt] (1) /usr/lib/x86_64-linux-gnu/libglfw.so.3(+0x59f7) [0x7ff20262b9f7]
  [bt] (0) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::runtime::gl::GlfwErrorCallback(int, char const*)+0x2f9) [0x7ff20980d969]
  File "/tvm/src/runtime/opengl/opengl_device_api.cc", line 82
Error: [65544] X11: The DISPLAY environment variable is missing

On the other hand, it succeeded to do same thing with FCRC version even on non-GPU colab runtime.
So I guess my build method is also wrong.
I will check https://github.com/uwsampl/tvm as @jroesch advised.
Thanks.