diff --git a/3rdparty/dmlc-core b/3rdparty/dmlc-core index c8f7f9c81dfc..14bf7e884328 160000 --- a/3rdparty/dmlc-core +++ b/3rdparty/dmlc-core @@ -1 +1 @@ -Subproject commit c8f7f9c81dfcf2489d3bbc6d3b2a9200a20fbcde +Subproject commit 14bf7e884328eb97bfde160ec6f64c20f5337459 diff --git a/CMakeLists.txt b/CMakeLists.txt index f7950fbde3fb..d2953a001cd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,7 @@ if(MSVC) add_definitions(-DDMLC_STRICT_CXX11) add_definitions(-DNOMINMAX) set(CMAKE_C_FLAGS "/MP") + set(CMAKE_CXX_FLAGS "/Zc:__cplusplus") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj") else() include(CheckCXXCompilerFlag) diff --git a/ci/build_windows.py b/ci/build_windows.py index 2590d211c671..3398c608d881 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -33,13 +33,20 @@ import zipfile from distutils.dir_util import copy_tree from enum import Enum -from subprocess import check_call +from subprocess import check_call, call from util import * + +# Fix for broken PATH with newline inserted presumably by VS studio installation of SQL server or +# other component which makes visual studio stop working. +os.environ['PATH']=os.environ.get('PATH').replace('\n','') + KNOWN_VCVARS = { + # https://gitlab.kitware.com/cmake/cmake/issues/18920 'VS 2015': r'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat', - 'VS 2017': r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat' + 'VS 2017': r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat', + 'VS 2019': r'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat' } @@ -54,10 +61,14 @@ class BuildFlavour(Enum): CMAKE_FLAGS = { 'WIN_CPU': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=OFF ' '-DUSE_CUDNN=OFF ' '-DENABLE_CUDA_RTC=OFF ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=open ' '-DUSE_LAPACK=ON ' @@ -67,10 +78,14 @@ class BuildFlavour(Enum): '-DCMAKE_BUILD_TYPE=Release') , 'WIN_CPU_MKLDNN': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=OFF ' '-DUSE_CUDNN=OFF ' '-DENABLE_CUDA_RTC=OFF ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=open ' '-DUSE_LAPACK=ON ' @@ -80,10 +95,14 @@ class BuildFlavour(Enum): '-DCMAKE_BUILD_TYPE=Release') , 'WIN_CPU_MKLDNN_MKL': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=OFF ' '-DUSE_CUDNN=OFF ' '-DENABLE_CUDA_RTC=OFF ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=mkl ' '-DUSE_LAPACK=ON ' @@ -93,10 +112,14 @@ class BuildFlavour(Enum): '-DCMAKE_BUILD_TYPE=Release') , 'WIN_CPU_MKL': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=OFF ' '-DUSE_CUDNN=OFF ' '-DENABLE_CUDA_RTC=OFF ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=mkl ' '-DUSE_LAPACK=ON ' @@ -106,10 +129,14 @@ class BuildFlavour(Enum): '-DCMAKE_BUILD_TYPE=Release') , 'WIN_GPU': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=ON ' '-DUSE_CUDNN=ON ' '-DENABLE_CUDA_RTC=ON ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=open ' '-DUSE_LAPACK=ON ' @@ -120,10 +147,14 @@ class BuildFlavour(Enum): '-DCMAKE_BUILD_TYPE=Release') , 'WIN_GPU_MKLDNN': ( + '-DCMAKE_C_COMPILER=cl ' + '-DCMAKE_CXX_COMPILER=cl ' '-DUSE_CUDA=ON ' '-DUSE_CUDNN=ON ' '-DENABLE_CUDA_RTC=ON ' '-DUSE_OPENCV=ON ' + '-DOpenCV_RUNTIME=vc15 ' + '-DOpenCV_ARCH=x64 ' '-DUSE_OPENMP=ON ' '-DUSE_BLAS=open ' '-DUSE_LAPACK=ON ' @@ -140,38 +171,40 @@ def windows_build(args): logging.info("Using vcvars environment:\n{}".format(args.vcvars)) path = args.output - os.makedirs(path, exist_ok=True) + + # cuda thrust + VS is flaky so try multiple times if fail + MAXIMUM_TRY = 5 + build_try = 0 - mxnet_root = get_mxnet_root() - logging.info("Found MXNet root: {}".format(mxnet_root)) + while build_try < MAXIMUM_TRY: + if os.path.exists(path): + shutil.rmtree(path) + os.makedirs(path, exist_ok=True) - url = 'https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-win64-x64.zip' - with tempfile.TemporaryDirectory() as tmpdir: - cmake_file_path = download_file(url, tmpdir) - with zipfile.ZipFile(cmake_file_path, 'r') as zip_ref: - # Create $tmpdir\cmake-3.16.1-win64-x64\bin\cmake.exe - zip_ref.extractall(tmpdir) + mxnet_root = get_mxnet_root() + logging.info("Found MXNet root: {}".format(mxnet_root)) with remember_cwd(): os.chdir(path) - cmd = "\"{}\" && {} -G \"NMake Makefiles JOM\" {} {}".format( - args.vcvars, - os.path.join(tmpdir, 'cmake-3.16.1-win64-x64', 'bin', 'cmake.exe'), - CMAKE_FLAGS[args.flavour], mxnet_root) + cmd = "\"{}\" && cmake -G Ninja {} {}".format(args.vcvars, + CMAKE_FLAGS[args.flavour], + mxnet_root) logging.info("Generating project with CMake:\n{}".format(cmd)) check_call(cmd, shell=True) - cmd = "\"{}\" && jom".format(args.vcvars) - logging.info("Building with jom:\n{}".format(cmd)) + cmd = "\"{}\" && ninja".format(args.vcvars) + logging.info("Building:\n{}".format(cmd)) t0 = int(time.time()) - check_call(cmd, shell=True) - - logging.info( - "Build flavour: {} complete in directory: \"{}\"".format( - args.flavour, os.path.abspath(path))) - logging.info("Build took {}".format( - datetime.timedelta(seconds=int(time.time() - t0)))) + ret = call(cmd, shell=True) + + if ret != 0: + build_try += 1 + logging.info("{} build(s) have failed".format(build_try)) + else: + logging.info("Build flavour: {} complete in directory: \"{}\"".format(args.flavour, os.path.abspath(path))) + logging.info("Build took {}".format(datetime.timedelta(seconds=int(time.time() - t0)))) + break windows_package(args) @@ -193,6 +226,7 @@ def windows_package(args): for dll in dlls: logging.info("packing dll: %s", dll) shutil.copy(dll, pkgdir_lib) + os.chdir(get_mxnet_root()) logging.info('packing python bindings') copy_tree('python', j(pkgdir, 'python')) @@ -200,6 +234,7 @@ def windows_package(args): copy_tree('include', j(pkgdir, 'include')) logging.info("Compressing package: %s", pkgfile) check_call(['7z', 'a', pkgfile, pkgdir]) + check_call('refreshenv', shell=True) def nix_build(args): @@ -221,9 +256,6 @@ def main(): logging.getLogger().setLevel(logging.INFO) logging.basicConfig(format='%(asctime)-15s %(message)s') logging.info("MXNet Windows build helper") - instance_info = ec2_instance_info() - if instance_info: - logging.info("EC2: %s", instance_info) parser = argparse.ArgumentParser() parser.add_argument("-o", "--output", @@ -233,7 +265,7 @@ def main(): parser.add_argument("--vcvars", help="vcvars batch file location, typically inside vs studio install dir", - default=KNOWN_VCVARS['VS 2015'], + default=KNOWN_VCVARS['VS 2019'], type=str) parser.add_argument("--arch", @@ -253,12 +285,8 @@ def main(): system = platform.system() if system == 'Windows': logging.info("Detected Windows platform") - if 'OpenBLAS_HOME' not in os.environ: - os.environ["OpenBLAS_HOME"] = "C:\\Program Files\\OpenBLAS-v0.2.19" - if 'OpenCV_DIR' not in os.environ: - os.environ["OpenCV_DIR"] = "C:\\Program Files\\OpenCV-v3.4.1\\build" if 'CUDA_PATH' not in os.environ: - os.environ["CUDA_PATH"] = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2" + os.environ["CUDA_PATH"] = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" if 'MKL_ROOT' not in os.environ: os.environ["MKL_ROOT"] = "C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries\\windows\\mkl" windows_build(args) diff --git a/ci/jenkins/Jenkins_steps.groovy b/ci/jenkins/Jenkins_steps.groovy index e6e7c5d278d3..216fde5d7f59 100644 --- a/ci/jenkins/Jenkins_steps.groovy +++ b/ci/jenkins/Jenkins_steps.groovy @@ -89,7 +89,7 @@ def python3_gpu_ut_cython(docker_container_name) { } //------------------------------------------------------------------------------------------ - +/* def compile_unix_cpu_openblas() { return ['CPU: Openblas': { node(NODE_LINUX_CPU) { @@ -651,6 +651,7 @@ def compile_unix_amalgamation() { } }] } +*/ def compile_windows_cpu() { return ['Build CPU windows':{ @@ -708,6 +709,7 @@ def compile_windows_cpu_mkl() { }] } + def compile_windows_gpu() { return ['Build GPU windows':{ node(NODE_WINDOWS_CPU) { @@ -735,7 +737,7 @@ def compile_windows_gpu_mkldnn() { } }] } - +/* def test_static_scala_cpu() { return ['Static build CPU 14.04 Scala' : { node(NODE_LINUX_CPU) { @@ -1343,7 +1345,7 @@ def test_centos7_scala_cpu() { } }] } - +*/ def test_windows_python3_gpu() { return ['Python 3: GPU Win':{ node(NODE_WINDOWS_GPU) { @@ -1427,7 +1429,7 @@ def test_windows_julia10_cpu() { } }] } - +/* def test_qemu_armv7_cpu() { return ['ARMv7 QEMU': { node(NODE_LINUX_CPU) { @@ -1794,5 +1796,5 @@ def test_artifact_repository() { } }] } - +*/ return this diff --git a/ci/safe_docker_run.py b/ci/safe_docker_run.py index 97ece4aecd2f..877ad4ff21be 100755 --- a/ci/safe_docker_run.py +++ b/ci/safe_docker_run.py @@ -38,8 +38,9 @@ from util import config_logging -DOCKER_STOP_TIMEOUT_SECONDS = 3 +DOCKER_STOP_TIMEOUT_SECONDS = 10 CONTAINER_WAIT_SECONDS = 600 +DOCKER_CLIENT_TIMEOUT = 600 class SafeDockerClient: @@ -54,7 +55,7 @@ def _trim_container_id(cid): return cid[:12] def __init__(self): - self._docker_client = docker.from_env() + self._docker_client = docker.from_env(timeout=DOCKER_CLIENT_TIMEOUT) self._containers = set() self._docker_stop_timeout = DOCKER_STOP_TIMEOUT_SECONDS self._container_wait_seconds = CONTAINER_WAIT_SECONDS @@ -245,4 +246,4 @@ def main(command_line_arguments): if __name__ == "__main__": - exit(main(sys.argv[1:])) + exit(main(sys.argv[1:])) \ No newline at end of file diff --git a/ci/windows_dev_env/setup.ps1 b/ci/windows_dev_env/setup.ps1 new file mode 100644 index 000000000000..1edc5d3debc8 --- /dev/null +++ b/ci/windows_dev_env/setup.ps1 @@ -0,0 +1,62 @@ +# 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. + + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest +function Check-Call { + param ( + [scriptblock]$ScriptBlock + ) + Write-Host "Executing $ScriptBlock" + & @ScriptBlock + if (($lastexitcode -ne 0)) { + Write-Error "Execution failed with $lastexitcode" + exit $lastexitcode + } +} +Check-Call { setx PATH "$($env:path);c:\Program Files\CMake\bin;C:\Program Files\opencv\x64\vc15\bin;" /m } +Set-ExecutionPolicy Bypass -Scope Process -Force +$progressPreference = 'silentlyContinue' +Invoke-WebRequest -Uri https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v7.8.4/npp.7.8.4.Installer.exe -OutFile npp.7.8.4.Installer.exe +Check-Call { .\npp.7.8.4.Installer.exe /S } +Invoke-WebRequest -Uri https://chocolatey.org/install.ps1 -OutFile install.ps1 +./install.ps1 +#Check-Call { C:\ProgramData\chocolatey\choco install python2 -y --no-progress } +Check-Call { C:\ProgramData\chocolatey\choco install python --version=3.7.0 --force -y --no-progress -r} +Check-Call { C:\Python37\python -m pip install --upgrade pip } +Check-Call { C:\Python37\python -m pip install -r requirements.txt } +#Check-Call { C:\Python27\python -m pip install --upgrade pip } +#Check-Call { C:\Python27\python -m pip install -r requirements.txt } + +Check-Call { C:\ProgramData\chocolatey\choco install git -y -r --no-progress } +Check-Call { C:\ProgramData\chocolatey\choco install 7zip -y -r --no-progress } +Check-Call { C:\ProgramData\chocolatey\choco install cmake -y -r --no-progress } +Check-Call { C:\ProgramData\chocolatey\choco install ninja -y -r --no-progress } + +# Deps +Check-Call { C:\Python37\python windows_deps_headless_installer.py } + +# Other software +#Check-Call { C:\ProgramData\chocolatey\choco install jom -y } +#Check-Call { C:\ProgramData\chocolatey\choco install mingw -y -r --no-progress } +Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -y -r --no-progress } + +# update path after all software is installed +refreshenv + +Write-Output "End" diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py new file mode 100644 index 000000000000..5dc3b64690e0 --- /dev/null +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -0,0 +1,397 @@ +# 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. + + +"""Dependency installer for Windows""" + +__author__ = 'Pedro Larroy, Chance Bair' +__version__ = '0.2' + +import argparse +import errno +import logging +import os +import psutil +import shutil +import subprocess +import urllib +import stat +import tempfile +import zipfile +from time import sleep +from urllib.error import HTTPError +import logging +from subprocess import check_output, check_call, call +import re +import sys +import urllib.request +import contextlib + +import ssl + +ssl._create_default_https_context = ssl._create_unverified_context + +log = logging.getLogger(__name__) + + +DEPS = { + 'openblas': 'https://windows-post-install.s3-us-west-2.amazonaws.com/OpenBLAS-windows-v0_2_19.zip', + 'opencv': 'https://windows-post-install.s3-us-west-2.amazonaws.com/opencv-windows-4.1.2-vc14_vc15.zip', + 'cudnn': 'https://windows-post-install.s3-us-west-2.amazonaws.com/cudnn-10.2-windows10-x64-v7.6.5.32.zip', + 'nvdriver': 'https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_398.75_server2016.zip', + 'perl': 'http://strawberryperl.com/download/5.30.1.1/strawberry-perl-5.30.1.1-64bit.msi', + 'clang': 'https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/LLVM-9.0.1-win64.exe', + # This installation of CMake breaks windows PATH when executing vcvars, installing from + # chocolatey from powershell instead. + 'cmake': 'https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2-win64-x64.msi' +} + +DEFAULT_SUBPROCESS_TIMEOUT = 3600 + + +@contextlib.contextmanager +def remember_cwd(): + ''' + Restore current directory when exiting context + ''' + curdir = os.getcwd() + try: + yield + finally: + os.chdir(curdir) + + +def retry(target_exception, tries=4, delay_s=1, backoff=2): + """Retry calling the decorated function using an exponential backoff. + + http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/ + original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry + + :param target_exception: the exception to check. may be a tuple of + exceptions to check + :type target_exception: Exception or tuple + :param tries: number of times to try (not retry) before giving up + :type tries: int + :param delay_s: initial delay between retries in seconds + :type delay_s: int + :param backoff: backoff multiplier e.g. value of 2 will double the delay + each retry + :type backoff: int + """ + import time + from functools import wraps + + def decorated_retry(f): + @wraps(f) + def f_retry(*args, **kwargs): + mtries, mdelay = tries, delay_s + while mtries > 1: + try: + return f(*args, **kwargs) + except target_exception as e: + logging.warning("Exception: %s, Retrying in %d seconds...", str(e), mdelay) + time.sleep(mdelay) + mtries -= 1 + mdelay *= backoff + return f(*args, **kwargs) + + return f_retry # true decorator + + return decorated_retry + + +@retry((ValueError, OSError, HTTPError), tries=5, delay_s=2, backoff=5) +def download(url, dest=None, progress=False) -> str: + from urllib.request import urlopen + from urllib.parse import (urlparse, urlunparse) + import progressbar + import http.client + + class ProgressCB(): + def __init__(self): + self.pbar = None + + def __call__(self, block_num, block_size, total_size): + if not self.pbar and total_size > 0: + self.pbar = progressbar.bar.ProgressBar(max_value=total_size) + downloaded = block_num * block_size + if self.pbar: + if downloaded < total_size: + self.pbar.update(downloaded) + else: + self.pbar.finish() + if dest and os.path.isdir(dest): + local_file = os.path.split(urlparse(url).path)[1] + local_path = os.path.normpath(os.path.join(dest, local_file)) + else: + local_path = dest + with urlopen(url) as c: + content_length = c.getheader('content-length') + length = int(content_length) if content_length and isinstance(c, http.client.HTTPResponse) else None + if length and local_path and os.path.exists(local_path) and os.stat(local_path).st_size == length: + log.debug(f"download('{url}'): Already downloaded.") + return local_path + log.debug(f"download({url}, {local_path}): downloading {length} bytes") + if local_path: + with tempfile.NamedTemporaryFile(delete=False) as tmpfd: + urllib.request.urlretrieve(url, filename=tmpfd.name, reporthook=ProgressCB() if progress else None) + shutil.move(tmpfd.name, local_path) + else: + (local_path, _) = urllib.request.urlretrieve(url, reporthook=ProgressCB()) + log.debug(f"download({url}, {local_path}'): done.") + return local_path + + +# Takes arguments and runs command on host. Shell is disabled by default. +# TODO: Move timeout to args +def run_command(*args, shell=False, timeout=DEFAULT_SUBPROCESS_TIMEOUT, **kwargs): + try: + logging.info("Issuing command: {}".format(args)) + res = subprocess.check_output(*args, shell=shell, timeout=timeout).decode("utf-8").replace("\r\n", "\n") + logging.info("Output: {}".format(res)) + except subprocess.CalledProcessError as e: + raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) + return res + + +# Copies source directory recursively to destination. +def copy(src, dest): + try: + shutil.copytree(src, dest) + logging.info("Moved {} to {}".format(src, dest)) + except OSError as e: + # If the error was caused because the source wasn't a directory + if e.errno == errno.ENOTDIR: + shutil.copy(src, dest) + logging.info("Moved {} to {}".format(src, dest)) + else: + raise RuntimeError("copy return with error: {}".format(e)) + + +# Workaround for windows readonly attribute error +def on_rm_error(func, path, exc_info): + # path contains the path of the file that couldn't be removed + # let's just assume that it's read-only and unlink it. + os.chmod(path, stat.S_IWRITE) + os.unlink(path) + + +def install_vs(): + # Visual Studio 2019 + # Components: https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community?view=vs-2019#visual-studio-core-editor-included-with-visual-studio-community-2019 + logging.info("Installing Visual Studio 2019...") + vs_file_path = download('https://windows-post-install.s3-us-west-2.amazonaws.com/vs_community__1246179388.1585201415.exe') + run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(vs_file_path, + vs_file_path.split('\\')[-1]), shell=True) + vs_file_path = vs_file_path + '.exe' + ret = call(vs_file_path + + ' --add Microsoft.VisualStudio.Workload.ManagedDesktop' + ' --add Microsoft.VisualStudio.Workload.NetCoreTools' + ' --add Microsoft.VisualStudio.Workload.NetWeb' + ' --add Microsoft.VisualStudio.Workload.Node' + ' --add Microsoft.VisualStudio.Workload.Office' + ' --add Microsoft.VisualStudio.Component.TypeScript.2.0' + ' --add Microsoft.VisualStudio.Component.TestTools.WebLoadTest' + ' --add Component.GitHub.VisualStudio' + ' --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core' + ' --add Microsoft.VisualStudio.Component.Static.Analysis.Tools' + ' --add Microsoft.VisualStudio.Component.VC.CMake.Project' + ' --add Microsoft.VisualStudio.Component.VC.140' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.18362.Desktop' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.18362.UWP' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.18362.UWP.Native' + ' --add Microsoft.VisualStudio.ComponentGroup.Windows10SDK.18362' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.16299' + ' --wait' + ' --passive' + ' --norestart' + ) + + if ret == 3010 or ret == 0: + # 3010 is restart required + logging.info("VS install successful.") + else: + raise RuntimeError("VS failed to install, exit status {}".format(ret)) + # Workaround for --wait sometimes ignoring the subprocesses doing component installs + + def vs_still_installing(): + return {'vs_installer.exe', 'vs_installershell.exe', 'vs_setup_bootstrapper.exe'} & set(map(lambda process: process.name(), psutil.process_iter())) + timer = 0 + while vs_still_installing() and timer < DEFAULT_SUBPROCESS_TIMEOUT: + logging.warning("VS installers still running for %d s", timer) + if timer % 60 == 0: + logging.info("Waiting for Visual Studio to install for the last {} seconds".format(str(timer))) + sleep(1) + timer += 1 + if vs_still_installing(): + logging.warning("VS install still running after timeout (%d)", DEFAULT_SUBPROCESS_TIMEOUT) + else: + logging.info("Visual studio install complete.") + + +def install_cmake(): + logging.info("Installing CMAKE") + cmake_file_path = download(DEPS['cmake'], '.') + check_call(['msiexec ', '/n', '/passive', '/i', cmake_file_path]) + logging.info("CMAKE install complete") + + +def install_perl(): + logging.info("Installing Perl") + with tempfile.TemporaryDirectory() as tmpdir: + perl_file_path = download(DEPS['perl'], tmpdir) + check_call(['msiexec ', '/n', '/passive', '/i', perl_file_path]) + logging.info("Perl install complete") + + +def install_clang(): + logging.info("Installing Clang") + with tempfile.TemporaryDirectory() as tmpdir: + clang_file_path = download(DEPS['clang'], tmpdir) + run_command(clang_file_path + " /S /D=C:\\Program Files\\LLVM") + logging.info("Clang install complete") + + +def install_openblas(): + logging.info("Installing OpenBLAS") + local_file = download(DEPS['openblas']) + with zipfile.ZipFile(local_file, 'r') as zip: + zip.extractall("C:\\Program Files") + run_command("PowerShell Set-ItemProperty -path 'hklm:\\system\\currentcontrolset\\control\\session manager\\environment' -Name OpenBLAS_HOME -Value 'C:\\Program Files\\OpenBLAS-windows-v0_2_19'") + logging.info("Openblas Install complete") + + +def install_mkl(): + logging.info("Installing MKL 2019.3.203...") + file_path = download("http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/15247/w_mkl_2019.3.203.exe") + run_command("{} --silent --remove-extracted-files yes --a install -output=C:\mkl-install-log.txt -eula=accept".format(file_path)) + logging.info("MKL Install complete") + + +def install_opencv(): + logging.info("Installing OpenCV") + with tempfile.TemporaryDirectory() as tmpdir: + local_file = download(DEPS['opencv']) + with zipfile.ZipFile(local_file, 'r') as zip: + zip.extractall(tmpdir) + copy(f'{tmpdir}\\opencv\\build', r'c:\Program Files\opencv') + + run_command("PowerShell Set-ItemProperty -path 'hklm:\\system\\currentcontrolset\\control\\session manager\\environment' -Name OpenCV_DIR -Value 'C:\\Program Files\\opencv'") + logging.info("OpenCV install complete") + + +def install_cudnn(): + # cuDNN + logging.info("Installing cuDNN") + with tempfile.TemporaryDirectory() as tmpdir: + local_file = download(DEPS['cudnn']) + with zipfile.ZipFile(local_file, 'r') as zip: + zip.extractall(tmpdir) + copy(tmpdir+"\\cuda\\bin\\cudnn64_7.dll", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\bin") + copy(tmpdir+"\\cuda\\include\\cudnn.h", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\include") + copy(tmpdir+"\\cuda\\lib\\x64\\cudnn.lib", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\lib\\x64") + logging.info("cuDNN install complete") + + +def install_gpu_driver(force=False): + if has_gpu() or force: + logging.info("GPU detected") + install_nvdriver() + + +def install_nvdriver(): + logging.info("Installing Nvidia Display Drivers...") + with tempfile.TemporaryDirectory(prefix='nvidia drivers') as tmpdir: + local_file = download(DEPS['nvdriver']) + with zipfile.ZipFile(local_file, 'r') as zip: + zip.extractall(tmpdir) + with remember_cwd(): + os.chdir(tmpdir) + check_call(".\setup.exe -noreboot -clean -noeula -nofinish -passive") + logging.info("NVidia install complete") + + +def install_cuda(): + # CUDA 10.2 and patches + logging.info("Installing CUDA 10.2 and Patches...") + cuda_10_2_file_path = download( + 'http://developer.download.nvidia.com/compute/cuda/10.2/Prod/network_installers/cuda_10.2.89_win10_network.exe') + check_call("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_10_2_file_path, + cuda_10_2_file_path.split('\\')[-1]), shell=True) + cuda_10_2_file_path = cuda_10_2_file_path + '.exe' + check_call(cuda_10_2_file_path + ' -s') + + +def add_paths(): + # TODO: Add python paths (python -> C:\\Python37\\python.exe, python2 -> C:\\Python27\\python.exe) + logging.info("Adding Windows Kits to PATH...") + current_path = run_command( + "PowerShell (Get-Itemproperty -path 'hklm:\\system\\currentcontrolset\\control\\session manager\\environment' -Name Path).Path") + current_path = current_path.rstrip() + logging.debug("current_path: {}".format(current_path)) + new_path = current_path + \ + ";C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.16299.0\\x86;C:\\Program Files\\OpenBLAS-windows-v0_2_19\\bin;C:\\Program Files\\LLVM\\bin" + logging.debug("new_path: {}".format(new_path)) + run_command("PowerShell Set-ItemProperty -path 'hklm:\\system\\currentcontrolset\\control\\session manager\\environment' -Name Path -Value '" + new_path + "'") + + +def has_gpu(): + gpu_family = {'p2', 'p3', 'g4dn', 'p3dn', 'g3', 'g2', 'g3s'} + + def instance_family(): + return urllib.request.urlopen('http://instance-data/latest/meta-data/instance-type').read().decode().split('.')[0] + try: + return instance_family() in gpu_family + except: + return False + + +def script_name() -> str: + """:returns: script name with leading paths removed""" + return os.path.split(sys.argv[0])[1] + + +def main(): + logging.getLogger().setLevel(os.environ.get('LOGLEVEL', logging.DEBUG)) + logging.basicConfig(stream=sys.stdout, format='{}: %(asctime)sZ %(levelname)s %(message)s'.format(script_name())) + + parser = argparse.ArgumentParser() + parser.add_argument('-g', '--gpu', + help='GPU install', + default=False, + action='store_true') + args = parser.parse_args() + if args.gpu or has_gpu(): + install_gpu_driver(force=True) + else: + logging.info("GPU environment skipped") + # needed for compilation with nvcc + install_cuda() + install_cudnn() + install_vs() + # installed from choco + # install_cmake() + install_openblas() + install_mkl() + install_opencv() + install_perl() + install_clang() + add_paths() + + +if __name__ == "__main__": + exit(main()) diff --git a/docs/static_site/src/pages/get_started/windows_setup.md b/docs/static_site/src/pages/get_started/windows_setup.md index 559c7e4fa989..046ddd563335 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -137,95 +137,27 @@ Check the chart below for other options or refer to [PyPI for other MXNet pip pa ## Build from Source -**IMPORTANT: It is recommended that you review the [build from source guide](build_from_source) first.** It describes many of the build options that come with MXNet in more detail. You may decide to install additional dependencies and modify your build flags after reviewing this material. -We provide two primary options to build and install MXNet yourself using [Microsoft Visual Studio 2017](https://www.visualstudio.com/downloads/) or [Microsoft Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/). +For automated setting up of developer environment in windows, use script bundle from the +![ci/windows_dev_env](https://github.com/apache/incubator-mxnet/tree/master/ci/windows_dev_env/) +folder. Copy to a local directory and execute: -**NOTE:** Visual Studio 2017's compiler is `vc15`. This is not to be confused with Visual Studio 2015's compiler, `vc14`. - -You also have the option to install MXNet with MKL or MKL-DNN. In this case it is recommended that you refer to the [MKLDNN_README](https://mxnet.apache.org/api/python/docs/tutorials/performance/backend/mkldnn/mkldnn_readme.html). - -**Option 1: Build with Microsoft Visual Studio 2017 (VS2017)** - -To build and install MXNet yourself using [VS2017](https://www.visualstudio.com/downloads/), you need the following dependencies. You may try a newer version of a particular dependency, but please open a pull request or [issue](https://github.com/apache/incubator-mxnet/issues/new) to update this guide if a newer version is validated. - -1. Install or update VS2017. - - If [VS2017](https://www.visualstudio.com/downloads/) is not already installed, download and install it. You can download and install the free community edition. - - When prompted about installing Git, go ahead and install it. - - If VS2017 is already installed you will want to update it. Proceed to the next step to modify your installation. You will be given the opportunity to update VS2017 as well -1. Follow the [instructions for opening the Visual Studio Installer](https://docs.microsoft.com/en-us/visualstudio/install/modify-visual-studio) to modify `Individual components`. -1. Once in the Visual Studio Installer application, update as needed, then look for and check `VC++ 2017 version 15.4 v14.11 toolset`, and click `Modify`. -1. Change the version of the Visual studio 2017 to v14.11 using the following command (by default the VS2017 is installed in the following path): -``` -"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.11 -``` -1. Download and install [CMake](https://cmake.org/download) if it is not already installed. [CMake v3.12.2](https://cmake.org/files/v3.12/cmake-3.12.2-win64-x64.msi) has been tested with MXNet. -1. Download and run the [OpenCV](https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.4.1/opencv-3.4.1-vc14_vc15.exe/download) package. There are more recent versions of OpenCV, so please create an issue/PR to update this info if you validate one of these later versions. -1. This will unzip several files. You can place them in another directory if you wish. We will use `C:\utils`(```mkdir C:\utils```) as our default path. -1. Set the environment variable `OpenCV_DIR` to point to the OpenCV build directory that you just unzipped. Start ```cmd``` and type `set OpenCV_DIR=C:\utils\opencv\build`. -1. If you don’t have the Intel Math Kernel Library (MKL) installed, you can install it and follow the [MKLDNN_README](https://mxnet.apache.org/api/python/docs/tutorials/performance/backend/mkldnn/mkldnn_readme.html) from here, or you can use OpenBLAS. These instructions will assume you're using OpenBLAS. -1. Download the [OpenBlas](https://sourceforge.net/projects/openblas/files/v0.2.19/OpenBLAS-v0.2.19-Win64-int32.zip/download) package. Later versions of OpenBLAS are available, but you would need to build from source. v0.2.19 is the most recent version that ships with binaries. Contributions of more recent binaries would be appreciated. -1. Unzip the file, rename it to ```OpenBLAS``` and put it under `C:\utils`. You can place the unzipped files and folders in another directory if you wish. -1. Set the environment variable `OpenBLAS_HOME` to point to the OpenBLAS directory that contains the `include` and `lib` directories and type `set OpenBLAS_HOME=C:\utils\OpenBLAS` on the command prompt(```cmd```). -1. Download and install [CUDA](https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal). If you already had CUDA, then installed VS2017, you should reinstall CUDA now so that you get the CUDA toolkit components for VS2017 integration. Note that the latest CUDA version supported by MXNet is [9.2](https://developer.nvidia.com/cuda-92-download-archive). You might also want to find other CUDA verion on the [Legacy Releases](https://developer.nvidia.com/cuda-toolkit-archive). -1. Download and install cuDNN. To get access to the download link, register as an NVIDIA community user. Then follow the [link](http://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#install-windows) to install the cuDNN and put those libraries into ```C:\cuda```. -1. Download and install [git](https://git-for-windows.github.io/) if you haven't already. - -After you have installed all of the required dependencies, build the MXNet source code: - -1. Start ```cmd``` in windows. -2. Download the MXNet source code from GitHub by using following command: -``` -cd C:\ -git clone https://github.com/apache/incubator-mxnet.git --recursive -``` -3. Verify that the `DCUDNN_INCLUDE` and `DCUDNN_LIBRARY` environment variables are pointing to the `include` folder and `cudnn.lib` file of your CUDA installed location, and `C:\incubator-mxnet` is the location of the source code you just cloned in the previous step. -4. Create a build dir using the following command and go to the directory, for example: -``` -mkdir C:\incubator-mxnet\build -cd C:\incubator-mxnet\build -``` -5. Compile the MXNet source code with `cmake` by using following command: ``` -cmake -G "Visual Studio 15 2017 Win64" -T cuda=9.2,host=x64 -DUSE_CUDA=1 -DUSE_CUDNN=1 -DUSE_NVRTC=1 -DUSE_OPENCV=1 -DUSE_OPENMP=1 -DUSE_BLAS=open -DUSE_LAPACK=1 -DUSE_DIST_KVSTORE=0 -DCUDA_ARCH_LIST=Common -DCUDA_TOOLSET=9.2 -DCUDNN_INCLUDE=C:\cuda\include -DCUDNN_LIBRARY=C:\cuda\lib\x64\cudnn.lib "C:\incubator-mxnet" +.\setup.ps1 ``` -* Make sure you set the environment variables correctly (OpenBLAS_HOME, OpenCV_DIR) and change the version of the Visual studio 2017 to v14.11 before enter above command. -6. After the CMake successfully completed, compile the MXNet source code by using following command: -``` -msbuild mxnet.sln /p:Configuration=Release;Platform=x64 /maxcpucount -``` - - -**Option 2: Build with Visual Studio 2015** - -To build and install MXNet yourself using [Microsoft Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/), you need the following dependencies. You may try a newer version of a particular dependency, but please open a pull request or [issue](https://github.com/apache/incubator-mxnet/issues/new) to update this guide if a newer version is validated. -1. If [Microsoft Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/) is not already installed, download and install it. You can download and install the free community edition. At least Update 3 of Microsoft Visual Studio 2015 is required to build MXNet from source. Upgrade via it's ```Tools -> Extensions and Updates... | Product Updates``` menu. -2. Download and install [CMake](https://cmake.org/) if it is not already installed. -3. Download and install [OpenCV](http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/opencv-3.0.0.exe/download). -4. Unzip the OpenCV package. -5. Set the environment variable ```OpenCV_DIR``` to point to the ```OpenCV build directory``` (```C:\opencv\build\x64\vc14``` for example). Also, you need to add the OpenCV bin directory (```C:\opencv\build\x64\vc14\bin``` for example) to the ``PATH`` variable. -6. If you don't have the Intel Math Kernel Library (MKL) installed, download and install [OpenBlas](http://sourceforge.net/projects/openblas/files/v0.2.14/). -7. Set the environment variable ```OpenBLAS_HOME``` to point to the ```OpenBLAS``` directory that contains the ```include``` and ```lib``` directories. Typically, you can find the directory in ```C:\Program files (x86)\OpenBLAS\```. -8. Download and install [CUDA](https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64) and [cuDNN](https://developer.nvidia.com/cudnn). To get access to the download link, register as an NVIDIA community user. -9. Set the environment variable ```CUDACXX``` to point to the ```CUDA Compiler```(```C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin\nvcc.exe``` for example). -10. Set the environment variable ```CUDNN_ROOT``` to point to the ```cuDNN``` directory that contains the ```include```, ```lib``` and ```bin``` directories (```C:\Downloads\cudnn-9.1-windows7-x64-v7\cuda``` for example). +This will install the recommended VS Community, Python, git, and other dependencies needed to build in windows. +Then use the following to build. The `--flavour` option selects the build flavour. Use +`.\build_windows.py --help` to list the different build flavours. -After you have installed all of the required dependencies, build the MXNet source code: +``` +C:\Python37\python.exe .\ci\build_windows.py +``` -1. Download the MXNet source code from [GitHub](https://github.com/apache/incubator-mxnet) (make sure you also download third parties submodules e.g. ```git clone --recurse-submodules```). -2. Use [CMake](https://cmake.org/) to create a Visual Studio solution in ```./build```. -3. In Visual Studio, open the solution file,```.sln```, and compile it. These commands produce a library called ```mxnet.dll``` in the ```./build/Release/``` or ```./build/Debug``` folder. -  -Next, we install ```graphviz``` library that we use for visualizing network graphs you build on MXNet. We will also install [Jupyter Notebook](http://jupyter.readthedocs.io/) used for running MXNet tutorials and examples. -- Install ```graphviz``` by downloading MSI installer from [Graphviz Download Page](https://graphviz.gitlab.io/_pages/Download/Download_windows.html). -**Note** Make sure to add graphviz executable path to PATH environment variable. Refer [here for more details](http://stackoverflow.com/questions/35064304/runtimeerror-make-sure-the-graphviz-executables-are-on-your-systems-path-aft) -- Install ```Jupyter``` by installing [Anaconda for Python 2.7](https://www.anaconda.com/download/) -**Note** Do not install Anaconda for Python 3.5. MXNet has a few compatibility issues with Python 3.5. -We have installed MXNet core library. Next, we will install MXNet interface package for programming language of your choice: +Now that you have installed MXNet core library, you are ready to optionally install an MXNet interface package for a programming language of your choice: - [Python](#install-the-mxnet-package-for-python) - [R](#install-the-mxnet-package-for-r) - [Julia](#install-the-mxnet-package-for-julia) @@ -233,30 +165,9 @@ We have installed MXNet core library. Next, we will install MXNet interface pack ## Install the MXNet Package for Python -These steps are required after building from source. If you already installed MXNet by using pip, you do not need to do these steps to use MXNet with Python. - -1. Install ```Python``` using windows installer available [here](https://www.python.org/downloads/release/python-2712/). -2. Install ```Numpy``` using windows installer available [here](https://scipy.org/index.html). -3. Start ```cmd``` and create a folder named ```common```(```mkdir C:\common```) -4. Download the [mingw64_dll.zip](https://sourceforge.net/projects/openblas/files/v0.2.12/mingw64_dll.zip/download), unzip and copy three libraries (.dll files) that openblas.dll depends on to ```C:\common```. -5. Copy the required .dll file to ```C:\common``` and make sure following libraries (.dll files) in the folder. -``` -libgcc_s_seh-1.dll (in mingw64_dll) -libgfortran-3.dll (in mingw64_dll) -libquadmath-0.dll (in mingw64_dll) -libopenblas.dll (in OpenBlas folder you download) -opencv_world341.dll (in OpenCV folder you download) -``` -6. Add ```C:\common``` to Environment Variables. - * Type ```control sysdm.cpl``` on ```cmp``` - * Select the **Advanced tab** and click **Environment Variables** - * Double click the **Path** and click **New** - * Add ```C:\common``` and click OK -7. Use setup.py to install the package. ```bash # Assuming you are in root mxnet source code folder - cd python - python setup.py install + pip install --upgrade --force-reinstall -e python ``` Done! We have installed MXNet with Python interface. @@ -487,4 +398,4 @@ For more details about installing and using MXNet with Julia, see the [MXNet Jul ## Installing the MXNet Package for Scala -MXNet-Scala is not yet available for Windows. +MXNet-Scala is not yet available for Windows. \ No newline at end of file