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

[cmake] source file globbing is done incorrectly #6267

Closed
sabjohnso opened this issue Jan 11, 2024 · 2 comments · Fixed by #6268
Closed

[cmake] source file globbing is done incorrectly #6267

sabjohnso opened this issue Jan 11, 2024 · 2 comments · Fixed by #6268
Labels

Comments

@sabjohnso
Copy link
Contributor

Description

The attempt to include CUDA sources files only when USE_CUDA is true is done incorrectly, which can cause errors when LightGBM is built as part of a CMake superproject. Nesting, if() commands inside of a file(GLOB) command is just adding if(USE_CUDA) and endif() as globbing patters, not filtering the patterns between them.

file(
    GLOB
    SOURCES
      src/boosting/*.cpp
      src/io/*.cpp
      src/metric/*.cpp
      src/objective/*.cpp
      src/network/*.cpp
      src/treelearner/*.cpp
      src/utils/*.cpp
if(USE_CUDA)
      src/treelearner/*.cu
      src/boosting/cuda/*.cpp
      src/boosting/cuda/*.cu
      src/metric/cuda/*.cpp
      src/metric/cuda/*.cu
      src/objective/cuda/*.cpp
      src/objective/cuda/*.cu
      src/treelearner/cuda/*.cpp
      src/treelearner/cuda/*.cu
      src/io/cuda/*.cu
      src/io/cuda/*.cpp
      src/cuda/*.cpp
      src/cuda/*.cu
endif()
)

Reproducible example

Running CMake with tracing will allow you to see that you are not removing anything with the above command

cmake --trace --trace-expand --trace-redirect=trace.log -B build -S .

Tracing the will reveal that filtering the file globbing command failed: the CUDA files are included in the list of sources for the lightgbm_objs library, even though USE_CUDA is OFF.

/home/sbj/Sandbox/LightGBM/CMakeLists.txt(421):  file(GLOB SOURCES src/boosting/*.cpp src/io/*.cpp src/metric/*.cpp src/objective/*.cpp src/network/*.cpp src/treelearner/*.cpp src/utils/*.cpp if ( USE_CUDA ) src/treelearner/*.cu src/boosting/cuda/*.cpp src/boosting/cuda/*.cu src/metric/cuda/*.cpp src/metric/cuda/*.cu src/objective/cuda/*.cpp src/objective/cuda/*.cu src/treelearner/cuda/*.cpp src/treelearner/cuda/*.cu src/io/cuda/*.cu src/io/cuda/*.cpp src/cuda/*.cpp src/cuda/*.cu endif ( ) )
/home/sbj/Sandbox/LightGBM/CMakeLists.txt(448):  add_library(lightgbm_objs OBJECT /home/sbj/Sandbox/LightGBM/src/boosting/boosting.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/cuda/cuda_score_updater.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/cuda/cuda_score_updater.cu;/home/sbj/Sandbox/LightGBM/src/boosting/gbdt.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/gbdt_model_text.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/gbdt_prediction.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/prediction_early_stop.cpp;/home/sbj/Sandbox/LightGBM/src/boosting/sample_strategy.cpp;/home/sbj/Sandbox/LightGBM/src/cuda/cuda_algorithms.cu;/home/sbj/Sandbox/LightGBM/src/cuda/cuda_utils.cpp;/home/sbj/Sandbox/LightGBM/src/io/bin.cpp;/home/sbj/Sandbox/LightGBM/src/io/config.cpp;/home/sbj/Sandbox/LightGBM/src/io/config_auto.cpp;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_column_data.cpp;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_column_data.cu;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_metadata.cpp;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_row_data.cpp;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_tree.cpp;/home/sbj/Sandbox/LightGBM/src/io/cuda/cuda_tree.cu;/home/sbj/Sandbox/LightGBM/src/io/dataset.cpp;/home/sbj/Sandbox/LightGBM/src/io/dataset_loader.cpp;/home/sbj/Sandbox/LightGBM/src/io/file_io.cpp;/home/sbj/Sandbox/LightGBM/src/io/json11.cpp;/home/sbj/Sandbox/LightGBM/src/io/metadata.cpp;/home/sbj/Sandbox/LightGBM/src/io/parser.cpp;/home/sbj/Sandbox/LightGBM/src/io/train_share_states.cpp;/home/sbj/Sandbox/LightGBM/src/io/tree.cpp;/home/sbj/Sandbox/LightGBM/src/metric/cuda/cuda_binary_metric.cpp;/home/sbj/Sandbox/LightGBM/src/metric/cuda/cuda_pointwise_metric.cpp;/home/sbj/Sandbox/LightGBM/src/metric/cuda/cuda_pointwise_metric.cu;/home/sbj/Sandbox/LightGBM/src/metric/cuda/cuda_regression_metric.cpp;/home/sbj/Sandbox/LightGBM/src/metric/dcg_calculator.cpp;/home/sbj/Sandbox/LightGBM/src/metric/metric.cpp;/home/sbj/Sandbox/LightGBM/src/network/linker_topo.cpp;/home/sbj/Sandbox/LightGBM/src/network/linkers_mpi.cpp;/home/sbj/Sandbox/LightGBM/src/network/linkers_socket.cpp;/home/sbj/Sandbox/LightGBM/src/network/network.cpp;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_binary_objective.cpp;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_binary_objective.cu;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_multiclass_objective.cpp;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_multiclass_objective.cu;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_rank_objective.cpp;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_rank_objective.cu;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_regression_objective.cpp;/home/sbj/Sandbox/LightGBM/src/objective/cuda/cuda_regression_objective.cu;/home/sbj/Sandbox/LightGBM/src/objective/objective_function.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_best_split_finder.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_best_split_finder.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_data_partition.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_data_partition.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_gradient_discretizer.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_histogram_constructor.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_histogram_constructor.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_leaf_splits.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_leaf_splits.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_single_gpu_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/cuda/cuda_single_gpu_tree_learner.cu;/home/sbj/Sandbox/LightGBM/src/treelearner/data_parallel_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/feature_parallel_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/gpu_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/gradient_discretizer.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/linear_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/serial_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/treelearner/voting_parallel_tree_learner.cpp;/home/sbj/Sandbox/LightGBM/src/utils/openmp_wrapper.cpp )

Environment info

LightGBM version or commit hash: 5516533

Command(s) you used to install LightGBM
LigtGBM was cloned from github.com

Additional Comments

The following should fix the code:

file(
    GLOB
    SOURCES
      src/boosting/*.cpp
      src/io/*.cpp
      src/metric/*.cpp
      src/objective/*.cpp
      src/network/*.cpp
      src/treelearner/*.cpp
      src/utils/*.cpp)
file(
    GLOB
    LGBM_CUDA_SOURCES
      src/treelearner/*.cu
      src/boosting/cuda/*.cpp
      src/boosting/cuda/*.cu
      src/metric/cuda/*.cpp
      src/metric/cuda/*.cu
      src/objective/cuda/*.cpp
      src/objective/cuda/*.cu
      src/treelearner/cuda/*.cpp
      src/treelearner/cuda/*.cu
      src/io/cuda/*.cu
      src/io/cuda/*.cpp
      src/cuda/*.cpp
      src/cuda/*.cu)

if(USE_CUDA)
  list(APPEND SOURCES ${LGBM_CUDA_SOURCES})
endif()
@jameslamb jameslamb added the bug label Jan 11, 2024
@jameslamb
Copy link
Collaborator

Thanks for using LightGBM and for the excellent report!

Would you like to submit a pull request with a fix?

@jameslamb jameslamb changed the title source file globbing is done incorrectly [cmake] source file globbing is done incorrectly Jan 11, 2024
@jameslamb
Copy link
Collaborator

Ah I see you've already opened #6268. Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants