diff --git a/.gitignore b/.gitignore index 471d4100458..313bb1c3789 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,7 @@ CMakeFiles/ Debug build/ cpp/build/ +cpp/examples/*/install/ cpp/include/cudf/ipc_generated/*.h cpp/thirdparty/googletest/ diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index 7cacdfd39c3..99f9c698217 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -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 diff --git a/ci/run_cudf_examples.sh b/ci/run_cudf_examples.sh new file mode 100755 index 00000000000..71af6446748 --- /dev/null +++ b/ci/run_cudf_examples.sh @@ -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} diff --git a/ci/test_cpp.sh b/ci/test_cpp.sh index 995c8d7d71f..7865849bb74 100755 --- a/ci/test_cpp.sh +++ b/ci/test_cpp.sh @@ -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 diff --git a/ci/test_cpp_common.sh b/ci/test_cpp_common.sh old mode 100644 new mode 100755 index e1b2a367187..da847137a2b --- a/ci/test_cpp_common.sh +++ b/ci/test_cpp_common.sh @@ -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 diff --git a/conda/recipes/libcudf/install_libcudf_example.sh b/conda/recipes/libcudf/install_libcudf_example.sh index e249688a03b..1a52dec99e3 100644 --- a/conda/recipes/libcudf/install_libcudf_example.sh +++ b/conda/recipes/libcudf/install_libcudf_example.sh @@ -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 diff --git a/conda/recipes/libcudf/meta.yaml b/conda/recipes/libcudf/meta.yaml index 63eb83084dd..3af0b7885c3 100644 --- a/conda/recipes/libcudf/meta.yaml +++ b/conda/recipes/libcudf/meta.yaml @@ -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 diff --git a/cpp/examples/basic/CMakeLists.txt b/cpp/examples/basic/CMakeLists.txt index 759a43b5627..a3fe699667a 100644 --- a/cpp/examples/basic/CMakeLists.txt +++ b/cpp/examples/basic/CMakeLists.txt @@ -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 @@ -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) diff --git a/cpp/examples/build.sh b/cpp/examples/build.sh index 424da35ad18..9802c876930 100755 --- a/cpp/examples/build.sh +++ b/cpp/examples/build.sh @@ -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")} ################################################################################ @@ -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 diff --git a/cpp/examples/fetch_dependencies.cmake b/cpp/examples/fetch_dependencies.cmake index e4c11bbdeca..851405caf55 100644 --- a/cpp/examples/fetch_dependencies.cmake +++ b/cpp/examples/fetch_dependencies.cmake @@ -11,7 +11,10 @@ # 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 @@ -19,9 +22,11 @@ file( ) 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 diff --git a/cpp/examples/nested_types/CMakeLists.txt b/cpp/examples/nested_types/CMakeLists.txt index cb9430db237..8a900f6b5ae 100644 --- a/cpp/examples/nested_types/CMakeLists.txt +++ b/cpp/examples/nested_types/CMakeLists.txt @@ -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 @@ -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) diff --git a/cpp/examples/set_cuda_architecture.cmake b/cpp/examples/set_cuda_architecture.cmake new file mode 100644 index 00000000000..bed6cd2f357 --- /dev/null +++ b/cpp/examples/set_cuda_architecture.cmake @@ -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) diff --git a/cpp/examples/strings/CMakeLists.txt b/cpp/examples/strings/CMakeLists.txt index c90fa9dde16..a5654870544 100644 --- a/cpp/examples/strings/CMakeLists.txt +++ b/cpp/examples/strings/CMakeLists.txt @@ -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 @@ -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 "$<$:${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 "$<$:${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 "$<$:${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) diff --git a/cpp/examples/versions.cmake b/cpp/examples/versions.cmake new file mode 100644 index 00000000000..dff66b4d7d8 --- /dev/null +++ b/cpp/examples/versions.cmake @@ -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)