From b1841bd598ad0e609c4703c70aadbd2cb0160904 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 27 May 2020 23:14:50 +0000 Subject: [PATCH 01/58] Add specialized OpenCL/Python package build path --- CMakeLists.txt | 62 +++++++++++++---- CMakeOpenCLPythonPackage.txt | 110 ++++++++++++++++++++++++++++++ CMakeOpenCLPythonPackageCache.txt | 13 ++++ python-package/setup.py | 39 +++++++---- 4 files changed, 200 insertions(+), 24 deletions(-) create mode 100644 CMakeOpenCLPythonPackage.txt create mode 100644 CMakeOpenCLPythonPackageCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a07c3fe79b6f..bac1141e27d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ -if(USE_GPU OR APPLE) +if(__OPENCL_PYTHON_PACKAGE) + cmake_minimum_required(VERSION 3.11) +elseif(USE_GPU OR APPLE) cmake_minimum_required(VERSION 3.2) else() cmake_minimum_required(VERSION 2.8) @@ -20,6 +22,11 @@ if(APPLE) OPTION(APPLE_OUTPUT_DYLIB "Output dylib shared library" OFF) endif(APPLE) +if(__OPENCL_PYTHON_PACKAGE) + set(USE_GPU OFF CACHE BOOL "" FORCE) + message(WARNING "\nWARNING: building integrated OpenCL enabled components intended for Python package") +endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2") message(FATAL_ERROR "Insufficient gcc version") @@ -127,6 +134,11 @@ if(USE_GPU) ADD_DEFINITIONS(-DUSE_GPU) endif(USE_GPU) +if(__OPENCL_PYTHON_PACKAGE) + include(CMakeOpenCLPythonPackage.txt) + ADD_DEFINITIONS(-DUSE_GPU) +endif() + if(USE_HDFS) find_package(JNI REQUIRED) find_path(HDFS_INCLUDE_DIR hdfs.h REQUIRED) @@ -224,7 +236,7 @@ if(USE_MPI) include_directories(${MPI_CXX_INCLUDE_PATH}) endif(USE_MPI) -file(GLOB SOURCES +file(GLOB SHARED_SOURCES src/application/*.cpp src/boosting/*.cpp src/io/*.cpp @@ -234,19 +246,27 @@ file(GLOB SOURCES src/treelearner/*.cpp ) -add_executable(lightgbm src/main.cpp ${SOURCES}) -list(APPEND SOURCES "src/c_api.cpp") +add_library(L OBJECT ${SHARED_SOURCES}) + +add_executable(lightgbm src/main.cpp $) +list(APPEND LIBRARY_SOURCES "src/c_api.cpp") # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - list(APPEND SOURCES "src/lightgbm_R.cpp") + list(APPEND LIBRARY_SOURCES "src/lightgbm_R.cpp") endif(BUILD_FOR_R) -add_library(_lightgbm SHARED ${SOURCES}) +add_library(_lightgbm SHARED ${LIBRARY_SOURCES} $) if(MSVC) - set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") + set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") + # TODO: use uniquely named dll (in setup.py, lightgbm/libpath.py) to avoid runtime conflicts + #if(__OPENCL_PYTHON_PACKAGE) + # set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm-${OPENCL_PYTHON_PACKAGE_STAMP}") + #else() + # set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") + #endif() endif(MSVC) if(USE_SWIG) @@ -303,16 +323,34 @@ if(USE_GPU) TARGET_LINK_LIBRARIES(_lightgbm ${OpenCL_LIBRARY} ${Boost_LIBRARIES}) endif(USE_GPU) +if(__OPENCL_PYTHON_PACKAGE) + # targets OpenCL and Boost are added in CMakeOpenCLPythonPackage.txt + add_dependencies(L OpenCL Boost) + add_dependencies(lightgbm L) + add_dependencies(_lightgbm L) + # variables OPENCL_PYTHON_PACKAGE_* are set in CMakeOpenCLPythonPackage.txt + target_include_directories(L PRIVATE ${OPENCL_PYTHON_PACKAGE_INCLUDES}) + target_compile_definitions(L PRIVATE ${OPENCL_PYTHON_PACKAGE_DEFINITIONS}) + target_link_libraries(lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_LIBRARIES}) + target_link_libraries(_lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_LIBRARIES}) +endif() + if(USE_HDFS) TARGET_LINK_LIBRARIES(lightgbm ${HDFS_CXX_LIBRARIES}) TARGET_LINK_LIBRARIES(_lightgbm ${HDFS_CXX_LIBRARIES}) endif(USE_HDFS) -if(WIN32 AND (MINGW OR CYGWIN)) - TARGET_LINK_LIBRARIES(lightgbm Ws2_32) - TARGET_LINK_LIBRARIES(_lightgbm Ws2_32) - TARGET_LINK_LIBRARIES(lightgbm IPHLPAPI) - TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI) +if(WIN32) + if (MINGW OR CYGWIN) + TARGET_LINK_LIBRARIES(lightgbm Ws2_32) + TARGET_LINK_LIBRARIES(_lightgbm Ws2_32) + TARGET_LINK_LIBRARIES(lightgbm IPHLPAPI) + TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI) + endif() +else() + if(__OPENCL_PYTHON_PACKAGE) + target_link_libraries(lightgbm PRIVATE pthread dl) + endif() endif() if(BUILD_FOR_R) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt new file mode 100644 index 000000000000..edcf3c6ec12c --- /dev/null +++ b/CMakeOpenCLPythonPackage.txt @@ -0,0 +1,110 @@ + +set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) +set(BOOST_VERSION_DOT "1.73") +string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION_DOT}) + +set(OPENCL_HEADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git") +set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") +#set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") +#set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") +set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") +set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") +set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") +set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") +execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE LIGHTGBM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) +string(SHA1 OPENCL_PYTHON_PACKAGE_STAMP "${OPENCL_HEADER_REPOSITORY}@${OPENCL_HEADER_TAG};${OPENCL_LOADER_REPOSITORY}@${OPENCL_LOADER_TAG};${BOOST_REPOSITORY}@${BOOST_TAG};lightgbm@${LIGHTGBM_TAG}") +message(STATUS "OpenCL Python package build stamp: ${OPENCL_PYTHON_PACKAGE_STAMP}") + +# Build Independent OpenCL library +include(FetchContent) +FetchContent_Declare(OpenCL-Headers GIT_REPOSITORY ${OPENCL_HEADER_REPOSITORY} GIT_TAG ${OPENCL_HEADER_TAG}) +FetchContent_GetProperties(OpenCL-Headers) +if(NOT OpenCL-Headers_POPULATED) + FetchContent_Populate(OpenCL-Headers) + message(STATUS "Populated OpenCL Headers") +endif() +set(OPENCL_ICD_LOADER_HEADERS_DIR ${opencl-headers_SOURCE_DIR} CACHE PATH "") # for OpenCL ICD Loader +set(OpenCL_INCLUDE_DIR ${opencl-headers_SOURCE_DIR} CACHE PATH "") # for Boost::Compute + +FetchContent_Declare(OpenCL-ICD-Loader GIT_REPOSITORY ${OPENCL_LOADER_REPOSITORY} GIT_TAG ${OPENCL_LOADER_TAG}) +FetchContent_GetProperties(OpenCL-ICD-Loader) +if(NOT OpenCL-ICD-Loader_POPULATED) + FetchContent_Populate(OpenCL-ICD-Loader) + if(WIN32) + set(USE_DYNAMIC_VCXX_RUNTIME ON) + else() + set(OPENCL_ICD_LOADER_PIC ON) + endif() + add_subdirectory(${opencl-icd-loader_SOURCE_DIR} ${opencl-icd-loader_BINARY_DIR} EXCLUDE_FROM_ALL) + message(STATUS "Populated OpenCL ICD Loader") +endif() +list(APPEND OPENCL_PYTHON_PACKAGE_INCLUDES ${OPENCL_ICD_LOADER_HEADERS_DIR}) +if(WIN32) + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/Release/OpenCL.lib cfgmgr32.lib runtimeobject.lib) +else() + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/libOpenCL.a) +endif() +list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=220) + +# Build Independent Boost libraries +include(ExternalProject) +include(ProcessorCount) +ProcessorCount(J) +set(BOOST_BASE "${PROJECT_BINARY_DIR}/Boost") +if(WIN32) + set(BOOST_BOOTSTRAP "${BOOST_BASE}/source/bootstrap.bat") + set(BOOST_BUILD "${BOOST_BASE}/source/b2.exe") + set(BOOST_FLAGS "") + list(APPEND BOOST_SUBMODULES "libs/*" "tools/*") +else() + set(BOOST_BOOTSTRAP "${BOOST_BASE}/source/bootstrap.sh") + set(BOOST_BUILD "${BOOST_BASE}/source/b2") + set(BOOST_FLAGS -fPIC) + list(APPEND BOOST_SUBMODULES "libs/compute" "libs/chrono" "libs/config" "libs/filesystem" "libs/headers" "libs/io" "libs/predef" "libs/system" "libs/uuid" "tools/*") +endif() +ExternalProject_Add(Boost + TMP_DIR "${BOOST_BASE}/tmp" + STAMP_DIR "${BOOST_BASE}/stamp" + DOWNLOAD_DIR "${BOOST_BASE}/download" + SOURCE_DIR "${BOOST_BASE}/source" + BINARY_DIR "${BOOST_BASE}/source" + INSTALL_DIR "${BOOST_BASE}/install" + GIT_REPOSITORY ${BOOST_REPOSITORY} + GIT_TAG ${BOOST_TAG} + GIT_SUBMODULES ${BOOST_SUBMODULES} + GIT_SHALLOW ON + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND ${BOOST_BOOTSTRAP} + BUILD_COMMAND ${BOOST_BUILD} -sBOOST_ROOT=${BOOST_BASE}/source -a -q -j ${J} --with-headers --with-chrono --with-filesystem --with-system link=static runtime-link=shared variant=release threading=multi cxxflags="${BOOST_FLAGS}" + INSTALL_COMMAND "" +) +set(BOOST_INCLUDE ${BOOST_BASE}/source CACHE PATH "") +set(BOOST_LIBRARY ${BOOST_BASE}/source/stage/lib CACHE PATH "") +list(APPEND OPENCL_PYTHON_PACKAGE_INCLUDES ${BOOST_INCLUDE}) +if(WIN32) + if(MSVC) + if(${MSVC_VERSION} GREATER 1929) + set(MSVC_TOOLCHAIN_ID "unknown") + elseif(${MSVC_VERSION} GREATER 1919) + set(MSVC_TOOLCHAIN_ID "142") + elseif(${MSVC_VERSION} GREATER 1909) + set(MSVC_TOOLCHAIN_ID "141") + elseif(${MSVC_VERSION} GREATER 1899) + set(MSVC_TOOLCHAIN_ID "140") + else() + set(MSVC_TOOLCHAIN_ID "unknown") + endif() + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_filesystem-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_system-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_chrono-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) + else() + message(WARNING "MinGW Boost library names not yet specified") + endif() +else() + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_filesystem.a) + list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_system.a) +endif() + +set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) + diff --git a/CMakeOpenCLPythonPackageCache.txt b/CMakeOpenCLPythonPackageCache.txt new file mode 100644 index 000000000000..8831b292cd87 --- /dev/null +++ b/CMakeOpenCLPythonPackageCache.txt @@ -0,0 +1,13 @@ + +set(__OPENCL_PYTHON_PACKAGE ON CACHE BOOL "" FORCE) + +set(USE_MPI OFF CACHE BOOL "") +set(USE_OPENMP ON CACHE BOOL "") +set(USE_GPU OFF CACHE BOOL "") +set(USE_SWIG OFF CACHE BOOL "") +set(USE_HDFS OFF CACHE BOOL "") +set(USE_R35 OFF CACHE BOOL "") +set(USE_TIMETAG OFF CACHE BOOL "") +set(USE_DEBUG OFF CACHE BOOL "") +set(BUILD_FOR_R OFF CACHE BOOL "") + diff --git a/python-package/setup.py b/python-package/setup.py index 73f123baf42d..f653a044d8ae 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -28,7 +28,7 @@ def find_lib(): return LIB_PATH -def copy_files(use_gpu=False): +def copy_files(opencl_python_package=False, use_gpu=False): def copy_files_helper(folder_name): src = os.path.join(CURRENT_DIR, os.path.pardir, folder_name) @@ -50,14 +50,21 @@ def copy_files_helper(folder_name): distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "windows", "LightGBM.vcxproj"), os.path.join(CURRENT_DIR, "compile", "windows", "LightGBM.vcxproj"), verbose=0) - if use_gpu: - copy_files_helper('compute') - distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeLists.txt"), - os.path.join(CURRENT_DIR, "compile", "CMakeLists.txt"), - verbose=0) distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "LICENSE"), os.path.join(CURRENT_DIR, "LICENSE"), verbose=0) + distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeLists.txt"), + os.path.join(CURRENT_DIR, "compile", "CMakeLists.txt"), + verbose=0) + if opencl_python_package: + distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeOpenCLPythonPackage.txt"), + os.path.join(CURRENT_DIR, "compile", "CMakeOpenCLPythonPackage.txt"), + verbose=0) + distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeOpenCLPythonPackageCache.txt"), + os.path.join(CURRENT_DIR, "compile", "CMakeOpenCLPythonPackageCache.txt"), + verbose=0) + if use_gpu: + copy_files_helper('compute') def clear_path(path): @@ -90,7 +97,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, use_hdfs=False, boost_root=None, boost_dir=None, boost_include_dir=None, boost_librarydir=None, opencl_include_dir=None, opencl_library=None, - nomp=False, bit32=False): + nomp=False, bit32=False, opencl_python_package=False): if os.path.exists(os.path.join(CURRENT_DIR, "build_cpp")): shutil.rmtree(os.path.join(CURRENT_DIR, "build_cpp")) @@ -100,6 +107,12 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, logger.info("Starting to compile the library.") cmake_cmd = ["cmake", "../compile/"] + if opencl_python_package: + use_gpu = False + use_mpi = False + nomp = False + use_hdfs = False + cmake_cmd.append("-C../compile/CMakeOpenCLPythonPackageCache.txt") if use_gpu: cmake_cmd.append("-DUSE_GPU=ON") if boost_root: @@ -133,7 +146,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, else: status = 1 lib_path = os.path.join(CURRENT_DIR, "compile", "windows", "x64", "DLL", "lib_lightgbm.dll") - if not any((use_gpu, use_mpi, use_hdfs, nomp, bit32)): + if not any((use_gpu, use_mpi, use_hdfs, nomp, bit32, opencl_python_package)): logger.info("Starting to compile with MSBuild from existing solution file.") platform_toolsets = ("v142", "v141", "v140") for pt in platform_toolsets: @@ -166,7 +179,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, else: # Linux, Darwin (macOS), etc. logger.info("Starting to compile with CMake.") silent_call(cmake_cmd, raise_error=True, error_msg='Please install CMake and all required dependencies first') - silent_call(["make", "_lightgbm", "-j4"], raise_error=True, + silent_call(["make", "_lightgbm", "-j2"], raise_error=True, error_msg='An error has occurred while building lightgbm library file') os.chdir(CURRENT_DIR) @@ -186,6 +199,7 @@ class CustomInstall(install): user_options = install.user_options + [ ('mingw', 'm', 'Compile with MinGW'), + ('opencl-python-package', None, 'Compile integrated OpenCL version'), ('gpu', 'g', 'Compile GPU version'), ('mpi', None, 'Compile MPI version'), ('nomp', None, 'Compile version without OpenMP support'), @@ -203,6 +217,7 @@ class CustomInstall(install): def initialize_options(self): install.initialize_options(self) self.mingw = 0 + self.opencl_python_package = 0 self.gpu = 0 self.boost_root = None self.boost_dir = None @@ -226,12 +241,12 @@ def run(self): "please use 64-bit Python instead.") open(LOG_PATH, 'wb').close() if not self.precompile: - copy_files(use_gpu=self.gpu) + copy_files(opencl_python_package=self.opencl_python_package, use_gpu=self.gpu) compile_cpp(use_mingw=self.mingw, use_gpu=self.gpu, use_mpi=self.mpi, use_hdfs=self.hdfs, boost_root=self.boost_root, boost_dir=self.boost_dir, boost_include_dir=self.boost_include_dir, boost_librarydir=self.boost_librarydir, opencl_include_dir=self.opencl_include_dir, opencl_library=self.opencl_library, - nomp=self.nomp, bit32=self.bit32) + nomp=self.nomp, bit32=self.bit32, opencl_python_package=self.opencl_python_package) install.run(self) if os.path.isfile(LOG_PATH): os.remove(LOG_PATH) @@ -240,7 +255,7 @@ def run(self): class CustomSdist(sdist): def run(self): - copy_files(use_gpu=True) + copy_files(opencl_python_package=True, use_gpu=True) open(os.path.join(CURRENT_DIR, '_IS_SOURCE_PACKAGE.txt'), 'w').close() if os.path.exists(os.path.join(CURRENT_DIR, 'lightgbm', 'Release')): shutil.rmtree(os.path.join(CURRENT_DIR, 'lightgbm', 'Release')) From 27dffcb53ac8203cc5a6a4ad168cb4442a99f504 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Mon, 1 Jun 2020 21:57:12 -0700 Subject: [PATCH 02/58] Refer to upstream OpenCL repository --- CMakeOpenCLPythonPackage.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index edcf3c6ec12c..c144ed64205d 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -5,10 +5,10 @@ string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION_DOT}) set(OPENCL_HEADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git") set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") -#set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") -#set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") -set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") -set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") +set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") +set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") +#set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") +#set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE LIGHTGBM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) From 2958084381ebeea59e3ab0fc021451d4922648c6 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 3 Jun 2020 16:52:35 +0000 Subject: [PATCH 03/58] Reset build job count in setup.py --- python-package/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-package/setup.py b/python-package/setup.py index f653a044d8ae..afac0bf80f9c 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -179,7 +179,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, else: # Linux, Darwin (macOS), etc. logger.info("Starting to compile with CMake.") silent_call(cmake_cmd, raise_error=True, error_msg='Please install CMake and all required dependencies first') - silent_call(["make", "_lightgbm", "-j2"], raise_error=True, + silent_call(["make", "_lightgbm", "-j4"], raise_error=True, error_msg='An error has occurred while building lightgbm library file') os.chdir(CURRENT_DIR) From d8241b71321c8c3ec3c7d2d7ad8dedf7b1fbc206 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 3 Jun 2020 11:45:22 -0800 Subject: [PATCH 04/58] Add --opencl-python-pacakge option to wheel --- .ci/test_windows.ps1 | 2 +- python-package/setup.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index fd0e9f95a5e4..c2cad70a6e30 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -49,7 +49,7 @@ elseif ($env:TASK -eq "sdist") { } elseif ($env:TASK -eq "bdist") { cd $env:BUILD_SOURCESDIRECTORY/python-package - python setup.py bdist_wheel --plat-name=win-amd64 --universal ; Check-Output $? + python setup.py bdist_wheel --opencl-python-package --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { diff --git a/python-package/setup.py b/python-package/setup.py index f653a044d8ae..40a94a29a8d8 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -16,6 +16,7 @@ from setuptools.command.install import install from setuptools.command.install_lib import install_lib from setuptools.command.sdist import sdist +from wheel.bdist_wheel import bdist_wheel def find_lib(): @@ -80,14 +81,10 @@ def clear_path(path): def silent_call(cmd, raise_error=False, error_msg=''): try: - output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) with open(LOG_PATH, "ab") as log: - log.write(output) + subprocess.check_call(cmd, stderr=log, stdout=log) return 0 except Exception as err: - if isinstance(err, subprocess.CalledProcessError): - with open(LOG_PATH, "ab") as log: - log.write(err.output) if raise_error: raise Exception("\n".join((error_msg, LOG_NOTICE))) return 1 @@ -268,6 +265,26 @@ def run(self): os.remove(os.path.join(CURRENT_DIR, '_IS_SOURCE_PACKAGE.txt')) +class CustomBdistWheel(bdist_wheel): + """Supports --opencl-python-package to allow building OpenCL wheels on Windows. + + Other install options should be added over time when needed. + """ + + user_options = bdist_wheel.user_options + [ + ('opencl-python-package', None, 'Compile integrated OpenCL version'), + ] + + def initialize_options(self): + bdist_wheel.initialize_options(self) + self.opencl_python_package = False + + def run(self): + install = self.distribution.get_command_obj('install') + install.opencl_python_package = opencl_python_package + bdist_wheel.run(self) + + if __name__ == "__main__": CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) LOG_PATH = os.path.join(os.path.expanduser('~'), 'LightGBM_compilation.log') @@ -300,6 +317,7 @@ def run(self): 'install': CustomInstall, 'install_lib': CustomInstallLib, 'sdist': CustomSdist, + 'bdist_wheel': CustomBdistWheel, }, packages=find_packages(), include_package_data=True, From e21fbc9c04c79524df7c2bc038970c3319c80e8b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 3 Jun 2020 13:32:14 -0400 Subject: [PATCH 05/58] Fix some typos. --- python-package/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-package/setup.py b/python-package/setup.py index 40a94a29a8d8..97ffbeb63d07 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -275,13 +275,13 @@ class CustomBdistWheel(bdist_wheel): ('opencl-python-package', None, 'Compile integrated OpenCL version'), ] - def initialize_options(self): + def initialize_options(self): bdist_wheel.initialize_options(self) self.opencl_python_package = False def run(self): install = self.distribution.get_command_obj('install') - install.opencl_python_package = opencl_python_package + install.opencl_python_package = self.opencl_python_package bdist_wheel.run(self) From eeb1104406de0c6c6b7d1e191426f8f8ed03ce0a Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 3 Jun 2020 13:58:46 -0400 Subject: [PATCH 06/58] Run test for dual CPU/GPU code in CI --- .ci/test_windows.ps1 | 10 ++++++++++ tests/python_package_test/test_dual.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/python_package_test/test_dual.py diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index c2cad70a6e30..7d70b2ad2341 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -48,6 +48,11 @@ elseif ($env:TASK -eq "sdist") { cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar } elseif ($env:TASK -eq "bdist") { + # Install the Intel CPU runtime, so we can run tests against OpenCL + choco install opencl-intel-cpu-runtime -y + Write-Output "Current OpenCL drivers:" + Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --opencl-python-package --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? @@ -61,6 +66,11 @@ elseif ($env:TASK -eq "bdist") { } } +if ($env:TASK -eq "bdist") { + # Also run GPU tests; see tests/python_package_test/test_dual.py + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" +} + if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" } else { diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py new file mode 100644 index 000000000000..1b897e462bda --- /dev/null +++ b/tests/python_package_test/test_dual.py @@ -0,0 +1,20 @@ +"""Tests for dual GPU+CPU support.""" + +import os +import pytest + +import lightgbm as lgb +import numpy as np + +@pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, + reason="Only run if appropriate env variable is set") +@pytest.mark.parametrize("device", ["cpu", "gpu"]) +def test_both_gpu_and_cpu(device): + """If compiled appropriately, the same installation will support both GPU and CPU.""" + data = np.random.rand(500, 10) + label = np.random.randint(2, size=500) + validation_data = train_data = lgb.Dataset(data, label=label) + + param = {'num_leaves': 31, 'objective': 'binary', 'device': device} + # This will raise an exception if it's an unsupported device: + lgb.train(param, train_data, 10, valid_sets=[validation_data]) \ No newline at end of file From 519a5b9dc54ed45b6843af40775d7d6ed0a29027 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 3 Jun 2020 18:50:20 +0000 Subject: [PATCH 07/58] TEMPORARY: refer to OpenCL fork to ensure Linux CI builds succeed --- CMakeOpenCLPythonPackage.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index c144ed64205d..edcf3c6ec12c 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -5,10 +5,10 @@ string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION_DOT}) set(OPENCL_HEADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git") set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") -set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") -set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") -#set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") -#set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") +#set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") +#set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") +set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") +set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE LIGHTGBM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) From 239dc49063fa478d2425597da0d2394ea98254da Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 3 Jun 2020 15:11:27 -0400 Subject: [PATCH 08/58] Try switching to OpenCL 2.0 --- CMakeOpenCLPythonPackage.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index c144ed64205d..b029dcfcc327 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -44,7 +44,7 @@ if(WIN32) else() list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/libOpenCL.a) endif() -list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=220) +list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=200) # Build Independent Boost libraries include(ExternalProject) From 84b6804ee4b0f44dbeabefe041358237a48a86e8 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 3 Jun 2020 19:45:52 +0000 Subject: [PATCH 09/58] Remove intermediate cmake target --- CMakeLists.txt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bac1141e27d3..d0839d9e8ab3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,7 +236,7 @@ if(USE_MPI) include_directories(${MPI_CXX_INCLUDE_PATH}) endif(USE_MPI) -file(GLOB SHARED_SOURCES +file(GLOB SOURCES src/application/*.cpp src/boosting/*.cpp src/io/*.cpp @@ -246,18 +246,16 @@ file(GLOB SHARED_SOURCES src/treelearner/*.cpp ) -add_library(L OBJECT ${SHARED_SOURCES}) +add_executable(lightgbm src/main.cpp ${SOURCES}) +list(APPEND SOURCES "src/c_api.cpp") -add_executable(lightgbm src/main.cpp $) - -list(APPEND LIBRARY_SOURCES "src/c_api.cpp") # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - list(APPEND LIBRARY_SOURCES "src/lightgbm_R.cpp") + list(APPEND SOURCES "src/lightgbm_R.cpp") endif(BUILD_FOR_R) -add_library(_lightgbm SHARED ${LIBRARY_SOURCES} $) +add_library(_lightgbm SHARED ${SOURCES}) if(MSVC) set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") @@ -325,12 +323,13 @@ endif(USE_GPU) if(__OPENCL_PYTHON_PACKAGE) # targets OpenCL and Boost are added in CMakeOpenCLPythonPackage.txt - add_dependencies(L OpenCL Boost) - add_dependencies(lightgbm L) - add_dependencies(_lightgbm L) + add_dependencies(lightgbm OpenCL Boost) + add_dependencies(_lightgbm OpenCL Boost) # variables OPENCL_PYTHON_PACKAGE_* are set in CMakeOpenCLPythonPackage.txt - target_include_directories(L PRIVATE ${OPENCL_PYTHON_PACKAGE_INCLUDES}) - target_compile_definitions(L PRIVATE ${OPENCL_PYTHON_PACKAGE_DEFINITIONS}) + target_include_directories(lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_INCLUDES}) + target_include_directories(_lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_INCLUDES}) + target_compile_definitions(lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_DEFINITIONS}) + target_compile_definitions(_lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_DEFINITIONS}) target_link_libraries(lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_LIBRARIES}) target_link_libraries(_lightgbm PRIVATE ${OPENCL_PYTHON_PACKAGE_LIBRARIES}) endif() From ec4b3f4880088ba7fbc2f42539b3a7297c2f9491 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Thu, 4 Jun 2020 20:22:04 +0000 Subject: [PATCH 10/58] Restrict OpenCL headers to documented API version --- CMakeOpenCLPythonPackage.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index edcf3c6ec12c..b63989e71376 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -44,7 +44,7 @@ if(WIN32) else() list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/libOpenCL.a) endif() -list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=220) +list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=120) # Build Independent Boost libraries include(ExternalProject) From ed65913908c619cdcd827acdb26e566cbf3a535e Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 5 Jun 2020 16:40:13 -0400 Subject: [PATCH 11/58] Refresh the environment after installation --- .ci/test_windows.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 7d70b2ad2341..db97b0714ef3 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -50,6 +50,7 @@ elseif ($env:TASK -eq "sdist") { elseif ($env:TASK -eq "bdist") { # Install the Intel CPU runtime, so we can run tests against OpenCL choco install opencl-intel-cpu-runtime -y + RefreshEnv Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors From 3b0b910b839c259f44f91294ca8d7d6d57d1045a Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 5 Jun 2020 15:03:28 -0400 Subject: [PATCH 12/58] Try testing with two processes --- .ci/test_windows.ps1 | 12 +++++++----- tests/python_package_test/test_dual.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index db97b0714ef3..a790110adf65 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -67,11 +67,6 @@ elseif ($env:TASK -eq "bdist") { } } -if ($env:TASK -eq "bdist") { - # Also run GPU tests; see tests/python_package_test/test_dual.py - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" -} - if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" } else { @@ -80,6 +75,13 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq } pytest $tests ; Check-Output $? +if ($env:TASK -eq "bdist") { + # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "cpu" + pytest -k test_both_cpu_and_gpu ; Check-Output $? + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "gpu" + pytest -k test_both_cpu_and_gpu ; Check-Output $? +} if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py" diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index 1b897e462bda..c5aa3d97dcaa 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -8,13 +8,13 @@ @pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, reason="Only run if appropriate env variable is set") -@pytest.mark.parametrize("device", ["cpu", "gpu"]) -def test_both_gpu_and_cpu(device): +def test_both_gpu_and_cpu(): """If compiled appropriately, the same installation will support both GPU and CPU.""" data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {'num_leaves': 31, 'objective': 'binary', 'device': device} + param = {'num_leaves': 31, 'objective': 'binary', + 'device': os.environ["LIGHTGBM_TEST_DUAL_CPU_GPU"]} # This will raise an exception if it's an unsupported device: lgb.train(param, train_data, 10, valid_sets=[validation_data]) \ No newline at end of file From 1fc78782badbe3e5015981e8e65f28937691ad43 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Mon, 8 Jun 2020 20:06:35 +0000 Subject: [PATCH 13/58] Use command line definition to activate integrated build --- CMakeLists.txt | 9 +++++++++ CMakeOpenCLPythonPackageCache.txt | 13 ------------- python-package/setup.py | 5 +---- 3 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 CMakeOpenCLPythonPackageCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d0839d9e8ab3..5853baca67db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,16 @@ if(APPLE) endif(APPLE) if(__OPENCL_PYTHON_PACKAGE) + set(__OPENCL_PYTHON_PACKAGE ON CACHE BOOL "" FORCE) set(USE_GPU OFF CACHE BOOL "" FORCE) + set(USE_MPI OFF CACHE BOOL "") + set(USE_OPENMP ON CACHE BOOL "") + set(USE_SWIG OFF CACHE BOOL "") + set(USE_HDFS OFF CACHE BOOL "") + set(USE_R35 OFF CACHE BOOL "") + set(USE_TIMETAG OFF CACHE BOOL "") + set(USE_DEBUG OFF CACHE BOOL "") + set(BUILD_FOR_R OFF CACHE BOOL "") message(WARNING "\nWARNING: building integrated OpenCL enabled components intended for Python package") endif() diff --git a/CMakeOpenCLPythonPackageCache.txt b/CMakeOpenCLPythonPackageCache.txt deleted file mode 100644 index 8831b292cd87..000000000000 --- a/CMakeOpenCLPythonPackageCache.txt +++ /dev/null @@ -1,13 +0,0 @@ - -set(__OPENCL_PYTHON_PACKAGE ON CACHE BOOL "" FORCE) - -set(USE_MPI OFF CACHE BOOL "") -set(USE_OPENMP ON CACHE BOOL "") -set(USE_GPU OFF CACHE BOOL "") -set(USE_SWIG OFF CACHE BOOL "") -set(USE_HDFS OFF CACHE BOOL "") -set(USE_R35 OFF CACHE BOOL "") -set(USE_TIMETAG OFF CACHE BOOL "") -set(USE_DEBUG OFF CACHE BOOL "") -set(BUILD_FOR_R OFF CACHE BOOL "") - diff --git a/python-package/setup.py b/python-package/setup.py index afac0bf80f9c..2a219a5d80fb 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -60,9 +60,6 @@ def copy_files_helper(folder_name): distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeOpenCLPythonPackage.txt"), os.path.join(CURRENT_DIR, "compile", "CMakeOpenCLPythonPackage.txt"), verbose=0) - distutils.file_util.copy_file(os.path.join(CURRENT_DIR, os.path.pardir, "CMakeOpenCLPythonPackageCache.txt"), - os.path.join(CURRENT_DIR, "compile", "CMakeOpenCLPythonPackageCache.txt"), - verbose=0) if use_gpu: copy_files_helper('compute') @@ -112,7 +109,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_mpi=False, use_mpi = False nomp = False use_hdfs = False - cmake_cmd.append("-C../compile/CMakeOpenCLPythonPackageCache.txt") + cmake_cmd.append("-D__OPENCL_PYTHON_PACKAGE=ON") if use_gpu: cmake_cmd.append("-DUSE_GPU=ON") if boost_root: From 7747d63ed5966af2bfe9d1ebd5cd16102b37bb7f Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 9 Jun 2020 13:54:27 -0400 Subject: [PATCH 14/58] Make tests run correctly --- .ci/test_windows.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index a790110adf65..3b0debde8606 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -78,9 +78,9 @@ pytest $tests ; Check-Output $? if ($env:TASK -eq "bdist") { # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "cpu" - pytest -k test_both_cpu_and_gpu ; Check-Output $? + pytest tests\python_package_test\test_dual.py ; Check-Output $? $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "gpu" - pytest -k test_both_cpu_and_gpu ; Check-Output $? + pytest tests\python_package_test\test_dual.py ; Check-Output $? } if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide From ed344fbcc8a054e8c6adc3dd7115950f0c7b9c91 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 9 Jun 2020 10:24:49 -0400 Subject: [PATCH 15/58] Correct directory --- .ci/test_windows.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 3b0debde8606..40fdded468b5 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -78,9 +78,9 @@ pytest $tests ; Check-Output $? if ($env:TASK -eq "bdist") { # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "cpu" - pytest tests\python_package_test\test_dual.py ; Check-Output $? + pytest $env:BUILD_SOURCESDIRECTORY\tests\python_package_test\test_dual.py ; Check-Output $? $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "gpu" - pytest tests\python_package_test\test_dual.py ; Check-Output $? + pytest $env:BUILD_SOURCESDIRECTORY\tests\python_package_test\test_dual.py ; Check-Output $? } if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide From bf226e3ad42ec21b1b86ccf8367f1cfd3a4c6eaa Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 9 Jun 2020 11:13:58 -0400 Subject: [PATCH 16/58] Try newer OpenCL runtime --- .ci/test_windows.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 40fdded468b5..1de2c9b76732 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -49,7 +49,16 @@ elseif ($env:TASK -eq "sdist") { } elseif ($env:TASK -eq "bdist") { # Install the Intel CPU runtime, so we can run tests against OpenCL - choco install opencl-intel-cpu-runtime -y + curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi + $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" + $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru + Get-Content msi.log + If (@(0,3010) -contains $return.exitcode) { + Write-Output "OpenCL install successful" + } else { + Write-Output "OpenCL install failed, aborting" + exit 1 + } RefreshEnv Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors From 3e57182a494f44ac3a832c8a1a374edcdadf98d4 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 9 Jun 2020 12:57:40 -0400 Subject: [PATCH 17/58] If we hit OpenCL code path that's good enough --- .ci/test_windows.ps1 | 4 +--- tests/python_package_test/test_dual.py | 30 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 1de2c9b76732..20f09d111250 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -86,9 +86,7 @@ pytest $tests ; Check-Output $? if ($env:TASK -eq "bdist") { # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "cpu" - pytest $env:BUILD_SOURCESDIRECTORY\tests\python_package_test\test_dual.py ; Check-Output $? - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "gpu" + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" pytest $env:BUILD_SOURCESDIRECTORY\tests\python_package_test\test_dual.py ; Check-Output $? } if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index c5aa3d97dcaa..b923c4a840bf 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -5,16 +5,40 @@ import lightgbm as lgb import numpy as np +from lightgbm.basic import LightGBMError + @pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, reason="Only run if appropriate env variable is set") -def test_both_gpu_and_cpu(): +def test_cpu_works(): """If compiled appropriately, the same installation will support both GPU and CPU.""" data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) param = {'num_leaves': 31, 'objective': 'binary', - 'device': os.environ["LIGHTGBM_TEST_DUAL_CPU_GPU"]} + 'device': 'cpu'} # This will raise an exception if it's an unsupported device: - lgb.train(param, train_data, 10, valid_sets=[validation_data]) \ No newline at end of file + lgb.train(param, train_data, 10, valid_sets=[validation_data]) + + +@pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, + reason="Only run if appropriate env variable is set") +def test_gpu_works(): + """If compiled appropriately, the same installation will support both GPU and CPU.""" + data = np.random.rand(500, 10) + label = np.random.randint(2, size=500) + validation_data = train_data = lgb.Dataset(data, label=label) + + try: + param = {'num_leaves': 31, 'objective': 'binary', + 'device': 'gpu'} + lgb.train(param, train_data, 10, valid_sets=[validation_data]) + except LightGBMError as e: + if str(e) == "No OpenCL device found": + # This is fine, it means there's no OpenCL device available, + # and OpenCL device is only searched for if we successfully + # loaded OpenCL GPU backend. + pass + else: + raise \ No newline at end of file From af176a6cfdc7a24ae3d690a05e6ef6c131b171bc Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 9 Jun 2020 18:00:14 +0000 Subject: [PATCH 18/58] Flag reference to unofficial repo with FIXME --- CMakeOpenCLPythonPackage.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index b63989e71376..de27e4cb33d7 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -5,10 +5,13 @@ string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION_DOT}) set(OPENCL_HEADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git") set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") + +# FIXME -- remove reference to OpenCL ICD Loader fork after decision on whether or not to include Linux build #set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") #set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") + set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE LIGHTGBM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) From 180c92924a6ab401ead9f766eb6aa69b790d5dfc Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Thu, 27 Aug 2020 21:14:13 +0000 Subject: [PATCH 19/58] TEMPORARY: update private repo tag for dependency --- CMakeOpenCLPythonPackage.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt index de27e4cb33d7..5f2ecc709214 100644 --- a/CMakeOpenCLPythonPackage.txt +++ b/CMakeOpenCLPythonPackage.txt @@ -10,7 +10,7 @@ set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") #set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") #set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") -set(OPENCL_LOADER_TAG "e42b3464e63f30cb0b818d88b836dd9e02ddbd7b") +set(OPENCL_LOADER_TAG "3d93e6b630a3592e4ab40f3fcc69a70d5ab8cc42") set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") From 7ce602881943288c0d23122767981449af5b47da Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 22 Sep 2020 15:16:53 -0400 Subject: [PATCH 20/58] Further post-merge fixes. --- .ci/test_windows.ps1 | 2 +- CMakeOpenCLPythonPackage.txt | 113 ----------------------------------- python-package/setup.py | 6 +- 3 files changed, 4 insertions(+), 117 deletions(-) delete mode 100644 CMakeOpenCLPythonPackage.txt diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index f346f9d9745c..6ba4a4ed9f5e 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -64,7 +64,7 @@ elseif ($env:TASK -eq "bdist") { Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors cd $env:BUILD_SOURCESDIRECTORY/python-package - python setup.py bdist_wheel --opencl-python-package --plat-name=win-amd64 --universal ; Check-Output $? + python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { diff --git a/CMakeOpenCLPythonPackage.txt b/CMakeOpenCLPythonPackage.txt deleted file mode 100644 index 5f2ecc709214..000000000000 --- a/CMakeOpenCLPythonPackage.txt +++ /dev/null @@ -1,113 +0,0 @@ - -set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) -set(BOOST_VERSION_DOT "1.73") -string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION_DOT}) - -set(OPENCL_HEADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git") -set(OPENCL_HEADER_TAG "3f7c1f77f8e1a3c9b48765c713ca19013e95b91e") - -# FIXME -- remove reference to OpenCL ICD Loader fork after decision on whether or not to include Linux build -#set(OPENCL_LOADER_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") -#set(OPENCL_LOADER_TAG "bbdf079426d859fb8a68c332b41b714f9c87d6ad") -set(OPENCL_LOADER_REPOSITORY "https://github.com/tpboudreau/OpenCL-ICD-Loader.git") -set(OPENCL_LOADER_TAG "3d93e6b630a3592e4ab40f3fcc69a70d5ab8cc42") - -set(BOOST_REPOSITORY "https://github.com/boostorg/boost.git") -set(BOOST_TAG "boost-${BOOST_VERSION_DOT}.0") -execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE LIGHTGBM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) -string(SHA1 OPENCL_PYTHON_PACKAGE_STAMP "${OPENCL_HEADER_REPOSITORY}@${OPENCL_HEADER_TAG};${OPENCL_LOADER_REPOSITORY}@${OPENCL_LOADER_TAG};${BOOST_REPOSITORY}@${BOOST_TAG};lightgbm@${LIGHTGBM_TAG}") -message(STATUS "OpenCL Python package build stamp: ${OPENCL_PYTHON_PACKAGE_STAMP}") - -# Build Independent OpenCL library -include(FetchContent) -FetchContent_Declare(OpenCL-Headers GIT_REPOSITORY ${OPENCL_HEADER_REPOSITORY} GIT_TAG ${OPENCL_HEADER_TAG}) -FetchContent_GetProperties(OpenCL-Headers) -if(NOT OpenCL-Headers_POPULATED) - FetchContent_Populate(OpenCL-Headers) - message(STATUS "Populated OpenCL Headers") -endif() -set(OPENCL_ICD_LOADER_HEADERS_DIR ${opencl-headers_SOURCE_DIR} CACHE PATH "") # for OpenCL ICD Loader -set(OpenCL_INCLUDE_DIR ${opencl-headers_SOURCE_DIR} CACHE PATH "") # for Boost::Compute - -FetchContent_Declare(OpenCL-ICD-Loader GIT_REPOSITORY ${OPENCL_LOADER_REPOSITORY} GIT_TAG ${OPENCL_LOADER_TAG}) -FetchContent_GetProperties(OpenCL-ICD-Loader) -if(NOT OpenCL-ICD-Loader_POPULATED) - FetchContent_Populate(OpenCL-ICD-Loader) - if(WIN32) - set(USE_DYNAMIC_VCXX_RUNTIME ON) - else() - set(OPENCL_ICD_LOADER_PIC ON) - endif() - add_subdirectory(${opencl-icd-loader_SOURCE_DIR} ${opencl-icd-loader_BINARY_DIR} EXCLUDE_FROM_ALL) - message(STATUS "Populated OpenCL ICD Loader") -endif() -list(APPEND OPENCL_PYTHON_PACKAGE_INCLUDES ${OPENCL_ICD_LOADER_HEADERS_DIR}) -if(WIN32) - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/Release/OpenCL.lib cfgmgr32.lib runtimeobject.lib) -else() - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${opencl-icd-loader_BINARY_DIR}/libOpenCL.a) -endif() -list(APPEND OPENCL_PYTHON_PACKAGE_DEFINITIONS CL_TARGET_OPENCL_VERSION=120) - -# Build Independent Boost libraries -include(ExternalProject) -include(ProcessorCount) -ProcessorCount(J) -set(BOOST_BASE "${PROJECT_BINARY_DIR}/Boost") -if(WIN32) - set(BOOST_BOOTSTRAP "${BOOST_BASE}/source/bootstrap.bat") - set(BOOST_BUILD "${BOOST_BASE}/source/b2.exe") - set(BOOST_FLAGS "") - list(APPEND BOOST_SUBMODULES "libs/*" "tools/*") -else() - set(BOOST_BOOTSTRAP "${BOOST_BASE}/source/bootstrap.sh") - set(BOOST_BUILD "${BOOST_BASE}/source/b2") - set(BOOST_FLAGS -fPIC) - list(APPEND BOOST_SUBMODULES "libs/compute" "libs/chrono" "libs/config" "libs/filesystem" "libs/headers" "libs/io" "libs/predef" "libs/system" "libs/uuid" "tools/*") -endif() -ExternalProject_Add(Boost - TMP_DIR "${BOOST_BASE}/tmp" - STAMP_DIR "${BOOST_BASE}/stamp" - DOWNLOAD_DIR "${BOOST_BASE}/download" - SOURCE_DIR "${BOOST_BASE}/source" - BINARY_DIR "${BOOST_BASE}/source" - INSTALL_DIR "${BOOST_BASE}/install" - GIT_REPOSITORY ${BOOST_REPOSITORY} - GIT_TAG ${BOOST_TAG} - GIT_SUBMODULES ${BOOST_SUBMODULES} - GIT_SHALLOW ON - UPDATE_COMMAND "" - PATCH_COMMAND "" - CONFIGURE_COMMAND ${BOOST_BOOTSTRAP} - BUILD_COMMAND ${BOOST_BUILD} -sBOOST_ROOT=${BOOST_BASE}/source -a -q -j ${J} --with-headers --with-chrono --with-filesystem --with-system link=static runtime-link=shared variant=release threading=multi cxxflags="${BOOST_FLAGS}" - INSTALL_COMMAND "" -) -set(BOOST_INCLUDE ${BOOST_BASE}/source CACHE PATH "") -set(BOOST_LIBRARY ${BOOST_BASE}/source/stage/lib CACHE PATH "") -list(APPEND OPENCL_PYTHON_PACKAGE_INCLUDES ${BOOST_INCLUDE}) -if(WIN32) - if(MSVC) - if(${MSVC_VERSION} GREATER 1929) - set(MSVC_TOOLCHAIN_ID "unknown") - elseif(${MSVC_VERSION} GREATER 1919) - set(MSVC_TOOLCHAIN_ID "142") - elseif(${MSVC_VERSION} GREATER 1909) - set(MSVC_TOOLCHAIN_ID "141") - elseif(${MSVC_VERSION} GREATER 1899) - set(MSVC_TOOLCHAIN_ID "140") - else() - set(MSVC_TOOLCHAIN_ID "unknown") - endif() - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_filesystem-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_system-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_chrono-vc${MSVC_TOOLCHAIN_ID}-mt-x64-${BOOST_VERSION_UNDERSCORE}.lib) - else() - message(WARNING "MinGW Boost library names not yet specified") - endif() -else() - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_filesystem.a) - list(APPEND OPENCL_PYTHON_PACKAGE_LIBRARIES ${BOOST_LIBRARY}/libboost_system.a) -endif() - -set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) - diff --git a/python-package/setup.py b/python-package/setup.py index 5775306ca04a..0450e3bd82c2 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -265,13 +265,13 @@ def run(self): class CustomBdistWheel(bdist_wheel): - """Supports --opencl-python-package to allow building OpenCL wheels on Windows. + """Supports --integrated-opencl to allow building OpenCL wheels on Windows. Other install options should be added over time when needed. """ user_options = bdist_wheel.user_options + [ - ('opencl-python-package', None, 'Compile integrated OpenCL version'), + ('integrated-opencl', None, 'Compile integrated OpenCL version'), ] def initialize_options(self): @@ -280,7 +280,7 @@ def initialize_options(self): def run(self): install = self.distribution.get_command_obj('install') - install.opencl_python_package = self.opencl_python_package + install.integrated_opencl = self.integrated_opencl bdist_wheel.run(self) From d9ad5a779b1f2594143d35323970c44d992cda7b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 23 Sep 2020 11:10:39 -0400 Subject: [PATCH 21/58] Fix attribute name. --- python-package/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-package/setup.py b/python-package/setup.py index 0450e3bd82c2..5f32183dcde2 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -276,7 +276,7 @@ class CustomBdistWheel(bdist_wheel): def initialize_options(self): bdist_wheel.initialize_options(self) - self.opencl_python_package = False + self.integrated_opencl = False def run(self): install = self.distribution.get_command_obj('install') From 69381fd5ebbf3c86a226953665858b35dfae0dac Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 23 Sep 2020 13:56:09 -0400 Subject: [PATCH 22/58] Reformat with black. --- tests/python_package_test/test_dual.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index b923c4a840bf..e7063df1ba9a 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -8,22 +8,25 @@ from lightgbm.basic import LightGBMError -@pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, - reason="Only run if appropriate env variable is set") +@pytest.mark.skipif( + os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, + reason="Only run if appropriate env variable is set", +) def test_cpu_works(): """If compiled appropriately, the same installation will support both GPU and CPU.""" data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {'num_leaves': 31, 'objective': 'binary', - 'device': 'cpu'} + param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} # This will raise an exception if it's an unsupported device: lgb.train(param, train_data, 10, valid_sets=[validation_data]) -@pytest.mark.skipif(os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, - reason="Only run if appropriate env variable is set") +@pytest.mark.skipif( + os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, + reason="Only run if appropriate env variable is set", +) def test_gpu_works(): """If compiled appropriately, the same installation will support both GPU and CPU.""" data = np.random.rand(500, 10) @@ -31,14 +34,13 @@ def test_gpu_works(): validation_data = train_data = lgb.Dataset(data, label=label) try: - param = {'num_leaves': 31, 'objective': 'binary', - 'device': 'gpu'} + param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} lgb.train(param, train_data, 10, valid_sets=[validation_data]) except LightGBMError as e: if str(e) == "No OpenCL device found": # This is fine, it means there's no OpenCL device available, - # and OpenCL device is only searched for if we successfully + # and OpenCL device is only searched for if we successfully # loaded OpenCL GPU backend. pass else: - raise \ No newline at end of file + raise From 67f4cb82699f89d2f65e09a6631603a5c89af694 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Mon, 2 Nov 2020 22:24:23 +0000 Subject: [PATCH 23/58] Rewrite config.h before library compilation for Windows wheel --- .ci/test_windows.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 6ba4a4ed9f5e..7eb92a7d1960 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -63,6 +63,13 @@ elseif ($env:TASK -eq "bdist") { Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + Set-Variable -Name CONFIG_HEADER -Value "$env:BUILD_SOURCESDIRECTORY/include/LightGBM/config.h" + (Get-Content (Get-Variable CONFIG_HEADER -valueOnly)).replace('std::string device_type = "cpu";', 'std::string device_type = "gpu";') | Set-Content (Get-Variable CONFIG_HEADER -valueOnly) + If (!(Select-String -Path (Get-Variable CONFIG_HEADER -valueOnly) -Pattern 'std::string device_type = "gpu";' -Quiet)) { + Write-Output "Rewriting config.h for GPU device type failed" + Exit -1 + } + cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? From 25b1d8851dd328e8d3cf3a6851692e3274a155cb Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 3 Nov 2020 21:08:06 +0000 Subject: [PATCH 24/58] Run dual cpu/gpu test once only for Windows bdist CI --- .ci/test_windows.ps1 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 7eb92a7d1960..9efeb8640531 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -72,7 +72,7 @@ elseif ($env:TASK -eq "bdist") { cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? - cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? + cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { cd $env:BUILD_SOURCESDIRECTORY\python-package @@ -88,14 +88,13 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq } else { # cannot test C API with "sdist" task $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" + if ($env:TASK -eq "bdist") { + # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" + } } pytest $tests ; Check-Output $? -if ($env:TASK -eq "bdist") { - # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" - pytest $env:BUILD_SOURCESDIRECTORY\tests\python_package_test\test_dual.py ; Check-Output $? -} if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py" From 6df3eb620432b03e98dfcc67e99c8fee46acc7be Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 4 Nov 2020 19:18:13 +0000 Subject: [PATCH 25/58] Avoid C API tests when building gpu library for wheel --- .ci/test_windows.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 9efeb8640531..bcf2ad65b9bf 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -84,14 +84,14 @@ elseif ($env:TASK -eq "bdist") { } if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { + # cannot test C API with "sdist" task + $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" +} elseif ($env:TASK -eq "bdist") { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" + # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" } else { - # cannot test C API with "sdist" task $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" - if ($env:TASK -eq "bdist") { - # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" - } } pytest $tests ; Check-Output $? From 67f254006a327ae3c9317e78adcfb30930499898 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 4 Nov 2020 20:34:20 +0000 Subject: [PATCH 26/58] TEMPORARY -- add clinfo tool to vm for debugging --- .ci/test_windows.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index bcf2ad65b9bf..54be895ee39a 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -63,6 +63,11 @@ elseif ($env:TASK -eq "bdist") { Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + # TEMPORARY for debugging + curl https://ci.appveyor.com/api/projects/oblomov/clinfo/artifacts/clinfo.exe?job=platform%3a+x64 -o clinfo.exe + .\clinfo.exe + # /TEMPORARY + Set-Variable -Name CONFIG_HEADER -Value "$env:BUILD_SOURCESDIRECTORY/include/LightGBM/config.h" (Get-Content (Get-Variable CONFIG_HEADER -valueOnly)).replace('std::string device_type = "cpu";', 'std::string device_type = "gpu";') | Set-Content (Get-Variable CONFIG_HEADER -valueOnly) If (!(Select-String -Path (Get-Variable CONFIG_HEADER -valueOnly) -Pattern 'std::string device_type = "gpu";' -Quiet)) { From 4f04a94bfd8ebccce9bf2850eacf009e934081c3 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 4 Nov 2020 22:24:32 +0000 Subject: [PATCH 27/58] Increase compilation logging --- python-package/setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python-package/setup.py b/python-package/setup.py index 5f32183dcde2..417ff4db092a 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -127,6 +127,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_cuda=False, use_mpi=False, cmake_cmd.append("-DUSE_OPENMP=OFF") if use_hdfs: cmake_cmd.append("-DUSE_HDFS=ON") + logger.info("Base cmake command: %s", cmake_cmd) if system() in {'Windows', 'Microsoft'}: if use_mingw: @@ -159,7 +160,7 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_cuda=False, use_mpi=False, arch = "Win32" if bit32 else "x64" vs_versions = ("Visual Studio 16 2019", "Visual Studio 15 2017", "Visual Studio 14 2015") for vs in vs_versions: - logger.info("Starting to compile with %s." % vs) + logger.info("Starting to compile with %s (%s).", vs, arch) status = silent_call(cmake_cmd + ["-G", vs, "-A", arch]) if status == 0: break From 1c28c4622ba4d8173d79a5167fe4e614d62b924c Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 4 Nov 2020 23:31:07 +0000 Subject: [PATCH 28/58] Rename OpenCL registry parameter after driver installation --- .ci/test_windows.ps1 | 2 ++ python-package/setup.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 54be895ee39a..899dbc557c91 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -60,6 +60,8 @@ elseif ($env:TASK -eq "bdist") { exit 1 } RefreshEnv + Rename-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" -Name "intelocl64.dll" -NewName "C:\Program Files (x86)\Common Files\Intel\OpenCL\windows\compiler\lib\intel64_win\intelocl64.dll" + RefreshEnv Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors diff --git a/python-package/setup.py b/python-package/setup.py index 417ff4db092a..1c28ba17143e 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -127,7 +127,6 @@ def compile_cpp(use_mingw=False, use_gpu=False, use_cuda=False, use_mpi=False, cmake_cmd.append("-DUSE_OPENMP=OFF") if use_hdfs: cmake_cmd.append("-DUSE_HDFS=ON") - logger.info("Base cmake command: %s", cmake_cmd) if system() in {'Windows', 'Microsoft'}: if use_mingw: From 477fd428b4e7ee764f7cf5332464cee49adf5bf3 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 6 Nov 2020 07:16:13 +0000 Subject: [PATCH 29/58] Install legacy OpenCL runtime --- .ci/test_windows.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 899dbc557c91..85167dfefcd5 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -49,8 +49,12 @@ elseif ($env:TASK -eq "sdist") { } elseif ($env:TASK -eq "bdist") { # Install the Intel CPU runtime, so we can run tests against OpenCL - curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi - $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" + Write-Output "Downloading OpenCL runtime" + #curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi + #$msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" + curl -o opencl_runtime_16.1.2_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/12512/opencl_runtime_16.1.2_x64_setup.msi + Write-Output "Installing OpenCL runtime" + $msiarglist = "/i opencl_runtime_16.1.2_x64_setup.msi /quiet /norestart /log msi.log" $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru Get-Content msi.log If (@(0,3010) -contains $return.exitcode) { @@ -60,12 +64,11 @@ elseif ($env:TASK -eq "bdist") { exit 1 } RefreshEnv - Rename-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" -Name "intelocl64.dll" -NewName "C:\Program Files (x86)\Common Files\Intel\OpenCL\windows\compiler\lib\intel64_win\intelocl64.dll" - RefreshEnv Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors # TEMPORARY for debugging + Write-Output "Interrogating OpenCL runtime" curl https://ci.appveyor.com/api/projects/oblomov/clinfo/artifacts/clinfo.exe?job=platform%3a+x64 -o clinfo.exe .\clinfo.exe # /TEMPORARY From f6d0dee4297aadb54f94b06dc9239f7e80f05578 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 6 Nov 2020 07:37:01 +0000 Subject: [PATCH 30/58] ... --- .ci/test_windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 85167dfefcd5..76440bb46c2e 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -53,8 +53,8 @@ elseif ($env:TASK -eq "bdist") { #curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi #$msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" curl -o opencl_runtime_16.1.2_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/12512/opencl_runtime_16.1.2_x64_setup.msi - Write-Output "Installing OpenCL runtime" $msiarglist = "/i opencl_runtime_16.1.2_x64_setup.msi /quiet /norestart /log msi.log" + Write-Output "Installing OpenCL runtime" $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru Get-Content msi.log If (@(0,3010) -contains $return.exitcode) { From 5fd426bfb2a382bf212b22ebb5b05bda46a5dafd Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 10 Nov 2020 18:27:18 +0000 Subject: [PATCH 31/58] Remove config.h change, clinfo installation, latest opencl runtime reference --- .ci/test_windows.ps1 | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 76440bb46c2e..240ff75df608 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -50,8 +50,6 @@ elseif ($env:TASK -eq "sdist") { elseif ($env:TASK -eq "bdist") { # Install the Intel CPU runtime, so we can run tests against OpenCL Write-Output "Downloading OpenCL runtime" - #curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi - #$msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" curl -o opencl_runtime_16.1.2_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/12512/opencl_runtime_16.1.2_x64_setup.msi $msiarglist = "/i opencl_runtime_16.1.2_x64_setup.msi /quiet /norestart /log msi.log" Write-Output "Installing OpenCL runtime" @@ -67,19 +65,6 @@ elseif ($env:TASK -eq "bdist") { Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors - # TEMPORARY for debugging - Write-Output "Interrogating OpenCL runtime" - curl https://ci.appveyor.com/api/projects/oblomov/clinfo/artifacts/clinfo.exe?job=platform%3a+x64 -o clinfo.exe - .\clinfo.exe - # /TEMPORARY - - Set-Variable -Name CONFIG_HEADER -Value "$env:BUILD_SOURCESDIRECTORY/include/LightGBM/config.h" - (Get-Content (Get-Variable CONFIG_HEADER -valueOnly)).replace('std::string device_type = "cpu";', 'std::string device_type = "gpu";') | Set-Content (Get-Variable CONFIG_HEADER -valueOnly) - If (!(Select-String -Path (Get-Variable CONFIG_HEADER -valueOnly) -Pattern 'std::string device_type = "gpu";' -Quiet)) { - Write-Output "Rewriting config.h for GPU device type failed" - Exit -1 - } - cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? From 4d3a7248078e438bd84b2a9076aa4ecd2a2abb5c Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 10 Nov 2020 19:32:48 +0000 Subject: [PATCH 32/58] Add explicit script exit --- .ci/test_windows.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 240ff75df608..3feab8a4f883 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -88,7 +88,9 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq } else { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" } +Write-Output "Running tests" pytest $tests ; Check-Output $? +Write-Output "Tests completed" if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide @@ -102,3 +104,6 @@ if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -e conda install -q -y -n $env:CONDA_ENV ipywidgets notebook jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb ; Check-Output $? # run all notebooks } + +Write-Output "Exiting" +Exit 0 From 97489e3486f53c26d5c3436af9e2d0babf83e32a Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 17 Nov 2020 22:34:50 +0000 Subject: [PATCH 33/58] revert to 18.1 intel driver --- .ci/test_windows.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 3feab8a4f883..b71c4764b1fa 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -50,8 +50,8 @@ elseif ($env:TASK -eq "sdist") { elseif ($env:TASK -eq "bdist") { # Install the Intel CPU runtime, so we can run tests against OpenCL Write-Output "Downloading OpenCL runtime" - curl -o opencl_runtime_16.1.2_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/12512/opencl_runtime_16.1.2_x64_setup.msi - $msiarglist = "/i opencl_runtime_16.1.2_x64_setup.msi /quiet /norestart /log msi.log" + curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi + $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" Write-Output "Installing OpenCL runtime" $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru Get-Content msi.log @@ -82,7 +82,7 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq # cannot test C API with "sdist" task $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" } elseif ($env:TASK -eq "bdist") { - $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" + $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" } else { @@ -104,6 +104,3 @@ if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -e conda install -q -y -n $env:CONDA_ENV ipywidgets notebook jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb ; Check-Output $? # run all notebooks } - -Write-Output "Exiting" -Exit 0 From cbfec02659816f0cb321e1184994a9c2f37d2a77 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Thu, 19 Nov 2020 18:26:22 +0000 Subject: [PATCH 34/58] Run test_dual.py in two different modes --- .ci/test_windows.ps1 | 45 +++++++++++++++----------- tests/python_package_test/test_dual.py | 38 ++++++++++++++-------- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index b71c4764b1fa..e17df51c0b41 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -48,23 +48,6 @@ elseif ($env:TASK -eq "sdist") { cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar } elseif ($env:TASK -eq "bdist") { - # Install the Intel CPU runtime, so we can run tests against OpenCL - Write-Output "Downloading OpenCL runtime" - curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi - $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" - Write-Output "Installing OpenCL runtime" - $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru - Get-Content msi.log - If (@(0,3010) -contains $return.exitcode) { - Write-Output "OpenCL install successful" - } else { - Write-Output "OpenCL install failed, aborting" - exit 1 - } - RefreshEnv - Write-Output "Current OpenCL drivers:" - Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors - cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? @@ -83,14 +66,38 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" } elseif ($env:TASK -eq "bdist") { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" - # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py + # Test that package works with no OpenCL platform installed; see tests/python_package_test/test_dual.py $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" } else { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" } Write-Output "Running tests" pytest $tests ; Check-Output $? -Write-Output "Tests completed" + +if ($env:TASK -eq "bdist") { + # Install the Intel CPU runtime, so we can run tests against OpenCL + Write-Output "Downloading OpenCL runtime" + curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi + $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" + Write-Output "Installing OpenCL runtime" + $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru + Get-Content msi.log + If (@(0,3010) -contains $return.exitcode) { + Write-Output "OpenCL install successful" + } else { + Write-Output "OpenCL install failed, aborting" + exit 1 + } + RefreshEnv + Write-Output "Current OpenCL drivers:" + Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + + $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test/test_dual.py" + # Test that package works with OpenCL platform installed; see tests/python_package_test/test_dual.py + $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "2" + Write-Output "Running auxiliary tests" + pytest $tests ; Check-Output $? +} if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index e7063df1ba9a..cef6e5f2d6a5 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -17,10 +17,12 @@ def test_cpu_works(): data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} - # This will raise an exception if it's an unsupported device: - lgb.train(param, train_data, 10, valid_sets=[validation_data]) + + # With the properly built library, running on the cpu should work + # whether an OpenCL runtime is installed (LIGHTGBM_TEST_DUAL_CPU_GPU="2") + # or not (LIGHTGBM_TEST_DUAL_CPU_GPU="1") + gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) @pytest.mark.skipif( @@ -29,18 +31,28 @@ def test_cpu_works(): ) def test_gpu_works(): """If compiled appropriately, the same installation will support both GPU and CPU.""" + TEST_DUAL_MODE = os.getenv('LIGHTGBM_TEST_DUAL_CPU_GPU') + data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - - try: - param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} - lgb.train(param, train_data, 10, valid_sets=[validation_data]) - except LightGBMError as e: - if str(e) == "No OpenCL device found": - # This is fine, it means there's no OpenCL device available, - # and OpenCL device is only searched for if we successfully - # loaded OpenCL GPU backend. - pass + param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} + + if TEST_DUAL_MODE == "1": + # We do NOT expect OpenCL to be installed, + # so we expect train({'device': 'gpu'}) to fail gracefully ... + try: + gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) + except LightGBMError as e: + if str(e) == "No OpenCL device found": # ... with this message + pass + else: + # We do not expect it to fail with a different message + raise else: + # We do not expect it to succeed raise + else: + # MODE must be "2", so we expect OpenCL to be installed and + # train({'device': 'gpu'}) to run successfully + gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) From 78bd0a2503708e65c37e72e77da9455b313eed84 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 24 Nov 2020 19:31:47 +0000 Subject: [PATCH 35/58] Revert "Run test_dual.py in two different modes" This reverts commit cbfec02659816f0cb321e1184994a9c2f37d2a77. --- .ci/test_windows.ps1 | 45 +++++++++++--------------- tests/python_package_test/test_dual.py | 38 ++++++++-------------- 2 files changed, 32 insertions(+), 51 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index e17df51c0b41..b71c4764b1fa 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -48,6 +48,23 @@ elseif ($env:TASK -eq "sdist") { cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar } elseif ($env:TASK -eq "bdist") { + # Install the Intel CPU runtime, so we can run tests against OpenCL + Write-Output "Downloading OpenCL runtime" + curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi + $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" + Write-Output "Installing OpenCL runtime" + $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru + Get-Content msi.log + If (@(0,3010) -contains $return.exitcode) { + Write-Output "OpenCL install successful" + } else { + Write-Output "OpenCL install failed, aborting" + exit 1 + } + RefreshEnv + Write-Output "Current OpenCL drivers:" + Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? @@ -66,38 +83,14 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" } elseif ($env:TASK -eq "bdist") { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" - # Test that package works with no OpenCL platform installed; see tests/python_package_test/test_dual.py + # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1" } else { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" } Write-Output "Running tests" pytest $tests ; Check-Output $? - -if ($env:TASK -eq "bdist") { - # Install the Intel CPU runtime, so we can run tests against OpenCL - Write-Output "Downloading OpenCL runtime" - curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi - $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" - Write-Output "Installing OpenCL runtime" - $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru - Get-Content msi.log - If (@(0,3010) -contains $return.exitcode) { - Write-Output "OpenCL install successful" - } else { - Write-Output "OpenCL install failed, aborting" - exit 1 - } - RefreshEnv - Write-Output "Current OpenCL drivers:" - Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors - - $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test/test_dual.py" - # Test that package works with OpenCL platform installed; see tests/python_package_test/test_dual.py - $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "2" - Write-Output "Running auxiliary tests" - pytest $tests ; Check-Output $? -} +Write-Output "Tests completed" if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index cef6e5f2d6a5..e7063df1ba9a 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -17,12 +17,10 @@ def test_cpu_works(): data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} - # With the properly built library, running on the cpu should work - # whether an OpenCL runtime is installed (LIGHTGBM_TEST_DUAL_CPU_GPU="2") - # or not (LIGHTGBM_TEST_DUAL_CPU_GPU="1") - gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) + param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} + # This will raise an exception if it's an unsupported device: + lgb.train(param, train_data, 10, valid_sets=[validation_data]) @pytest.mark.skipif( @@ -31,28 +29,18 @@ def test_cpu_works(): ) def test_gpu_works(): """If compiled appropriately, the same installation will support both GPU and CPU.""" - TEST_DUAL_MODE = os.getenv('LIGHTGBM_TEST_DUAL_CPU_GPU') - data = np.random.rand(500, 10) label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} - - if TEST_DUAL_MODE == "1": - # We do NOT expect OpenCL to be installed, - # so we expect train({'device': 'gpu'}) to fail gracefully ... - try: - gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) - except LightGBMError as e: - if str(e) == "No OpenCL device found": # ... with this message - pass - else: - # We do not expect it to fail with a different message - raise + + try: + param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} + lgb.train(param, train_data, 10, valid_sets=[validation_data]) + except LightGBMError as e: + if str(e) == "No OpenCL device found": + # This is fine, it means there's no OpenCL device available, + # and OpenCL device is only searched for if we successfully + # loaded OpenCL GPU backend. + pass else: - # We do not expect it to succeed raise - else: - # MODE must be "2", so we expect OpenCL to be installed and - # train({'device': 'gpu'}) to run successfully - gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) From 9f4c4535d0f10360d5f3463ad70c3a7a43b68a4b Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 24 Nov 2020 19:44:59 +0000 Subject: [PATCH 36/58] Remove unused expected failure test --- tests/python_package_test/test_dual.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index e7063df1ba9a..24c2424648bd 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -19,7 +19,6 @@ def test_cpu_works(): validation_data = train_data = lgb.Dataset(data, label=label) param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} - # This will raise an exception if it's an unsupported device: lgb.train(param, train_data, 10, valid_sets=[validation_data]) @@ -33,14 +32,5 @@ def test_gpu_works(): label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - try: - param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} - lgb.train(param, train_data, 10, valid_sets=[validation_data]) - except LightGBMError as e: - if str(e) == "No OpenCL device found": - # This is fine, it means there's no OpenCL device available, - # and OpenCL device is only searched for if we successfully - # loaded OpenCL GPU backend. - pass - else: - raise + param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} + lgb.train(param, train_data, 10, valid_sets=[validation_data]) From 48f25fafc3d6c38c1623b9c675704863e9a13ae4 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 00:28:24 +0000 Subject: [PATCH 37/58] Install OpenCL in separate powershell script --- .ci/install_opencl.ps1 | 18 ++++++++++ .ci/test_windows.ps1 | 50 ++++++++++++++++++-------- .vsts-ci.yml | 3 ++ tests/python_package_test/test_dual.py | 8 ++--- 4 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 .ci/install_opencl.ps1 diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 new file mode 100644 index 000000000000..4ff9a3ed0d69 --- /dev/null +++ b/.ci/install_opencl.ps1 @@ -0,0 +1,18 @@ + +Write-Output "Agent platform information:" +Get-WmiObject -Class Win32_ComputerSystem +Get-WmiObject -Class Win32_Processor +Get-WmiObject -Class Win32_BIOS + +if ($env:TASK -eq "bdist") { + Write-Output "Downloading OpenCL runtime" + $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" + curl -o .\$installer https://gamma-rho.com/$installer + + Write-Output "Installing OpenCL runtime" + Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + + Write-Output "Current OpenCL drivers:" + Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors +} + diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 8e708cef92db..3e7eb6dcd89d 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -6,6 +6,39 @@ function Check-Output { } } +function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) { + [Environment]::GetEnvironmentVariable($Name, $Scope) +} + +function Get-EnvironmentVariableNames([System.EnvironmentVariableTarget] $Scope) { + switch ($Scope) { + 'User' { Get-Item 'HKCU:\Environment' | Select-Object -ExpandProperty Property } + 'Machine' { Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' | Select-Object -ExpandProperty Property } + 'Process' { Get-ChildItem Env:\ | Select-Object -ExpandProperty Key } + default { throw "Unsupported environment scope: $Scope" } + } +} + +function Update-SessionEnvironment { + Write-Debug "Running 'Update-SessionEnvironment' - Updating the environment variables for the session." + #ordering is important here, $user comes after so we can override $machine + 'Machine', 'User' | + % { + $scope = $_ + Get-EnvironmentVariableNames -Scope $scope | + % { + Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_) + } + } + #Path gets special treatment b/c it munges the two together + $paths = 'Machine', 'User' | + % { + (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';' + } | + Select -Unique + $Env:PATH = $paths -join ';' +} + # unify environment variables for Azure devops and AppVeyor if (Test-Path env:APPVEYOR) { $env:APPVEYOR = "true" @@ -48,20 +81,7 @@ elseif ($env:TASK -eq "sdist") { cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar } elseif ($env:TASK -eq "bdist") { - # Install the Intel CPU runtime, so we can run tests against OpenCL - Write-Output "Downloading OpenCL runtime" - curl -o opencl_runtime_18.1_x64_setup.msi http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/13794/opencl_runtime_18.1_x64_setup.msi - $msiarglist = "/i opencl_runtime_18.1_x64_setup.msi /quiet /norestart /log msi.log" - Write-Output "Installing OpenCL runtime" - $return = Start-Process msiexec -ArgumentList $msiarglist -Wait -passthru - Get-Content msi.log - If (@(0,3010) -contains $return.exitcode) { - Write-Output "OpenCL install successful" - } else { - Write-Output "OpenCL install failed, aborting" - exit 1 - } - RefreshEnv + Update-SessionEnvironment Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors @@ -104,3 +124,5 @@ if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -e conda install -q -y -n $env:CONDA_ENV ipywidgets notebook jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb ; Check-Output $? # run all notebooks } + +conda deactivate diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 9341134b6bcd..0dbaabff9053 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -124,6 +124,9 @@ jobs: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' + - script: | + cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/install_opencl.ps1" + displayName: 'Install OpenCL' - script: | cmd /c "conda init powershell" cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1" diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index 24c2424648bd..f0c5e83618dd 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -18,8 +18,8 @@ def test_cpu_works(): label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {"num_leaves": 31, "objective": "binary", "device": "cpu"} - lgb.train(param, train_data, 10, valid_sets=[validation_data]) + param = {"verbosity": 2, "num_leaves": 31, "objective": "binary", "device": "cpu"} + gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) @pytest.mark.skipif( @@ -32,5 +32,5 @@ def test_gpu_works(): label = np.random.randint(2, size=500) validation_data = train_data = lgb.Dataset(data, label=label) - param = {"num_leaves": 31, "objective": "binary", "device": "gpu"} - lgb.train(param, train_data, 10, valid_sets=[validation_data]) + param = {"verbosity": 2, "num_leaves": 31, "objective": "binary", "device": "gpu"} + gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) From a38977f56b9088aef1fe6f299081a8cf1c1bd0b2 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 00:48:25 +0000 Subject: [PATCH 38/58] fix setup.py imports --- .ci/install_opencl.ps1 | 4 ++++ python-package/setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 4ff9a3ed0d69..af9b94e4ef63 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -5,6 +5,8 @@ Get-WmiObject -Class Win32_Processor Get-WmiObject -Class Win32_BIOS if ($env:TASK -eq "bdist") { + Write-Output "Installing OpenCL" + Write-Output "Downloading OpenCL runtime" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" curl -o .\$installer https://gamma-rho.com/$installer @@ -14,5 +16,7 @@ if ($env:TASK -eq "bdist") { Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors +} else { + Write-Output "OpenCL installation not required" } diff --git a/python-package/setup.py b/python-package/setup.py index 568eec6928f7..bf3914438566 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -11,9 +11,9 @@ from setuptools.command.install import install from setuptools.command.install_lib import install_lib from setuptools.command.sdist import sdist -from wheel.bdist_wheel import bdist_wheel from distutils.dir_util import copy_tree, create_tree, remove_tree from distutils.file_util import copy_file +from wheel.bdist_wheel import bdist_wheel LIGHTGBM_OPTIONS = [ From b00d907641a62f32669a63753a9e5e90d25a18ce Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 01:28:26 +0000 Subject: [PATCH 39/58] activate conda env after session update --- .ci/test_windows.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 3e7eb6dcd89d..587abee4c865 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -56,9 +56,9 @@ conda activate conda config --set always_yes yes --set changeps1 no conda update -q -y conda conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz scikit-learn scipy ; Check-Output $? -conda activate $env:CONDA_ENV if ($env:TASK -eq "regular") { + conda activate $env:CONDA_ENV mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build cmake -A x64 .. ; cmake --build . --target ALL_BUILD --config Release ; Check-Output $? cd $env:BUILD_SOURCESDIRECTORY/python-package @@ -67,6 +67,7 @@ if ($env:TASK -eq "regular") { cp $env:BUILD_SOURCESDIRECTORY/Release/lightgbm.exe $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif ($env:TASK -eq "sdist") { + conda activate $env:CONDA_ENV cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py sdist --formats gztar ; Check-Output $? cd dist; pip install @(Get-ChildItem *.gz) -v ; Check-Output $? @@ -85,11 +86,13 @@ elseif ($env:TASK -eq "bdist") { Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + conda activate $env:CONDA_ENV cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --python-tag py3 ; Check-Output $? cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { + conda activate $env:CONDA_ENV cd $env:BUILD_SOURCESDIRECTORY\python-package if ($env:COMPILER -eq "MINGW") { python setup.py install --mingw ; Check-Output $? @@ -124,5 +127,3 @@ if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -e conda install -q -y -n $env:CONDA_ENV ipywidgets notebook jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb ; Check-Output $? # run all notebooks } - -conda deactivate From 7e8c5bc4bb86135ce1ed4a2b4251ee9e2355de38 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 02:22:49 +0000 Subject: [PATCH 40/58] separate update functions; exit opencl installation on error --- .ci/install_opencl.ps1 | 16 +++++++++++----- .ci/test_windows.ps1 | 33 +-------------------------------- .ci/update_environment.ps1 | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 .ci/update_environment.ps1 diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index af9b94e4ef63..bfb9dc289f96 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -6,16 +6,22 @@ Get-WmiObject -Class Win32_BIOS if ($env:TASK -eq "bdist") { Write-Output "Installing OpenCL" - Write-Output "Downloading OpenCL runtime" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" curl -o .\$installer https://gamma-rho.com/$installer - Write-Output "Installing OpenCL runtime" Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} - - Write-Output "Current OpenCL drivers:" - Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors + if ($property -eq $null) { + Write-Output "Unable to install OpenCL runtime" + Write-Output "Setting EXIT" + $host.SetShouldExit(-1) + Exit -1 + } else { + Write-Output "Successfully installed OpenCL runtime" + Write-Output "Current OpenCL drivers:" + Write-Output $property + } } else { Write-Output "OpenCL installation not required" } diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 587abee4c865..e3b884360740 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -6,38 +6,7 @@ function Check-Output { } } -function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) { - [Environment]::GetEnvironmentVariable($Name, $Scope) -} - -function Get-EnvironmentVariableNames([System.EnvironmentVariableTarget] $Scope) { - switch ($Scope) { - 'User' { Get-Item 'HKCU:\Environment' | Select-Object -ExpandProperty Property } - 'Machine' { Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' | Select-Object -ExpandProperty Property } - 'Process' { Get-ChildItem Env:\ | Select-Object -ExpandProperty Key } - default { throw "Unsupported environment scope: $Scope" } - } -} - -function Update-SessionEnvironment { - Write-Debug "Running 'Update-SessionEnvironment' - Updating the environment variables for the session." - #ordering is important here, $user comes after so we can override $machine - 'Machine', 'User' | - % { - $scope = $_ - Get-EnvironmentVariableNames -Scope $scope | - % { - Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_) - } - } - #Path gets special treatment b/c it munges the two together - $paths = 'Machine', 'User' | - % { - (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';' - } | - Select -Unique - $Env:PATH = $paths -join ';' -} +. $env:BUILD_SOURCESDIRECTORY/.ci/update_environment.ps1 # unify environment variables for Azure devops and AppVeyor if (Test-Path env:APPVEYOR) { diff --git a/.ci/update_environment.ps1 b/.ci/update_environment.ps1 new file mode 100644 index 000000000000..6e2a7d5c12dc --- /dev/null +++ b/.ci/update_environment.ps1 @@ -0,0 +1,34 @@ + +function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) { + [Environment]::GetEnvironmentVariable($Name, $Scope) +} + +function Get-EnvironmentVariableNames([System.EnvironmentVariableTarget] $Scope) { + switch ($Scope) { + 'User' { Get-Item 'HKCU:\Environment' | Select-Object -ExpandProperty Property } + 'Machine' { Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' | Select-Object -ExpandProperty Property } + 'Process' { Get-ChildItem Env:\ | Select-Object -ExpandProperty Key } + default { throw "Unsupported environment scope: $Scope" } + } +} + +function Update-SessionEnvironment { + Write-Debug "Running 'Update-SessionEnvironment' - Updating the environment variables for the session." + #ordering is important here, $user comes after so we can override $machine + 'Machine', 'User' | + % { + $scope = $_ + Get-EnvironmentVariableNames -Scope $scope | + % { + Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_) + } + } + #Path gets special treatment b/c it munges the two together + $paths = 'Machine', 'User' | + % { + (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';' + } | + Select -Unique + $Env:PATH = $paths -join ';' +} + From e721d95686fdf13a50b8f7366c7555907ce844a5 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 06:02:17 +0000 Subject: [PATCH 41/58] nothing; start pipeline --- .ci/install_opencl.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index bfb9dc289f96..b91e59540e11 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -11,6 +11,7 @@ if ($env:TASK -eq "bdist") { curl -o .\$installer https://gamma-rho.com/$installer Write-Output "Installing OpenCL runtime" Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { Write-Output "Unable to install OpenCL runtime" From ae74d0eb89b647dac729c29e3f362a148f12688a Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 06:18:17 +0000 Subject: [PATCH 42/58] download from original source --- .ci/install_opencl.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index b91e59540e11..3ccd3edb1383 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -7,10 +7,12 @@ Get-WmiObject -Class Win32_BIOS if ($env:TASK -eq "bdist") { Write-Output "Installing OpenCL" Write-Output "Downloading OpenCL runtime" - $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" - curl -o .\$installer https://gamma-rho.com/$installer + curl -o AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe + #$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" + #curl -o .\$installer https://gamma-rho.com/$installer Write-Output "Installing OpenCL runtime" - Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + Invoke-Command -ScriptBlock {Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + #Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { From cd50a78ae28dc4fde1e96e709d2f9cc843558320 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 06:50:54 +0000 Subject: [PATCH 43/58] specify tls version for installer download --- .ci/install_opencl.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 3ccd3edb1383..553a86b254c0 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -7,12 +7,12 @@ Get-WmiObject -Class Win32_BIOS if ($env:TASK -eq "bdist") { Write-Output "Installing OpenCL" Write-Output "Downloading OpenCL runtime" - curl -o AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe - #$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" - #curl -o .\$installer https://gamma-rho.com/$installer + #curl -o AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe + $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" + curl --ipv4 --tlsv1.2 --output $installer https://gamma-rho.com/$installer Write-Output "Installing OpenCL runtime" - Invoke-Command -ScriptBlock {Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} - #Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + #Invoke-Command -ScriptBlock {Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { From 41915ded468eba430ebca5f8eaa2ae61517b1928 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 16:03:16 +0000 Subject: [PATCH 44/58] eliminate variable from command --- .ci/install_opencl.ps1 | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 553a86b254c0..d208a85e177b 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,27 +1,25 @@ -Write-Output "Agent platform information:" -Get-WmiObject -Class Win32_ComputerSystem -Get-WmiObject -Class Win32_Processor -Get-WmiObject -Class Win32_BIOS - if ($env:TASK -eq "bdist") { - Write-Output "Installing OpenCL" + Write-Output "Installing OpenCL CPU platform" + + Write-Output "Agent platform information:" + Get-WmiObject -Class Win32_ComputerSystem + Get-WmiObject -Class Win32_Processor + Get-WmiObject -Class Win32_BIOS + Write-Output "Downloading OpenCL runtime" - #curl -o AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe - $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" - curl --ipv4 --tlsv1.2 --output $installer https://gamma-rho.com/$installer + Invoke-WebRequest -OutFile AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe -Uri https://gamma-rho.com/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe Write-Output "Installing OpenCL runtime" - #Invoke-Command -ScriptBlock {Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} - Invoke-Command -ScriptBlock {Start-Process .\$installer -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + Invoke-Command -ScriptBlock {Start-Process 'AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe' -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { - Write-Output "Unable to install OpenCL runtime" + Write-Output "Unable to install OpenCL CPU platform" Write-Output "Setting EXIT" $host.SetShouldExit(-1) Exit -1 } else { - Write-Output "Successfully installed OpenCL runtime" + Write-Output "Successfully installed OpenCL CPU platform" Write-Output "Current OpenCL drivers:" Write-Output $property } From c3031b69cff0c01fd87444cac1e46cc825708252 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Fri, 11 Dec 2020 23:18:56 +0000 Subject: [PATCH 45/58] download opencl installer in parts --- .ci/install_opencl.ps1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index d208a85e177b..3878caf9e4bb 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -7,10 +7,18 @@ if ($env:TASK -eq "bdist") { Get-WmiObject -Class Win32_Processor Get-WmiObject -Class Win32_BIOS - Write-Output "Downloading OpenCL runtime" - Invoke-WebRequest -OutFile AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe -Uri https://gamma-rho.com/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe - Write-Output "Installing OpenCL runtime" - Invoke-Command -ScriptBlock {Start-Process 'AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe' -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} + Write-Output "Downloading OpenCL platform installer" + $parts = @("1", "2", "3", "4", "EXE") + foreach ($p in $parts) { + Write-Output " - downloading part $($p)" + Invoke-WebRequest -OutFile "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" -Uri "https://gamma-rho.com/split/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" + } + Write-Output " - combining parts" + Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.EXE" -Wait + Start-Sleep -Seconds 10 + + Write-Output "Running OpenCL platform installer" + Invoke-Command -ScriptBlock {Start-Process '.\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe' -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { From bcaceb8565dd6e8377d50f4d97a55b71393397b8 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sat, 12 Dec 2020 00:04:58 +0000 Subject: [PATCH 46/58] remove duplicate setup.py command class entry --- python-package/setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python-package/setup.py b/python-package/setup.py index bf3914438566..b37f9f05217a 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -366,7 +366,6 @@ def run(self): cmdclass={ 'install': CustomInstall, 'install_lib': CustomInstallLib, - 'bdist_wheel': CustomBdistWheel, 'sdist': CustomSdist, 'bdist_wheel': CustomBdistWheel, }, From 93964866c99c8b124537d7e1540534c39e412219 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sat, 12 Dec 2020 01:46:53 +0000 Subject: [PATCH 47/58] download smaller parts --- .ci/install_opencl.ps1 | 6 +++--- .ci/update_environment.ps1 | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 3878caf9e4bb..1cfcb3ba8d8c 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -8,12 +8,12 @@ if ($env:TASK -eq "bdist") { Get-WmiObject -Class Win32_BIOS Write-Output "Downloading OpenCL platform installer" - $parts = @("1", "2", "3", "4", "EXE") + $parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") foreach ($p in $parts) { Write-Output " - downloading part $($p)" - Invoke-WebRequest -OutFile "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" -Uri "https://gamma-rho.com/split/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" + Invoke-WebRequest -OutFile "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" -Uri "https://gamma-rho.com/parts/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" } - Write-Output " - combining parts" + Write-Output "Combining downloaded parts" Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.EXE" -Wait Start-Sleep -Seconds 10 diff --git a/.ci/update_environment.ps1 b/.ci/update_environment.ps1 index 6e2a7d5c12dc..0e12ba3fb164 100644 --- a/.ci/update_environment.ps1 +++ b/.ci/update_environment.ps1 @@ -1,3 +1,18 @@ +<# + Copyright 2011 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC + + Licensed 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. +#> function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) { [Environment]::GetEnvironmentVariable($Name, $Scope) From 88b9c49392097dade93fb62ba1b7cdbf8976a83a Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sat, 12 Dec 2020 06:47:45 +0000 Subject: [PATCH 48/58] remove redundant bdist wheel class --- .ci/install_opencl.ps1 | 2 +- .ci/test_windows.ps1 | 2 -- python-package/setup.py | 22 +--------------------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 1cfcb3ba8d8c..9e8565a3fb9a 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -13,7 +13,7 @@ if ($env:TASK -eq "bdist") { Write-Output " - downloading part $($p)" Invoke-WebRequest -OutFile "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" -Uri "https://gamma-rho.com/parts/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" } - Write-Output "Combining downloaded parts" + Write-Output "Combining OpenCL platform installer parts" Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.EXE" -Wait Start-Sleep -Seconds 10 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index e3b884360740..59c4ff6a6bc9 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -80,9 +80,7 @@ if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq } else { $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" } -Write-Output "Running tests" pytest $tests ; Check-Output $? -Write-Output "Tests completed" if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide diff --git a/python-package/setup.py b/python-package/setup.py index b37f9f05217a..a2e8a0cf3560 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -314,26 +314,6 @@ def run(self): os.remove(os.path.join(CURRENT_DIR, '_IS_SOURCE_PACKAGE.txt')) -class CustomBdistWheel(bdist_wheel): - """Supports --integrated-opencl to allow building OpenCL wheels on Windows. - - Other install options should be added over time when needed. - """ - - user_options = bdist_wheel.user_options + [ - ('integrated-opencl', None, 'Compile integrated OpenCL version'), - ] - - def initialize_options(self): - bdist_wheel.initialize_options(self) - self.integrated_opencl = False - - def run(self): - install = self.distribution.get_command_obj('install') - install.integrated_opencl = self.integrated_opencl - bdist_wheel.run(self) - - if __name__ == "__main__": CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) LOG_PATH = os.path.join(os.path.expanduser('~'), 'LightGBM_compilation.log') @@ -366,8 +346,8 @@ def run(self): cmdclass={ 'install': CustomInstall, 'install_lib': CustomInstallLib, - 'sdist': CustomSdist, 'bdist_wheel': CustomBdistWheel, + 'sdist': CustomSdist, }, packages=find_packages(), include_package_data=True, From 54a2eb4f176cb4ff471eba5f69a637001a04c237 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sat, 12 Dec 2020 08:19:15 +0000 Subject: [PATCH 49/58] Import chocolatey modules and use RefreshEnv --- .ci/test_windows.ps1 | 5 ++-- .ci/update_environment.ps1 | 49 -------------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 .ci/update_environment.ps1 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 59c4ff6a6bc9..b7fecb89eec7 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -6,7 +6,8 @@ function Check-Output { } } -. $env:BUILD_SOURCESDIRECTORY/.ci/update_environment.ps1 +$module = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" +Import-Module "$module" ; Check-Output $? # unify environment variables for Azure devops and AppVeyor if (Test-Path env:APPVEYOR) { @@ -51,7 +52,7 @@ elseif ($env:TASK -eq "sdist") { cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar } elseif ($env:TASK -eq "bdist") { - Update-SessionEnvironment + RefreshEnv Write-Output "Current OpenCL drivers:" Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors diff --git a/.ci/update_environment.ps1 b/.ci/update_environment.ps1 deleted file mode 100644 index 0e12ba3fb164..000000000000 --- a/.ci/update_environment.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -<# - Copyright 2011 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC - - Licensed 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. -#> - -function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) { - [Environment]::GetEnvironmentVariable($Name, $Scope) -} - -function Get-EnvironmentVariableNames([System.EnvironmentVariableTarget] $Scope) { - switch ($Scope) { - 'User' { Get-Item 'HKCU:\Environment' | Select-Object -ExpandProperty Property } - 'Machine' { Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' | Select-Object -ExpandProperty Property } - 'Process' { Get-ChildItem Env:\ | Select-Object -ExpandProperty Key } - default { throw "Unsupported environment scope: $Scope" } - } -} - -function Update-SessionEnvironment { - Write-Debug "Running 'Update-SessionEnvironment' - Updating the environment variables for the session." - #ordering is important here, $user comes after so we can override $machine - 'Machine', 'User' | - % { - $scope = $_ - Get-EnvironmentVariableNames -Scope $scope | - % { - Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_) - } - } - #Path gets special treatment b/c it munges the two together - $paths = 'Machine', 'User' | - % { - (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';' - } | - Select -Unique - $Env:PATH = $paths -join ';' -} - From cf52ec0ff884fec4891d6901ef00efed2dcb846a Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sun, 13 Dec 2020 01:56:47 +0000 Subject: [PATCH 50/58] insert pipeline cache for opencl installer --- .ci/download_opencl.ps1 | 26 ++++++++++++++++++++++ .ci/install_opencl.ps1 | 48 ++++++++++++++++------------------------- .vsts-ci.yml | 12 +++++++++++ 3 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 .ci/download_opencl.ps1 diff --git a/.ci/download_opencl.ps1 b/.ci/download_opencl.ps1 new file mode 100644 index 000000000000..1c1540858c72 --- /dev/null +++ b/.ci/download_opencl.ps1 @@ -0,0 +1,26 @@ + +$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" +$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" + +Write-Output "Downloading OpenCL platform installer" +$parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") +foreach ($p in $parts) { + Write-Output " - downloading part $($p)" + Invoke-WebRequest -OutFile "$installer.$p" -Uri "https://gamma-rho.com/parts/$installer.$p" +} + +Write-Output "Combining OpenCL platform installer parts" +Start-Process "$installer.EXE" -Wait +Start-Sleep -Seconds 10 +New-Item $cache -ItemType Directory | Out-Null +Move-Item -Path "$installer" -Destination "$cache\$installer" | Out-Null + +if (Test-Path "$cache\$installer") { + Write-Output "Successfully downloaded OpenCL platform installer" +} else { + Write-Output "Unable to download OpenCL platform installer" + Write-Output "Setting EXIT" + $host.SetShouldExit(-1) + Exit -1 +} + diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 9e8565a3fb9a..f993b87e0b97 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,37 +1,25 @@ -if ($env:TASK -eq "bdist") { - Write-Output "Installing OpenCL CPU platform" +Write-Output "Installing OpenCL CPU platform" - Write-Output "Agent platform information:" - Get-WmiObject -Class Win32_ComputerSystem - Get-WmiObject -Class Win32_Processor - Get-WmiObject -Class Win32_BIOS +Write-Output "Agent platform information:" +Get-WmiObject -Class Win32_ComputerSystem +Get-WmiObject -Class Win32_Processor +Get-WmiObject -Class Win32_BIOS - Write-Output "Downloading OpenCL platform installer" - $parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") - foreach ($p in $parts) { - Write-Output " - downloading part $($p)" - Invoke-WebRequest -OutFile "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" -Uri "https://gamma-rho.com/parts/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.$($p)" - } - Write-Output "Combining OpenCL platform installer parts" - Start-Process ".\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe.EXE" -Wait - Start-Sleep -Seconds 10 +$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" +$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" +Write-Output "Running OpenCL installer" +Invoke-Command -ScriptBlock {Start-Process "$cache\$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} - Write-Output "Running OpenCL platform installer" - Invoke-Command -ScriptBlock {Start-Process '.\AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe' -ArgumentList '/S /V"/quiet /norestart /passive /log amd_opencl_sdk.log"' -Wait} - - $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors - if ($property -eq $null) { - Write-Output "Unable to install OpenCL CPU platform" - Write-Output "Setting EXIT" - $host.SetShouldExit(-1) - Exit -1 - } else { - Write-Output "Successfully installed OpenCL CPU platform" - Write-Output "Current OpenCL drivers:" - Write-Output $property - } +$property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors +if ($property -eq $null) { + Write-Output "Unable to install OpenCL CPU platform" + Write-Output "Setting EXIT" + $host.SetShouldExit(-1) + Exit -1 } else { - Write-Output "OpenCL installation not required" + Write-Output "Successfully installed OpenCL CPU platform" + Write-Output "Current OpenCL drivers:" + Write-Output $property } diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 0dbaabff9053..f5d9de069ef8 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -124,8 +124,20 @@ jobs: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' + - task: Cache@2 + inputs: + key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "1"' + path: $(Pipeline.Workspace)/opencl_windows-amd_cpu-v3_0_130_135 + cacheHitVar: OPENCL_INSTALLER_FOUND + condition: eq(variables.TASK, 'bdist') + displayName: 'Cache OpenCL' + - script: | + cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/download_opencl.ps1" + condition: and(eq(variables.TASK, 'bdist'), ne(variables.OPENCL_INSTALLER_FOUND, 'true')) + displayName: 'Download OpenCL' - script: | cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/install_opencl.ps1" + condition: eq(variables.TASK, 'bdist') displayName: 'Install OpenCL' - script: | cmd /c "conda init powershell" From 817065c130e39220276415fada6581dd6f13a90e Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sun, 13 Dec 2020 02:40:04 +0000 Subject: [PATCH 51/58] rerun to ensure pipeline cache hit --- .ci/install_opencl.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index f993b87e0b97..dc058f7bcc25 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -8,6 +8,7 @@ Get-WmiObject -Class Win32_BIOS $cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" + Write-Output "Running OpenCL installer" Invoke-Command -ScriptBlock {Start-Process "$cache\$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} From 7abc286b22724905a2d3d77af8ae9923ef494859 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Sun, 13 Dec 2020 17:00:59 +0000 Subject: [PATCH 52/58] add comments, test another pipeline cache hit --- .ci/download_opencl.ps1 | 6 +++++- .ci/install_opencl.ps1 | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.ci/download_opencl.ps1 b/.ci/download_opencl.ps1 index 1c1540858c72..5cd96ce8fc4e 100644 --- a/.ci/download_opencl.ps1 +++ b/.ci/download_opencl.ps1 @@ -1,4 +1,6 @@ +# Download OpenCL platform installer executable into workspace cache + $cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" @@ -9,9 +11,11 @@ foreach ($p in $parts) { Invoke-WebRequest -OutFile "$installer.$p" -Uri "https://gamma-rho.com/parts/$installer.$p" } -Write-Output "Combining OpenCL platform installer parts" +Write-Output "Reassembling OpenCL platform installer" Start-Process "$installer.EXE" -Wait Start-Sleep -Seconds 10 + +Write-Output "Caching OpenCL platform installer" New-Item $cache -ItemType Directory | Out-Null Move-Item -Path "$installer" -Destination "$cache\$installer" | Out-Null diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index dc058f7bcc25..bf14569f40c9 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,4 +1,6 @@ +# Install OpenCL platform from installer executable expected in workspace cache + Write-Output "Installing OpenCL CPU platform" Write-Output "Agent platform information:" From a11991200dbd5002d648507b96a7e4d1d1aab93d Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 15 Dec 2020 02:01:02 +0000 Subject: [PATCH 53/58] remove cache task; download full installer file from new location --- .ci/download_opencl.ps1 | 30 ------------------------------ .ci/install_opencl.ps1 | 18 +++++++++++++----- .ci/test_windows.ps1 | 2 ++ .vsts-ci.yml | 11 ----------- 4 files changed, 15 insertions(+), 46 deletions(-) delete mode 100644 .ci/download_opencl.ps1 diff --git a/.ci/download_opencl.ps1 b/.ci/download_opencl.ps1 deleted file mode 100644 index 5cd96ce8fc4e..000000000000 --- a/.ci/download_opencl.ps1 +++ /dev/null @@ -1,30 +0,0 @@ - -# Download OpenCL platform installer executable into workspace cache - -$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" -$installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" - -Write-Output "Downloading OpenCL platform installer" -$parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") -foreach ($p in $parts) { - Write-Output " - downloading part $($p)" - Invoke-WebRequest -OutFile "$installer.$p" -Uri "https://gamma-rho.com/parts/$installer.$p" -} - -Write-Output "Reassembling OpenCL platform installer" -Start-Process "$installer.EXE" -Wait -Start-Sleep -Seconds 10 - -Write-Output "Caching OpenCL platform installer" -New-Item $cache -ItemType Directory | Out-Null -Move-Item -Path "$installer" -Destination "$cache\$installer" | Out-Null - -if (Test-Path "$cache\$installer") { - Write-Output "Successfully downloaded OpenCL platform installer" -} else { - Write-Output "Unable to download OpenCL platform installer" - Write-Output "Setting EXIT" - $host.SetShouldExit(-1) - Exit -1 -} - diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index bf14569f40c9..3daca623bdd5 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,6 +1,4 @@ -# Install OpenCL platform from installer executable expected in workspace cache - Write-Output "Installing OpenCL CPU platform" Write-Output "Agent platform information:" @@ -8,15 +6,25 @@ Get-WmiObject -Class Win32_ComputerSystem Get-WmiObject -Class Win32_Processor Get-WmiObject -Class Win32_BIOS -$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -Write-Output "Running OpenCL installer" -Invoke-Command -ScriptBlock {Start-Process "$cache\$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} +Write-Output "Downloading OpenCL installer" +Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer" +if (-Not (Test-Path ".\$installer")) { + Write-Output "Unable to download OpenCL installer" + Write-Output "Unable to install OpenCL CPU platform" + Write-Output "Setting EXIT" + $host.SetShouldExit(-1) + Exit -1 +} +Write-Output "Running OpenCL installer" +Invoke-Command -ScriptBlock {Start-Process "$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { Write-Output "Unable to install OpenCL CPU platform" + Write-Output "OpenCL installation log:" + Get-Content "opencl.log" Write-Output "Setting EXIT" $host.SetShouldExit(-1) Exit -1 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index b7fecb89eec7..df05ac10cdf7 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -6,6 +6,8 @@ function Check-Output { } } +# Import the Chocolatey profile module so that the RefreshEnv command +# invoked below properly updates the current PowerShell session enviroment. $module = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" Import-Module "$module" ; Check-Output $? diff --git a/.vsts-ci.yml b/.vsts-ci.yml index f5d9de069ef8..a27f10741616 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -124,17 +124,6 @@ jobs: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' - - task: Cache@2 - inputs: - key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "1"' - path: $(Pipeline.Workspace)/opencl_windows-amd_cpu-v3_0_130_135 - cacheHitVar: OPENCL_INSTALLER_FOUND - condition: eq(variables.TASK, 'bdist') - displayName: 'Cache OpenCL' - - script: | - cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/download_opencl.ps1" - condition: and(eq(variables.TASK, 'bdist'), ne(variables.OPENCL_INSTALLER_FOUND, 'true')) - displayName: 'Download OpenCL' - script: | cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/install_opencl.ps1" condition: eq(variables.TASK, 'bdist') From 2f133751f242c37dcae772a5e42f62064b74e8ca Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 15 Dec 2020 03:32:58 +0000 Subject: [PATCH 54/58] try another installer download timing --- .ci/install_opencl.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 3daca623bdd5..deb041893837 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,6 +1,5 @@ Write-Output "Installing OpenCL CPU platform" - Write-Output "Agent platform information:" Get-WmiObject -Class Win32_ComputerSystem Get-WmiObject -Class Win32_Processor From 761a48c87c3f922325f667f2f9e73e7d945abe0a Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 15 Dec 2020 20:25:30 +0000 Subject: [PATCH 55/58] reinsert pipeline cache --- .ci/install_opencl.ps1 | 45 ++++++++++++++++++++++++++++++------------ .vsts-ci.yml | 7 +++++++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index deb041893837..a87822ce03d2 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,24 +1,43 @@ Write-Output "Installing OpenCL CPU platform" -Write-Output "Agent platform information:" -Get-WmiObject -Class Win32_ComputerSystem -Get-WmiObject -Class Win32_Processor -Get-WmiObject -Class Win32_BIOS +$cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" -Write-Output "Downloading OpenCL installer" -Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer" -if (-Not (Test-Path ".\$installer")) { - Write-Output "Unable to download OpenCL installer" - Write-Output "Unable to install OpenCL CPU platform" - Write-Output "Setting EXIT" - $host.SetShouldExit(-1) - Exit -1 +if ($env:OPENCL_INSTALLER_FOUND -ne 'true') { + # Pipeline cache miss; download OpenCL platform installer executable + # into workspace cache + + Write-Output "Downloading OpenCL platform installer" + $parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") + foreach ($p in $parts) { + Write-Output " - downloading part $($p)" + Invoke-WebRequest -OutFile "$installer.$p" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer.$p" + } + + Write-Output "Reassembling OpenCL platform installer" + Start-Process "$installer.EXE" -Wait + Start-Sleep -Seconds 10 + + Write-Output "Caching OpenCL platform installer" + New-Item $cache -ItemType Directory | Out-Null + Move-Item -Path "$installer" -Destination "$cache\$installer" | Out-Null + + if (Test-Path "$cache\$installer") { + Write-Output "Successfully downloaded OpenCL platform installer" + } else { + Write-Output "Unable to download OpenCL platform installer" + Write-Output "Setting EXIT" + $host.SetShouldExit(-1) + Exit -1 + } } +# Install OpenCL platform from installer executable expected in workspace cache + Write-Output "Running OpenCL installer" -Invoke-Command -ScriptBlock {Start-Process "$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} +Invoke-Command -ScriptBlock {Start-Process "$cache\$installer" -ArgumentList '/S /V"/quiet /norestart /passive /log opencl.log"' -Wait} + $property = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors if ($property -eq $null) { Write-Output "Unable to install OpenCL CPU platform" diff --git a/.vsts-ci.yml b/.vsts-ci.yml index a27f10741616..f6ce3a1521d4 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -124,6 +124,13 @@ jobs: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' + - task: Cache@2 + inputs: + key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "2"' + path: $(Pipeline.Workspace)/opencl_windows-amd_cpu-v3_0_130_135 + cacheHitVar: OPENCL_INSTALLER_FOUND + condition: eq(variables.TASK, 'bdist') + displayName: 'Cache OpenCL' - script: | cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/install_opencl.ps1" condition: eq(variables.TASK, 'bdist') From 822bb34ea0da6a9132fcf848e1f9526fa3d92bd5 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 15 Dec 2020 20:56:24 +0000 Subject: [PATCH 56/58] retain cache task; download full file on cache miss --- .ci/install_opencl.ps1 | 10 +--------- .vsts-ci.yml | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index a87822ce03d2..f47ec75d95dc 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -9,15 +9,7 @@ if ($env:OPENCL_INSTALLER_FOUND -ne 'true') { # into workspace cache Write-Output "Downloading OpenCL platform installer" - $parts = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "EXE") - foreach ($p in $parts) { - Write-Output " - downloading part $($p)" - Invoke-WebRequest -OutFile "$installer.$p" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer.$p" - } - - Write-Output "Reassembling OpenCL platform installer" - Start-Process "$installer.EXE" -Wait - Start-Sleep -Seconds 10 + Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer" Write-Output "Caching OpenCL platform installer" New-Item $cache -ItemType Directory | Out-Null diff --git a/.vsts-ci.yml b/.vsts-ci.yml index f6ce3a1521d4..2c4e97060b22 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -126,7 +126,7 @@ jobs: displayName: 'Set Variables' - task: Cache@2 inputs: - key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "2"' + key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "3"' path: $(Pipeline.Workspace)/opencl_windows-amd_cpu-v3_0_130_135 cacheHitVar: OPENCL_INSTALLER_FOUND condition: eq(variables.TASK, 'bdist') From f456487d1d1f82bdde1d6b06220175956718bd88 Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Tue, 15 Dec 2020 21:50:46 +0000 Subject: [PATCH 57/58] test cache hit again --- .ci/install_opencl.ps1 | 6 ++++-- .vsts-ci.yml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index f47ec75d95dc..9dcb741287df 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,12 +1,14 @@ Write-Output "Installing OpenCL CPU platform" +# TODO(tpboudreau): consider removing the pipeline cache and downloading the +# installer unconditionally on every run if download time improves sufficiently + $cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe" if ($env:OPENCL_INSTALLER_FOUND -ne 'true') { - # Pipeline cache miss; download OpenCL platform installer executable - # into workspace cache + # Pipeline cache miss; download OpenCL platform installer executable into workspace cache Write-Output "Downloading OpenCL platform installer" Invoke-WebRequest -OutFile "$installer" -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/$installer" diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 2c4e97060b22..ff563c1a241f 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -126,7 +126,7 @@ jobs: displayName: 'Set Variables' - task: Cache@2 inputs: - key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "3"' + key: '"opencl.windows" | "amd.cpu" | "v3.0.130.135" | "1"' path: $(Pipeline.Workspace)/opencl_windows-amd_cpu-v3_0_130_135 cacheHitVar: OPENCL_INSTALLER_FOUND condition: eq(variables.TASK, 'bdist') From 29932a7233c589423f8a427bc7d3698f866aa17e Mon Sep 17 00:00:00 2001 From: TP Boudreau Date: Wed, 16 Dec 2020 00:20:23 +0000 Subject: [PATCH 58/58] remove todo --- .ci/install_opencl.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/.ci/install_opencl.ps1 b/.ci/install_opencl.ps1 index 9dcb741287df..8303629a04b0 100644 --- a/.ci/install_opencl.ps1 +++ b/.ci/install_opencl.ps1 @@ -1,9 +1,6 @@ Write-Output "Installing OpenCL CPU platform" -# TODO(tpboudreau): consider removing the pipeline cache and downloading the -# installer unconditionally on every run if download time improves sufficiently - $cache = "$env:PIPELINE_WORKSPACE\opencl_windows-amd_cpu-v3_0_130_135" $installer = "AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe"