Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial attempt at building OpenCL wheel for Windows #3051

Closed
wants to merge 13 commits into from
Closed
51 changes: 51 additions & 0 deletions .ci/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,57 @@ elseif ($env:TASK -eq "bdist") {
python setup.py bdist_wheel --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:TASK -eq "bdist_opencl") {
# Get the OpenCL headers
curl -o opencl_headers.zip https://github.com/KhronosGroup/OpenCL-Headers/archive/v2020.03.13.zip
Expand-Archive opencl_headers.zip

# Build the OpenCL ICD so we have a OpenCL.lib
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader
cd OpenCL-ICD-Loader
git checkout v2020.03.13
cp -r ..\opencl_headers\OpenCL-Headers-2020.03.13\CL inc
mkdir build
cd build
cmake -G "Visual Studio 15 2017" ..
cd ..
$msbuildarglist = "/p:Configuration=Release build\OpenCL.vcxproj"
$return = Start-Process C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild -ArgumentList $msbuildarglist -Wait -passthru
If (@(0,3010) -contains $return.exitcode) {
Write-Output "OpenCL ICD build successful"
} else {
Write-Output "OpenCL ICD build failed, aborting"
exit 1
}
cd ..

# The Intel CPU runtime, so we can run OpenCL code
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
}
Write-Output "Current OpenCL drivers:"
Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors
$env:LGBM_GPU = "1"
$env:LGBM_BOOST_ROOT = "$env:BOOST_ROOT_1_72_0"
echo "BOOST: $env:LGBM_BOOST_ROOT"
$env:LGBM_OPENCL_INCLUDE_DIR = "$pwd\opencl_headers\OpenCL-Headers-2020.03.13\"
$env:LGBM_OPENCL_LIBRARY = "$PWD\OpenCL-ICD-Loader\build\Release\OpenCL.lib"
# Set default device to GPU:
cd $env:BUILD_SOURCESDIRECTORY
(Get-Content include\LightGBM\config.h).replace('std::string device_type = "cpu";', 'std::string device_type = "gpu";') | Set-Content include\LightGBM\config.h
# Build the wheel:
cd $env:BUILD_SOURCESDIRECTORY/python-package
python setup.py bdist_wheel --plat-name=win-amd64 --universal ; Check-Output $?
cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $?
Get-ChildItem *.whl | Rename-Item -NewName { $_.Name -replace 'lightgbm-','lightgbm-opencl-' }
cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY
} elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) {
cd $env:BUILD_SOURCESDIRECTORY\python-package
if ($env:COMPILER -eq "MINGW") {
Expand Down
26 changes: 14 additions & 12 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,19 @@ jobs:
strategy:
maxParallel: 4
matrix:
r_package:
TASK: r-package
COMPILER: MSVC
regular:
TASK: regular
PYTHON_VERSION: 3.6
sdist:
TASK: sdist
PYTHON_VERSION: 2.7
bdist:
TASK: bdist
#r_package:
# TASK: r-package
# COMPILER: MSVC
#regular:
# TASK: regular
# PYTHON_VERSION: 3.6
#sdist:
# TASK: sdist
# PYTHON_VERSION: 2.7
#bdist:
# TASK: bdist
bdist_opencl:
TASK: bdist_opencl
steps:
- powershell: |
Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
Expand All @@ -139,7 +141,7 @@ jobs:
cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1"
displayName: Test
- task: PublishBuildArtifacts@1
condition: and(succeeded(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
condition: and(succeeded(), in(variables['TASK'], 'regular', 'sdist', 'bdist', 'bdist_opencl'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: PackageAssets
Expand Down
27 changes: 14 additions & 13 deletions python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import struct
import subprocess
import sys
from os import environ

from platform import system
from setuptools import find_packages, setup
Expand Down Expand Up @@ -202,19 +203,19 @@ class CustomInstall(install):

def initialize_options(self):
install.initialize_options(self)
self.mingw = 0
self.gpu = 0
self.boost_root = None
self.boost_dir = None
self.boost_include_dir = None
self.boost_librarydir = None
self.opencl_include_dir = None
self.opencl_library = None
self.mpi = 0
self.hdfs = 0
self.precompile = 0
self.nomp = 0
self.bit32 = 0
self.mingw = environ.get("LGBM_MINGW", 0)
self.gpu = environ.get("LGBM_GPU", 0)
self.boost_root = environ.get("LGBM_BOOST_ROOT", None)
self.boost_dir = environ.get("LGBM_BOOST_DIR", None)
self.boost_include_dir = environ.get("LGBM_BOOST_INCLUDE_DIR", None)
self.boost_librarydir = environ.get("LGBM_BOOST_LIBRARY_DIR", None)
self.opencl_include_dir = environ.get("LGBM_OPENCL_INCLUDE_DIR", None)
self.opencl_library = environ.get("LGBM_OPENCL_LIBRARY", None)
self.mpi = environ.get("LGBM_MPI", 0)
self.hdfs = environ.get("LGBM_HDFS", 0)
self.precompile = environ.get("LGBM_PRECOMPILE", 0)
self.nomp = environ.get("LGBM_NOMP", 0)
self.bit32 = environ.get("LGBM_BIT32", 0)

def run(self):
if (8 * struct.calcsize("P")) != 64:
Expand Down