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

[CUDA] Add CUDA_ARCHITECTURES to fix CMake warnings (#3754) #4268

Merged
merged 1 commit into from
May 16, 2021
Merged

[CUDA] Add CUDA_ARCHITECTURES to fix CMake warnings (#3754) #4268

merged 1 commit into from
May 16, 2021

Conversation

RobinDong
Copy link
Contributor

Set property CUDA_ARCHITECTURES would fix the warnings reported by CMake 3.20.x

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much! I checked and it does seem that these changes will resolve the warnings with newer versions of CMake.


Those CI jobs test with the latest version of CMake, which is 3.20.2 as of today.

Get:1 https://apt.kitware.com/ubuntu focal/main amd64 cmake-data all 3.20.2-0kitware1ubuntu20.04.1 [1807 kB]
Get:2 https://apt.kitware.com/ubuntu focal/main amd64 cmake amd64 3.20.2-0kitware1ubuntu20.04.1 [10.5 MB]

Have you tested these changes against older versions of CMake? LightGBM currently supported CMake>=3.16 for CUDA builds.

LightGBM/CMakeLists.txt

Lines 27 to 28 in c1d2dbe

elseif(USE_CUDA)
cmake_minimum_required(VERSION 3.16)

I'm just leaving a "comment" review because I'd like to be sure this change doesn't break compatibility with older CMake versions. If you haven't tested that and aren't able to easily test it, I can try in the next day or two.

@RobinDong
Copy link
Contributor Author

Thanks very much! I checked and it does seem that these changes will resolve the warnings with newer versions of CMake.

Those CI jobs test with the latest version of CMake, which is 3.20.2 as of today.

Get:1 https://apt.kitware.com/ubuntu focal/main amd64 cmake-data all 3.20.2-0kitware1ubuntu20.04.1 [1807 kB]
Get:2 https://apt.kitware.com/ubuntu focal/main amd64 cmake amd64 3.20.2-0kitware1ubuntu20.04.1 [10.5 MB]

Have you tested these changes against older versions of CMake? LightGBM currently supported CMake>=3.16 for CUDA builds.

LightGBM/CMakeLists.txt

Lines 27 to 28 in c1d2dbe

elseif(USE_CUDA)
cmake_minimum_required(VERSION 3.16)

I'm just leaving a "comment" review because I'd like to be sure this change doesn't break compatibility with older CMake versions. If you haven't tested that and aren't able to easily test it, I can try in the next day or two.

Hi James,

Thank you for your review.
I have tested this patch for CMake-3.16.9 and CMake-3.19.8 by using cmake -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc -DUSE_CUDA=ON .. and they all work well.

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobinDong Thanks a lot for picking this issue up!
I have some comments and question below:

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@jameslamb jameslamb changed the title [CUDA] Add CMake property to fix warning (#3754) [CUDA] Add CUDA_ARCHITECTURES to fix CMake warnings (#3754) May 11, 2021
@jameslamb
Copy link
Collaborator

I've updated the title of this pull request to be a bit more explicit. PR titles become changelog entries in this project (see, for example, https://github.com/microsoft/LightGBM/releases/tag/v3.2.1), and I want to make it easier for anyone looking for CUDA-related changes in the next release to find them.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@StrikerRUS
Copy link
Collaborator

@jameslamb

If you haven't tested that and aren't able to easily test it, I can try in the next day or two.

You've said you have an easy access to Linux with CUDA machine. If that's still true, could you please check this PR with CMake 3.16? I want to be sure these changes don't make old CMake panic with unrecognized target property.
#4268 (comment)

@jameslamb
Copy link
Collaborator

If that's still true, could you please check this PR with CMake 3.16?

yep, definitely! I'll try soon and let you know what I find.

@jameslamb
Copy link
Collaborator

Compilation seemed to succeed and I don't see any warnings! Using CUDA 10.2 and CMake 3.16.9 (the latest version in the 3.16 series, as far as I could tell from https://cmake.org/cmake/help/latest/release/3.16.html).

output of nvidia-smi
Fri May 14 20:01:32 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 207...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   51C    P8    10W /  N/A |    286MiB /  7982MiB |     12%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

I used nvidia-docker to test this. Ran this command:

nvidia-docker run \
    --env DEBIAN_FRONTEND="noninteractive" \
    -it nvidia/cuda:10.2-devel-ubuntu18.04 \
    /bin/bash

Then this script inside the container:

testing scripts
apt-get update
apt-get install \
    -y \
    software-properties-common \
    apt-transport-https \
    curl \
    git \
    wget \
    libcurl4-openssl-dev \
    default-jdk-headless \
    libssl-dev \
    libxml2-dev \
    libboost-dev \
    libboost-system-dev \
    libboost-filesystem-dev \
    clinfo

# see install instructions at https://cmake.org/install/
mkdir -p /tmp/cmake-install
pushd /tmp/cmake-install

    CMAKE_VERSION=3.16.9
    CMAKE_TARBALL=cmake-${CMAKE_VERSION}.tar.gz

    curl -OL \
        https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TARBALL}
    tar -xvzf ${CMAKE_TARBALL}
    rm -rf ./${CMAKE_TARBALL}
    cd cmake-${CMAKE_VERSION}
    ./bootstrap
    make
    make install
popd

# check CMake version
cmake --version

# get LightGBM from PR 4268
git clone --recursive https://github.com/RobinDong/LightGBM.git --branch master

cd LightGBM
mkdir ./build
cd ./build
cmake \
    -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
    -DUSE_CUDA=ON \
    ..

make _lightgbm -j4

See the logs below.

logs from 'cmake ..'

ran the following

cmake \
    -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
    -DUSE_CUDA=ON \
    ..

which resulted in these logs

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The CUDA compiler identification is NVIDIA 10.2.89
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda (found suitable version "10.2", minimum required is "9.0") 
-- CMAKE_CUDA_FLAGS: -Xcompiler=-fopenmp -Xcompiler=-fPIC -Xcompiler=-Wall -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -O3 -lineinfo
-- ALLFEATS_DEFINES: -DPOWER_FEATURE_WORKGROUPS=12;-DUSE_CONSTANT_BUF=0;-DENABLE_ALL_FEATURES
-- FULLDATA_DEFINES: -DPOWER_FEATURE_WORKGROUPS=12;-DUSE_CONSTANT_BUF=0;-DENABLE_ALL_FEATURES;-DIGNORE_INDICES
-- Performing Test MM_PREFETCH
-- Performing Test MM_PREFETCH - Success
-- Using _mm_prefetch
-- Performing Test MM_MALLOC
-- Performing Test MM_MALLOC - Success
-- Using _mm_malloc
-- Configuring done
-- Generating done
-- Build files have been written to: /root/LightGBM/build
logs from 'make _lightgbm'

ran the following

make _lightgbm -j2

which resulted in the following logs

Scanning dependencies of target histo_16_64_256_sp
Scanning dependencies of target histo_16_64_256-fulldata_sp_const
[  2%] Building CUDA object CMakeFiles/histo_16_64_256_sp.dir/src/treelearner/kernels/histogram_16_64_256.cu.o
[  5%] Building CUDA object CMakeFiles/histo_16_64_256-fulldata_sp_const.dir/src/treelearner/kernels/histogram_16_64_256.cu.o
[  5%] Built target histo_16_64_256-fulldata_sp_const
Scanning dependencies of target histo_16_64_256_sp_const
[  7%] Building CUDA object CMakeFiles/histo_16_64_256_sp_const.dir/src/treelearner/kernels/histogram_16_64_256.cu.o
[  7%] Built target histo_16_64_256_sp
Scanning dependencies of target histo_16_64_256-fulldata_sp
[ 10%] Building CUDA object CMakeFiles/histo_16_64_256-fulldata_sp.dir/src/treelearner/kernels/histogram_16_64_256.cu.o
[ 10%] Built target histo_16_64_256_sp_const
[ 10%] Built target histo_16_64_256-fulldata_sp
Scanning dependencies of target _lightgbm
[ 15%] Building CXX object CMakeFiles/_lightgbm.dir/src/boosting/boosting.cpp.o
[ 15%] Building CXX object CMakeFiles/_lightgbm.dir/src/boosting/gbdt.cpp.o
[ 17%] Building CXX object CMakeFiles/_lightgbm.dir/src/boosting/gbdt_model_text.cpp.o
[ 20%] Building CXX object CMakeFiles/_lightgbm.dir/src/boosting/gbdt_prediction.cpp.o
[ 22%] Building CXX object CMakeFiles/_lightgbm.dir/src/boosting/prediction_early_stop.cpp.o
[ 25%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/bin.cpp.o
[ 27%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/config.cpp.o
[ 30%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/config_auto.cpp.o
[ 32%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/dataset.cpp.o
[ 35%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/dataset_loader.cpp.o
[ 37%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/file_io.cpp.o
[ 40%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/json11.cpp.o
[ 42%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/metadata.cpp.o
[ 45%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/parser.cpp.o
[ 47%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/train_share_states.cpp.o
[ 50%] Building CXX object CMakeFiles/_lightgbm.dir/src/io/tree.cpp.o
[ 52%] Building CXX object CMakeFiles/_lightgbm.dir/src/metric/dcg_calculator.cpp.o
[ 55%] Building CXX object CMakeFiles/_lightgbm.dir/src/metric/metric.cpp.o
[ 57%] Building CXX object CMakeFiles/_lightgbm.dir/src/network/ifaddrs_patch.cpp.o
[ 60%] Building CXX object CMakeFiles/_lightgbm.dir/src/network/linker_topo.cpp.o
[ 62%] Building CXX object CMakeFiles/_lightgbm.dir/src/network/linkers_mpi.cpp.o
[ 65%] Building CXX object CMakeFiles/_lightgbm.dir/src/network/linkers_socket.cpp.o
[ 67%] Building CXX object CMakeFiles/_lightgbm.dir/src/network/network.cpp.o
[ 70%] Building CXX object CMakeFiles/_lightgbm.dir/src/objective/objective_function.cpp.o
[ 72%] Building CUDA object CMakeFiles/_lightgbm.dir/src/treelearner/cuda_kernel_launcher.cu.o
[ 75%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/cuda_tree_learner.cpp.o
[ 77%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/data_parallel_tree_learner.cpp.o
[ 80%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/feature_parallel_tree_learner.cpp.o
[ 82%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/gpu_tree_learner.cpp.o
[ 85%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/linear_tree_learner.cpp.o
[ 87%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/serial_tree_learner.cpp.o
[ 90%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/tree_learner.cpp.o
[ 92%] Building CXX object CMakeFiles/_lightgbm.dir/src/treelearner/voting_parallel_tree_learner.cpp.o
[ 95%] Building CXX object CMakeFiles/_lightgbm.dir/src/c_api.cpp.o
[ 97%] Linking CUDA device code CMakeFiles/_lightgbm.dir/cmake_device_link.o
[100%] Linking CXX shared library ../lib_lightgbm.so
[100%] Built target _lightgbm

Now that I have this script working, it would be fairly easy and quick to test other CMake versions, so please let me know if there are other versions you'd like me to check.

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameslamb Thank you very much for verifying with CMake 3.16!

@RobinDong Many thanks for your great help! We will really appreciate your further contributions to CMake and CUDA things.

@StrikerRUS
Copy link
Collaborator

@RobinDong Please update to the latest master branch to fix Dask environmental issues we fixed recently and we are ready to merge.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants