Skip to content

Commit

Permalink
[docs] [ci] encourage use of cmake --build (#6368)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Mar 20, 2024
1 parent 631e0a2 commit 4332b9d
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 171 deletions.
36 changes: 13 additions & 23 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ if [[ "${TASK}" == "r-package" ]] || [[ "${TASK}" == "r-rchk" ]]; then
fi

if [[ "$TASK" == "cpp-tests" ]]; then
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
if [[ $METHOD == "with-sanitizers" ]]; then
extra_cmake_opts="-DUSE_SANITIZER=ON"
if [[ -n $SANITIZERS ]]; then
Expand All @@ -31,9 +30,9 @@ if [[ "$TASK" == "cpp-tests" ]]; then
else
extra_cmake_opts=""
fi
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON $extra_cmake_opts ..
make testlightgbm -j4 || exit 1
./../testlightgbm || exit 1
cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON $extra_cmake_opts
cmake --build build --target testlightgbm -j4 || exit 1
./testlightgbm || exit 1
exit 0
fi

Expand All @@ -42,21 +41,20 @@ CONDA_PYTHON_REQUIREMENT="python=$PYTHON_VERSION[build=*cpython]"
if [[ $TASK == "if-else" ]]; then
mamba create -q -y -n $CONDA_ENV ${CONDA_PYTHON_REQUIREMENT} numpy
source activate $CONDA_ENV
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build && cmake .. && make lightgbm -j4 || exit 1
cmake -B build -S . || exit 1
cmake --build build --target lightgbm -j4 || exit 1
cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit 1
cd $BUILD_DIRECTORY/build && make lightgbm -j4 || exit 1
cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit 1
exit 0
fi

if [[ $TASK == "swig" ]]; then
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
if [[ $OS_NAME == "macos" ]]; then
cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
cmake -B build -S . -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON
else
cmake -DUSE_SWIG=ON ..
cmake -B build -S . -DUSE_SWIG=ON
fi
make -j4 || exit 1
cmake --build build -j4 || exit 1
if [[ $OS_NAME == "linux" ]] && [[ $COMPILER == "gcc" ]]; then
objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit 1
objdump -T $BUILD_DIRECTORY/lib_lightgbm_swig.so >> $BUILD_DIRECTORY/objdump.log || exit 1
Expand Down Expand Up @@ -224,9 +222,7 @@ if [[ $TASK == "gpu" ]]; then
pytest $BUILD_DIRECTORY/tests || exit 1
exit 0
elif [[ $METHOD == "source" ]]; then
mkdir $BUILD_DIRECTORY/build
cd $BUILD_DIRECTORY/build
cmake -DUSE_GPU=ON ..
cmake -B build -S . -DUSE_GPU=ON
fi
elif [[ $TASK == "cuda" ]]; then
sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' $BUILD_DIRECTORY/include/LightGBM/config.h
Expand All @@ -252,9 +248,7 @@ elif [[ $TASK == "cuda" ]]; then
pytest $BUILD_DIRECTORY/tests || exit 1
exit 0
elif [[ $METHOD == "source" ]]; then
mkdir $BUILD_DIRECTORY/build
cd $BUILD_DIRECTORY/build
cmake -DUSE_CUDA=ON ..
cmake -B build -S . -DUSE_CUDA=ON
fi
elif [[ $TASK == "mpi" ]]; then
if [[ $METHOD == "pip" ]]; then
Expand All @@ -275,17 +269,13 @@ elif [[ $TASK == "mpi" ]]; then
pytest $BUILD_DIRECTORY/tests || exit 1
exit 0
elif [[ $METHOD == "source" ]]; then
mkdir $BUILD_DIRECTORY/build
cd $BUILD_DIRECTORY/build
cmake -DUSE_MPI=ON -DUSE_DEBUG=ON ..
cmake -B build -S . -DUSE_MPI=ON -DUSE_DEBUG=ON
fi
else
mkdir $BUILD_DIRECTORY/build
cd $BUILD_DIRECTORY/build
cmake ..
cmake -B build -S .
fi

make _lightgbm -j4 || exit 1
cmake --build build --target _lightgbm -j4 || exit 1

cd $BUILD_DIRECTORY && sh ./build-python.sh install --precompile --user || exit 1
pytest $BUILD_DIRECTORY/tests || exit 1
Expand Down
16 changes: 7 additions & 9 deletions .ci/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ if ($env:TASK -eq "r-package") {
}

if ($env:TASK -eq "cpp-tests") {
mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON -A x64 ..
cmake --build . --target testlightgbm --config Debug ; Check-Output $?
cd ../Debug
.\testlightgbm.exe ; Check-Output $?
cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON -A x64
cmake --build build --target testlightgbm --config Debug ; Check-Output $?
.\Debug\testlightgbm.exe ; Check-Output $?
Exit 0
}

Expand All @@ -32,8 +30,8 @@ if ($env:TASK -eq "swig") {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory("$env:BUILD_SOURCESDIRECTORY/swig/swigwin.zip", "$env:BUILD_SOURCESDIRECTORY/swig")
$env:PATH = "$env:BUILD_SOURCESDIRECTORY/swig/swigwin-4.0.2;" + $env:PATH
mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build
cmake -A x64 -DUSE_SWIG=ON .. ; cmake --build . --target ALL_BUILD --config Release ; Check-Output $?
cmake -B build -S . -A x64 -DUSE_SWIG=ON ; Check-Output $?
cmake --build build --target ALL_BUILD --config Release ; Check-Output $?
if ($env:AZURE -eq "true") {
cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar ; Check-Output $?
}
Expand Down Expand Up @@ -71,8 +69,8 @@ if ($env:TASK -ne "bdist") {
}

if ($env:TASK -eq "regular") {
mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build
cmake -A x64 .. ; cmake --build . --target ALL_BUILD --config Release ; Check-Output $?
cmake -B build -S . -A x64 ; Check-Output $?
cmake --build build --target ALL_BUILD --config Release ; Check-Output $?
cd $env:BUILD_SOURCESDIRECTORY
sh $env:BUILD_SOURCESDIRECTORY/build-python.sh install --precompile ; Check-Output $?
cp $env:BUILD_SOURCESDIRECTORY/Release/lib_lightgbm.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY
Expand Down
9 changes: 4 additions & 5 deletions docker/dockerfile-cli
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ RUN git clone \
--branch stable \
--depth 1 \
https://github.com/Microsoft/LightGBM && \
mkdir LightGBM/build && \
cd LightGBM/build && \
cmake .. && \
make -j4 && \
make install && \
cd ./Lightgbm && \
cmake -B build -S . && \
cmake --build build -j4 && \
cmake --install build && \
cd "${HOME}" && \
rm -rf LightGBM

Expand Down
6 changes: 3 additions & 3 deletions docker/gpu/dockerfile-cli-only-distroless.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# LightGBM
WORKDIR /opt
RUN git clone --recursive --branch stable --depth 1 https://github.com/Microsoft/LightGBM && \
cd LightGBM && mkdir build && cd build && \
cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=${OPENCL_LIBRARIES}/libOpenCL.so.1 -DOpenCL_INCLUDE_DIR=$OPENCL_INCLUDE_DIR .. && \
make OPENCL_HEADERS=$OPENCL_INCLUDE_DIR LIBOPENCL=$OPENCL_LIBRARIES
cd LightGBM && \
cmake -B build -S . -DUSE_GPU=1 -DOpenCL_LIBRARY=${OPENCL_LIBRARIES}/libOpenCL.so.1 -DOpenCL_INCLUDE_DIR=$OPENCL_INCLUDE_DIR && \
OPENCL_HEADERS=$OPENCL_INCLUDE_DIR LIBOPENCL=$OPENCL_LIBRARIES cmake --build build

FROM gcr.io/distroless/cc-debian10
COPY --from=build \
Expand Down
6 changes: 3 additions & 3 deletions docker/gpu/dockerfile-cli-only.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# LightGBM
WORKDIR /opt
RUN git clone --recursive --branch stable --depth 1 https://github.com/Microsoft/LightGBM && \
cd LightGBM && mkdir build && cd build && \
cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=${OPENCL_LIBRARIES}/libOpenCL.so.1 -DOpenCL_INCLUDE_DIR=$OPENCL_INCLUDE_DIR .. && \
make OPENCL_HEADERS=$OPENCL_INCLUDE_DIR LIBOPENCL=$OPENCL_LIBRARIES
cd LightGBM && \
cmake -B build -S . -DUSE_GPU=1 -DOpenCL_LIBRARY=${OPENCL_LIBRARIES}/libOpenCL.so.1 -DOpenCL_INCLUDE_DIR=$OPENCL_INCLUDE_DIR && \
OPENCL_HEADERS=$OPENCL_INCLUDE_DIR LIBOPENCL=$OPENCL_LIBRARIES cmake --build build

FROM nvidia/opencl:runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
6 changes: 3 additions & 3 deletions docker/gpu/dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ RUN conda config --set always_yes yes --set changeps1 no && \

RUN cd /usr/local/src && mkdir lightgbm && cd lightgbm && \
git clone --recursive --branch stable --depth 1 https://github.com/microsoft/LightGBM && \
cd LightGBM && mkdir build && cd build && \
cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ .. && \
make OPENCL_HEADERS=/usr/local/cuda-8.0/targets/x86_64-linux/include LIBOPENCL=/usr/local/cuda-8.0/targets/x86_64-linux/lib
cd LightGBM && \
cmake -B build -S . -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ && \
OPENCL_HEADERS=/usr/local/cuda-8.0/targets/x86_64-linux/include LIBOPENCL=/usr/local/cuda-8.0/targets/x86_64-linux/lib cmake --build build

ENV PATH /usr/local/src/lightgbm/LightGBM:${PATH}

Expand Down
9 changes: 3 additions & 6 deletions docs/GPU-Tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ Now we are ready to checkout LightGBM and compile it with GPU support:

git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake -DUSE_GPU=1 ..
cmake -B build -S . -DUSE_GPU=1
  # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
# cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..
make -j$(nproc)
cd ..
# cmake -B build -S . -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/
cmake --build build -j$(nproc)

You will see two binaries are generated, ``lightgbm`` and ``lib_lightgbm.so``.

Expand Down
Loading

0 comments on commit 4332b9d

Please sign in to comment.