diff --git a/.ci/setup.sh b/.ci/setup.sh index 87d7294288e0..d53a5a80c2c4 100755 --- a/.ci/setup.sh +++ b/.ci/setup.sh @@ -79,8 +79,7 @@ else # Linux sudo apt-get update sudo apt-get install --no-install-recommends -y \ libboost1.74-dev \ - ocl-icd-opencl-dev \ - pocl-opencl-icd + ocl-icd-opencl-dev else # in manylinux image sudo yum update -y sudo yum install -y \ @@ -90,6 +89,47 @@ else # Linux || exit -1 fi fi + if [[ $TASK == "gpu" || $TASK == "bdist" ]]; then + if [[ $IN_UBUNTU_LATEST_CONTAINER == "true" ]]; then + sudo apt-get update + sudo apt-get install --no-install-recommends -y \ + pocl-opencl-icd + elif [[ $(uname -m) == "aarch64" ]]; then + yum install -y \ + epel-release \ + gcc-c++ \ + hwloc-devel \ + sudo + yum install -y \ + llvm-toolset-7.0-clang-devel \ + llvm-toolset-7.0-llvm-devel \ + ocl-icd-devel + git clone --depth 1 --branch v1.8 https://github.com/pocl/pocl.git + cmake \ + -B pocl/build \ + -S pocl \ + -DCMAKE_BUILD_TYPE=release \ + -DCMAKE_C_COMPILER=/usr/bin/gcc \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++ \ + -DCMAKE_C_FLAGS=-std=gnu99 \ + -DPOCL_INSTALL_ICD_VENDORDIR=/etc/OpenCL/vendors \ + -DPOCL_DEBUG_MESSAGES=OFF \ + -DINSTALL_OPENCL_HEADERS=OFF \ + -DENABLE_SPIR=OFF \ + -DENABLE_POCLCC=OFF \ + -DENABLE_TESTS=OFF \ + -DENABLE_EXAMPLES=OFF \ + -DLLC_HOST_CPU=generic + cmake --build pocl/build -j4 + sudo cmake --install pocl/build + elif [[ $(uname -m) == "x86_64" ]]; then + sudo yum update -y + sudo yum install -y \ + ocl-icd-devel \ + opencl-headers \ + || exit -1 + fi + fi if [[ $TASK == "cuda" || $TASK == "cuda_exp" ]]; then echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections apt-get update diff --git a/.ci/test.sh b/.ci/test.sh index f73fbe915cc6..fbe0835838f0 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -161,10 +161,12 @@ elif [[ $TASK == "bdist" ]]; then else PLATFORM="manylinux2014_$ARCH" fi - cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=$PLATFORM --python-tag py3 || exit -1 + cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --integrated-opencl --plat-name=$PLATFORM --python-tag py3 || exit -1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp dist/lightgbm-$LGB_VER-py3-none-$PLATFORM.whl $BUILD_ARTIFACTSTAGINGDIRECTORY fi + # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py + export LIGHTGBM_TEST_DUAL_CPU_GPU=1 fi pip install --user $BUILD_DIRECTORY/python-package/dist/*.whl || exit -1 pytest $BUILD_DIRECTORY/tests || exit -1 diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 6d7628b1f2df..d68d3bd93824 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -187,7 +187,8 @@ jobs: EOF cat > docker-script.sh <`_ You may need to install `wheel `_ via ``pip install wheel`` first. -Compiled library that is included in the wheel file supports both **GPU** and **CPU** versions out of the box. This feature is experimental and available only for **Windows** currently. To use **GPU** version you only need to install OpenCL Runtime libraries. For NVIDIA and AMD GPU they are included in the ordinary drivers for your graphics card, so no action is required. If you would like your AMD or Intel CPU to act like a GPU (for testing and debugging) you can install `AMD APP SDK `_. +Compiled library that is included in the wheel file supports both **GPU** and **CPU** versions out of the box. This feature is experimental and available only for **Windows** and **Linux** currently. To use **GPU** version you only need to install OpenCL Runtime libraries. For NVIDIA and AMD GPU they are included in the ordinary drivers for your graphics card, so no action is required. If you would like your AMD or Intel CPU to act like a GPU (for testing and debugging) you can install `AMD APP SDK `_ on **Windows** and `PoCL `_ on **Linux**. Many modern Linux distributions provide packages for PoCL, look for ``pocl-opencl-icd`` on Debian-based distributions and ``pocl`` on RedHat-based distributions. For **Windows** users, `VC runtime `_ is needed if **Visual Studio** (2015 or newer) is not installed. diff --git a/tests/python_package_test/test_dual.py b/tests/python_package_test/test_dual.py index cd31a7d9b3b9..75c54c83eb94 100644 --- a/tests/python_package_test/test_dual.py +++ b/tests/python_package_test/test_dual.py @@ -2,6 +2,7 @@ """Tests for dual GPU+CPU support.""" import os +import platform import pytest from sklearn.metrics import log_loss @@ -26,9 +27,11 @@ def test_cpu_and_gpu_work(): params_gpu = params_cpu.copy() params_gpu["device"] = "gpu" - params_gpu["gpu_use_dp"] = True + # Double-precision floats are only supported on x86_64 with PoCL + params_gpu["gpu_use_dp"] = (platform.machine() == "x86_64") gpu_bst = lgb.train(params_gpu, data, num_boost_round=10) gpu_score = log_loss(y, gpu_bst.predict(X)) - assert cpu_score == pytest.approx(gpu_score) + rel = 1e-6 if params_gpu["gpu_use_dp"] else 1e-4 + assert cpu_score == pytest.approx(gpu_score, rel=rel) assert gpu_score < 0.242