From e4dff32c5ea6fb54b541bf11ba89da4639ad5954 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 2 Jan 2020 15:40:43 -0800 Subject: [PATCH 01/25] Update documentation with automated windows environment scripts --- .../src/pages/get_started/windows_setup.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..ebefba8b0eea 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -137,6 +137,25 @@ Check the chart below for other options or refer to [PyPI for other MXNet pip pa ## Build from Source + + +### *NEW* Automated environment setup. + +For automated setting up of developer environment in windows, use script bundle from the ![windows.zip](https://windows-post-install.s3-us-west-2.amazonaws.com/windows.zip) +file. Extract into a folder and execute the following command in a powershell console: + +``` +.\setup.ps1 +``` + +This will install VS Community 2017, Python, and other dependencies needed to build in windows. +After that, follow the steps below starting from "build the MXNet source code" section. + + + +### Manual installation. + + **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/). From 08787d67d6701ec525f90ff088a7c85fa3a25653 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 2 Jan 2020 17:48:34 -0800 Subject: [PATCH 02/25] Add scripts --- ci/windows_dev_env/requirements.txt | 4 + ci/windows_dev_env/setup.ps1 | 51 +++ .../windows_deps_headless_installer.py | 364 ++++++++++++++++++ .../src/pages/get_started/windows_setup.md | 10 +- 4 files changed, 424 insertions(+), 5 deletions(-) create mode 100644 ci/windows_dev_env/requirements.txt create mode 100644 ci/windows_dev_env/setup.ps1 create mode 100755 ci/windows_dev_env/windows_deps_headless_installer.py diff --git a/ci/windows_dev_env/requirements.txt b/ci/windows_dev_env/requirements.txt new file mode 100644 index 000000000000..1e5334521b15 --- /dev/null +++ b/ci/windows_dev_env/requirements.txt @@ -0,0 +1,4 @@ +psutil +boto3 +python-jenkins +progressbar2 diff --git a/ci/windows_dev_env/setup.ps1 b/ci/windows_dev_env/setup.ps1 new file mode 100644 index 000000000000..67132072fc5a --- /dev/null +++ b/ci/windows_dev_env/setup.ps1 @@ -0,0 +1,51 @@ +# 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 + } +} +Set-ExecutionPolicy Bypass -Scope Process -Force +Invoke-WebRequest -Uri https://chocolatey.org/install.ps1 -OutFile install.ps1 +./install.ps1 +Check-Call { C:\ProgramData\chocolatey\choco install python2 -y } +Check-Call { C:\ProgramData\chocolatey\choco install python --version=3.7.0 --force -y } +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 } +# 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 7zip -y } +Check-Call { C:\ProgramData\chocolatey\choco install mingw -y } +Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -y } +Check-Call { C:\ProgramData\chocolatey\choco install git -y } + +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 100755 index 000000000000..5dc462d171f1 --- /dev/null +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -0,0 +1,364 @@ +# 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 +import re + +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-v3_4_1-vc14.zip', + 'cudnn': 'https://windows-post-install.s3-us-west-2.amazonaws.com/cudnn-9.2-windows10-x64-v7.4.2.24.zip', + 'nvdriver': 'https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_398.75_server2016.zip', + 'cmake': 'https://windows-post-install.s3-us-west-2.amazonaws.com/cmake-3.15.5-win64-x64.msi' +} + + +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=True) -> 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.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): + try: + logging.info("Issuing command: {}".format(args)) + res = subprocess.check_output(args, shell=shell, timeout=1800).decode("utf-8").replace("\r\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 CE 2017 + # Path: C:\Program Files (x86)\Microsoft Visual Studio 14.0 + # Components: https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community?view=vs-2017#visual-studio-core-editor-included-with-visual-studio-community-2017 + logging.info("Installing Visual Studio CE 2017...") + vs_file_path = download('https://aka.ms/eac464') + 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' + run_command(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.15063.Desktop' \ + ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP' \ + ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP.Native' \ + ' --add Microsoft.VisualStudio.ComponentGroup.Windows10SDK.15063' \ + ' --wait' \ + ' --passive' \ + ' --norestart' + ) + # Workaround for --wait sometimes ignoring the subprocesses doing component installs + timer = 0 + while {'vs_installer.exe', 'vs_installershell.exe', 'vs_setup_bootstrapper.exe'} & set(map(lambda process: process.name(), psutil.process_iter())): + if timer % 60 == 0: + logging.info("Waiting for Visual Studio to install for the last {} seconds".format(str(timer))) + timer += 1 + logging.info("Visual studio install complete.") + + + +def install_cmake(): + logging.info("Installing CMAKE") + cmake_file_path = download(DEPS['cmake']) + run_command("msiexec /i {} /quiet /norestart ADD_CMAKE_TO_PATH=System".format(cmake_file_path)) + logging.info("CMAKE 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") + local_file = download(DEPS['opencv']) + 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 OpenCV_DIR -Value 'C:\\Program Files\\OpenCV-windows-v3_4_1-vc14'") + 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\\v9.2\\bin") + copy(tmpdir+"\\cuda\\include\\cudnn.h","C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\include") + copy(tmpdir+"\\cuda\\lib\\x64\\cudnn.lib","C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\lib\\x64") + logging.info("cuDNN install complete") + + +def install_nvdriver(): + logging.info("Installing Nvidia Display Drivers...") + with tempfile.TemporaryDirectory() as tmpdir: + local_file = download(DEPS['nvdriver']) + with zipfile.ZipFile(local_file, 'r') as zip: + zip.extractall(tmpdir) + run_command(tmpdir + "\\setup.exe /n /s /noeula /nofinish") + logging.info("NVidia install complete") + + +def install_cuda(): + # CUDA 9.2 and patches + logging.info("Installing CUDA 9.2 and Patches...") + cuda_9_2_file_path = download('https://developer.nvidia.com/compute/cuda/9.2/Prod2/network_installers2/cuda_9.2.148_win10_network') + run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_9_2_file_path, cuda_9_2_file_path.split('\\')[-1]), shell=True) + cuda_9_2_file_path = cuda_9_2_file_path + '.exe' + run_command(cuda_9_2_file_path \ + + ' -s nvcc_9.2' \ + + ' cuobjdump_9.2' \ + + ' nvprune_9.2' \ + + ' cupti_9.2' \ + + ' gpu_library_advisor_9.2' \ + + ' memcheck_9.2' \ + + ' nvdisasm_9.2' \ + + ' nvprof_9.2' \ + + ' visual_profiler_9.2' \ + + ' visual_studio_integration_9.2' \ + + ' demo_suite_9.2' \ + + ' documentation_9.2' \ + + ' cublas_9.2' \ + + ' cublas_dev_9.2' \ + + ' cudart_9.2' \ + + ' cufft_9.2' \ + + ' cufft_dev_9.2' \ + + ' curand_9.2' \ + + ' curand_dev_9.2' \ + + ' cusolver_9.2' \ + + ' cusolver_dev_9.2' \ + + ' cusparse_9.2' \ + + ' cusparse_dev_9.2' \ + + ' nvgraph_9.2' \ + + ' nvgraph_dev_9.2' \ + + ' npp_9.2' \ + + ' npp_dev_9.2' \ + + ' nvrtc_9.2' \ + + ' nvrtc_dev_9.2' \ + + ' nvml_dev_9.2' \ + + ' occupancy_calculator_9.2' + ) + # Download patches and assume less than 100 patches exist + for patch_number in range(1, 100): + if patch_number == 100: + raise Exception('Probable patch loop: CUDA patch downloader is downloading at least 100 patches!') + cuda_9_2_patch_file_path = download("https://developer.nvidia.com/compute/cuda/9.2/Prod2/patches/{0}/cuda_9.2.148.{0}_windows".format(patch_number)) + if cuda_9_2_patch_file_path == 404: + break + run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_9_2_patch_file_path, cuda_9_2_patch_file_path.split('\\')[-1]), shell=True) + cuda_9_2_patch_file_path = cuda_9_2_patch_file_path + '.exe' + run_command("{} -s".format(cuda_9_2_patch_file_path)) + + +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") + 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" + 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(): + hwinfo = check_output(['powershell','gwmi', 'win32_pnpEntity']) + m = re.search('3D Video', hwinfo.decode()) + if m: + return True + 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(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: + if has_gpu(): + logging.info("GPU detected") + install_nvdriver() + install_cuda() + install_cudnn() + else: + logging.info("GPU not detected") + install_vs() + install_cmake() + install_openblas() + install_mkl() + install_opencv() + 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 ebefba8b0eea..79b692a35f9f 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -141,16 +141,16 @@ Check the chart below for other options or refer to [PyPI for other MXNet pip pa ### *NEW* Automated environment setup. -For automated setting up of developer environment in windows, use script bundle from the ![windows.zip](https://windows-post-install.s3-us-west-2.amazonaws.com/windows.zip) -file. Extract into a folder and execute the following command in a powershell console: +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: ``` .\setup.ps1 ``` -This will install VS Community 2017, Python, and other dependencies needed to build in windows. -After that, follow the steps below starting from "build the MXNet source code" section. - +This will install the recommended VS Community, Python, git, and other dependencies needed to build in windows. +After that, follow the steps below starting from "build the MXNet source code" section below. ### Manual installation. From 5ee2ab1726d92a83fb9f17fb6f66a1b35acbea16 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 2 Jan 2020 18:04:57 -0800 Subject: [PATCH 03/25] Fix import --- ci/windows_dev_env/windows_deps_headless_installer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index 5dc462d171f1..ffe3e30a9aa3 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -37,6 +37,7 @@ import logging from subprocess import check_output import re +import sys log = logging.getLogger(__name__) From bdda75cd1f4581d79960fe373be39b8054f82d35 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 2 Jan 2020 18:20:12 -0800 Subject: [PATCH 04/25] Remove all the useless garbage for the manual windows setup --- .../src/pages/get_started/windows_setup.md | 121 ++---------------- 1 file changed, 11 insertions(+), 110 deletions(-) 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 79b692a35f9f..bb21ca0c68c9 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -138,9 +138,6 @@ Check the chart below for other options or refer to [PyPI for other MXNet pip pa ## Build from Source - -### *NEW* Automated environment setup. - 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: @@ -152,130 +149,34 @@ folder. Copy to a local directory and execute: This will install the recommended VS Community, Python, git, and other dependencies needed to build in windows. After that, follow the steps below starting from "build the MXNet source code" section below. - -### Manual installation. - - -**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/). - -**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" ``` -* 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: +C:\Python37\python.exe .\ci\build_windows.py ``` -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. +These commands produce a library called ```mxnet.dll``` in the ```./build/Release/``` or ```./build/Debug``` folder. -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). -After you have installed all of the required dependencies, build the MXNet source code: +We have installed MXNet core library. Next, we will install MXNet interface package for 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) +- **Scala** is not yet available for Windows -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. +### Optional step: -  -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``` 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: -- [Python](#install-the-mxnet-package-for-python) -- [R](#install-the-mxnet-package-for-r) -- [Julia](#install-the-mxnet-package-for-julia) -- **Scala** is not yet available for Windows ## 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. +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. From 4e038241a3996fd01a00e5608768ca553dfb73a9 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 3 Jan 2020 20:18:57 -0800 Subject: [PATCH 05/25] Fix bugs, turn off gpu autodetect --- .../windows_deps_headless_installer.py | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index ffe3e30a9aa3..f75981eaa864 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -39,6 +39,10 @@ import re import sys +import ssl + +ssl._create_default_https_context = ssl._create_unverified_context + log = logging.getLogger(__name__) @@ -50,6 +54,8 @@ 'cmake': 'https://windows-post-install.s3-us-west-2.amazonaws.com/cmake-3.15.5-win64-x64.msi' } +DEFAULT_SUBPROCESS_TIMEOUT=3600 + def retry(target_exception, tries=4, delay_s=1, backoff=2): """Retry calling the decorated function using an exponential backoff. @@ -134,10 +140,10 @@ def __call__(self, block_num, block_size, total_size): # Takes arguments and runs command on host. Shell is disabled by default. # TODO: Move timeout to args -def run_command(args, shell=False): +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=1800).decode("utf-8").replace("\r\n", "") + 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)) @@ -196,13 +202,19 @@ def install_vs(): ' --norestart' ) # 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_installer.exe', 'vs_installershell.exe', 'vs_setup_bootstrapper.exe'} & set(map(lambda process: process.name(), psutil.process_iter())): + 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 - logging.info("Visual studio install complete.") - + 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(): @@ -299,16 +311,6 @@ def install_cuda(): + ' nvml_dev_9.2' \ + ' occupancy_calculator_9.2' ) - # Download patches and assume less than 100 patches exist - for patch_number in range(1, 100): - if patch_number == 100: - raise Exception('Probable patch loop: CUDA patch downloader is downloading at least 100 patches!') - cuda_9_2_patch_file_path = download("https://developer.nvidia.com/compute/cuda/9.2/Prod2/patches/{0}/cuda_9.2.148.{0}_windows".format(patch_number)) - if cuda_9_2_patch_file_path == 404: - break - run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_9_2_patch_file_path, cuda_9_2_patch_file_path.split('\\')[-1]), shell=True) - cuda_9_2_patch_file_path = cuda_9_2_patch_file_path + '.exe' - run_command("{} -s".format(cuda_9_2_patch_file_path)) def add_paths(): @@ -322,9 +324,11 @@ def add_paths(): def has_gpu(): + # FIXME: this is too simplistic and not reliable as of now. hwinfo = check_output(['powershell','gwmi', 'win32_pnpEntity']) - m = re.search('3D Video', hwinfo.decode()) - if m: + m_g3 = re.search('3D Video', hwinfo.decode()) # G3 + m_p3 = re.search('NVIDIA Tesla', hwinfo.decode()) # P3 + if m_g3 or m_p3: return True return False @@ -336,7 +340,7 @@ def script_name() -> str: def main(): logging.getLogger().setLevel(os.environ.get('LOGLEVEL', logging.DEBUG)) - logging.basicConfig(format='{}: %(asctime)sZ %(levelname)s %(message)s'.format(script_name())) + logging.basicConfig(stream=sys.stdout, format='{}: %(asctime)sZ %(levelname)s %(message)s'.format(script_name())) parser = argparse.ArgumentParser() @@ -345,14 +349,13 @@ def main(): default=False, action='store_true') args = parser.parse_args() - #if args.gpu: - if has_gpu(): + if args.gpu: logging.info("GPU detected") install_nvdriver() install_cuda() install_cudnn() else: - logging.info("GPU not detected") + logging.info("GPU environment skipped") install_vs() install_cmake() install_openblas() From 04cf74489978b035e7fd92a651bd8478b3b94634 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 03:36:27 +0000 Subject: [PATCH 06/25] vs update changes and cmake --- ci/build_windows.py | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index b334b68fef2c..979cf0012f86 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -39,7 +39,8 @@ KNOWN_VCVARS = { '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\vcvarsx86_amd64.bat', + 'VS 2019': r'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat' } @@ -145,35 +146,23 @@ def windows_build(args): mxnet_root = get_mxnet_root() logging.info("Found MXNet root: {}".format(mxnet_root)) - url = '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/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) - - 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) - 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)) - - 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)))) - windows_package(args) + with remember_cwd(): + os.chdir(path) + cmd = "\"{}\" && cmake -G \"NMake Makefiles JOM\" {} {}".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)) + + 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)))) + windows_package(args) def windows_package(args): pkgfile = 'windows_package.7z' @@ -230,7 +219,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", From 4633bae47522c427a168df028f02d6c08b7027b3 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 23:26:06 +0000 Subject: [PATCH 07/25] Use vs2017, change opencv path --- ci/build_windows.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 979cf0012f86..55fbe8b9b05f 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -219,7 +219,7 @@ def main(): parser.add_argument("--vcvars", help="vcvars batch file location, typically inside vs studio install dir", - default=KNOWN_VCVARS['VS 2019'], + default=KNOWN_VCVARS['VS 2017'], type=str) parser.add_argument("--arch", @@ -242,7 +242,7 @@ def main(): 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" + os.environ["OpenCV_DIR"] = "C:\\Program Files\\opencv\\build" if 'CUDA_PATH' not in os.environ: os.environ["CUDA_PATH"] = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2" if 'MKL_ROOT' not in os.environ: From 44a2dd74367e95dba2acdc3d484595ee9afa7393 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 23:29:44 +0000 Subject: [PATCH 08/25] Revert to VS 2015, VS 2017 fails with out of heap VS 2019 fails with missing kernel32.lib --- ci/build_windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 55fbe8b9b05f..6b4fb3d6eea8 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -219,7 +219,7 @@ def main(): parser.add_argument("--vcvars", help="vcvars batch file location, typically inside vs studio install dir", - default=KNOWN_VCVARS['VS 2017'], + default=KNOWN_VCVARS['VS 2015'], type=str) parser.add_argument("--arch", From 6f043d18deca92457ca6c8eacb6d7b041e67dd20 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 10 Jan 2020 01:25:10 +0000 Subject: [PATCH 09/25] build with ninja --- ci/build_windows.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 6b4fb3d6eea8..8462348cd1fb 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -154,8 +154,8 @@ def windows_build(args): 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) From fef129e1b88c7b7578b0d56c88226fcb4cab41cb Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 10 Jan 2020 01:27:34 +0000 Subject: [PATCH 10/25] Switch to ninja, remove uneccesary OpenCV_DIR var --- ci/build_windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 8462348cd1fb..544eafa2e5d5 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -148,7 +148,7 @@ def windows_build(args): with remember_cwd(): os.chdir(path) - cmd = "\"{}\" && cmake -G \"NMake Makefiles JOM\" {} {}".format(args.vcvars, + cmd = "\"{}\" && cmake -G Ninja {} {}".format(args.vcvars, CMAKE_FLAGS[args.flavour], mxnet_root) logging.info("Generating project with CMake:\n{}".format(cmd)) @@ -241,8 +241,8 @@ def main(): 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\\build" + #if 'OpenCV_DIR' not in os.environ: + # os.environ["OpenCV_DIR"] = "C:\\Program Files\\opencv\\build" if 'CUDA_PATH' not in os.environ: os.environ["CUDA_PATH"] = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2" if 'MKL_ROOT' not in os.environ: From f43a504be6b06a76eb1038130a38349dbd1c71b9 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 17:30:09 -0800 Subject: [PATCH 11/25] Update opencv and cmake --- .../windows_deps_headless_installer.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index f75981eaa864..2e551be4f094 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -35,7 +35,7 @@ from time import sleep from urllib.error import HTTPError import logging -from subprocess import check_output +from subprocess import check_output, check_call import re import sys @@ -48,10 +48,10 @@ 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-v3_4_1-vc14.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-9.2-windows10-x64-v7.4.2.24.zip', 'nvdriver': 'https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_398.75_server2016.zip', - 'cmake': 'https://windows-post-install.s3-us-west-2.amazonaws.com/cmake-3.15.5-win64-x64.msi' + 'cmake': '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/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2-win64-x64.msi' } DEFAULT_SUBPROCESS_TIMEOUT=3600 @@ -118,7 +118,7 @@ def __call__(self, block_num, block_size, total_size): self.pbar.finish() if dest and os.path.isdir(dest): local_file = os.path.split(urlparse(url).path)[1] - local_path = os.path.join(dest, local_file) + local_path = os.path.normpath(os.path.join(dest, local_file)) else: local_path = dest with urlopen(url) as c: @@ -219,8 +219,8 @@ def vs_still_installing(): def install_cmake(): logging.info("Installing CMAKE") - cmake_file_path = download(DEPS['cmake']) - run_command("msiexec /i {} /quiet /norestart ADD_CMAKE_TO_PATH=System".format(cmake_file_path)) + cmake_file_path = download(DEPS['cmake'], '.') + check_call(['msiexec ', '/n', '/passive', '/i', cmake_file_path]) logging.info("CMAKE install complete") @@ -242,10 +242,13 @@ def install_mkl(): def install_opencv(): logging.info("Installing OpenCV") - local_file = download(DEPS['opencv']) - 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 OpenCV_DIR -Value 'C:\\Program Files\\OpenCV-windows-v3_4_1-vc14'") + 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', '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") @@ -357,7 +360,7 @@ def main(): else: logging.info("GPU environment skipped") install_vs() - install_cmake() + #install_cmake() install_openblas() install_mkl() install_opencv() From ad12100da37a183f4b59e6d3603fd0c4396f345a Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 17:30:43 -0800 Subject: [PATCH 12/25] update setup.ps1 --- ci/windows_dev_env/setup.ps1 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ci/windows_dev_env/setup.ps1 b/ci/windows_dev_env/setup.ps1 index 67132072fc5a..2b94c996af26 100644 --- a/ci/windows_dev_env/setup.ps1 +++ b/ci/windows_dev_env/setup.ps1 @@ -1,3 +1,4 @@ + # 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 @@ -32,20 +33,25 @@ function Check-Call { Set-ExecutionPolicy Bypass -Scope Process -Force Invoke-WebRequest -Uri https://chocolatey.org/install.ps1 -OutFile install.ps1 ./install.ps1 -Check-Call { C:\ProgramData\chocolatey\choco install python2 -y } -Check-Call { C:\ProgramData\chocolatey\choco install python --version=3.7.0 --force -y } +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 } 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 } +Check-Call { C:\ProgramData\chocolatey\choco install 7zip -y } +Check-Call { C:\ProgramData\chocolatey\choco install cmake -y } +Check-Call { setx PATH "$($env:path);c:\Program Files\CMake\bin" } +Check-Call { C:\ProgramData\chocolatey\choco install ninja -y } + # Deps -Check-Call { C:\Python37\python windows_deps_headless_installer.py } +Check-Call { C:\Python37\python windows_deps_headless_installer.py --gpu } # Other software -Check-Call { C:\ProgramData\chocolatey\choco install jom -y } -Check-Call { C:\ProgramData\chocolatey\choco install 7zip -y } -Check-Call { C:\ProgramData\chocolatey\choco install mingw -y } -Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -y } -Check-Call { C:\ProgramData\chocolatey\choco install git -y } +#Check-Call { C:\ProgramData\chocolatey\choco install jom -y } +#Check-Call { C:\ProgramData\chocolatey\choco install mingw -y } +#Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -y } Write-Output "End" From 654f54c511374d1fae2cc05af8480da8f193ddf1 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 17:55:48 -0800 Subject: [PATCH 13/25] EC2 gpu autodetection --- .../windows_deps_headless_installer.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index 2e551be4f094..bfc546a4811e 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -38,6 +38,7 @@ from subprocess import check_output, check_call import re import sys +import urllib.request import ssl @@ -327,13 +328,14 @@ def add_paths(): def has_gpu(): - # FIXME: this is too simplistic and not reliable as of now. - hwinfo = check_output(['powershell','gwmi', 'win32_pnpEntity']) - m_g3 = re.search('3D Video', hwinfo.decode()) # G3 - m_p3 = re.search('NVIDIA Tesla', hwinfo.decode()) # P3 - if m_g3 or m_p3: - return True - return False + 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: @@ -352,7 +354,7 @@ def main(): default=False, action='store_true') args = parser.parse_args() - if args.gpu: + if args.gpu or has_gpu(): logging.info("GPU detected") install_nvdriver() install_cuda() From 0b5ae1bf5c737f9828802dc20f1eae745cfe459c Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 9 Jan 2020 18:16:27 -0800 Subject: [PATCH 14/25] Fix opencv path --- ci/windows_dev_env/windows_deps_headless_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index bfc546a4811e..f9ff8d73a6a5 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -247,7 +247,7 @@ def install_opencv(): local_file = download(DEPS['opencv']) with zipfile.ZipFile(local_file, 'r') as zip: zip.extractall(tmpdir) - copy(f'{tmpdir}\opencv\build', 'c:\Program Files\opencv') + 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") From 6511e73eee2b98222490371aec0decd94846138c Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Tue, 14 Jan 2020 01:35:47 +0000 Subject: [PATCH 15/25] Update to VS 2017 and to 64 bit host. Work around compiler running out of heap. --- ci/build_windows.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 544eafa2e5d5..87ea4d3fcd2b 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -38,8 +38,9 @@ from util import * 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\vcvarsx86_amd64.bat' } @@ -219,7 +220,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 2017'], type=str) parser.add_argument("--arch", From 67f131b416c11f31e45da1185775b9c52cf38da0 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Mon, 13 Jan 2020 17:53:22 -0800 Subject: [PATCH 16/25] Add warning on GPU detect --- ci/windows_dev_env/windows_deps_headless_installer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/windows_dev_env/windows_deps_headless_installer.py b/ci/windows_dev_env/windows_deps_headless_installer.py index f9ff8d73a6a5..06fa3b69a0c4 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -334,6 +334,7 @@ def instance_family(): try: return instance_family() in gpu_family except: + logging.warning("Looks like we are not running in AWS, couldn't detect a GPU instance, please use --gpu argument directly to install GPU related utilities.") return False From 83a9576d06c3e012fe7c6fe7ebe677b7c937c9f1 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Mon, 13 Jan 2020 17:58:46 -0800 Subject: [PATCH 17/25] remove unnecessary vars --- ci/build_windows.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/build_windows.py b/ci/build_windows.py index 87ea4d3fcd2b..3fbbde9c1c66 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -240,10 +240,6 @@ 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\\build" if 'CUDA_PATH' not in os.environ: os.environ["CUDA_PATH"] = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2" if 'MKL_ROOT' not in os.environ: From d01b0cfc5e3092f1f46c1edf19c9c2196089afaa Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Tue, 14 Jan 2020 19:06:30 -0800 Subject: [PATCH 18/25] Update docs/static_site/src/pages/get_started/windows_setup.md Co-Authored-By: Aaron Markham --- docs/static_site/src/pages/get_started/windows_setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bb21ca0c68c9..980bb0519a1a 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -156,7 +156,7 @@ C:\Python37\python.exe .\ci\build_windows.py These commands produce a library called ```mxnet.dll``` in the ```./build/Release/``` or ```./build/Debug``` folder. -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) From e1241564ed7f9289585d94adc75fce3ded172dab Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 17 Jan 2020 15:00:32 -0800 Subject: [PATCH 19/25] Fix broken VS path --- ci/build_windows.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/build_windows.py b/ci/build_windows.py index 3fbbde9c1c66..1b2e06688da4 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -37,6 +37,11 @@ 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', From f32a43aad59b998f8c0617e2df8d573422d6cc69 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Thu, 16 Jan 2020 16:25:48 -0800 Subject: [PATCH 20/25] doc fixes --- .../static_site/src/pages/get_started/windows_setup.md | 10 ---------- 1 file changed, 10 deletions(-) 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 980bb0519a1a..21d14af4d161 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -162,18 +162,8 @@ Now that you have installed MXNet core library, you are ready to optionally inst - [Julia](#install-the-mxnet-package-for-julia) - **Scala** is not yet available for Windows -### Optional step: - -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. - - ## Install the MXNet Package for Python -Use setup.py to install the package. ```bash # Assuming you are in root mxnet source code folder pip install --upgrade --force-reinstall -e python From bee3d85c315a234d3ee441b85431d497c6a0aca5 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 17 Jan 2020 15:13:50 -0800 Subject: [PATCH 21/25] CR comment --- docs/static_site/src/pages/get_started/windows_setup.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 21d14af4d161..55897999a677 100644 --- a/docs/static_site/src/pages/get_started/windows_setup.md +++ b/docs/static_site/src/pages/get_started/windows_setup.md @@ -147,7 +147,8 @@ folder. Copy to a local directory and execute: ``` This will install the recommended VS Community, Python, git, and other dependencies needed to build in windows. -After that, follow the steps below starting from "build the MXNet source code" section below. +Then use the following to build. The `--flavour` option selects the build flavour. Use +`.\build_windows.py --help` to list the different build flavours. ``` C:\Python37\python.exe .\ci\build_windows.py From d7a4d2649700797a2cd3ae91bf89eb1f4f0459c2 Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 17 Jan 2020 19:10:26 -0800 Subject: [PATCH 22/25] remove gpu flag --- ci/windows_dev_env/setup.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/windows_dev_env/setup.ps1 b/ci/windows_dev_env/setup.ps1 index 2b94c996af26..9fab9e549e57 100644 --- a/ci/windows_dev_env/setup.ps1 +++ b/ci/windows_dev_env/setup.ps1 @@ -1,4 +1,3 @@ - # 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 @@ -47,7 +46,7 @@ Check-Call { setx PATH "$($env:path);c:\Program Files\CMake\bin" } Check-Call { C:\ProgramData\chocolatey\choco install ninja -y } # Deps -Check-Call { C:\Python37\python windows_deps_headless_installer.py --gpu } +Check-Call { C:\Python37\python windows_deps_headless_installer.py } # Other software #Check-Call { C:\ProgramData\chocolatey\choco install jom -y } From 08c3a552bf9a790a1be7691aa4722472d485fd2f Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Fri, 14 Feb 2020 19:17:46 -0800 Subject: [PATCH 23/25] update dep scripts --- ci/windows_dev_env/setup.ps1 | 25 ++- .../windows_deps_headless_installer.py | 203 ++++++++++-------- 2 files changed, 132 insertions(+), 96 deletions(-) diff --git a/ci/windows_dev_env/setup.ps1 b/ci/windows_dev_env/setup.ps1 index 9fab9e549e57..e0bc65a454ab 100644 --- a/ci/windows_dev_env/setup.ps1 +++ b/ci/windows_dev_env/setup.ps1 @@ -29,28 +29,31 @@ function Check-Call { exit $lastexitcode } } +Check-Call { setx PATH "$($env:path);c:\Program Files\CMake\bin;" /m } Set-ExecutionPolicy Bypass -Scope Process -Force 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 } +#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:\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 } -Check-Call { C:\ProgramData\chocolatey\choco install 7zip -y } -Check-Call { C:\ProgramData\chocolatey\choco install cmake -y } -Check-Call { setx PATH "$($env:path);c:\Program Files\CMake\bin" } -Check-Call { C:\ProgramData\chocolatey\choco install ninja -y } +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 } -#Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -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 index 06fa3b69a0c4..f104b68a572b 100755 --- a/ci/windows_dev_env/windows_deps_headless_installer.py +++ b/ci/windows_dev_env/windows_deps_headless_installer.py @@ -35,10 +35,11 @@ from time import sleep from urllib.error import HTTPError import logging -from subprocess import check_output, check_call +from subprocess import check_output, check_call, call import re import sys import urllib.request +import contextlib import ssl @@ -48,14 +49,28 @@ 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-9.2-windows10-x64-v7.4.2.24.zip', - 'nvdriver': 'https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_398.75_server2016.zip', - 'cmake': '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/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2-win64-x64.msi' + '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-9.2-windows10-x64-v7.4.2.24.zip', + 'nvdriver': 'https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_398.75_server2016.zip', + # This installation of CMake breaks windows PATH when executing vcvars, installing from + # chocolatey from powershell instead. + 'cmake': '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/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2-win64-x64.msi' } -DEFAULT_SUBPROCESS_TIMEOUT=3600 +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): @@ -98,7 +113,7 @@ def f_retry(*args, **kwargs): @retry((ValueError, OSError, HTTPError), tries=5, delay_s=2, backoff=5) -def download(url, dest=None, progress=True) -> str: +def download(url, dest=None, progress=False) -> str: from urllib.request import urlopen from urllib.parse import (urlparse, urlunparse) import progressbar @@ -166,11 +181,11 @@ def copy(src, dest): # Workaround for windows readonly attribute error -def on_rm_error( func, path, exc_info): +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 ) + os.chmod(path, stat.S_IWRITE) + os.unlink(path) def install_vs(): @@ -179,30 +194,38 @@ def install_vs(): # Components: https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community?view=vs-2017#visual-studio-core-editor-included-with-visual-studio-community-2017 logging.info("Installing Visual Studio CE 2017...") vs_file_path = download('https://aka.ms/eac464') - run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(vs_file_path, vs_file_path.split('\\')[-1]), shell=True) + 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' - run_command(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.15063.Desktop' \ - ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP' \ - ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP.Native' \ - ' --add Microsoft.VisualStudio.ComponentGroup.Windows10SDK.15063' \ - ' --wait' \ - ' --passive' \ - ' --norestart' - ) + 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.15063.Desktop' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP' + ' --add Microsoft.VisualStudio.Component.Windows10SDK.15063.UWP.Native' + ' --add Microsoft.VisualStudio.ComponentGroup.Windows10SDK.15063' + ' --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 @@ -260,85 +283,99 @@ def install_cudnn(): 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\\v9.2\\bin") - copy(tmpdir+"\\cuda\\include\\cudnn.h","C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\include") - copy(tmpdir+"\\cuda\\lib\\x64\\cudnn.lib","C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\lib\\x64") + copy(tmpdir+"\\cuda\\bin\\cudnn64_7.dll", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\bin") + copy(tmpdir+"\\cuda\\include\\cudnn.h", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\include") + copy(tmpdir+"\\cuda\\lib\\x64\\cudnn.lib", "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.2\\lib\\x64") logging.info("cuDNN install complete") +def install_gpu_packages(force=False): + if has_gpu() or force: + logging.info("GPU detected") + install_nvdriver() + install_cuda() + install_cudnn() + + def install_nvdriver(): logging.info("Installing Nvidia Display Drivers...") - with tempfile.TemporaryDirectory() as tmpdir: + with tempfile.TemporaryDirectory(prefix='nvidia drivers') as tmpdir: local_file = download(DEPS['nvdriver']) with zipfile.ZipFile(local_file, 'r') as zip: zip.extractall(tmpdir) - run_command(tmpdir + "\\setup.exe /n /s /noeula /nofinish") + with remember_cwd(): + os.chdir(tmpdir) + check_call(".\setup.exe -noreboot -clean -noeula -nofinish -passive") logging.info("NVidia install complete") def install_cuda(): # CUDA 9.2 and patches logging.info("Installing CUDA 9.2 and Patches...") - cuda_9_2_file_path = download('https://developer.nvidia.com/compute/cuda/9.2/Prod2/network_installers2/cuda_9.2.148_win10_network') - run_command("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_9_2_file_path, cuda_9_2_file_path.split('\\')[-1]), shell=True) + cuda_9_2_file_path = download( + 'https://developer.nvidia.com/compute/cuda/9.2/Prod2/network_installers2/cuda_9.2.148_win10_network') + check_call("PowerShell Rename-Item -Path {} -NewName \"{}.exe\"".format(cuda_9_2_file_path, + cuda_9_2_file_path.split('\\')[-1]), shell=True) cuda_9_2_file_path = cuda_9_2_file_path + '.exe' - run_command(cuda_9_2_file_path \ - + ' -s nvcc_9.2' \ - + ' cuobjdump_9.2' \ - + ' nvprune_9.2' \ - + ' cupti_9.2' \ - + ' gpu_library_advisor_9.2' \ - + ' memcheck_9.2' \ - + ' nvdisasm_9.2' \ - + ' nvprof_9.2' \ - + ' visual_profiler_9.2' \ - + ' visual_studio_integration_9.2' \ - + ' demo_suite_9.2' \ - + ' documentation_9.2' \ - + ' cublas_9.2' \ - + ' cublas_dev_9.2' \ - + ' cudart_9.2' \ - + ' cufft_9.2' \ - + ' cufft_dev_9.2' \ - + ' curand_9.2' \ - + ' curand_dev_9.2' \ - + ' cusolver_9.2' \ - + ' cusolver_dev_9.2' \ - + ' cusparse_9.2' \ - + ' cusparse_dev_9.2' \ - + ' nvgraph_9.2' \ - + ' nvgraph_dev_9.2' \ - + ' npp_9.2' \ - + ' npp_dev_9.2' \ - + ' nvrtc_9.2' \ - + ' nvrtc_dev_9.2' \ - + ' nvml_dev_9.2' \ - + ' occupancy_calculator_9.2' - ) + check_call(cuda_9_2_file_path + + ' -s nvcc_9.2' + + ' cuobjdump_9.2' + + ' nvprune_9.2' + + ' cupti_9.2' + + ' gpu_library_advisor_9.2' + + ' memcheck_9.2' + + ' nvdisasm_9.2' + + ' nvprof_9.2' + + ' visual_profiler_9.2' + + ' visual_studio_integration_9.2' + + ' demo_suite_9.2' + + ' documentation_9.2' + + ' cublas_9.2' + + ' cublas_dev_9.2' + + ' cudart_9.2' + + ' cufft_9.2' + + ' cufft_dev_9.2' + + ' curand_9.2' + + ' curand_dev_9.2' + + ' cusolver_9.2' + + ' cusolver_dev_9.2' + + ' cusparse_9.2' + + ' cusparse_dev_9.2' + + ' nvgraph_9.2' + + ' nvgraph_dev_9.2' + + ' npp_9.2' + + ' npp_dev_9.2' + + ' nvrtc_9.2' + + ' nvrtc_dev_9.2' + + ' nvml_dev_9.2' + + ' occupancy_calculator_9.2' + ) 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 = 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" + 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" 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: - logging.warning("Looks like we are not running in AWS, couldn't detect a GPU instance, please use --gpu argument directly to install GPU related utilities.") return False - def script_name() -> str: """:returns: script name with leading paths removed""" return os.path.split(sys.argv[0])[1] @@ -348,22 +385,18 @@ 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') + action='store_true') args = parser.parse_args() if args.gpu or has_gpu(): - logging.info("GPU detected") - install_nvdriver() - install_cuda() - install_cudnn() + install_gpu_packages(force=True) else: logging.info("GPU environment skipped") install_vs() - #install_cmake() + # install_cmake() install_openblas() install_mkl() install_opencv() @@ -371,4 +404,4 @@ def main(): if __name__ == "__main__": - exit (main()) + exit(main()) From 78ef0ef9772c379c332e98223841872638a77d1c Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Tue, 18 Feb 2020 14:32:33 -0800 Subject: [PATCH 24/25] opencv and vs15 fixes, depending on the environment the compiler is not picked up (mingw or gcc is picked up instead) --- ci/build_windows.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ci/build_windows.py b/ci/build_windows.py index 1b2e06688da4..e08085e29a9a 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -61,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 ' @@ -74,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 ' @@ -87,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 ' @@ -100,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 ' @@ -113,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 ' @@ -127,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 ' From 12f3c9ee4b1bda66b9af76210a5ccca863be238e Mon Sep 17 00:00:00 2001 From: Pedro Larroy Date: Wed, 19 Feb 2020 15:43:06 -0800 Subject: [PATCH 25/25] Increase docker timeouts --- ci/safe_docker_run.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/safe_docker_run.py b/ci/safe_docker_run.py index 97ece4aecd2f..c60780aa4644 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