Skip to content

Commit

Permalink
Fix CMake files in libcudf C++ examples to use existing libcudf build…
Browse files Browse the repository at this point in the history
… if present (#15348)

This PR fixes the CMake artifacts for libcudf examples and includes CI updates to create executable `libcudf-example` conda package to run from CI

Authors:
  - Muhammad Haseeb (https://github.com/mhaseeb123)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Robert Maynard (https://github.com/robertmaynard)
  - Jake Awe (https://github.com/AyodeAwe)

URL: #15348
  • Loading branch information
mhaseeb123 authored Apr 18, 2024
1 parent cb8e434 commit b8d003e
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 12 deletions.
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)

0 comments on commit b8d003e

Please sign in to comment.