Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TVM 0.7.0 Dockerfile for x86_64 CPU
# TVM 0.7.0 built with NNPACK and LLVM-11
# !!! CPU ONLY !!!
# !!! CPU ONLY !!!
# !!! CPU ONLY !!!
# build with Ninja(6GB RAM, 12 CPUs)
# 内存给的太少会导致构建失败
# 大陆环境请配合代理使用(我构建时使用了透明代理)
FROM debian:stable-20210329
# 安装基本环境(后面要用到 wget,这里提前安装)
RUN apt update \
&& apt install -y openssh-server git vim curl wget sudo ninja-build python3 python3-dev python3-setuptools python3-pip gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
# 安装 LLVM
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster main" >> /etc/apt/sources.list \
&& echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster main" >> /etc/apt/sources.list \
&& echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main" >> /etc/apt/sources.list \
&& echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main" >> /etc/apt/sources.list \
&& apt update \
&& apt install -y clang-11 lldb-11 lld-11 libllvm-11-ocaml-dev libllvm11 llvm-11 llvm-11-dev llvm-11-doc llvm-11-examples llvm-11-runtime
# 克隆 NNPACK 和 tvm 到 WORKDIR
RUN git clone --recursive https://github.com/Maratyszcza/NNPACK.git /tvm-build/NNPACK \
&& git clone --recursive https://github.com/apache/tvm /tvm-build/tvm
WORKDIR /tvm-build/NNPACK/build
RUN sed -i "s|gnu99|gnu99 -fPIC|g" ../CMakeLists.txt \
&& sed -i "s|gnu++11|gnu++11 -fPIC|g" ../CMakeLists.txt \
&& cmake -G Ninja -D BUILD_SHARED_LIBS=ON .. \
&& ninja \
&& ninja install \
&& echo "/usr/local/lib" > /etc/ld.so.conf.d/nnpack.conf \
&& ldconfig
# 构建 tvm 并且设置环境
WORKDIR /tvm-build/tvm/build
RUN cp ../cmake/config.cmake ./ \
&& sed -i 's/USE_LLVM OFF/USE_LLVM ON/' config.cmake \
&& sed -i 's/USE_NNPACK OFF/USE_NNPACK ON/' config.cmake \
&& cmake .. -G Ninja \
&& ninja \
&& echo "export TVM_HOME=/tvm-build/tvm/" >> /etc/profile \
&& echo "export PYTHONPATH=\$TVM_HOME/python:\${PYTHONPATH}" >> /etc/profile
# 设置环境变量
ENV TVM_HOME "/tvm-build/tvm"
ENV PYTHONPATH "${PYTHONPATH}:$TVM_HOME/python"
# 安装 Python 包
RUN python3 -m pip install numpy decorator attrs tornado psutil xgboost cloudpickle pytest Pillow matplotlib \
&& python3 -m pip install jupyterlab
# 创建用户并开启 SSH 服务(用户名和密码在结尾处有说明)
RUN useradd -rm -d /home/tvm -s /bin/bash -g root -G sudo -u 1000 tvm \
&& echo 'tvm:tvm' | chpasswd \
&& service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
WORKDIR /home/tvm
# 安装完成
# 可以透过 ssh 登入,用户名 tvm 密码 tvm
# tvm 源文件在 /tvm-build 目录下
# 用户 tvm 工作目录在 /home/tvm
# 记得映射 container 的端口
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment