From 1de0b66e60649bfd2c5f869136e83447a794ad00 Mon Sep 17 00:00:00 2001 From: Leonard Lausen Date: Sat, 2 May 2020 18:28:18 -0700 Subject: [PATCH] Update to thrust 1.9.8 on Windows (#18218) * Update to thrust 1.9.8 on Windows * Remove debug logic --- CMakeLists.txt | 2 +- ci/build_windows.py | 69 +++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8adddca6712..3eb9829f25c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,7 @@ if(MSVC) add_definitions(-DDMLC_STRICT_CXX11) add_definitions(-DNOMINMAX) set(CMAKE_C_FLAGS "/MP") - set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} /bigobj") else() include(CheckCXXCompilerFlag) if(USE_CXX14_IF_AVAILABLE) diff --git a/ci/build_windows.py b/ci/build_windows.py index 2590d211c671..f84e5153a851 100755 --- a/ci/build_windows.py +++ b/ci/build_windows.py @@ -31,6 +31,7 @@ import tempfile import time import zipfile +import requests from distutils.dir_util import copy_tree from enum import Enum from subprocess import check_call @@ -115,7 +116,6 @@ class BuildFlavour(Enum): '-DUSE_LAPACK=ON ' '-DUSE_DIST_KVSTORE=OFF ' '-DMXNET_CUDA_ARCH="5.2" ' - '-DCMAKE_CXX_FLAGS="/FS /MD /O2 /Ob2" ' '-DUSE_MKL_IF_AVAILABLE=OFF ' '-DCMAKE_BUILD_TYPE=Release') @@ -130,7 +130,6 @@ class BuildFlavour(Enum): '-DUSE_DIST_KVSTORE=OFF ' '-DMXNET_CUDA_ARCH="5.2" ' '-DUSE_MKLDNN=ON ' - '-DCMAKE_CXX_FLAGS="/FS /MD /O2 /Ob2" ' '-DCMAKE_BUILD_TYPE=Release') } @@ -142,36 +141,50 @@ def windows_build(args): path = args.output os.makedirs(path, exist_ok=True) + if os.path.exists(path): + shutil.rmtree(path) + os.makedirs(path, exist_ok=True) + mxnet_root = get_mxnet_root() logging.info("Found MXNet root: {}".format(mxnet_root)) - 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) - + if 'GPU' in args.flavour: + # Get Thrust version to be shipped in Cuda 11, due to flakyness of + # older Thrust versions with MSVC 19 compiler 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)))) + tmpdirname = tempfile.mkdtemp() + os.chdir(tmpdirname) + r = requests.get('https://github.com/thrust/thrust/archive/1.9.8.zip', allow_redirects=True) + with open('thrust.zip', 'wb') as f: + f.write(r.content) + with zipfile.ZipFile('thrust.zip', 'r') as zip_ref: + zip_ref.extractall('.') + thrust_path = os.path.join(tmpdirname, "thrust-1.9.8") + + with remember_cwd(): + os.chdir(path) + env = os.environ.copy() + if 'GPU' in args.flavour: + env["CXXFLAGS"] = '/FS /MD /O2 /Ob2 /I {}'.format(thrust_path) + env["CUDAFLAGS"] = '-I {}'.format(thrust_path) + cmd = "\"{}\" && cmake -GNinja {} {}".format(args.vcvars, + CMAKE_FLAGS[args.flavour], + mxnet_root) + logging.info("Generating project with CMake:\n{}".format(cmd)) + check_call(cmd, shell=True, env=env) + + cmd = "\"{}\" && ninja".format(args.vcvars) + logging.info("Building:\n{}".format(cmd)) + + t0 = int(time.time()) + ret = call(cmd, shell=True) + + if ret != 0: + logging.info("Build failed") + sys.exit(1) + + 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)