From fc777572f5c1850ecfbfe05f4a268f8600f9f231 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 2 Apr 2024 18:36:37 -0500 Subject: [PATCH] Add dependency on CUDA. (#46) * Add dependency on CUDA. * Pin same compilers as rest of RAPIDS. * Remove extra else(). * Use other compiler packages. * Remove sysroot. * Several changes to make CI pass. * Update to 24.04. Closes #47. * Fix lint. * Update style checks to use pre-commit. * Add checks to dependencies.yaml. * Cleanup. * Add checks file key. --- .gitignore | 2 +- .pre-commit-config.yaml | 21 ++++++++++++++++ CMakeLists.txt | 7 +++--- Doxyfile.in | 2 +- GPUTreeShap/gpu_treeshap.h | 18 +++++++------- README.md | 2 +- ci/check_style.sh | 33 ++++++++++--------------- ci/release/update-version.sh | 4 +-- dependencies.yaml | 47 +++++++++++++++++++++++++++++++++--- fetch_rapids.cmake | 4 +-- tests/test_gpu_treeshap.cu | 5 ++-- 11 files changed, 100 insertions(+), 45 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitignore b/.gitignore index 2dbf1a6..47702aa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ build/ *.pdf *.csv *.png -*.pyc \ No newline at end of file +*.pyc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e9ccfab --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +# Copyright (c) 2024, NVIDIA CORPORATION. + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - repo: https://github.com/cpplint/cpplint + rev: 1.6.1 + hooks: + - id: cpplint + args: ["--recursive"] + - repo: https://github.com/rapidsai/pre-commit-hooks + rev: v0.0.3 + hooks: + - id: verify-copyright + args: ["--fix", "--main-branch", "main"] + +default_language_version: + python: python3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f9d3c6..34ac201 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2020-2023 NVIDIA CORPORATION. +# Copyright (c) 2020-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR) include(FetchContent) -project(GPUTreeShap VERSION 23.08.00 LANGUAGES CXX CUDA) +project(GPUTreeShap VERSION 24.04.00 LANGUAGES CXX CUDA) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CUDA_STANDARD 17) @@ -65,9 +65,8 @@ if(BUILD_GTEST) target_compile_options(TestGPUTreeShap PRIVATE $<$: ${COMPILE_OPTIONS}>) if(NOT MSVC) target_compile_options(TestGPUTreeShap PRIVATE $<$:${GCC_COMPILE_OPTIONS}>) - else() endif() - target_link_libraries(TestGPUTreeShap PRIVATE gtest gtest_main) + target_link_libraries(TestGPUTreeShap PRIVATE GTest::gtest GTest::gtest_main) endif() if(BUILD_EXAMPLES) diff --git a/Doxyfile.in b/Doxyfile.in index 09c72a1..f3f1c6f 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -38,7 +38,7 @@ PROJECT_NAME = "GPUTreeShap" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "23.08" +PROJECT_NUMBER = "24.04" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/GPUTreeShap/gpu_treeshap.h b/GPUTreeShap/gpu_treeshap.h index b40f2c9..bc213d3 100644 --- a/GPUTreeShap/gpu_treeshap.h +++ b/GPUTreeShap/gpu_treeshap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1234,15 +1234,15 @@ void ComputeBias(const PathVectorT& device_paths, DoubleVectorT* bias) { * ensemble size. * * \exception std::invalid_argument Thrown when an invalid argument error - * condition occurs. + * condition occurs. * \tparam PathIteratorT Thrust type iterator, may be * thrust::device_ptr for device memory, or stl iterator/raw pointer for host - * memory. + * memory. * \tparam PhiIteratorT Thrust type iterator, may be * thrust::device_ptr for device memory, or stl iterator/raw pointer for host - * memory. Value type must be floating point. + * memory. Value type must be floating point. * \tparam DatasetT User-specified - * dataset container. + * dataset container. * \tparam DeviceAllocatorT Optional thrust style * allocator. * @@ -1256,13 +1256,13 @@ void ComputeBias(const PathVectorT& device_paths, DoubleVectorT* bias) { * root with feature_idx = -1 and zero_fraction = 1.0. The ordering of path * elements inside a unique path does not matter - the result will be the same. * Paths may contain duplicate features. See the PathElement class for more - * information. - * \param end Path end iterator. + * information. + * \param end Path end iterator. * \param num_groups Number * of output groups. In multiclass classification the algorithm outputs feature - * contributions per output class. + * contributions per output class. * \param phis_begin Begin iterator for output - * phis. + * phis. * \param phis_end End iterator for output phis. */ template , diff --git a/README.md b/README.md index 613090d..75e2aad 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ GPUTreeShap is a cuda implementation of the TreeShap algorithm by Lundberg et al See the associated publication [here](https://arxiv.org/abs/2010.13972) ``` @misc{mitchell2022gputreeshap, - title={GPUTreeShap: Massively Parallel Exact Calculation of SHAP Scores for Tree Ensembles}, + title={GPUTreeShap: Massively Parallel Exact Calculation of SHAP Scores for Tree Ensembles}, author={Rory Mitchell and Eibe Frank and Geoffrey Holmes}, year={2022}, eprint={2010.13972}, diff --git a/ci/check_style.sh b/ci/check_style.sh index 788f37e..3e5f4ff 100755 --- a/ci/check_style.sh +++ b/ci/check_style.sh @@ -1,27 +1,20 @@ #!/bin/bash -# Copyright (c) 2023, NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. -# Ignore errors -set +e -RETVAL="0" +set -euo pipefail +rapids-logger "Create checks conda environment" . /opt/conda/etc/profile.d/conda.sh -# Check for a consistent code format -pip install cpplint -FORMAT=$(cpplint --recursive GPUTreeShap tests example benchmark 2>&1) -FORMAT_RETVAL=$? -if [ "$RETVAL" = "0" ]; then - RETVAL=$FORMAT_RETVAL -fi +ENV_YAML_DIR="$(mktemp -d)" -# Output results if failure otherwise show pass -if [ "$FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: cpplint format check; begin output\n\n" - echo -e "$FORMAT" - echo -e "\n\n>>>> FAILED: cpplint format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: cpplint format check\n\n" -fi +rapids-dependency-file-generator \ + --output conda \ + --file_key checks \ + --matrix "cuda=${RAPIDS_CUDA_VERSION%.*};arch=$(arch);py=${RAPIDS_PY_VERSION}" | tee "${ENV_YAML_DIR}/env.yaml" -exit $RETVAL +rapids-mamba-retry env create --force -f "${ENV_YAML_DIR}/env.yaml" -n checks +conda activate checks + +# Run pre-commit checks +pre-commit run --all-files --show-diff-on-failure diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index 0172066..c411943 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2023 NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. ############################### # gputreeshap Version Updater # ############################### @@ -31,7 +31,7 @@ function sed_runner() { } # CMakeLists -sed_runner 's/'"GPUTREESHAP VERSION .* LANGUAGES"'/'"GPUTREESHAP VERSION ${NEXT_FULL_TAG} LANGUAGES"'/g' CMakeLists.txt +sed_runner 's/'"GPUTreeShap VERSION .* LANGUAGES"'/'"GPUTreeShap VERSION ${NEXT_FULL_TAG} LANGUAGES"'/g' CMakeLists.txt # rapids-cmake version sed_runner 's/'"branch-.*\/RAPIDS.cmake"'/'"branch-${NEXT_SHORT_TAG}\/RAPIDS.cmake"'/g' fetch_rapids.cmake diff --git a/dependencies.yaml b/dependencies.yaml index 23b7b95..333b122 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -4,21 +4,62 @@ files: output: none includes: - build + - cuda_version + - cuda - docs + checks: + output: none + includes: + - checks channels: - rapidsai - conda-forge dependencies: build: common: - - output_types: [conda] + - output_types: conda packages: - binutils - cmake - - gxx <=11 + - gcc=11.* + - gxx=11.* - make + checks: + common: + - output_types: [conda, requirements] + packages: + - pre-commit + cuda_version: + specific: + - output_types: conda + matrices: + - matrix: + cuda: "11.8" + packages: + - cuda-version=11.8 + - matrix: + cuda: "12.0" + packages: + - cuda-version=12.0 + - matrix: + cuda: "12.2" + packages: + - cuda-version=12.2 + cuda: + specific: + - output_types: conda + matrices: + - matrix: + cuda: "12.*" + packages: + - cuda-nvcc + - cuda-cudart-dev + - matrix: + cuda: "11.*" + # GPUTreeShap CI uses the container's CUDA 11.8. + packages: docs: common: - - output_types: [conda] + - output_types: conda packages: - doxygen diff --git a/fetch_rapids.cmake b/fetch_rapids.cmake index dab6e5a..f494812 100644 --- a/fetch_rapids.cmake +++ b/fetch_rapids.cmake @@ -1,5 +1,5 @@ # ============================================================================= -# Copyright (c) 2023, NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except # in compliance with the License. You may obtain a copy of the License at @@ -12,7 +12,7 @@ # the License. # ============================================================================= if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/GPUTREESHAP_RAPIDS.cmake) - file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-23.08/RAPIDS.cmake + file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-24.04/RAPIDS.cmake ${CMAKE_CURRENT_BINARY_DIR}/GPUTREESHAP_RAPIDS.cmake ) endif() diff --git a/tests/test_gpu_treeshap.cu b/tests/test_gpu_treeshap.cu index 4586186..be8d09c 100644 --- a/tests/test_gpu_treeshap.cu +++ b/tests/test_gpu_treeshap.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include #include @@ -25,7 +27,6 @@ #include #include #include -#include "gtest/gtest.h" #include "tests/test_utils.h" #include "../GPUTreeShap/gpu_treeshap.h"