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

Fix CMake files in libcudf C++ examples to use existing libcudf build if present #15348

Merged
merged 30 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6401ef2
updates for libcudf examples cmake files
mhaseeb123 Mar 20, 2024
360d78a
Applying suggested fixes
mhaseeb123 Mar 20, 2024
24149bb
reverting CUDF_TAG to fetch_dependencies and handle in set_cuda_arch
mhaseeb123 Mar 22, 2024
90bd8b0
Adding CI artifacts to build and run libcudf examples
mhaseeb123 Mar 22, 2024
28ed85b
set cuda_architectures in each example
mhaseeb123 Apr 1, 2024
0f44faf
updates from cmake-format
mhaseeb123 Apr 8, 2024
aafd3be
add working directory variable to avoid mishandled sed
mhaseeb123 Apr 11, 2024
ee0100a
update file permissions for ci to run
mhaseeb123 Apr 12, 2024
8e5dfce
Merge branch 'rapidsai:branch-24.06' into cudf-examples-cmake-fix
mhaseeb123 Apr 16, 2024
9a65213
adding more CI artifacts for examples
mhaseeb123 Apr 16, 2024
51c89a2
Merge branch 'cudf-examples-cmake-fix' of https://github.com/mhaseeb1…
mhaseeb123 Apr 16, 2024
1370176
minor pre-commit fixes
mhaseeb123 Apr 16, 2024
bc00b9e
handle CMAKE_INSTALL_PREFIX in examples build
mhaseeb123 Apr 16, 2024
74aa66a
test CI with default CMAKE_INSTALL_PREFIX
mhaseeb123 Apr 16, 2024
80e705c
Merge branch 'cudf-examples-cmake-fix' of https://github.com/mhaseeb1…
mhaseeb123 Apr 16, 2024
0ac6f61
minor pre-commit fix
mhaseeb123 Apr 16, 2024
3e18bf3
revert custom install prefix and test CI.
mhaseeb123 Apr 16, 2024
fa3bf00
Use $PREFIX as CMAKE_INSTALL_PREFIX
mhaseeb123 Apr 16, 2024
1cbde69
minor fix for paths
mhaseeb123 Apr 16, 2024
a265da7
Merge branch 'branch-24.06' into cudf-examples-cmake-fix
mhaseeb123 Apr 16, 2024
9d8bf76
update install logic and fix for default behavior
mhaseeb123 Apr 16, 2024
f180fa7
Merge branch 'cudf-examples-cmake-fix' of https://github.com/mhaseeb1…
mhaseeb123 Apr 16, 2024
ad3f6a6
incorporting suggested changes from reviews
mhaseeb123 Apr 16, 2024
324e6dc
Merge branch 'branch-24.06' into cudf-examples-cmake-fix
mhaseeb123 Apr 16, 2024
00d1e2b
pre-commit eol
mhaseeb123 Apr 16, 2024
d767c49
Merge branch 'cudf-examples-cmake-fix' of https://github.com/mhaseeb1…
mhaseeb123 Apr 16, 2024
72089ac
apply reviewer suggestions
mhaseeb123 Apr 17, 2024
f984c01
Merge branch 'branch-24.06' into cudf-examples-cmake-fix
mhaseeb123 Apr 17, 2024
c088772
minor improvements
mhaseeb123 Apr 17, 2024
996367d
minor improvements and add default LIB_BUILD_DIR
mhaseeb123 Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ CMakeFiles/
Debug
build/
cpp/build/
cpp/examples/*/install/
cpp/include/cudf/ipc_generated/*.h
cpp/thirdparty/googletest/

Expand Down
2 changes: 1 addition & 1 deletion ci/release/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sed_runner "s/version == ${CURRENT_SHORT_TAG}/version == ${NEXT_SHORT_TAG}/g" RE
sed_runner "s/cudf=${CURRENT_SHORT_TAG}/cudf=${NEXT_SHORT_TAG}/g" README.md

# Libcudf examples update
sed_runner "s/CUDF_TAG branch-${CURRENT_SHORT_TAG}/CUDF_TAG branch-${NEXT_SHORT_TAG}/" cpp/examples/fetch_dependencies.cmake
sed_runner "s/CUDF_TAG branch-${CURRENT_SHORT_TAG}/CUDF_TAG branch-${NEXT_SHORT_TAG}/" cpp/examples/versions.cmake

# CI files
for FILE in .github/workflows/*.yaml; do
Expand Down
20 changes: 20 additions & 0 deletions ci/run_cudf_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Copyright (c) 2024, NVIDIA CORPORATION.

set -uo pipefail

EXITCODE=0
trap "EXITCODE=1" ERR

# Support customizing the examples' install location
cd "${INSTALL_PREFIX:-${CONDA_PREFIX:-/usr}}/bin/examples/libcudf/";

compute-sanitizer --tool memcheck basic_example

compute-sanitizer --tool memcheck deduplication

compute-sanitizer --tool memcheck custom_optimized names.csv
compute-sanitizer --tool memcheck custom_prealloc names.csv
compute-sanitizer --tool memcheck custom_with_malloc names.csv

exit ${EXITCODE}
6 changes: 6 additions & 0 deletions ci/test_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ rapids-logger "Run libcudf gtests"
./ci/run_cudf_ctests.sh -j20
SUITEERROR=$?

if (( ${SUITEERROR} == 0 )); then
rapids-logger "Run libcudf examples"
./ci/run_cudf_examples.sh
SUITEERROR=$?
fi

if (( ${SUITEERROR} == 0 )); then
rapids-logger "Run libcudf_kafka gtests"
./ci/run_cudf_kafka_ctests.sh -j20
Expand Down
2 changes: 1 addition & 1 deletion ci/test_cpp_common.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rapids-print-env

rapids-mamba-retry install \
--channel "${CPP_CHANNEL}" \
libcudf libcudf_kafka libcudf-tests
libcudf libcudf_kafka libcudf-tests libcudf-example

rapids-logger "Check GPU usage"
nvidia-smi
5 changes: 3 additions & 2 deletions conda/recipes/libcudf/install_libcudf_example.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2024, NVIDIA CORPORATION.

./cpp/examples/build.sh
# build and install libcudf examples
./cpp/examples/build.sh --install
2 changes: 1 addition & 1 deletion conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ outputs:
license: Apache-2.0
license_family: APACHE
license_file: LICENSE
summary: libcudf_example library
summary: libcudf example executables
- name: libcudf-tests
version: {{ version }}
script: install_libcudf_tests.sh
Expand Down
11 changes: 10 additions & 1 deletion cpp/examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

cmake_minimum_required(VERSION 3.26.4)

include(../set_cuda_architecture.cmake)

# initialize cuda architecture
rapids_cuda_init_architectures(basic_example)
rapids_cuda_set_architectures(RAPIDS)

project(
basic_example
VERSION 0.0.1
Expand All @@ -14,3 +20,6 @@ include(../fetch_dependencies.cmake)
add_executable(basic_example src/process_csv.cpp)
target_link_libraries(basic_example PRIVATE cudf::cudf)
target_compile_features(basic_example PRIVATE cxx_std_17)

install(TARGETS basic_example DESTINATION bin/examples/libcudf)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/4stock_5day.csv DESTINATION bin/examples/libcudf)
29 changes: 29 additions & 0 deletions cpp/examples/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,34 @@ set -euo pipefail

# Parallelism control
PARALLEL_LEVEL=${PARALLEL_LEVEL:-4}
# Installation disabled by default
INSTALL_EXAMPLES=false

# Check for -i or --install flags to enable installation
ARGS=$(getopt -o i --long install -- "$@")
eval set -- "$ARGS"
while [ : ]; do
case "$1" in
-i | --install)
INSTALL_EXAMPLES=true
shift
;;
--) shift;
break
;;
esac
done

# Root of examples
EXAMPLES_DIR=$(dirname "$(realpath "$0")")

# Set up default libcudf build directory and install prefix if conda build
if [ "${CONDA_BUILD:-"0"}" == "1" ]; then
LIB_BUILD_DIR="${LIB_BUILD_DIR:-${SRC_DIR/cpp/build}}"
INSTALL_PREFIX="${INSTALL_PREFIX:-${PREFIX}}"
fi

# libcudf build directory
LIB_BUILD_DIR=${LIB_BUILD_DIR:-$(readlink -f "${EXAMPLES_DIR}/../build")}

################################################################################
Expand All @@ -25,6 +50,10 @@ build_example() {
cmake -S ${example_dir} -B ${build_dir} -Dcudf_ROOT="${LIB_BUILD_DIR}"
# Build
cmake --build ${build_dir} -j${PARALLEL_LEVEL}
# Install if needed
if [ "$INSTALL_EXAMPLES" = true ]; then
cmake --install ${build_dir} --prefix ${INSTALL_PREFIX:-${example_dir}/install}
fi
}

build_example basic
Expand Down
11 changes: 8 additions & 3 deletions cpp/examples/fetch_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================
set(CPM_DOWNLOAD_VERSION v0.35.3)

include(${CMAKE_CURRENT_LIST_DIR}/versions.cmake)

set(CPM_DOWNLOAD_VERSION v0.38.5)
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/${CPM_DOWNLOAD_VERSION}/get_cpm.cmake
${CMAKE_BINARY_DIR}/cmake/get_cpm.cmake
)
include(${CMAKE_BINARY_DIR}/cmake/get_cpm.cmake)

set(CUDF_TAG branch-24.06)
# find or build it via CPM
CPMFindPackage(
NAME cudf GIT_REPOSITORY https://github.com/rapidsai/cudf
NAME cudf
FIND_PACKAGE_ARGUMENTS "PATHS ${cudf_ROOT} ${cudf_ROOT}/latest" GIT_REPOSITORY
https://github.com/rapidsai/cudf
GIT_TAG ${CUDF_TAG}
GIT_SHALLOW
TRUE
Expand Down
11 changes: 10 additions & 1 deletion cpp/examples/nested_types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

cmake_minimum_required(VERSION 3.26.4)

include(../set_cuda_architecture.cmake)

# initialize cuda architecture
rapids_cuda_init_architectures(nested_types)
rapids_cuda_set_architectures(RAPIDS)

project(
nested_types
VERSION 0.0.1
Expand All @@ -14,3 +20,6 @@ include(../fetch_dependencies.cmake)
add_executable(deduplication deduplication.cpp)
target_link_libraries(deduplication PRIVATE cudf::cudf)
target_compile_features(deduplication PRIVATE cxx_std_17)

install(TARGETS deduplication DESTINATION bin/examples/libcudf)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/example.json DESTINATION bin/examples/libcudf)
28 changes: 28 additions & 0 deletions cpp/examples/set_cuda_architecture.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# =============================================================================
# Copyright (c) 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

include(${CMAKE_CURRENT_LIST_DIR}/versions.cmake)

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/libcudf_cpp_examples_RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/${CUDF_TAG}/RAPIDS.cmake
${CMAKE_CURRENT_BINARY_DIR}/libcudf_cpp_examples_RAPIDS.cmake
)
endif()
include(${CMAKE_CURRENT_BINARY_DIR}/libcudf_cpp_examples_RAPIDS.cmake)

include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
include(rapids-export)
include(rapids-find)
15 changes: 13 additions & 2 deletions cpp/examples/strings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

cmake_minimum_required(VERSION 3.26.4)

include(../set_cuda_architecture.cmake)

# initialize cuda architecture
rapids_cuda_init_architectures(strings_examples)
rapids_cuda_set_architectures(RAPIDS)

project(
strings_examples
VERSION 0.0.1
Expand All @@ -12,22 +18,27 @@ include(../fetch_dependencies.cmake)

list(APPEND CUDF_CUDA_FLAGS --expt-extended-lambda --expt-relaxed-constexpr)

#
add_executable(libcudf_apis libcudf_apis.cpp)
target_compile_features(libcudf_apis PRIVATE cxx_std_17)
target_link_libraries(libcudf_apis PRIVATE cudf::cudf nvToolsExt)
install(TARGETS libcudf_apis DESTINATION bin/examples/libcudf)

add_executable(custom_with_malloc custom_with_malloc.cu)
target_compile_features(custom_with_malloc PRIVATE cxx_std_17)
target_compile_options(custom_with_malloc PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>")
target_link_libraries(custom_with_malloc PRIVATE cudf::cudf nvToolsExt)
install(TARGETS custom_with_malloc DESTINATION bin/examples/libcudf)

add_executable(custom_prealloc custom_prealloc.cu)
target_compile_features(custom_prealloc PRIVATE cxx_std_17)
target_compile_options(custom_prealloc PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>")
target_link_libraries(custom_prealloc PRIVATE cudf::cudf nvToolsExt)
install(TARGETS custom_prealloc DESTINATION bin/examples/libcudf)

add_executable(custom_optimized custom_optimized.cu)
target_compile_features(custom_optimized PRIVATE cxx_std_17)
target_compile_options(custom_optimized PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>")
target_link_libraries(custom_optimized PRIVATE cudf::cudf nvToolsExt)
install(TARGETS custom_optimized DESTINATION bin/examples/libcudf)

install(FILES ${CMAKE_CURRENT_LIST_DIR}/names.csv DESTINATION bin/examples/libcudf)
15 changes: 15 additions & 0 deletions cpp/examples/versions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# =============================================================================
# Copyright (c) 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

set(CUDF_TAG branch-24.06)
Loading