From 5176f803ca305b7f38c71d81ccff5c91fd505fb1 Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Tue, 26 Sep 2017 22:24:37 -0700 Subject: [PATCH] [TEST] Checkin test docker and scripts (#48) --- nnvm/Jenkinsfile | 126 ++++++++++++++++++ nnvm/Makefile | 6 +- nnvm/include/nnvm/compiler/op_attr_types.h | 2 +- nnvm/include/nnvm/op_attr_types.h | 2 +- nnvm/python/nnvm/_base.py | 4 +- nnvm/python/nnvm/symbol.py | 13 +- nnvm/python/setup.py | 3 + nnvm/tests/ci_build/Dockerfile.gpu | 44 ++++++ nnvm/tests/ci_build/Dockerfile.lint | 6 + nnvm/tests/ci_build/README.md | 36 +++++ nnvm/tests/ci_build/ci_build.sh | 126 ++++++++++++++++++ .../ci_build/install/ubuntu_install_core.sh | 6 + .../ci_build/install/ubuntu_install_llvm.sh | 17 +++ .../ci_build/install/ubuntu_install_mxnet.sh | 2 + .../ci_build/install/ubuntu_install_onnx.sh | 7 + .../ci_build/install/ubuntu_install_opencl.sh | 11 ++ .../ci_build/install/ubuntu_install_python.sh | 5 + .../install/ubuntu_install_python_package.sh | 3 + .../ci_build/install/ubuntu_install_sphinx.sh | 1 + nnvm/tests/ci_build/with_the_same_user | 34 +++++ .../python/frontend/mxnet/test_forward.py | 9 +- .../python/frontend/onnx/test_forward.py | 10 +- nnvm/tests/scripts/task_build.sh | 16 +++ nnvm/tests/scripts/task_clean.sh | 6 + nnvm/tests/scripts/task_frontend_test.sh | 9 ++ nnvm/tests/scripts/task_lint.sh | 15 +++ nnvm/tests/scripts/task_python_docs.sh | 12 ++ nnvm/tests/scripts/task_python_test.sh | 11 ++ nnvm/tutorials/imagenet_inference_gpu.py | 2 +- 29 files changed, 524 insertions(+), 20 deletions(-) create mode 100644 nnvm/Jenkinsfile create mode 100644 nnvm/tests/ci_build/Dockerfile.gpu create mode 100644 nnvm/tests/ci_build/Dockerfile.lint create mode 100644 nnvm/tests/ci_build/README.md create mode 100755 nnvm/tests/ci_build/ci_build.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_core.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_llvm.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_mxnet.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_onnx.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_opencl.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_python.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_python_package.sh create mode 100644 nnvm/tests/ci_build/install/ubuntu_install_sphinx.sh create mode 100644 nnvm/tests/ci_build/with_the_same_user create mode 100755 nnvm/tests/scripts/task_build.sh create mode 100755 nnvm/tests/scripts/task_clean.sh create mode 100755 nnvm/tests/scripts/task_frontend_test.sh create mode 100755 nnvm/tests/scripts/task_lint.sh create mode 100755 nnvm/tests/scripts/task_python_docs.sh create mode 100755 nnvm/tests/scripts/task_python_test.sh diff --git a/nnvm/Jenkinsfile b/nnvm/Jenkinsfile new file mode 100644 index 000000000000..de3cfd3021af --- /dev/null +++ b/nnvm/Jenkinsfile @@ -0,0 +1,126 @@ +#!groovy +// -*- mode: groovy -*- +// Jenkins pipeline +// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/ + +// nnvm libraries +nnvm_lib = "tvm/lib/libtvm.so, tvm/lib/libtvm_runtime.so, lib/libnnvm_top.so, config.mk" + +// command to start a docker container +docker_run = 'tests/ci_build/ci_build.sh' +// timeout in minutes +max_time = 60 + +// initialize source codes +def init_git() { + checkout scm + retry(5) { + timeout(time: 2, unit: 'MINUTES') { + sh 'git submodule update --init --recursive' + } + } +} + +def init_git_win() { + checkout scm + retry(5) { + timeout(time: 2, unit: 'MINUTES') { + bat 'git submodule update --init --recursive' + } + } +} + +stage("Sanity Check") { + timeout(time: max_time, unit: 'MINUTES') { + node('linux') { + ws('workspace/tvm/sanity') { + init_git() + sh "${docker_run} lint ./tests/scripts/task_lint.sh" + } + } + } +} + +// Run make. First try to do an incremental make from a previous workspace in hope to +// accelerate the compilation. If something wrong, clean the workspace and then +// build from scratch. +def make(docker_type, make_flag) { + timeout(time: max_time, unit: 'MINUTES') { + try { + sh "${docker_run} ${docker_type} ./tests/script/task_build.sh ${make_flag}" + } catch (exc) { + echo 'Incremental compilation failed. Fall back to build from scratch' + sh "${docker_run} ${docker_type} ./tests/script/task_clean.sh" + sh "${docker_run} ${docker_type} ./tests/script/task_build.sh ${make_flag}" + } + } +} + +// pack libraries for later use +def pack_lib(name, libs) { + sh """ + echo "Packing ${libs} into ${name}" + echo ${libs} | sed -e 's/,/ /g' | xargs md5sum + """ + stash includes: libs, name: name +} + + +// unpack libraries saved before +def unpack_lib(name, libs) { + unstash name + sh """ + echo "Unpacked ${libs} from ${name}" + echo ${libs} | sed -e 's/,/ /g' | xargs md5sum + """ +} + +stage('Build') { + timeout(time: max_time, unit: 'MINUTES') { + node('GPU' && 'linux') { + ws('workspace/nnvm/build-gpu') { + init_git() + make('gpu', '-j2') + pack_lib('gpu', nnvm_lib) + } + } + } +} + +stage('Tests') { + parallel 'python': { + node('GPU' && 'linux') { + ws('workspace/nnvm/it-python-gpu') { + init_git() + unpack_lib('gpu', nnvm_lib) + timeout(time: max_time, unit: 'MINUTES') { + sh "${docker_run} gpu ./tests/scripts/task_python_test.sh" + sh "${docker_run} gpu ./tests/scripts/task_frontend_test.sh" + } + } + } + }, + 'docs': { + node('GPU' && 'linux') { + ws('workspace/nnvm/docs-python-gpu') { + init_git() + unpack_lib('gpu', nnvm_lib) + timeout(time: max_time, unit: 'MINUTES') { + sh "${docker_run} gpu ./tests/scripts/task_python_docs.sh" + } + pack_lib('mydocs', 'docs.tgz') + } + } + } +} + +stage('Deploy') { + node('docker' && 'doc') { + ws('workspace/nnvm/deploy-docs') { + if (env.BRANCH_NAME == "master") { + unpack_lib('mydocs', 'docs.tgz') + sh "tar xf docs.tgz -C /var/docs" + } + } + } +} diff --git a/nnvm/Makefile b/nnvm/Makefile index 515856c5f078..24a23b054349 100644 --- a/nnvm/Makefile +++ b/nnvm/Makefile @@ -38,7 +38,7 @@ PLUGIN_OBJ = include $(NNVM_PLUGINS) # specify tensor path -.PHONY: clean all test lint pylint doc cython cython3 cyclean +.PHONY: clean all test lint cpplint pylint doc cython cython3 cyclean UNAME_S := $(shell uname -s) @@ -87,7 +87,9 @@ cython3: cyclean: rm -rf python/nnvm/*/*.so python/nnvm/*/*.dylib python/nnvm/*/*.cpp -lint: pylint +lint: pylint cpplint + +cpplint: python dmlc-core/scripts/lint.py nnvm cpp include src pylint: diff --git a/nnvm/include/nnvm/compiler/op_attr_types.h b/nnvm/include/nnvm/compiler/op_attr_types.h index 9b9fbed4455f..f8d32320ac00 100644 --- a/nnvm/include/nnvm/compiler/op_attr_types.h +++ b/nnvm/include/nnvm/compiler/op_attr_types.h @@ -1,6 +1,6 @@ /*! * Copyright (c) 2017 by Contributors - * \file op_attr_types.h + * \file nnvm/compiler/op_attr_types.h * \brief The Expr and related elements in DataFlow construction. */ #ifndef NNVM_COMPILER_OP_ATTR_TYPES_H_ diff --git a/nnvm/include/nnvm/op_attr_types.h b/nnvm/include/nnvm/op_attr_types.h index 25c8c6395bab..e7bbb9685f6d 100644 --- a/nnvm/include/nnvm/op_attr_types.h +++ b/nnvm/include/nnvm/op_attr_types.h @@ -1,6 +1,6 @@ /*! * Copyright (c) 2016 by Contributors - * \file op_attr_types.h + * \file nnvm/op_attr_types.h * \brief Data structures that can appear in operator attributes. */ #ifndef NNVM_OP_ATTR_TYPES_H_ diff --git a/nnvm/python/nnvm/_base.py b/nnvm/python/nnvm/_base.py index 225b0844c4f9..1c25f4cfe551 100644 --- a/nnvm/python/nnvm/_base.py +++ b/nnvm/python/nnvm/_base.py @@ -3,6 +3,7 @@ """ ctypes library of nnvm and helper functions """ from __future__ import absolute_import +import os import sys import ctypes import numpy as np @@ -44,7 +45,8 @@ def _load_lib(): __version__ = libinfo.__version__ # library instance of nnvm _LIB = _load_lib() - +# The FFI mode of TVM +_FFI_MODE = os.environ.get("TVM_FFI", "auto") # type definitions nn_uint = ctypes.c_uint diff --git a/nnvm/python/nnvm/symbol.py b/nnvm/python/nnvm/symbol.py index 888623403772..bca63a3656f2 100644 --- a/nnvm/python/nnvm/symbol.py +++ b/nnvm/python/nnvm/symbol.py @@ -11,21 +11,24 @@ from numbers import Number as _Number from . import _base -from ._base import _LIB, check_call as _check_call +from ._base import _LIB, check_call as _check_call, _FFI_MODE from .attribute import AttrScope from . import _symbol_internal as _internal # Use different verison of SymbolBase # When possible, use cython to speedup part of computation. +IMPORT_EXCEPT = RuntimeError if _FFI_MODE == "cython" else ImportError + try: - if int(_os.environ.get("MXNET_ENABLE_CYTHON", True)) == 0: - from ._ctypes.symbol import SymbolBase, _init_symbol_module - elif _sys.version_info >= (3, 0): + if _FFI_MODE == "ctypes": + raise ImportError() + if _sys.version_info >= (3, 0): from ._cy3.symbol import SymbolBase, _init_symbol_module else: from ._cy2.symbol import SymbolBase, _init_symbol_module -except ImportError: +except IMPORT_EXCEPT: + # pylint: disable=wrong-import-position from ._ctypes.symbol import SymbolBase, _init_symbol_module diff --git a/nnvm/python/setup.py b/nnvm/python/setup.py index 74ada0c6b83a..5f5b3cada78d 100644 --- a/nnvm/python/setup.py +++ b/nnvm/python/setup.py @@ -3,6 +3,9 @@ from distutils.core import setup def config_cython(): + # temporary disable cython for now + # as NNVM uses local DLL build + return [] try: from Cython.Build import cythonize from distutils.extension import Extension diff --git a/nnvm/tests/ci_build/Dockerfile.gpu b/nnvm/tests/ci_build/Dockerfile.gpu new file mode 100644 index 000000000000..b7cda20f169d --- /dev/null +++ b/nnvm/tests/ci_build/Dockerfile.gpu @@ -0,0 +1,44 @@ +FROM nvidia/cuda:8.0-cudnn7-devel + +# Base scripts +RUN apt-get update --fix-missing + +COPY install/ubuntu_install_core.sh /install/ubuntu_install_core.sh +RUN bash /install/ubuntu_install_core.sh + +COPY install/ubuntu_install_python.sh /install/ubuntu_install_python.sh +RUN bash /install/ubuntu_install_python.sh + +COPY install/ubuntu_install_llvm.sh /install/ubuntu_install_llvm.sh +RUN bash /install/ubuntu_install_llvm.sh + +COPY install/ubuntu_install_opencl.sh /install/ubuntu_install_opencl.sh +RUN bash /install/ubuntu_install_opencl.sh + +COPY install/ubuntu_install_python_package.sh /install/ubuntu_install_python_package.sh +RUN bash /install/ubuntu_install_python_package.sh + +COPY install/ubuntu_install_sphinx.sh /install/ubuntu_install_sphinx.sh +RUN bash /install/ubuntu_install_sphinx.sh + +# Fix recommonmark to latest version +RUN git clone https://github.com/rtfd/recommonmark +RUN cd recommonmark; python setup.py install + +# Enable doxygen for c++ doc build +RUN apt-get update && apt-get install -y doxygen graphviz libprotobuf-dev protobuf-compiler + +# DL Frameworks +COPY install/ubuntu_install_mxnet.sh /install/ubuntu_install_mxnet.sh +RUN bash /install/ubuntu_install_mxnet.sh + +COPY install/ubuntu_install_onnx.sh /install/ubuntu_install_onnx.sh +RUN bash /install/ubuntu_install_onnx.sh + +# Environment variables +ENV PATH=/usr/local/nvidia/bin:${PATH} +ENV PATH=/usr/local/cuda/bin:${PATH} +ENV CPLUS_INCLUDE_PATH=/usr/local/cuda/include:${CPLUS_INCLUDE_PATH} +ENV C_INCLUDE_PATH=/usr/local/cuda/include:${C_INCLUDE_PATH} +ENV LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/nvidia/lib64:${LIBRARY_PATH} +ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} diff --git a/nnvm/tests/ci_build/Dockerfile.lint b/nnvm/tests/ci_build/Dockerfile.lint new file mode 100644 index 000000000000..4ba4ca3be294 --- /dev/null +++ b/nnvm/tests/ci_build/Dockerfile.lint @@ -0,0 +1,6 @@ +# For lint test +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install -y python-pip sudo +RUN apt-get install -y doxygen graphviz +RUN pip install cpplint pylint diff --git a/nnvm/tests/ci_build/README.md b/nnvm/tests/ci_build/README.md new file mode 100644 index 000000000000..68f0c2d0e96a --- /dev/null +++ b/nnvm/tests/ci_build/README.md @@ -0,0 +1,36 @@ +# CI Build Scripts + +This directory contains the files and setup instructions to run all tests. + +## Run locally + +To run locally, we need to first install +[docker](https://docs.docker.com/engine/installation/) and +[nvidia-docker](https://github.com/NVIDIA/nvidia-docker/wiki). + +Then we can run the tasks defined in the [Jenkinsfile](../../Jenkinsfile) by +using (`ci_build.sh`)[./ci_build.sh]. For example + +- lint the python codes + + ```bash + ./ci_build.sh lint make pylint + ``` + +- build codes with CUDA supports + + ```bash + ./ci_build.sh gpu tests/scripts/task_build.sh + ``` + +- do the python unittest + + ```bash + ./ci_build.sh gpu tests/scripts/task_python_test.sh + ``` + +- build the documents. The results will be available at `docs/_build/html` + + ```bash + tests/ci_build/ci_build.sh gpu tests/scripts/task_python_docs.sh + ``` diff --git a/nnvm/tests/ci_build/ci_build.sh b/nnvm/tests/ci_build/ci_build.sh new file mode 100755 index 000000000000..db4283ca9753 --- /dev/null +++ b/nnvm/tests/ci_build/ci_build.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash +# +# Execute command within a docker container +# +# Usage: ci_build.sh [--dockerfile ] [-it] +# +# +# CONTAINER_TYPE: Type of the docker container used the run the build: e.g., +# (cpu | gpu) +# +# DOCKERFILE_PATH: (Optional) Path to the Dockerfile used for docker build. If +# this optional value is not supplied (via the --dockerfile +# flag), will use Dockerfile.CONTAINER_TYPE in default +# +# COMMAND: Command to be executed in the docker container +# +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Get the command line arguments. +CONTAINER_TYPE=$( echo "$1" | tr '[:upper:]' '[:lower:]' ) +shift 1 + +# Dockerfile to be used in docker build +DOCKERFILE_PATH="${SCRIPT_DIR}/Dockerfile.${CONTAINER_TYPE}" +DOCKER_CONTEXT_PATH="${SCRIPT_DIR}" + +if [[ "$1" == "--dockerfile" ]]; then + DOCKERFILE_PATH="$2" + DOCKER_CONTEXT_PATH=$(dirname "${DOCKERFILE_PATH}") + echo "Using custom Dockerfile path: ${DOCKERFILE_PATH}" + echo "Using custom docker build context path: ${DOCKER_CONTEXT_PATH}" + shift 2 +fi + +if [[ "$1" == "-it" ]]; then + CI_DOCKER_EXTRA_PARAMS+=('-it') + shift 1 +fi + +if [[ ! -f "${DOCKERFILE_PATH}" ]]; then + echo "Invalid Dockerfile path: \"${DOCKERFILE_PATH}\"" + exit 1 +fi + +COMMAND=("$@") + +# Validate command line arguments. +if [ "$#" -lt 1 ] || [ ! -e "${SCRIPT_DIR}/Dockerfile.${CONTAINER_TYPE}" ]; then + supported_container_types=$( ls -1 ${SCRIPT_DIR}/Dockerfile.* | \ + sed -n 's/.*Dockerfile\.\([^\/]*\)/\1/p' | tr '\n' ' ' ) + echo "Usage: $(basename $0) CONTAINER_TYPE COMMAND" + echo " CONTAINER_TYPE can be one of [${supported_container_types}]" + echo " COMMAND is a command (with arguments) to run inside" + echo " the container." + exit 1 +fi + +# Use nvidia-docker if the container is GPU. +if [[ "${CONTAINER_TYPE}" == *"gpu"* ]]; then + DOCKER_BINARY="nvidia-docker" +else + DOCKER_BINARY="docker" +fi + +# Helper function to traverse directories up until given file is found. +function upsearch () { + test / == "$PWD" && return || \ + test -e "$1" && echo "$PWD" && return || \ + cd .. && upsearch "$1" +} + +# Set up WORKSPACE and BUILD_TAG. Jenkins will set them for you or we pick +# reasonable defaults if you run it outside of Jenkins. +WORKSPACE="${WORKSPACE:-${SCRIPT_DIR}/../../}" +BUILD_TAG="${BUILD_TAG:-nnvm-ci}" + +# Determine the docker image name +DOCKER_IMG_NAME="${BUILD_TAG}.${CONTAINER_TYPE}" + +# Under Jenkins matrix build, the build tag may contain characters such as +# commas (,) and equal signs (=), which are not valid inside docker image names. +DOCKER_IMG_NAME=$(echo "${DOCKER_IMG_NAME}" | sed -e 's/=/_/g' -e 's/,/-/g') + +# Convert to all lower-case, as per requirement of Docker image names +DOCKER_IMG_NAME=$(echo "${DOCKER_IMG_NAME}" | tr '[:upper:]' '[:lower:]') + +# Print arguments. +echo "WORKSPACE: ${WORKSPACE}" +echo "CI_DOCKER_EXTRA_PARAMS: ${CI_DOCKER_EXTRA_PARAMS[@]}" +echo "COMMAND: ${COMMAND[@]}" +echo "CONTAINER_TYPE: ${CONTAINER_TYPE}" +echo "BUILD_TAG: ${BUILD_TAG}" +echo "DOCKER CONTAINER NAME: ${DOCKER_IMG_NAME}" +echo "" + + +# Build the docker container. +echo "Building container (${DOCKER_IMG_NAME})..." +docker build -t ${DOCKER_IMG_NAME} \ + -f "${DOCKERFILE_PATH}" "${DOCKER_CONTEXT_PATH}" + +# Check docker build status +if [[ $? != "0" ]]; then + echo "ERROR: docker build failed." + exit 1 +fi + +# Run the command inside the container. +echo "Running '${COMMAND[@]}' inside ${DOCKER_IMG_NAME}..." + +# By default we cleanup - remove the container once it finish running (--rm) +# and share the PID namespace (--pid=host) so the process inside does not have +# pid 1 and SIGKILL is propagated to the process inside (jenkins can kill it). +echo ${DOCKER_BINARY} +${DOCKER_BINARY} run --rm --pid=host \ + -v ${WORKSPACE}:/workspace \ + -w /workspace \ + -e "CI_BUILD_HOME=/workspace" \ + -e "CI_BUILD_USER=$(id -u -n)" \ + -e "CI_BUILD_UID=$(id -u)" \ + -e "CI_BUILD_GROUP=$(id -g -n)" \ + -e "CI_BUILD_GID=$(id -g)" \ + ${CI_DOCKER_EXTRA_PARAMS[@]} \ + ${DOCKER_IMG_NAME} \ + bash tests/ci_build/with_the_same_user \ + ${COMMAND[@]} diff --git a/nnvm/tests/ci_build/install/ubuntu_install_core.sh b/nnvm/tests/ci_build/install/ubuntu_install_core.sh new file mode 100644 index 000000000000..9823ae0788ac --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_core.sh @@ -0,0 +1,6 @@ +# install libraries for building c++ core on ubuntu +apt-get install -y --no-install-recommends --force-yes \ + git make libgtest-dev cmake wget unzip libtinfo-dev libz-dev\ + libcurl4-openssl-dev libopenblas-dev g++ sudo + +cd /usr/src/gtest && cmake CMakeLists.txt && make && cp *.a /usr/lib diff --git a/nnvm/tests/ci_build/install/ubuntu_install_llvm.sh b/nnvm/tests/ci_build/install/ubuntu_install_llvm.sh new file mode 100644 index 000000000000..e5b28b911f61 --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_llvm.sh @@ -0,0 +1,17 @@ +echo deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main\ + >> /etc/apt/sources.list.d/llvm.list +echo deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main\ + >> /etc/apt/sources.list.d/llvm.list + +echo deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\ + >> /etc/apt/sources.list.d/llvm.list +echo deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\ + >> /etc/apt/sources.list.d/llvm.list + +echo deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main\ + >> /etc/apt/sources.list.d/llvm.list +echo deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main\ + >> /etc/apt/sources.list.d/llvm.list + +wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - +apt-get update && apt-get install -y --force-yes llvm-4.0 llvm-5.0 llvm-6.0 diff --git a/nnvm/tests/ci_build/install/ubuntu_install_mxnet.sh b/nnvm/tests/ci_build/install/ubuntu_install_mxnet.sh new file mode 100644 index 000000000000..ebf641e2a910 --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_mxnet.sh @@ -0,0 +1,2 @@ +pip2 install mxnet +pip3 install mxnet diff --git a/nnvm/tests/ci_build/install/ubuntu_install_onnx.sh b/nnvm/tests/ci_build/install/ubuntu_install_onnx.sh new file mode 100644 index 000000000000..ec4cae1be2d0 --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_onnx.sh @@ -0,0 +1,7 @@ +pip2 install onnx +pip3 install onnx + +pip2 install http://download.pytorch.org/whl/cu75/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl +pip2 install torchvision +pip3 install http://download.pytorch.org/whl/cu75/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl +pip3 install torchvision diff --git a/nnvm/tests/ci_build/install/ubuntu_install_opencl.sh b/nnvm/tests/ci_build/install/ubuntu_install_opencl.sh new file mode 100644 index 000000000000..636236539a98 --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_opencl.sh @@ -0,0 +1,11 @@ +# Install OpenCL runtime in nvidia docker. +apt-get install -y --no-install-recommends --force-yes \ + ocl-icd-libopencl1 \ + clinfo && \ + rm -rf /var/lib/apt/lists/* + +mkdir -p /etc/OpenCL/vendors && \ + echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd + +echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \ + echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf diff --git a/nnvm/tests/ci_build/install/ubuntu_install_python.sh b/nnvm/tests/ci_build/install/ubuntu_install_python.sh new file mode 100644 index 000000000000..c6f6f75c564e --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_python.sh @@ -0,0 +1,5 @@ +# install python and pip, don't modify this, modify install_python_package.sh +apt-get update && apt-get install -y python-pip python-dev python3-dev + +# the version of the pip shipped with ubuntu may be too lower, install a recent version here +cd /tmp && wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && python2 get-pip.py diff --git a/nnvm/tests/ci_build/install/ubuntu_install_python_package.sh b/nnvm/tests/ci_build/install/ubuntu_install_python_package.sh new file mode 100644 index 000000000000..fbed2e1904cd --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_python_package.sh @@ -0,0 +1,3 @@ +# install libraries for python package on ubuntu +pip2 install nose pylint numpy nose-timer cython decorator scipy tornado +pip3 install nose pylint numpy nose-timer cython decorator scipy tornado diff --git a/nnvm/tests/ci_build/install/ubuntu_install_sphinx.sh b/nnvm/tests/ci_build/install/ubuntu_install_sphinx.sh new file mode 100644 index 000000000000..767643f10488 --- /dev/null +++ b/nnvm/tests/ci_build/install/ubuntu_install_sphinx.sh @@ -0,0 +1 @@ +pip install sphinx==1.6.2 sphinx-gallery sphinx_rtd_theme matplotlib Image commonmark>=0.7.3 docutils>=0.11 diff --git a/nnvm/tests/ci_build/with_the_same_user b/nnvm/tests/ci_build/with_the_same_user new file mode 100644 index 000000000000..1e6ab883694b --- /dev/null +++ b/nnvm/tests/ci_build/with_the_same_user @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# This script is a wrapper creating the same user inside container as the one +# running the ci_build.sh outside the container. It also set the home directory +# for the user inside container to match the same absolute path as the workspace +# outside of container. Do not run this manually. It does not make sense. It is +# intended to be called by ci_build.sh only. + +set -e + +COMMAND=("$@") + +if ! touch /this_is_writable_file_system; then + echo "You can't write to your filesystem!" + echo "If you are in Docker you should check you do not have too many images" \ + "with too many files in them. Docker has some issue with it." + exit 1 +else + rm /this_is_writable_file_system +fi + +getent group "${CI_BUILD_GID}" || addgroup --gid "${CI_BUILD_GID}" "${CI_BUILD_GROUP}" +getent passwd "${CI_BUILD_UID}" || adduser --gid "${CI_BUILD_GID}" --uid "${CI_BUILD_UID}" \ + --gecos "${CI_BUILD_USER} (generated by with_the_same_user script)" \ + --disabled-password --home "${CI_BUILD_HOME}" --quiet "${CI_BUILD_USER}" +usermod -a -G sudo "${CI_BUILD_USER}" +echo "${CI_BUILD_USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-nopasswd-sudo + +HOME=${CI_BUILD_HOME}\ + sudo -u "#${CI_BUILD_UID}" --preserve-env\ + PATH=${PATH}\ + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}\ + HOME=${CI_BUILD_HOME}\ + ${COMMAND[@]} diff --git a/nnvm/tests/python/frontend/mxnet/test_forward.py b/nnvm/tests/python/frontend/mxnet/test_forward.py index 07acb74cfaa7..d19aa5664fdf 100644 --- a/nnvm/tests/python/frontend/mxnet/test_forward.py +++ b/nnvm/tests/python/frontend/mxnet/test_forward.py @@ -11,7 +11,8 @@ import model_zoo -def test_mxnet_frontend_impl(mx_symbol, data_shape=(1, 3, 224, 224), out_shape=(1, 1000)): +def verify_mxnet_frontend_impl(mx_symbol, data_shape=(1, 3, 224, 224), out_shape=(1, 1000)): + """Use name different from test to avoid let nose pick it up""" def get_mxnet_output(symbol, x, dtype='float32'): from collections import namedtuple Batch = namedtuple('Batch', ['data']) @@ -48,17 +49,17 @@ def get_tvm_output(symbol, x, args, auxs, target, ctx, dtype='float32'): def test_forward_mlp(): mlp = model_zoo.mx_mlp - test_mxnet_frontend_impl(mlp) + verify_mxnet_frontend_impl(mlp) def test_forward_vgg(): for n in [11]: mx_sym = model_zoo.mx_vgg[n] - test_mxnet_frontend_impl(mx_sym) + verify_mxnet_frontend_impl(mx_sym) def test_forward_resnet(): for n in [18]: mx_sym = model_zoo.mx_resnet[n] - test_mxnet_frontend_impl(mx_sym) + verify_mxnet_frontend_impl(mx_sym) if __name__ == '__main__': test_forward_mlp() diff --git a/nnvm/tests/python/frontend/onnx/test_forward.py b/nnvm/tests/python/frontend/onnx/test_forward.py index 36020103b934..155b054f47a9 100644 --- a/nnvm/tests/python/frontend/onnx/test_forward.py +++ b/nnvm/tests/python/frontend/onnx/test_forward.py @@ -4,10 +4,10 @@ from tvm.contrib import graph_runtime from nnvm.testing.config import ctx_list import onnx -import onnx_caffe2.backend from model_zoo import super_resolution -def test_onnx_forward_impl(graph_file, data_shape, out_shape): +def verify_onnx_forward_impl(graph_file, data_shape, out_shape): + import onnx_caffe2.backend def get_caffe2_output(graph, x, dtype='float32'): prepared_backend = onnx_caffe2.backend.prepare(graph) W = {graph.input[-1]: x.astype(dtype)} @@ -35,8 +35,8 @@ def get_tvm_output(graph, x, target, ctx, dtype='float32'): tvm_out = get_tvm_output(graph, x, target, ctx, dtype) np.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5) -def test_super_resolution_example(): - test_onnx_forward_impl(super_resolution[0], (1, 1, 224, 224), (1, 1, 672, 672)) +def verify_super_resolution_example(): + verify_onnx_forward_impl(super_resolution[0], (1, 1, 224, 224), (1, 1, 672, 672)) if __name__ == '__main__': - test_super_resolution_example() + verify_super_resolution_example() diff --git a/nnvm/tests/scripts/task_build.sh b/nnvm/tests/scripts/task_build.sh new file mode 100755 index 000000000000..e8ced824ff94 --- /dev/null +++ b/nnvm/tests/scripts/task_build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +echo "Build TVM..." +cd tvm +cp make/config.mk . +echo USE_CUDNN=1 >> config.mk +echo USE_CUDA=1 >> config.mk +echo USE_OPENCL=1 >> config.mk +echo LLVM_CONFIG=llvm-config-4.0 >> config.mk +echo USE_RPC=1 >> config.mk +echo USE_BLAS=openblas >> config.mk +echo USE_GRAPH_RUNTIME=1 >> config.mk +make "$@" +cd .. + +echo "Build NNVM..." +make "$@" diff --git a/nnvm/tests/scripts/task_clean.sh b/nnvm/tests/scripts/task_clean.sh new file mode 100755 index 000000000000..f4c02ed639c3 --- /dev/null +++ b/nnvm/tests/scripts/task_clean.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "Cleanup data..." +cd tvm +make clean +cd .. +make clean diff --git a/nnvm/tests/scripts/task_frontend_test.sh b/nnvm/tests/scripts/task_frontend_test.sh new file mode 100755 index 000000000000..9218a5c08e0b --- /dev/null +++ b/nnvm/tests/scripts/task_frontend_test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +export PYTHONPATH=python:tvm/python:tvm/topi/python + +echo "Running ONNX frontend test..." +python -m nose -v tests/python/frontend/onnx || exit -1 + +echo "Running MXNet frontend test..." +python -m nose -v tests/python/frontend/mxnet || exit -1 diff --git a/nnvm/tests/scripts/task_lint.sh b/nnvm/tests/scripts/task_lint.sh new file mode 100755 index 000000000000..a6774a189f35 --- /dev/null +++ b/nnvm/tests/scripts/task_lint.sh @@ -0,0 +1,15 @@ +#!/bin/bash +echo "Check codestyle of c++ code..." +make cpplint || exit -1 +echo "Check codestyle of python code..." +make pylint || exit -1 +echo "Check documentations of c++ code..." +make doc 2>log.txt +(cat log.txt| grep -v ENABLE_PREPROCESSING |grep -v "unsupported tag") > logclean.txt +echo "---------Error Log----------" +cat logclean.txt +echo "----------------------------" +(cat logclean.txt|grep warning) && exit -1 +(cat logclean.txt|grep error) && exit -1 +rm logclean.txt +rm log.txt diff --git a/nnvm/tests/scripts/task_python_docs.sh b/nnvm/tests/scripts/task_python_docs.sh new file mode 100755 index 000000000000..94fa73e5e2de --- /dev/null +++ b/nnvm/tests/scripts/task_python_docs.sh @@ -0,0 +1,12 @@ +#!/bin/bash +mkdir -p docs/_build/html +# C++ doc +make doc + +rm -rf python/nnvm/*.pyc python/nnvm/*/*.pyc + +cd docs +PYTHONPATH=../python:../tvm/python:../tvm/topi/python make html || exit -1 +cd _build/html +tar czf docs.tgz * +mv docs.tgz ../../../ diff --git a/nnvm/tests/scripts/task_python_test.sh b/nnvm/tests/scripts/task_python_test.sh new file mode 100755 index 000000000000..c8dc662cc73c --- /dev/null +++ b/nnvm/tests/scripts/task_python_test.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +export PYTHONPATH=python:tvm/python:tvm/topi/python + +echo "Running unittest..." +python -m nose -v tests/python/unittest || exit -1 +python3 -m nose -v tests/python/unittest || exit -1 + +echo "Running compiler test..." +python -m nose -v tests/python/compiler || exit -1 +python3 -m nose -v tests/python/compiler || exit -1 diff --git a/nnvm/tutorials/imagenet_inference_gpu.py b/nnvm/tutorials/imagenet_inference_gpu.py index 98f0e94c6b5f..1eca09fe13cf 100644 --- a/nnvm/tutorials/imagenet_inference_gpu.py +++ b/nnvm/tutorials/imagenet_inference_gpu.py @@ -39,7 +39,7 @@ def tvm_callback_cuda_compile(code): # .. note:: # # In a typical workflow, we can get this pair from :any:`nnvm.frontend` -# Example: /nnvm-top/tests/python/frontend/mxnet/test_forward.py +# target = "cuda" ctx = tvm.gpu(0) batch_size = 1