From c239595c857620dfaeb84475b00c298ec79a54b1 Mon Sep 17 00:00:00 2001 From: abergeron Date: Wed, 5 Jun 2019 13:14:12 -0400 Subject: [PATCH] More fixes and tweaks to the cuda conda packages (#3281) --- .gitignore | 4 + conda/Dockerfile.cuda92 | 33 -------- ...Dockerfile.cuda100 => Dockerfile.template} | 10 ++- conda/{build_cuda.sh => Makefile} | 18 ++--- conda/build_cuda.py | 76 +++++++++++++++++++ conda/cross-linux.cmake | 37 --------- conda/nnvm/meta.yaml | 2 +- conda/topi/meta.yaml | 2 +- conda/tvm-libs/build.sh | 25 +----- conda/tvm-libs/meta.yaml | 3 +- conda/tvm/meta.yaml | 2 +- 11 files changed, 104 insertions(+), 108 deletions(-) delete mode 100644 conda/Dockerfile.cuda92 rename conda/{Dockerfile.cuda100 => Dockerfile.template} (72%) rename conda/{build_cuda.sh => Makefile} (66%) mode change 100755 => 100644 create mode 100644 conda/build_cuda.py delete mode 100644 conda/cross-linux.cmake diff --git a/.gitignore b/.gitignore index a7355739cf59..b23847a5e812 100644 --- a/.gitignore +++ b/.gitignore @@ -220,3 +220,7 @@ patched.txt # pipenv file Pipfile Pipfile.lock + +# conda package artifacts +conda/Dockerfile.cuda* +conda/pkg diff --git a/conda/Dockerfile.cuda92 b/conda/Dockerfile.cuda92 deleted file mode 100644 index ad2d8ffca6e0..000000000000 --- a/conda/Dockerfile.cuda92 +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -FROM nvidia/cuda:9.2-devel-centos6 - -RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - chmod +x ~/miniconda.sh && \ - ~/miniconda.sh -b -p /opt/conda && \ - rm ~/miniconda.sh && \ - /opt/conda/bin/conda install conda-build conda-verify && \ - /opt/conda/bin/conda clean -ya - -ENV PATH /opt/conda/bin:$PATH -ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 - -WORKDIR /workspace -RUN chmod -R a+w /workspace - -CMD conda build --output-folder /workspace/conda/pkg --variants '{cuda: True, cuda_version: 9.2}' /workspace/conda/tvm-libs diff --git a/conda/Dockerfile.cuda100 b/conda/Dockerfile.template similarity index 72% rename from conda/Dockerfile.cuda100 rename to conda/Dockerfile.template index def8c9ac5d6a..59b9ac96814e 100644 --- a/conda/Dockerfile.cuda100 +++ b/conda/Dockerfile.template @@ -15,7 +15,13 @@ # specific language governing permissions and limitations # under the License. -FROM nvidia/cuda:10.0-devel-centos6 +FROM nvidia/cuda:{{ cuda_version }}-devel-centos6 + +RUN curl -fsSL http://developer.download.nvidia.com/compute/redist/cudnn/v{{ cudnn_short_version }}/cudnn-{{ cuda_version }}-linux-x64-v{{ cudnn_version }}.tgz -O && \ + tar --no-same-owner -xzf cudnn-{{ cuda_version }}-linux-x64-v{{ cudnn_version }}.tgz -C /usr/local && \ + rm cudnn-{{ cuda_version }}-linux-x64-v{{ cudnn_version }}.tgz && \ + ldconfig + RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ chmod +x ~/miniconda.sh && \ @@ -30,4 +36,4 @@ ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 WORKDIR /workspace RUN chmod -R a+w /workspace -CMD conda build --output-folder /workspace/conda/pkg --variants '{cuda: True, cuda_version: 10.0}' /workspace/conda/tvm-libs +CMD conda build --output-folder /workspace/conda/pkg --variants '{cuda: True, cuda_version: {{ cuda_version }}}' /workspace/conda/tvm-libs diff --git a/conda/build_cuda.sh b/conda/Makefile old mode 100755 new mode 100644 similarity index 66% rename from conda/build_cuda.sh rename to conda/Makefile index 2f3207e22987..cda546ac73ce --- a/conda/build_cuda.sh +++ b/conda/Makefile @@ -5,22 +5,18 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -#/bin/sh -condadir=`dirname $0` -condadir=`readlink -f $condadir` -srcdir=`dirname $condadir` -docker build -t tvm-cuda100-forge $condadir -f $condadir/Dockerfile.cuda100 -docker run --rm -v $srcdir:/workspace tvm-cuda100-forge -docker build -t tvm-cuda92-forge $condadir -f $condadir/Dockerfile.cuda92 -docker run --rm -v $srcdir:/workspace tvm-cuda92-forge -sudo chown -R `whoami` $condadir/pkg +packages: + conda build tvm-libs + conda build tvm + conda build topi + conda built nnvm diff --git a/conda/build_cuda.py b/conda/build_cuda.py new file mode 100644 index 000000000000..47af6ce4564e --- /dev/null +++ b/conda/build_cuda.py @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import sys +import subprocess + +from jinja2 import Template + +CUDA_VERSIONS = ['10.0', '9.0'] + + +# Make sure that the cudnn version you set here is available +# for all the cuda versions that you want both from nvidia +# and from conda. + +# These two must be in sync +CUDNN_FULL_VERSION = '7.3.1.20' +CUDNN_VERSION = '7.3.1' + + +condadir = os.path.dirname(sys.argv[0]) +condadir = os.path.abspath(condadir) +srcdir = os.path.dirname(condadir) + + +with open(os.path.join(condadir, 'Dockerfile.template')) as f: + docker_template = Template(f.read()) + + +def render_dockerfile(version): + txt = docker_template.render(cuda_version=version, + cudnn_short_version=CUDNN_VERSION, + cudnn_version=CUDNN_FULL_VERSION) + fname = os.path.join(condadir, + 'Dockerfile.cuda' + version.replace('.', '')) + with open(fname, 'w') as f: + f.write(txt) + return fname + + +def build_docker(version): + vv = version.replace('.', '') + fname = render_dockerfile(version) + tagname = f'tvm-cuda{ vv }-forge' + subprocess.run(['docker', 'build', '-t', tagname, + condadir, '-f', fname], check=True) + return tagname + + +def build_pkg(version): + tagname = build_docker(version) + subprocess.run(['docker', 'run', '--rm', '-v', f'{ srcdir }:/workspace', + tagname], check=True) + + +if __name__ == '__main__': + build_versions = CUDA_VERSIONS + if len(sys.argv) > 1: + build_versions = sys.argv[1:] + for version in build_versions: + build_pkg(version) diff --git a/conda/cross-linux.cmake b/conda/cross-linux.cmake deleted file mode 100644 index f84ba8e44a26..000000000000 --- a/conda/cross-linux.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# this one is important -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_PLATFORM Linux) -#this one not so much -set(CMAKE_SYSTEM_VERSION 1) - -# specify the cross compiler -set(CMAKE_C_COMPILER $ENV{CC}) - -# where is the target environment -set(CMAKE_FIND_ROOT_PATH $ENV{PREFIX} $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot) - -# search for programs in the build host directories -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -# for libraries and headers in the target directories -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# god-awful hack because it seems to not run correct tests to determine this: -set(__CHAR_UNSIGNED___EXITCODE 1) diff --git a/conda/nnvm/meta.yaml b/conda/nnvm/meta.yaml index 883655f335cb..d948484a61e5 100644 --- a/conda/nnvm/meta.yaml +++ b/conda/nnvm/meta.yaml @@ -25,7 +25,7 @@ source: path: ../.. build: - number: 0 + number: 1 skip: True # [win] requirements: diff --git a/conda/topi/meta.yaml b/conda/topi/meta.yaml index bbba452a6422..f4bc8950d4c4 100644 --- a/conda/topi/meta.yaml +++ b/conda/topi/meta.yaml @@ -25,7 +25,7 @@ source: path: ../.. build: - number: 0 + number: 1 requirements: host: diff --git a/conda/tvm-libs/build.sh b/conda/tvm-libs/build.sh index d4cf2578b570..e0b85910475e 100644 --- a/conda/tvm-libs/build.sh +++ b/conda/tvm-libs/build.sh @@ -16,42 +16,25 @@ # specific language governing permissions and limitations # under the License. -# Fix for OSX build to hide the clang LLVM -rm -f ${BUILD_PREFIX}/bin/llvm-config -rm -rf ${BUILD_PREFIX}/lib/cmake - set -e -if [ -z "$PREFIX" ]; then - PREFIX="$CONDA_PREFIX" -fi - -if [ -z "$cuda" ] || [ "$cuda" == "False" ]; then - CUDA_OPT="" +if [ "$cuda" == "True" ]; then + CUDA_OPT="-DUSE_CUDA=ON -DUSE_CUBLAS=ON -DUSE_CUDNN=ON" else - CUDA_OPT="-DUSE_CUDA=ON -DUSE_CUBLAS=ON" + CUDA_OPT="" fi if [ "$target_platform" == "osx-64" ]; then # macOS 64 bits METAL_OPT="" # Conda can only target 10.9 for now - TOOLCHAIN_OPT="" else METAL_OPT="" - if [ "$target_platform" == "linux-64" ]; then - # Linux 64 bits - TOOLCHAIN_OPT="-DCMAKE_TOOLCHAIN_FILE=${RECIPE_DIR}/../cross-linux.cmake" - else - # Windows (or 32 bits, which we don't support) - METAL_OPT="" - TOOLCHAIN_OPT="" - fi fi rm -rf build || true mkdir -p build cd build -cmake $METAL_OPT $CUDA_OPT -DUSE_LLVM=ON -DINSTALL_DEV=ON -DCMAKE_INSTALL_PREFIX="$PREFIX" $TOOLCHAIN_OPT .. +cmake $METAL_OPT $CUDA_OPT -DUSE_LLVM=$PREFIX/bin/llvm-config -DINSTALL_DEV=ON -DCMAKE_INSTALL_PREFIX="$PREFIX" .. make -j${CPU_COUNT} VERBOSE=1 make install cd .. diff --git a/conda/tvm-libs/meta.yaml b/conda/tvm-libs/meta.yaml index 5126f5b30359..aad8f251c2a6 100644 --- a/conda/tvm-libs/meta.yaml +++ b/conda/tvm-libs/meta.yaml @@ -25,7 +25,7 @@ source: path: ../.. build: - number: 0 + number: 1 string: cuda{{ cuda_version }}_{{ PKG_BUILDNUM }} # [cuda] requirements: @@ -39,6 +39,7 @@ requirements: - zlib # [linux] run: - {{ pin_compatible('cudatoolkit', lower_bound=cuda_version, max_pin='x.x') }} # [cuda] + - {{ pin_compatible('cudnn', lower_bound='7.3.1', max_pin='x') }} # [cuda] about: home: https://github.com/dmlc/tvm diff --git a/conda/tvm/meta.yaml b/conda/tvm/meta.yaml index 693237ce07c0..221dc7950f75 100644 --- a/conda/tvm/meta.yaml +++ b/conda/tvm/meta.yaml @@ -25,7 +25,7 @@ source: path: ../.. build: - number: 0 + number: 1 requirements: build: