Skip to content

Commit

Permalink
Rework libcudf CMakeLists.txt to export targets for CPM (#7107)
Browse files Browse the repository at this point in the history
These changes rework libcudf's CMakeLists.txt files to export targets for inclusion by other CMake projects. I took inspiration from [RMM's CMakeLists.txt](https://github.com/rapidsai/rmm/blob/branch-0.18/CMakeLists.txt). However I'm not a CMake expert, and likely missed/messed up a few things.

I also [fixed](0a8e80d) those annoying `-Wstrict-prototypes` warnings we see compiling Cython files.

These changes are adequate to build libcudf as a dependency in another CMake project with [CPM](https://github.com/TheLartians/CPM.cmake), for example:

```cmake
function(find_and_configure_cudf VERSION)

    include(get_cpm)

    CPMAddPackage(NAME  cudf
        VERSION         ${VERSION}
        GIT_REPOSITORY  https://github.com/trxcllnt/cudf.git
        # Can also use a local path to your repo clone for testing
        # GIT_REPOSITORY  /home/ptaylor/dev/rapids/cudf
        GIT_TAG         fix/cmake-exports
        GIT_SHALLOW     TRUE
        SOURCE_SUBDIR   cpp
        OPTIONS         "BUILD_TESTS OFF"
                        "BUILD_BENCHMARKS OFF"
                        "ARROW_STATIC_LIB ON"
                        "JITIFY_USE_CACHE ON"
                        "CUDA_STATIC_RUNTIME ON"
                        "DISABLE_DEPRECATION_WARNING ON"
                        # control where generated JIT headers get placed
                        # so we don't cache-bust ccache every clean build
                        "CUDF_GENERATED_INCLUDE_DIR ${CPM_SOURCE_CACHE}/cudf-build"
    )
endfunction()

find_and_configure_cudf(${CUDF_VERSION})

add_target(${PROJECT_NAME} SHARED "${src_files}")
target_link_libraries(${PROJECT_NAME} rmm::rmm cudf::cudf)
```

Authors:
  - Paul Taylor (@trxcllnt)
  - Robert Maynard (@robertmaynard)

Approvers:
  - Jake Hemstad (@jrhemstad)
  - Keith Kraus (@kkraus14)

URL: #7107
  • Loading branch information
trxcllnt authored Mar 2, 2021
1 parent ed98f9a commit 61091a0
Show file tree
Hide file tree
Showing 31 changed files with 1,589 additions and 1,623 deletions.
14 changes: 4 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,18 @@ if buildAll || hasArg libcudf; then
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
${CUDF_CMAKE_CUDA_ARCHITECTURES} \
-DUSE_NVTX=${BUILD_NVTX} \
-DBUILD_TESTS=${BUILD_TESTS} \
-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \
-DDISABLE_DEPRECATION_WARNING=${BUILD_DISABLE_DEPRECATION_WARNING} \
-DPER_THREAD_DEFAULT_STREAM=${BUILD_PER_THREAD_DEFAULT_STREAM} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}

cd ${LIB_BUILD_DIR}
if [[ ${INSTALL_TARGET} != "" ]]; then
cmake --build . -j${PARALLEL_LEVEL} --target install_cudf ${VERBOSE_FLAG}
else
cmake --build . -j${PARALLEL_LEVEL} --target cudf ${VERBOSE_FLAG}
fi

if [[ ${BUILD_TESTS} == "ON" ]]; then
cmake --build . -j${PARALLEL_LEVEL} --target build_tests_cudf ${VERBOSE_FLAG}
fi
cmake --build . -j${PARALLEL_LEVEL} ${VERBOSE_FLAG}

if [[ ${BUILD_BENCHMARKS} == "ON" ]]; then
cmake --build . -j${PARALLEL_LEVEL} --target build_benchmarks_cudf ${VERBOSE_FLAG}
if [[ ${INSTALL_TARGET} != "" ]]; then
cmake --build . -j${PARALLEL_LEVEL} --target install ${VERBOSE_FLAG}
fi
fi

Expand Down
1,061 changes: 509 additions & 552 deletions cpp/CMakeLists.txt

Large diffs are not rendered by default.

289 changes: 80 additions & 209 deletions cpp/benchmarks/CMakeLists.txt

Large diffs are not rendered by default.

91 changes: 0 additions & 91 deletions cpp/cmake/Modules/ConfigureArrow.cmake

This file was deleted.

33 changes: 20 additions & 13 deletions cpp/cmake/Modules/ConfigureCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# limitations under the License.
#=============================================================================

# Auto-detect available GPU compute architectures
# Find the CUDAToolkit
find_package(CUDAToolkit REQUIRED)

include(${CUDA_DATAFRAME_SOURCE_DIR}/cmake/Modules/SetGPUArchs.cmake)
message(STATUS "CUDF: Building CUDF for GPU architectures: ${CMAKE_CUDA_ARCHITECTURES}")
# Must come after find_package(CUDAToolkit) because we symlink
# ccache as a compiler front-end for nvcc in gpuCI CPU builds.
enable_language(CUDA)

if(CMAKE_CUDA_COMPILER_VERSION)
# Compute the version. from CMAKE_CUDA_COMPILER_VERSION
Expand All @@ -30,32 +32,37 @@ message(VERBOSE "CUDF: CUDA_VERSION_MAJOR: ${CUDA_VERSION_MAJOR}")
message(VERBOSE "CUDF: CUDA_VERSION_MINOR: ${CUDA_VERSION_MINOR}")
message(STATUS "CUDF: CUDA_VERSION: ${CUDA_VERSION}")

# Auto-detect available GPU compute architectures

include(${CUDF_SOURCE_DIR}/cmake/Modules/SetGPUArchs.cmake)
message(STATUS "CUDF: Building CUDF for GPU architectures: ${CMAKE_CUDA_ARCHITECTURES}")

if(CMAKE_COMPILER_IS_GNUCXX)
string(APPEND CMAKE_CXX_FLAGS " -Wall -Werror -Wno-unknown-pragmas -Wno-error=deprecated-declarations")
list(APPEND CUDF_CXX_FLAGS -Wall -Werror -Wno-unknown-pragmas -Wno-error=deprecated-declarations)
if(CUDF_BUILD_TESTS OR CUDF_BUILD_BENCHMARKS)
# Suppress parentheses warning which causes gmock to fail
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler=-Wno-parentheses")
list(APPEND CUDF_CUDA_FLAGS -Xcompiler=-Wno-parentheses)
endif()
endif()

string(APPEND CMAKE_CUDA_FLAGS " --expt-extended-lambda --expt-relaxed-constexpr")
list(APPEND CUDF_CUDA_FLAGS --expt-extended-lambda --expt-relaxed-constexpr)

# set warnings as errors
string(APPEND CMAKE_CUDA_FLAGS " -Werror=cross-execution-space-call")
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler=-Wall,-Werror,-Wno-error=deprecated-declarations")
list(APPEND CUDF_CUDA_FLAGS -Werror=cross-execution-space-call)
list(APPEND CUDF_CUDA_FLAGS -Xcompiler=-Wall,-Werror,-Wno-error=deprecated-declarations)

if(DISABLE_DEPRECATION_WARNING)
string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated-declarations")
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler=-Wno-deprecated-declarations")
list(APPEND CUDF_CXX_FLAGS -Wno-deprecated-declarations)
list(APPEND CUDF_CUDA_FLAGS -Xcompiler=-Wno-deprecated-declarations)
endif()

# Option to enable line info in CUDA device compilation to allow introspection when profiling / memchecking
if(CMAKE_CUDA_LINEINFO)
string(APPEND CMAKE_CUDA_FLAGS " -lineinfo")
if(CUDA_ENABLE_LINEINFO)
list(APPEND CUDF_CUDA_FLAGS -lineinfo)
endif()

# Debug options
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(VERBOSE "CUDF: Building with debugging flags")
string(APPEND CMAKE_CUDA_FLAGS " -G -Xcompiler=-rdynamic")
list(APPEND CUDF_CUDA_FLAGS -G -Xcompiler=-rdynamic)
endif()
48 changes: 0 additions & 48 deletions cpp/cmake/Modules/ConfigureGoogleBenchmark.cmake

This file was deleted.

48 changes: 0 additions & 48 deletions cpp/cmake/Modules/ConfigureGoogleTest.cmake

This file was deleted.

File renamed without changes.
24 changes: 11 additions & 13 deletions cpp/cmake/Modules/SetGPUArchs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,25 @@ if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9)
list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "70")
endif()

if(${PROJECT_NAME}_BUILD_FOR_ALL_ARCHS)
set(CMAKE_CUDA_ARCHITECTURES ${SUPPORTED_CUDA_ARCHITECTURES})
elseif(${PROJECT_NAME}_BUILD_FOR_DETECTED_ARCHS)
include(${PROJECT_SOURCE_DIR}/cmake/EvalGpuArchs.cmake)
if(CUDF_BUILD_FOR_DETECTED_ARCHS)
include(${CUDF_SOURCE_DIR}/cmake/Modules/EvalGPUArchs.cmake)
evaluate_gpu_archs(CMAKE_CUDA_ARCHITECTURES)
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL")
unset(CMAKE_CUDA_ARCHITECTURES CACHE)
set(CUDF_BUILD_FOR_ALL_ARCHS TRUE)
else()
set(CUDF_BUILD_FOR_ALL_ARCHS FALSE)
list(TRANSFORM CMAKE_CUDA_ARCHITECTURES APPEND "-real")
endif()
endif()

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
if(CUDF_BUILD_FOR_ALL_ARCHS)
set(CMAKE_CUDA_ARCHITECTURES ${SUPPORTED_CUDA_ARCHITECTURES})
# CMake architecture list entry of "80" means to build compute and sm.
# What we want is for the newest arch only to build that way
# while the rest built only for sm.
list(SORT CMAKE_CUDA_ARCHITECTURES ORDER ASCENDING)
list(POP_BACK CMAKE_CUDA_ARCHITECTURES latest_arch)
list(TRANSFORM CMAKE_CUDA_ARCHITECTURES APPEND "-real")
list(APPEND CMAKE_CUDA_ARCHITECTURES ${latest_arch})
else()
foreach(arch IN LISTS CMAKE_CUDA_ARCHITECTURES)
string(APPEND CMAKE_CUDA_FLAGS " -gencode=arch=compute_${arch},code=sm_${arch}")
endforeach()

list(GET CMAKE_CUDA_ARCHITECTURES -1 ptx)
string(APPEND CMAKE_CUDA_FLAGS " -gencode=arch=compute_${ptx},code=compute_${ptx}")
unset(CMAKE_CUDA_ARCHITECTURES)
endif()
Loading

0 comments on commit 61091a0

Please sign in to comment.