diff --git a/build.sh b/build.sh index 38d5acdb6..eafe261d1 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ ARGS=$* # script, and that this script resides in the repo dir! REPODIR=$(cd $(dirname $0); pwd) -VALIDARGS="clean libcuspatial cuspatial tests -v -g -n -h --show_depr_warn" +VALIDARGS="clean libcuspatial cuspatial tests -v -g -n -h --allgpuarch --show_depr_warn" HELP="$0 [clean] [libcuspatial] [cuspatial] [tests] [-v] [-g] [-n] [-h] [-l] [--show_depr_warn] clean - remove all existing build artifacts and configuration (start over) @@ -29,6 +29,7 @@ HELP="$0 [clean] [libcuspatial] [cuspatial] [tests] [-v] [-g] [-n] [-h] [-l] [-- -g - build for debug -n - no install step -h - print this text + --allgpuarch - build for all supported GPU architectures --show_depr_warn - show cmake deprecation warnings default action (no args) is to build and install 'libcuspatial' then 'cuspatial' targets @@ -41,6 +42,7 @@ BUILD_DIRS="${LIBCUSPATIAL_BUILD_DIR} ${CUSPATIAL_BUILD_DIR}" VERBOSE_FLAG="" BUILD_TESTS=OFF BUILD_TYPE=Release +BUILD_ALL_GPU_ARCH=0 INSTALL_TARGET=install BUILD_DISABLE_DEPRECATION_WARNING=ON @@ -79,7 +81,10 @@ fi if hasArg -n; then INSTALL_TARGET="" fi -if hasArg --show-_depr_warn; then +if hasArg --allgpuarch; then + BUILD_ALL_GPU_ARCH=1 +fi +if hasArg --show_depr_warn; then BUILD_DISABLE_DEPRECATION_WARNING=OFF fi @@ -101,19 +106,32 @@ if hasArg clean; then done fi +if (( ${BUILD_ALL_GPU_ARCH} == 0 )); then + CUSPATIAL_CMAKE_CUDA_ARCHITECTURES="-DCMAKE_CUDA_ARCHITECTURES=" + echo "Building for the architecture of the GPU in the system..." +else + CUSPATIAL_CMAKE_CUDA_ARCHITECTURES="" + echo "Building for *ALL* supported GPU architectures..." +fi + ################################################################################ # Configure, build, and install libcuspatial if (( ${NUMARGS} == 0 )) || hasArg libcuspatial; then - mkdir -p ${LIBCUSPATIAL_BUILD_DIR} cd ${LIBCUSPATIAL_BUILD_DIR} cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ + ${CUSPATIAL_CMAKE_CUDA_ARCHITECTURES} \ -DCMAKE_CXX11_ABI=ON \ -DBUILD_TESTS=${BUILD_TESTS} \ -DDISABLE_DEPRECATION_WARNING=${BUILD_DISABLE_DEPRECATION_WARNING} \ - -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ + .. - cmake --build . -j ${PARALLEL_LEVEL} --target install ${VERBOSE_FLAG} + cmake --build . -j ${PARALLEL_LEVEL} ${VERBOSE_FLAG} + + if [[ ${INSTALL_TARGET} != "" ]]; then + cmake --build . -j ${PARALLEL_LEVEL} --target install ${VERBOSE_FLAG} + fi fi # Build and install the cuspatial Python package @@ -127,4 +145,3 @@ if (( ${NUMARGS} == 0 )) || hasArg cuspatial; then PARALLEL_LEVEL=${PARALLEL_LEVEL} python setup.py build_ext --inplace --library-dir=${LIBCUSPATIAL_BUILD_DIR} fi fi - diff --git a/conda/environments/cuspatial_dev_cuda10.1.yml b/conda/environments/cuspatial_dev_cuda10.1.yml index f7714d142..b3bb5c5b5 100644 --- a/conda/environments/cuspatial_dev_cuda10.1.yml +++ b/conda/environments/cuspatial_dev_cuda10.1.yml @@ -14,3 +14,5 @@ dependencies: - geopandas=0.7.0 - cmake>=3.14 - cython>=0.29,<0.30 + - gtest + - gmock diff --git a/conda/environments/cuspatial_dev_cuda10.2.yml b/conda/environments/cuspatial_dev_cuda10.2.yml index c5fd845bc..8d8d32946 100644 --- a/conda/environments/cuspatial_dev_cuda10.2.yml +++ b/conda/environments/cuspatial_dev_cuda10.2.yml @@ -14,3 +14,5 @@ dependencies: - geopandas=0.7.0 - cmake>=3.14 - cython>=0.29,<0.30 + - gtest + - gmock diff --git a/conda/environments/cuspatial_dev_cuda11.0.yml b/conda/environments/cuspatial_dev_cuda11.0.yml index 1f2a5c88c..e1ff6c339 100644 --- a/conda/environments/cuspatial_dev_cuda11.0.yml +++ b/conda/environments/cuspatial_dev_cuda11.0.yml @@ -14,3 +14,5 @@ dependencies: - geopandas=0.7.0 - cmake>=3.14 - cython>=0.29,<0.30 + - gtest + - gmock diff --git a/conda/recipes/libcuspatial/build.sh b/conda/recipes/libcuspatial/build.sh index f2c85c0ac..7a38584e4 100644 --- a/conda/recipes/libcuspatial/build.sh +++ b/conda/recipes/libcuspatial/build.sh @@ -2,7 +2,7 @@ # build cuspatial with verbose output if [[ -z "$PROJECT_FLASH" || "$PROJECT_FLASH" == "0" ]]; then - ./build.sh -v libcuspatial + ./build.sh -v libcuspatial --allgpuarch else - ./build.sh -v libcuspatial tests + ./build.sh -v libcuspatial tests --allgpuarch fi diff --git a/conda/recipes/libcuspatial/meta.yaml b/conda/recipes/libcuspatial/meta.yaml index a53ef3025..29ea18fcd 100644 --- a/conda/recipes/libcuspatial/meta.yaml +++ b/conda/recipes/libcuspatial/meta.yaml @@ -33,7 +33,7 @@ build: requirements: build: - - cmake >=3.12.4 + - cmake >=3.18 host: - libcudf {{ minor_version }}.* - librmm {{ minor_version }}.* @@ -52,4 +52,3 @@ about: license_family: Apache license_file: LICENSE summary: libcuspatial library - diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 222b389fb..6fc6f4efa 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -14,19 +14,57 @@ # limitations under the License. #============================================================================= -cmake_minimum_required(VERSION 3.12...3.17 FATAL_ERROR) +cmake_minimum_required(VERSION 3.18 FATAL_ERROR) + +# If `CMAKE_CUDA_ARCHITECTURES` is not defined, build for all supported architectures. If +# `CMAKE_CUDA_ARCHITECTURES` is set to an empty string (""), build for only the current +# architecture. If `CMAKE_CUDA_ARCHITECTURES` is specified by the user, use user setting. + +# This needs to be run before enabling the CUDA language due to the default initialization behavior +# of `CMAKE_CUDA_ARCHITECTURES`, https://gitlab.kitware.com/cmake/cmake/-/issues/21302 +if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") + set(CUSPATIAL_BUILD_FOR_ALL_ARCHS TRUE) +elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "") + set(CUSPATIAL_BUILD_FOR_DETECTED_ARCHS TRUE) +endif() -project(CUDA_SPATIAL VERSION 0.19.0 LANGUAGES C CXX CUDA) +project(CUSPATIAL VERSION 0.19.0 LANGUAGES C CXX) -if(NOT CMAKE_CUDA_COMPILER) - message(SEND_ERROR "CMake cannot locate a CUDA compiler") -endif() +# Needed because GoogleBenchmark changes the state of FindThreads.cmake, +# causing subsequent runs to have different values for the `Threads::Threads` target. +# Setting this flag ensures `Threads::Threads` is the same value in first run and subsequent runs. +set(THREADS_PREFER_PTHREAD_FLAG ON) ################################################################################################### -# - build type ------------------------------------------------------------------------------------ +# - build options --------------------------------------------------------------------------------- + +option(USE_NVTX "Build with NVTX support" ON) +option(BUILD_TESTS "Configure CMake to build tests" OFF) +option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF) +option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF) +option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF) +# Option to enable line info in CUDA device compilation to allow introspection when profiling / memchecking +option(CUDA_ENABLE_LINEINFO "Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler" OFF) +# cudart can be statically linked or dynamically linked. The python ecosystem wants dynamic linking +option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF) + +message(STATUS "CUSPATIAL: Build with NVTX support: ${USE_NVTX}") +message(STATUS "CUSPATIAL: Configure CMake to build tests: ${BUILD_TESTS}") +message(STATUS "CUSPATIAL: Configure CMake to build (google) benchmarks: ${BUILD_BENCHMARKS}") +message(STATUS "CUSPATIAL: Build with per-thread default stream: ${PER_THREAD_DEFAULT_STREAM}") +message(STATUS "CUSPATIAL: Disable warnings generated from deprecated declarations: ${DISABLE_DEPRECATION_WARNING}") +message(STATUS "CUSPATIAL: Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler: ${CUDA_ENABLE_LINEINFO}") +message(STATUS "CUSPATIAL: Statically link the CUDA runtime: ${CUDA_STATIC_RUNTIME}") # Set a default build type if none was specified set(DEFAULT_BUILD_TYPE "Release") +set(CUSPATIAL_BUILD_TESTS ${BUILD_TESTS}) +set(CUSPATIAL_BUILD_BENCHMARKS ${BUILD_BENCHMARKS}) + +set(CUSPATIAL_CXX_FLAGS "") +set(CUSPATIAL_CUDA_FLAGS "") +set(CUSPATIAL_CXX_DEFINITIONS "") +set(CUSPATIAL_CUDA_DEFINITIONS "") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.") @@ -37,300 +75,191 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() -################################################################################################### -# - compiler options ------------------------------------------------------------------------------ - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_C_COMPILER $ENV{CC}) -set(CMAKE_CXX_COMPILER $ENV{CXX}) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -set(CMAKE_CUDA_STANDARD 14) -set(CMAKE_CUDA_STANDARD_REQUIRED ON) - -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=deprecated-declarations") - - # Suppress parentheses warning which causes gmock to fail - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wno-parentheses") - -endif(CMAKE_COMPILER_IS_GNUCXX) - -if(CMAKE_CUDA_COMPILER_VERSION) - # Compute the version. from CMAKE_CUDA_COMPILER_VERSION - string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${CMAKE_CUDA_COMPILER_VERSION}) - string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${CMAKE_CUDA_COMPILER_VERSION}) - set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") - mark_as_advanced(CUDA_VERSION) -endif() - -message(STATUS "CUDA_VERSION_MAJOR: ${CUDA_VERSION_MAJOR}") -message(STATUS "CUDA_VERSION_MINOR: ${CUDA_VERSION_MINOR}") -message(STATUS "CUDA_VERSION: ${CUDA_VERSION}") - -# Always set this convenience variable -set(CUDA_VERSION_STRING "${CUDA_VERSION}") - -# Auto-detect available GPU compute architectures -set(GPU_ARCHS "ALL" CACHE STRING - "List of GPU architectures (semicolon-separated) to be compiled for. Pass 'ALL' if you want to compile for all supported GPU architectures. Empty string means to auto-detect the GPUs on the current system") - -if("${GPU_ARCHS}" STREQUAL "") - include(cmake/EvalGpuArchs.cmake) - evaluate_gpu_archs(GPU_ARCHS) -endif() - -if("${GPU_ARCHS}" STREQUAL "ALL") - set(GPU_ARCHS "60") - if((CUDA_VERSION_MAJOR EQUAL 9) OR (CUDA_VERSION_MAJOR GREATER 9)) - set(GPU_ARCHS "${GPU_ARCHS};70") - endif() - if((CUDA_VERSION_MAJOR EQUAL 10) OR (CUDA_VERSION_MAJOR GREATER 10)) - set(GPU_ARCHS "${GPU_ARCHS};75") - endif() -endif() -message("GPU_ARCHS = ${GPU_ARCHS}") - -foreach(arch ${GPU_ARCHS}) - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode=arch=compute_${arch},code=sm_${arch}") -endforeach() - -list(GET GPU_ARCHS -1 ptx) -set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode=arch=compute_${ptx},code=compute_${ptx}") - -set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda --expt-relaxed-constexpr") - -# set warnings as errors -# TODO: remove `no-maybe-unitialized` used to suppress warnings in rmm::exec_policy -set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Werror=cross-execution-space-call -Xcompiler -Wall,-Werror,-Wno-error=deprecated-declarations") - -option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF) -if(DISABLE_DEPRECATION_WARNING) - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wno-deprecated-declarations") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") -endif(DISABLE_DEPRECATION_WARNING) - -# Option to enable line info in CUDA device compilation to allow introspection when profiling / memchecking -option(CMAKE_CUDA_LINEINFO "Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler" OFF) -if (CMAKE_CUDA_LINEINFO) - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo") -endif(CMAKE_CUDA_LINEINFO) - -# Debug options -if(CMAKE_BUILD_TYPE MATCHES Debug) - message(STATUS "Building with debugging flags") - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G -Xcompiler -rdynamic") -endif(CMAKE_BUILD_TYPE MATCHES Debug) - -# To apply RUNPATH to transitive dependencies (this is a temporary solution) -set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--disable-new-dtags") -set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags") - -option(BUILD_TESTS "Configure CMake to build tests" OFF) - -option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF) - -################################################################################################### -# - cmake modules --------------------------------------------------------------------------------- - -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) - -include(FeatureSummary) -include(CheckIncludeFiles) -include(CheckLibraryExists) - -################################################################################################### -# - third party dependencies----------------------------------------------------------------------- -# add third party dependencies using CMake FetchContent - -add_subdirectory(cmake/thirdparty) - -################################################################################################### -# - copy libcu++ ------------------------------------------------------------------------------------ - -file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/libcudacxx") -file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/libcxx/include") - -file(INSTALL ${LIBCUDACXX_INCLUDE_DIR} DESTINATION ${CMAKE_BINARY_DIR}/include/libcudacxx/) -file(INSTALL ${LIBCXX_INCLUDE_DIR} DESTINATION ${CMAKE_BINARY_DIR}/include/libcxx/include/) +# Set RMM logging level +set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.") +set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF") +message(STATUS "CUSPATIAL: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.") ################################################################################################### # - conda environment ----------------------------------------------------------------------------- if("$ENV{CONDA_BUILD}" STREQUAL "1") - set(CMAKE_SYSTEM_PREFIX_PATH "$ENV{BUILD_PREFIX};$ENV{PREFIX};${CMAKE_SYSTEM_PREFIX_PATH}") + set(CMAKE_PREFIX_PATH "$ENV{BUILD_PREFIX};$ENV{PREFIX};${CMAKE_PREFIX_PATH}") set(CONDA_INCLUDE_DIRS "$ENV{BUILD_PREFIX}/include" "$ENV{PREFIX}/include") set(CONDA_LINK_DIRS "$ENV{BUILD_PREFIX}/lib" "$ENV{PREFIX}/lib") - message(STATUS "Conda build detected, CMAKE_SYSTEM_PREFIX_PATH set to: ${CMAKE_SYSTEM_PREFIX_PATH}") + message(VERBOSE "CUSPATIAL: Conda build detected, CMAKE_PREFIX_PATH set to: ${CMAKE_PREFIX_PATH}") elseif(DEFINED ENV{CONDA_PREFIX}) - set(CMAKE_SYSTEM_PREFIX_PATH "$ENV{CONDA_PREFIX};${CMAKE_SYSTEM_PREFIX_PATH}") + set(CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX};${CMAKE_PREFIX_PATH}") set(CONDA_INCLUDE_DIRS "$ENV{CONDA_PREFIX}/include") set(CONDA_LINK_DIRS "$ENV{CONDA_PREFIX}/lib") - message(STATUS "Conda environment detected, CMAKE_SYSTEM_PREFIX_PATH set to: ${CMAKE_SYSTEM_PREFIX_PATH}") -endif("$ENV{CONDA_BUILD}" STREQUAL "1") + message(VERBOSE "CUSPATIAL: Conda environment detected, CMAKE_PREFIX_PATH set to: ${CMAKE_PREFIX_PATH}") +endif() ################################################################################################### -# - RMM ------------------------------------------------------------------------------------------- - -find_path(RMM_INCLUDE "rmm" - HINTS "$ENV{RMM_ROOT}/include") - -message(STATUS "RMM: RMM_ROOT set to $ENV{RMM_ROOT}") -message(STATUS "RMM: RMM_INCLUDE set to ${RMM_INCLUDE}") - -# - CUDF ------------------------------------------------------------------------------------------- - -find_path(CUDF_INCLUDE "cudf" - HINTS "$ENV{CUDF_ROOT}/include") - -find_library(CUDF_LIBRARY "cudf" - HINTS "$ENV{CUDF_ROOT}/lib") - -message(STATUS "CUDF: CUDF_HOME set to $ENV{CUDF_HOME}") -message(STATUS "CUDF: CUDF_LIBRARY set to ${CUDF_LIBRARY}") -message(STATUS "CUDF: CUDF_INCLUDE set to ${CUDF_INCLUDE}") -message(STATUS "CUDF: THRUST_INCLUDE_DIR set to ${THRUST_INCLUDE_DIR}") -message(STATUS "CUDF: LIBCUDACXX_INCLUDE_DIR set to ${LIBCUDACXX_INCLUDE_DIR}") +# - compiler options ------------------------------------------------------------------------------ -add_library(cudf SHARED IMPORTED ${CUDF_LIBRARY}) -if (CUDF_INCLUDE AND CUDF_LIBRARY) - set_target_properties(cudf PROPERTIES IMPORTED_LOCATION ${CUDF_LIBRARY}) -endif (CUDF_INCLUDE AND CUDF_LIBRARY) +# * find CUDAToolkit package +# * determine GPU architectures +# * enable the CMake CUDA language +# * set other CUDA compilation flags +include(cmake/Modules/ConfigureCUDA.cmake) ################################################################################################### -# - gdal ------------------------------------------------------------------------------------------ +# - dependencies ---------------------------------------------------------------------------------- +# find gdal find_package(GDAL REQUIRED) - -if(NOT GDAL_FOUND) - message(FATAL_ERROR "GDAL not found, please check your settings.") -endif(NOT GDAL_FOUND) +# add third party dependencies using CPM +include(cmake/thirdparty/CUSPATIAL_GetCPM.cmake) +# find or add cuDF +include(cmake/thirdparty/CUSPATIAL_GetCUDF.cmake) ################################################################################################### -# - add gtest ------------------------------------------------------------------------------------- +# - library targets ------------------------------------------------------------------------------- -if(BUILD_TESTS) - include(CTest) - include(ConfigureGoogleTest) +add_library(cuspatial SHARED + src/indexing/construction/point_quadtree.cu + src/interpolate/cubic_spline.cu + src/io/shp/polygon_shapefile_reader.cpp + src/io/shp/polygon_shapefile_reader.cu + src/join/quadtree_point_in_polygon.cu + src/join/quadtree_point_to_nearest_polyline.cu + src/join/quadtree_poly_filtering.cu + src/spatial/polygon_bounding_box.cu + src/spatial/polyline_bounding_box.cu + src/spatial/point_in_polygon.cu + src/spatial_window/spatial_window.cu + src/spatial/haversine.cu + src/spatial/hausdorff.cu + src/spatial/lonlat_to_cartesian.cu + src/trajectory/derive_trajectories.cu + src/trajectory/trajectory_bounding_boxes.cu + src/trajectory/trajectory_distances_and_speeds.cu +) + +set_target_properties(cuspatial + PROPERTIES BUILD_RPATH "\$ORIGIN" + # set target compile options + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CUDA_STANDARD 14 + CUDA_STANDARD_REQUIRED ON + POSITION_INDEPENDENT_CODE ON + INTERFACE_POSITION_INDEPENDENT_CODE ON +) + +target_compile_options(cuspatial + PRIVATE "$<$:${CUSPATIAL_CXX_FLAGS}>" + "$<$:${CUSPATIAL_CUDA_FLAGS}>" +) + +target_compile_definitions(cuspatial + PUBLIC "$<$:${CUSPATIAL_CXX_DEFINITIONS}>" + "$:${CUSPATIAL_CUDA_DEFINITIONS}>>" +) + +# Disable Jitify log printing. See https://github.com/NVIDIA/jitify/issues/79 +target_compile_definitions(cuspatial PRIVATE "JITIFY_PRINT_LOG=0") + +# Specify include paths for the current target and dependents +target_include_directories(cuspatial + PUBLIC "$" + PRIVATE "$" + INTERFACE "$") + +# Add Conda library paths if specified +if(CONDA_LINK_DIRS) + target_link_directories(cuspatial PUBLIC "$") +endif() - if(GTEST_FOUND) - message(STATUS "Google C++ Testing Framework (Google Test) found in ${GTEST_ROOT}") - include_directories(${GTEST_INCLUDE_DIR}) - add_subdirectory(${CMAKE_SOURCE_DIR}/tests) - else() - message(AUTHOR_WARNING "Google C++ Testing Framework (Google Test) not found: automated tests are disabled.") - endif(GTEST_FOUND) -endif(BUILD_TESTS) +# Add Conda include paths if specified +if(CONDA_INCLUDE_DIRS) + target_include_directories(cuspatial PUBLIC "$") +endif() -################################################################################################### -# - add google benchmark -------------------------------------------------------------------------- +# Per-thread default stream +if(PER_THREAD_DEFAULT_STREAM) + target_compile_definitions(cuspatial PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM) +endif() -if(BUILD_BENCHMARKS) +# Disable NVTX if necessary +if(NOT USE_NVTX) + target_compile_definitions(cuspatial PUBLIC NVTX_DISABLE) +endif() - include(ConfigureGoogleBenchmark) +# Define spdlog level +target_compile_definitions(cuspatial PUBLIC "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}") - if(GBENCH_FOUND) - message(STATUS "Google C++ Benchmarking Framework (Google Benchmark) found in ${GBENCH_ROOT}") - include_directories(${GBENCH_INCLUDE_DIR}) - add_subdirectory(${CMAKE_SOURCE_DIR}/benchmarks) - else() - message(AUTHOR_WARNING "Google C++ Benchmarking Framework (Google Benchmark) not found: automated tests are disabled.") - endif(GBENCH_FOUND) +# Specify the target module library dependencies +target_link_libraries(cuspatial PUBLIC GDAL::GDAL cudf::cudf CUDA::cusparse) -endif(BUILD_BENCHMARKS) +add_library(cuspatial::cuspatial ALIAS cuspatial) ################################################################################################### -# - include paths --------------------------------------------------------------------------------- +# - add tests ------------------------------------------------------------------------------------- -include_directories("${THRUST_INCLUDE_DIR}" - "${LIBCUDACXX_INCLUDE_DIR}") - -if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) - include_directories("${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}") -endif(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) - -include_directories("${CMAKE_BINARY_DIR}/include" - "${CMAKE_SOURCE_DIR}/include" - "${CMAKE_SOURCE_DIR}/src" - "${RMM_INCLUDE}" - "${CUDF_INCLUDE}") - -if(CONDA_INCLUDE_DIRS) - include_directories("${CONDA_INCLUDE_DIRS}") -endif(CONDA_INCLUDE_DIRS) +if(CUSPATIAL_BUILD_TESTS) + # include CTest module -- automatically calls enable_testing() + include(CTest) + add_subdirectory(tests) +endif() ################################################################################################### -# - library paths --------------------------------------------------------------------------------- +# - add benchmarks -------------------------------------------------------------------------------- + +if(CUSPATIAL_BUILD_BENCHMARKS) + # Find or install GoogleBench + CPMFindPackage(NAME benchmark + VERSION 1.5.2 + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.5.2 + GIT_SHALLOW TRUE + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" + "BENCHMARK_ENABLE_INSTALL OFF") + add_subdirectory(benchmarks) +endif() -link_directories("${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}" # CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES is an undocumented/unsupported variable containing the link directories for nvcc - "${CMAKE_BINARY_DIR}/lib" - "${FLATBUFFERS_LIBRARY_DIR}" - "${GTEST_LIBRARY_DIR}") +################################################################################################### +# - install targets ------------------------------------------------------------------------------- -if(CONDA_LINK_DIRS) - link_directories("${CONDA_LINK_DIRS}") -endif(CONDA_LINK_DIRS) +include(GNUInstallDirs) -################################################################################################### -# - library targets ------------------------------------------------------------------------------- +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/cuspatial) +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME cuspatial) -add_library(cuspatial SHARED - src/indexing/construction/point_quadtree.cu - src/interpolate/cubic_spline.cu - src/io/shp/polygon_shapefile_reader.cpp - src/io/shp/polygon_shapefile_reader.cu - src/join/quadtree_point_in_polygon.cu - src/join/quadtree_point_to_nearest_polyline.cu - src/join/quadtree_poly_filtering.cu - src/spatial/polygon_bounding_box.cu - src/spatial/polyline_bounding_box.cu - src/spatial/point_in_polygon.cu - src/spatial_window/spatial_window.cu - src/spatial/haversine.cu - src/spatial/hausdorff.cu - src/spatial/lonlat_to_cartesian.cu - src/trajectory/derive_trajectories.cu - src/trajectory/trajectory_bounding_boxes.cu - src/trajectory/trajectory_distances_and_speeds.cu) - -#Override RPATH for cuspatial -SET_TARGET_PROPERTIES(cuspatial PROPERTIES BUILD_RPATH "\$ORIGIN") +install(TARGETS cuspatial + DESTINATION lib + EXPORT cuspatial-targets) -################################################################################################### -# - build options --------------------------------------------------------------------------------- +install(DIRECTORY ${CUSPATIAL_SOURCE_DIR}/include/cuspatial + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -option(USE_NVTX "Build with NVTX support" ON) -if(USE_NVTX) - message(STATUS "Using Nvidia Tools Extension") - find_library(NVTX_LIBRARY nvToolsExt PATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) - target_link_libraries(cuspatial ${NVTX_LIBRARY}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_NVTX") -endif(USE_NVTX) +include(CMakePackageConfigHelpers) +configure_package_config_file(cmake/cuspatial-config.cmake.in "${CUSPATIAL_BINARY_DIR}/cmake/cuspatial-config.cmake" + INSTALL_DESTINATION "${INSTALL_CONFIGDIR}") -################################################################################################### -# - link libraries -------------------------------------------------------------------------------- +write_basic_package_version_file("${CUSPATIAL_BINARY_DIR}/cmake/cuspatial-config-version.cmake" + COMPATIBILITY SameMinorVersion) -target_link_libraries(cuspatial cuda cudart cusparse GDAL::GDAL) -# Because libcudf.so doesn't contain any symbols, the linker will determine that it's okay to prune -# it before copying `DT_NEEDED` entries from it -target_link_libraries(cuspatial "-Wl,--no-as-needed" cudf "-Wl,--as-needed") +install(FILES "${CUSPATIAL_BINARY_DIR}/cmake/cuspatial-config.cmake" + "${CUSPATIAL_BINARY_DIR}/cmake/cuspatial-config-version.cmake" + DESTINATION "${INSTALL_CONFIGDIR}") -################################################################################################### -# - install targets ------------------------------------------------------------------------------- +install(EXPORT cuspatial-targets + FILE cuspatial-targets.cmake + NAMESPACE cuspatial:: + DESTINATION "${INSTALL_CONFIGDIR}") -install(TARGETS cuspatial - DESTINATION lib - COMPONENT cuspatial) +################################################################################################ +# - build export ------------------------------------------------------------------------------- -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/cuspatial - DESTINATION include - COMPONENT cuspatial) +configure_package_config_file(cmake/cuspatial-build-config.cmake.in ${CUSPATIAL_BINARY_DIR}/cuspatial-config.cmake + INSTALL_DESTINATION ${CUSPATIAL_BINARY_DIR}) -install(DIRECTORY ${CMAKE_BINARY_DIR}/include/libcxx - DESTINATION include/libcuspatial - COMPONENT cuspatial) +write_basic_package_version_file(${CUSPATIAL_BINARY_DIR}/cuspatial-config-version.cmake + COMPATIBILITY SameMinorVersion) -install(DIRECTORY ${CMAKE_BINARY_DIR}/include/libcudacxx - DESTINATION include/libcuspatial - COMPONENT cuspatial) +export(EXPORT cuspatial-targets + FILE ${CUSPATIAL_BINARY_DIR}/cuspatial-targets.cmake + NAMESPACE cuspatial::) diff --git a/cpp/benchmarks/CMakeLists.txt b/cpp/benchmarks/CMakeLists.txt index a027c7d77..dbb044476 100644 --- a/cpp/benchmarks/CMakeLists.txt +++ b/cpp/benchmarks/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2019-2020, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, 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,76 +14,40 @@ # limitations under the License. #============================================================================= -if(NOT CMAKE_CUDA_COMPILER) - message(SEND_ERROR "CMake cannot locate a CUDA compiler") -endif() - -################################################################################################### -# - common test utils ----------------------------------------------------------------------------- - -find_library(CUDFTESTUTIL_LIBRARY "libcudftestutil.a" - HINTS "$ENV{CUDF_ROOT}/lib") - -message(STATUS "CUDFTESTUTIL: CUDFTESTUTIL_LIBRARY set to ${CUDFTESTUTIL_LIBRARY}") - -add_library(cudftestutil STATIC IMPORTED ${CUDFTESTUTIL_LIBRARY}) -if (CUDFTESTUTIL_LIBRARY) - set_target_properties(cudftestutil PROPERTIES IMPORTED_LOCATION ${CUDFTESTUTIL_LIBRARY}) -endif (CUDFTESTUTIL_LIBRARY) - ################################################################################################### # - compiler function ----------------------------------------------------------------------------- -function(ConfigureBench CMAKE_BENCH_NAME CMAKE_BENCH_SRC) - add_executable(${CMAKE_BENCH_NAME} - ${CMAKE_BENCH_SRC} - "${CMAKE_CURRENT_SOURCE_DIR}/synchronization/synchronization.cpp") - set_target_properties(${CMAKE_BENCH_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - # By default the linker doesn't transitively add `DT_NEEDED` entries in executables like it does - # for shared libraries, so to work around current libcudf build behavior we're adding the linker - # flag - target_link_libraries(${CMAKE_BENCH_NAME} "-Wl,--copy-dt-needed-entries") - target_link_libraries(${CMAKE_BENCH_NAME} benchmark benchmark_main pthread cuspatial - cudftestutil) - set_target_properties(${CMAKE_BENCH_NAME} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/gbenchmarks") +# Use an OBJECT library so we only compile common source files only once +add_library(cuspatial_benchmark_common OBJECT + synchronization/synchronization.cpp) + +target_link_libraries(cuspatial_benchmark_common + PUBLIC benchmark::benchmark + cudf::cudftestutil + cuspatial) + +target_compile_options(cuspatial_benchmark_common + PUBLIC "$<$:${CUSPATIAL_CXX_FLAGS}>" + "$<$:${CUSPATIAL_CUDA_FLAGS}>") + +target_include_directories(cuspatial_benchmark_common + PUBLIC "$" + "$" + "$") + +function(ConfigureBench CMAKE_BENCH_NAME) + add_executable(${CMAKE_BENCH_NAME} ${ARGN}) + set_target_properties(${CMAKE_BENCH_NAME} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$") + target_link_libraries(${CMAKE_BENCH_NAME} PRIVATE benchmark::benchmark_main cuspatial_benchmark_common) endfunction(ConfigureBench) ################################################################################################### -# - include paths --------------------------------------------------------------------------------- - -include_directories("${THRUST_INCLUDE_DIR}" - "${LIBCUDACXX_INCLUDE_DIR}") - -include_directories("${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}" - "${CMAKE_BINARY_DIR}/include" - "${CMAKE_SOURCE_DIR}/include" - "${CMAKE_SOURCE_DIR}" - "${CMAKE_SOURCE_DIR}/src" - "${GDAL_INCLUDE_DIRS}" - "${GTEST_INCLUDE_DIR}" - "${GBENCH_INCLUDE_DIR}" - "${RMM_INCLUDE}" - "${CUDF_INCLUDE}" - "${CMAKE_CURRENT_SOURCE_DIR}") - +### benchmark sources ############################################################################# ################################################################################################### -# - library paths --------------------------------------------------------------------------------- - -link_directories("${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}" # CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES is an undocumented/unsupported variable containing the link directories for nvcc - "${CMAKE_BINARY_DIR}/lib" - "${CMAKE_BINARY_DIR}" - "${GDAL_LIBRARIES}" - "${CONDA_LINK_DIRS}" - "${GTEST_LIBRARY_DIR}" - "${GBENCH_LIBRARY_DIR}" - "${CUDF_LIBRARY}" - "${CUSPATIAL_LIBRARY}") ################################################################################################### # - hausdorff benchmark --------------------------------------------------------------------------- -set(HAUSDORFF_BENCH_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/hausdorff_benchmark.cpp") - -ConfigureBench(HAUSDORFF_BENCH "${HAUSDORFF_BENCH_SRC}") +ConfigureBench(HAUSDORFF_BENCH + hausdorff_benchmark.cpp) diff --git a/cpp/benchmarks/fixture/benchmark_fixture.hpp b/cpp/benchmarks/fixture/benchmark_fixture.hpp index 1c20ef4ab..560838932 100644 --- a/cpp/benchmarks/fixture/benchmark_fixture.hpp +++ b/cpp/benchmarks/fixture/benchmark_fixture.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ class benchmark : public ::benchmark::Fixture { public: virtual void SetUp(const ::benchmark::State& state) { - auto mr = make_pool(); + mr = make_pool(); rmm::mr::set_current_device_resource(mr.get()); // set default resource to pool } diff --git a/cpp/benchmarks/hausdorff_benchmark.cpp b/cpp/benchmarks/hausdorff_benchmark.cpp index 1f031eca0..ed3e872e7 100644 --- a/cpp/benchmarks/hausdorff_benchmark.cpp +++ b/cpp/benchmarks/hausdorff_benchmark.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-2021, 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,10 +19,9 @@ #include #include +#include #include -#include - static void BM_hausdorff(benchmark::State& state) { int32_t num_points = state.range(1) - 1; @@ -30,11 +29,10 @@ static void BM_hausdorff(benchmark::State& state) int32_t num_spaces = std::min(num_points, num_spaces_asked); int32_t num_points_per_space = num_points / num_spaces; - auto counting_iter = thrust::counting_iterator(); - auto zero_iter = thrust::make_transform_iterator(counting_iter, [](auto idx) { return 0; }); + auto zero_iter = thrust::make_constant_iterator(0); - auto space_offset_iter = thrust::make_transform_iterator( - counting_iter, [num_points_per_space](int32_t idx) { return idx * num_points_per_space; }); + auto space_offset_iter = cudf::detail::make_counting_transform_iterator( + 0, [num_points_per_space](int32_t idx) { return idx * num_points_per_space; }); auto xs = cudf::test::fixed_width_column_wrapper(zero_iter, zero_iter + num_points); auto ys = cudf::test::fixed_width_column_wrapper(zero_iter, zero_iter + num_points); @@ -51,6 +49,11 @@ static void BM_hausdorff(benchmark::State& state) } class HausdorffBenchmark : public cuspatial::benchmark { + virtual void SetUp(const ::benchmark::State& state) override + { + mr = std::make_shared(); + rmm::mr::set_current_device_resource(mr.get()); // set default resource to cuda + } }; #define DUMMY_BM_BENCHMARK_DEFINE(name) \ diff --git a/cpp/benchmarks/synchronization/synchronization.cpp b/cpp/benchmarks/synchronization/synchronization.cpp index c5a88bd64..bd8a4d1de 100644 --- a/cpp/benchmarks/synchronization/synchronization.cpp +++ b/cpp/benchmarks/synchronization/synchronization.cpp @@ -24,7 +24,7 @@ cuda_event_timer::cuda_event_timer(benchmark::State& state, bool flush_l2_cache, rmm::cuda_stream_view stream) - : p_state(&state), stream(stream) + : stream(stream), p_state(&state) { // flush all of L2$ if (flush_l2_cache) { diff --git a/cpp/cmake/Modules/ConfigureCUDA.cmake b/cpp/cmake/Modules/ConfigureCUDA.cmake new file mode 100644 index 000000000..e104eae78 --- /dev/null +++ b/cpp/cmake/Modules/ConfigureCUDA.cmake @@ -0,0 +1,58 @@ +#============================================================================= +# Copyright (c) 2021, 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. +#============================================================================= + +# Find the CUDAToolkit +find_package(CUDAToolkit REQUIRED) + +# Auto-detect available GPU compute architectures +include(${CMAKE_CURRENT_LIST_DIR}/SetGPUArchs.cmake) +message(STATUS "CUSPATIAL: Building CUSPATIAL 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. +# Must also come after we detect and potentially rewrite +# CMAKE_CUDA_ARCHITECTURES +enable_language(CUDA) + +if(CMAKE_COMPILER_IS_GNUCXX) + list(APPEND CUSPATIAL_CXX_FLAGS -Wall -Werror -Wno-unknown-pragmas -Wno-error=deprecated-declarations) + if(CUSPATIAL_BUILD_TESTS OR CUSPATIAL_BUILD_BENCHMARKS) + # Suppress parentheses warning which causes gmock to fail + list(APPEND CUSPATIAL_CUDA_FLAGS -Xcompiler=-Wno-parentheses) + endif() +endif(CMAKE_COMPILER_IS_GNUCXX) + +list(APPEND CUSPATIAL_CUDA_FLAGS --expt-extended-lambda --expt-relaxed-constexpr) + +# set warnings as errors +list(APPEND CUSPATIAL_CUDA_FLAGS -Werror=cross-execution-space-call) +list(APPEND CUSPATIAL_CUDA_FLAGS -Xcompiler=-Wall,-Werror,-Wno-error=deprecated-declarations) + +if(DISABLE_DEPRECATION_WARNING) + list(APPEND CUSPATIAL_CXX_FLAGS -Wno-deprecated-declarations) + list(APPEND CUSPATIAL_CUDA_FLAGS -Xcompiler=-Wno-deprecated-declarations) +endif() + +# Option to enable line info in CUDA device compilation to allow introspection when profiling / memchecking +if(CUDA_ENABLE_LINEINFO) + list(APPEND CUSPATIAL_CUDA_FLAGS -lineinfo) +endif() + +# Debug options +if(CMAKE_BUILD_TYPE MATCHES Debug) + message(STATUS "CUSPATIAL: Building with debugging flags") + list(APPEND CUSPATIAL_CUDA_FLAGS -G -Xcompiler=-rdynamic) +endif() diff --git a/cpp/cmake/Modules/ConfigureGoogleBenchmark.cmake b/cpp/cmake/Modules/ConfigureGoogleBenchmark.cmake deleted file mode 100644 index c37dff3f8..000000000 --- a/cpp/cmake/Modules/ConfigureGoogleBenchmark.cmake +++ /dev/null @@ -1,58 +0,0 @@ -set(GBENCH_ROOT "${CMAKE_BINARY_DIR}/googlebenchmark") - -set(GBENCH_CMAKE_ARGS " -DCMAKE_BUILD_TYPE=Release") - #" -Dgtest_build_samples=ON" - #" -DCMAKE_VERBOSE_MAKEFILE=ON") - -if(NOT CMAKE_CXX11_ABI) - message(STATUS "GBENCH: Disabling the GLIBCXX11 ABI") - list(APPEND GBENCH_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") - list(APPEND GBENCH_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") -elseif(CMAKE_CXX11_ABI) - message(STATUS "GBENCH: Enabling the GLIBCXX11 ABI") - list(APPEND GBENCH_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") - list(APPEND GBENCH_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") -endif(NOT CMAKE_CXX11_ABI) - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/GoogleBenchmark.CMakeLists.txt.cmake" - "${GBENCH_ROOT}/CMakeLists.txt") - -file(MAKE_DIRECTORY "${GBENCH_ROOT}/build") -file(MAKE_DIRECTORY "${GBENCH_ROOT}/install") - -execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . - RESULT_VARIABLE GBENCH_CONFIG - WORKING_DIRECTORY ${GBENCH_ROOT}) - -if(GBENCH_CONFIG) - message(FATAL_ERROR "Configuring Google Benchmark failed: " ${GBENCH_CONFIG}) -endif(GBENCH_CONFIG) - -set(PARALLEL_BUILD -j) -if($ENV{PARALLEL_LEVEL}) - set(NUM_JOBS $ENV{PARALLEL_LEVEL}) - set(PARALLEL_BUILD "${PARALLEL_BUILD}${NUM_JOBS}") -endif($ENV{PARALLEL_LEVEL}) - -if(${NUM_JOBS}) - if(${NUM_JOBS} EQUAL 1) - message(STATUS "GBENCH BUILD: Enabling Sequential CMake build") - elseif(${NUM_JOBS} GREATER 1) - message(STATUS "GBENCH BUILD: Enabling Parallel CMake build with ${NUM_JOBS} jobs") - endif(${NUM_JOBS} EQUAL 1) -else() - message(STATUS "GBENCH BUILD: Enabling Parallel CMake build with all threads") -endif(${NUM_JOBS}) - -execute_process(COMMAND ${CMAKE_COMMAND} --build .. -- ${PARALLEL_BUILD} - RESULT_VARIABLE GBENCH_BUILD - WORKING_DIRECTORY ${GBENCH_ROOT}/build) - -if(GBENCH_BUILD) - message(FATAL_ERROR "Building Google Benchmark failed: " ${GBENCH_BUILD}) -endif(GBENCH_BUILD) - -message(STATUS "Google Benchmark installed here: " ${GBENCH_ROOT}/install) -set(GBENCH_INCLUDE_DIR "${GBENCH_ROOT}/install/include") -set(GBENCH_LIBRARY_DIR "${GBENCH_ROOT}/install/lib" "${GBENCH_ROOT}/install/lib64") -set(GBENCH_FOUND TRUE) diff --git a/cpp/cmake/Modules/ConfigureGoogleTest.cmake b/cpp/cmake/Modules/ConfigureGoogleTest.cmake deleted file mode 100644 index 761dd74c2..000000000 --- a/cpp/cmake/Modules/ConfigureGoogleTest.cmake +++ /dev/null @@ -1,58 +0,0 @@ -set(GTEST_ROOT "${CMAKE_BINARY_DIR}/googletest") - -set(GTEST_CMAKE_ARGS "") - #" -Dgtest_build_samples=ON" - #" -DCMAKE_VERBOSE_MAKEFILE=ON") - -if(NOT CMAKE_CXX11_ABI) - message(STATUS "GTEST: Disabling the GLIBCXX11 ABI") - list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") - list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") -elseif(CMAKE_CXX11_ABI) - message(STATUS "GTEST: Enabling the GLIBCXX11 ABI") - list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") - list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") -endif(NOT CMAKE_CXX11_ABI) - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/GoogleTest.CMakeLists.txt.cmake" - "${GTEST_ROOT}/CMakeLists.txt") - -file(MAKE_DIRECTORY "${GTEST_ROOT}/build") -file(MAKE_DIRECTORY "${GTEST_ROOT}/install") - -execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . - RESULT_VARIABLE GTEST_CONFIG - WORKING_DIRECTORY ${GTEST_ROOT}) - -if(GTEST_CONFIG) - message(FATAL_ERROR "Configuring GoogleTest failed: " ${GTEST_CONFIG}) -endif(GTEST_CONFIG) - -set(PARALLEL_BUILD -j) -if($ENV{PARALLEL_LEVEL}) - set(NUM_JOBS $ENV{PARALLEL_LEVEL}) - set(PARALLEL_BUILD "${PARALLEL_BUILD}${NUM_JOBS}") -endif($ENV{PARALLEL_LEVEL}) - -if(${NUM_JOBS}) - if(${NUM_JOBS} EQUAL 1) - message(STATUS "GTEST BUILD: Enabling Sequential CMake build") - elseif(${NUM_JOBS} GREATER 1) - message(STATUS "GTEST BUILD: Enabling Parallel CMake build with ${NUM_JOBS} jobs") - endif(${NUM_JOBS} EQUAL 1) -else() - message(STATUS "GTEST BUILD: Enabling Parallel CMake build with all threads") -endif(${NUM_JOBS}) - -execute_process(COMMAND ${CMAKE_COMMAND} --build .. -- ${PARALLEL_BUILD} - RESULT_VARIABLE GTEST_BUILD - WORKING_DIRECTORY ${GTEST_ROOT}/build) - -if(GTEST_BUILD) - message(FATAL_ERROR "Building GoogleTest failed: " ${GTEST_BUILD}) -endif(GTEST_BUILD) - -message(STATUS "GoogleTest installed here: " ${GTEST_ROOT}/install) -set(GTEST_INCLUDE_DIR "${GTEST_ROOT}/install/include") -set(GTEST_LIBRARY_DIR "${GTEST_ROOT}/install/lib") -set(GTEST_FOUND TRUE) diff --git a/cpp/cmake/EvalGpuArchs.cmake b/cpp/cmake/Modules/EvalGPUArchs.cmake similarity index 65% rename from cpp/cmake/EvalGpuArchs.cmake rename to cpp/cmake/Modules/EvalGPUArchs.cmake index 740987e47..d0d833bea 100644 --- a/cpp/cmake/EvalGpuArchs.cmake +++ b/cpp/cmake/Modules/EvalGPUArchs.cmake @@ -1,4 +1,5 @@ -# Copyright (c) 2019, NVIDIA CORPORATION. +#============================================================================= +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,13 +12,22 @@ # 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. -# +#============================================================================= + +# Unset this first in case it's set to +set(CMAKE_CUDA_ARCHITECTURES OFF) + +# Enable CUDA so we can invoke nvcc +enable_language(CUDA) +# Function uses the CUDA runtime API to query the compute capability of the device, so if a user +# doesn't pass any architecture options to CMake we only build the current architecture function(evaluate_gpu_archs gpu_archs) set(eval_file ${PROJECT_BINARY_DIR}/eval_gpu_archs.cu) set(eval_exe ${PROJECT_BINARY_DIR}/eval_gpu_archs) set(error_file ${PROJECT_BINARY_DIR}/eval_gpu_archs.stderr.log) - file(WRITE ${eval_file} + file( + WRITE ${eval_file} " #include #include @@ -36,7 +46,7 @@ int main(int argc, char** argv) { } } if(archs.empty()) { - printf(\"ALL\"); + printf(\"${SUPPORTED_CUDA_ARCHITECTURES}\"); } else { bool first = true; for(const auto& arch : archs) { @@ -49,14 +59,12 @@ int main(int argc, char** argv) { } ") execute_process( - COMMAND ${CMAKE_CUDA_COMPILER} - -std=c++11 - -o ${eval_exe} - --run - ${eval_file} + COMMAND ${CMAKE_CUDA_COMPILER} -std=c++11 -o ${eval_exe} --run ${eval_file} OUTPUT_VARIABLE __gpu_archs OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_FILE ${error_file}) - message("Auto detection of gpu-archs: ${__gpu_archs}") - set(${gpu_archs} ${__gpu_archs} PARENT_SCOPE) + message(STATUS "CUSPATIAL: Auto detection of gpu-archs: ${__gpu_archs}") + set(${gpu_archs} + ${__gpu_archs} + PARENT_SCOPE) endfunction(evaluate_gpu_archs) diff --git a/cpp/cmake/Modules/SetGPUArchs.cmake b/cpp/cmake/Modules/SetGPUArchs.cmake new file mode 100644 index 000000000..f09d5ead8 --- /dev/null +++ b/cpp/cmake/Modules/SetGPUArchs.cmake @@ -0,0 +1,65 @@ +# ============================================================================= +# Copyright (c) 2021, 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. +# ============================================================================= + +# Build the list of supported architectures + +set(SUPPORTED_CUDA_ARCHITECTURES "60" "62" "70" "72" "75" "80") + +# Check for embedded vs workstation architectures +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # This is being built for Linux4Tegra or SBSA ARM64 + list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "60" "70") +else() + # This is being built for an x86 or x86_64 architecture + list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "62" "72") +endif() + +# CMake < 3.20 has a bug in FindCUDAToolkit where it won't properly detect the CUDAToolkit version +# when find_package(CUDAToolkit) occurs before enable_language(CUDA) +if(NOT DEFINED CUDAToolkit_VERSION AND CMAKE_CUDA_COMPILER) + execute_process(COMMAND ${CMAKE_CUDA_COMPILER} "--version" OUTPUT_VARIABLE NVCC_OUT) + if(NVCC_OUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=]) + set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}") + set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}") + set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") + endif() + unset(NVCC_OUT) +endif() + +if(CUDAToolkit_VERSION_MAJOR LESS 11) + list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "80") +endif() +if(CUDAToolkit_VERSION_MAJOR LESS 10) + list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "75") +endif() +if(CUDAToolkit_VERSION_MAJOR LESS 9) + list(REMOVE_ITEM SUPPORTED_CUDA_ARCHITECTURES "70") +endif() + +if(${PROJECT_NAME}_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(POP_BACK CMAKE_CUDA_ARCHITECTURES latest_arch) + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES APPEND "-real") + list(APPEND CMAKE_CUDA_ARCHITECTURES ${latest_arch}) + +elseif(${PROJECT_NAME}_BUILD_FOR_DETECTED_ARCHS) + include(${CMAKE_CURRENT_LIST_DIR}/EvalGPUArchs.cmake) + evaluate_gpu_archs(CMAKE_CUDA_ARCHITECTURES) + + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES APPEND "-real") +endif() diff --git a/cpp/cmake/Templates/GoogleBenchmark.CMakeLists.txt.cmake b/cpp/cmake/Templates/GoogleBenchmark.CMakeLists.txt.cmake deleted file mode 100644 index 3ba8c5d09..000000000 --- a/cpp/cmake/Templates/GoogleBenchmark.CMakeLists.txt.cmake +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.12) -project(cuspatial-GoogleBenchmark) - -include(ExternalProject) - -ExternalProject_Add(GoogleBenchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG v1.5.1 - SOURCE_DIR "${GBENCH_ROOT}/googlebenchmark" - BINARY_DIR "${GBENCH_ROOT}/build" - INSTALL_DIR "${GBENCH_ROOT}/install" - CMAKE_ARGS ${GBENCH_CMAKE_ARGS} -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${GBENCH_ROOT}/install) - # The flag BENCHMARK_ENABLE_TESTING=OFF prevents Google Benchmark from asking for Google Test. diff --git a/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake b/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake deleted file mode 100644 index 3e57e607f..000000000 --- a/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.12) -project(cuspatial-GoogleTest) - -include(ExternalProject) - -ExternalProject_Add(GoogleTest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.8.0 - SOURCE_DIR "${GTEST_ROOT}/googletest" - BINARY_DIR "${GTEST_ROOT}/build" - INSTALL_DIR "${GTEST_ROOT}/install" - CMAKE_ARGS ${GTEST_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=${GTEST_ROOT}/install) diff --git a/cpp/cmake/config.json b/cpp/cmake/config.json new file mode 100644 index 000000000..fa3f769cc --- /dev/null +++ b/cpp/cmake/config.json @@ -0,0 +1,42 @@ +{ + "parse": { + "additional_commands": { + "CPMFindPackage": { + "kwargs": { + "NAME": 1, + "GITHUB_REPOSITORY": "?", + "GIT_TAG": "?", + "VERSION": "?", + "GIT_SHALLOW": "?", + "OPTIONS": "*", + "FIND_PACKAGE_ARGUMENTS": "*" + } + }, + "ConfigureTest": { + "flags": ["TEST_NAME", "TEST_SRC"] + }, + "ConfigureBench": { + "flags": ["BENCH_NAME", "BENCH_SRC"] + } + } + }, + "format": { + "line_width": 100, + "tab_size": 2, + "command_case": "unchanged", + "max_lines_hwrap": 1, + "max_pargs_hwrap": 999 + }, + "lint": { + "disabled_codes": ["C0301"], + "function_pattern": "[0-9A-z_]+", + "macro_pattern": "[0-9A-z_]+", + "global_var_pattern": "[A-z][0-9A-z_]+", + "internal_var_pattern": "_[A-z][0-9A-z_]+", + "local_var_pattern": "[A-z][A-z0-9_]+", + "private_var_pattern": "_[0-9A-z_]+", + "public_var_pattern": "[A-z][0-9A-z_]+", + "argument_var_pattern": "[A-z][A-z0-9_]+", + "keyword_pattern": "[A-z][0-9A-z_]+" + } +} diff --git a/cpp/cmake/cuspatial-build-config.cmake.in b/cpp/cmake/cuspatial-build-config.cmake.in new file mode 100644 index 000000000..f9ffb9403 --- /dev/null +++ b/cpp/cmake/cuspatial-build-config.cmake.in @@ -0,0 +1,60 @@ +@PACKAGE_INIT@ + +cmake_minimum_required(VERSION 3.18) + +set(_possible_targets_to_promote + GDAL::GDAL + cuspatial::cuspatial) + +foreach(target IN LISTS _possible_targets_to_promote) + if(NOT TARGET ${target}) + list(APPEND _targets_to_promote ${target}) + endif() +endforeach() + +set(CUSPATIAL_VERSION @CUSPATIAL_VERSION@) +set(CUSPATIAL_VERSION_MAJOR @CUSPATIAL_VERSION_MAJOR@) +set(CUSPATIAL_VERSION_MINOR @CUSPATIAL_VERSION_MINOR@) +set(CUSPATIAL_SOURCE_DIR "@CUSPATIAL_SOURCE_DIR@") + +include(CMakeFindDependencyMacro) + +# make the src tree find modules available +list(PREPEND CMAKE_MODULE_PATH "@CUSPATIAL_SOURCE_DIR@/cmake/install/") +set(cudf_DIR "@cudf_DIR@") + +# * find CUDAToolkit package +# * determine GPU architectures +# * enable the CMake CUDA language +# * set other CUDA compilation flags +include(@CUSPATIAL_SOURCE_DIR@/cmake/Modules/ConfigureCUDA.cmake) + +################################################################################################### +# - dependencies ---------------------------------------------------------------------------------- + +find_dependency(GDAL) + +# add third party dependencies using CPM +include(@CUSPATIAL_SOURCE_DIR@/cmake/thirdparty/CUSPATIAL_GetCPM.cmake) + +# find cudf +set(CUSPATIAL_MIN_VERSION_cudf "${CUSPATIAL_VERSION_MAJOR}.${CUSPATIAL_VERSION_MINOR}") +include(@CUSPATIAL_SOURCE_DIR@/cmake/thirdparty/CUSPATIAL_GetCUDF.cmake) + +list(POP_FRONT CMAKE_MODULE_PATH) + +include("${CMAKE_CURRENT_LIST_DIR}/cuspatial-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cuspatial-config-version.cmake") + +check_required_components(cuspatial) + +foreach(target IN LISTS _targets_to_promote) + if(TARGET ${target}) + fix_cmake_global_defaults(${target}) + endif() +endforeach() + +set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE) diff --git a/cpp/cmake/cuspatial-config.cmake.in b/cpp/cmake/cuspatial-config.cmake.in new file mode 100644 index 000000000..14df71c51 --- /dev/null +++ b/cpp/cmake/cuspatial-config.cmake.in @@ -0,0 +1,75 @@ +@PACKAGE_INIT@ + + +#[=======================================================================[ + +Provide targets for the cuspatial library. + + +Imported Targets +^^^^^^^^^^^^^^^^ + +If cuspatial is found, this module defines the following IMPORTED GLOBAL +targets: + + cuspatial::cuspatial - The main cuspatial library. + GDAL::GDAL - The Geospatial Data Abstraction Library. + + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project:: + + cuspatial_FOUND + CUSPATIAL_VERSION + CUSPATIAL_VERSION_MAJOR + CUSPATIAL_VERSION_MINOR + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.18) + +set(_possible_targets_to_promote + GDAL::GDAL + cuspatial::cuspatial) + +foreach(target IN LISTS _possible_targets_to_promote) + if(NOT TARGET ${target}) + list(APPEND _targets_to_promote ${target}) + endif() +endforeach() + +set(CUSPATIAL_VERSION @CUSPATIAL_VERSION@) +set(CUSPATIAL_VERSION_MAJOR @CUSPATIAL_VERSION_MAJOR@) +set(CUSPATIAL_VERSION_MINOR @CUSPATIAL_VERSION_MINOR@) + +# make the bundled find modules in this directory available +list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +include(CMakeFindDependencyMacro) + +find_dependency(CUDAToolkit) +find_dependency(GDAL) +find_dependency(cudf @CUSPATIAL_MIN_VERSION_cudf@) + +list(POP_FRONT CMAKE_MODULE_PATH) + +include("${CMAKE_CURRENT_LIST_DIR}/cuspatial-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cuspatial-config-version.cmake") + +check_required_components(cuspatial) + +foreach(target IN LISTS _targets_to_promote) + if(TARGET ${target}) + get_target_property(_already_global ${target} IMPORTED_GLOBAL) + if(NOT _already_global) + set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE) + endif() + endif() +endforeach() + +set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE) diff --git a/cpp/cmake/thirdparty/CMakeLists.txt b/cpp/cmake/thirdparty/CMakeLists.txt deleted file mode 100644 index cbbb202f0..000000000 --- a/cpp/cmake/thirdparty/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -include(FetchContent) - -################################################################################################### -# - thrust/cub ------------------------------------------------------------------------------------ - -message("Fetching Thrust") - -FetchContent_Declare( - thrust - GIT_REPOSITORY https://github.com/thrust/thrust.git - # August 28, 2020 - GIT_TAG 52a8bda46c5c2128414d1d47f546b486ff0be2f0 -) - -FetchContent_GetProperties(thrust) -if(NOT thrust_POPULATED) - FetchContent_Populate(thrust) - # We are not using the thrust CMake targets, so no need to call `add_subdirectory()`. -endif() -set(THRUST_INCLUDE_DIR "${thrust_SOURCE_DIR}" PARENT_SCOPE) - -################################################################################################### -# - libcudacxx ------------------------------------------------------------------------------------ - -message("Fetching libcudacxx") - -FetchContent_Declare( - libcudacxx - GIT_REPOSITORY https://github.com/NVIDIA/libcudacxx.git - GIT_TAG 1.4.0 - GIT_SHALLOW true -) - -FetchContent_GetProperties(libcudacxx) -if(NOT libcudacxx_POPULATED) - FetchContent_Populate(libcudacxx) - # libcudacxx has no CMake targets, so no need to call `add_subdirectory()`. -endif() -set(LIBCUDACXX_DIR "${libcudacxx_SOURCE_DIR}" PARENT_SCOPE) -set(LIBCUDACXX_INCLUDE_DIR "${libcudacxx_SOURCE_DIR}/include/" PARENT_SCOPE) -set(LIBCXX_DIR "${libcudacxx_SOURCE_DIR}/libcxx/" PARENT_SCOPE) -set(LIBCXX_INCLUDE_DIR "${libcudacxx_SOURCE_DIR}/libcxx/include/" PARENT_SCOPE) diff --git a/cpp/cmake/thirdparty/CUSPATIAL_GetCPM.cmake b/cpp/cmake/thirdparty/CUSPATIAL_GetCPM.cmake new file mode 100644 index 000000000..d78f62359 --- /dev/null +++ b/cpp/cmake/thirdparty/CUSPATIAL_GetCPM.cmake @@ -0,0 +1,42 @@ +set(CPM_DOWNLOAD_VERSION 3b404296b539e596f39421c4e92bc803b299d964) # v0.27.5 + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + message(STATUS "CUSPATIAL: Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file( + DOWNLOAD + https://raw.githubusercontent.com/TheLartians/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake + ${CPM_DOWNLOAD_LOCATION}) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) + +function(cuspatial_save_if_enabled var) + if(CUSPATIAL_${var}) + unset(${var} PARENT_SCOPE) + unset(${var} CACHE) + endif() +endfunction() + +function(cuspatial_restore_if_enabled var) + if(CUSPATIAL_${var}) + set(${var} ON CACHE INTERNAL "" FORCE) + endif() +endfunction() + +function(fix_cmake_global_defaults target) + if(TARGET ${target}) + get_target_property(_is_imported ${target} IMPORTED) + get_target_property(_already_global ${target} IMPORTED_GLOBAL) + if(_is_imported AND NOT _already_global) + set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE) + endif() + endif() +endfunction() diff --git a/cpp/cmake/thirdparty/CUSPATIAL_GetCUDF.cmake b/cpp/cmake/thirdparty/CUSPATIAL_GetCUDF.cmake new file mode 100644 index 000000000..07be7aea6 --- /dev/null +++ b/cpp/cmake/thirdparty/CUSPATIAL_GetCUDF.cmake @@ -0,0 +1,45 @@ +#============================================================================= +# Copyright (c) 2021, 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. +#============================================================================= + +function(find_and_configure_cudf VERSION) + + if(TARGET cudf::cudf) + return() + endif() + + cuspatial_save_if_enabled(BUILD_TESTS) + cuspatial_save_if_enabled(BUILD_BENCHMARKS) + CPMFindPackage(NAME cudf + VERSION ${VERSION} + GIT_REPOSITORY https://github.com/rapidsai/cudf.git + GIT_TAG branch-${VERSION} + GIT_SHALLOW TRUE + SOURCE_SUBDIR cpp + OPTIONS "BUILD_TESTS OFF" + "BUILD_BENCHMARKS OFF" + FIND_PACKAGE_ARGUMENTS "COMPONENTS testing") + cuspatial_restore_if_enabled(BUILD_TESTS) + cuspatial_restore_if_enabled(BUILD_BENCHMARKS) + + # Make sure consumers of cuspatial can see cudf::cudf + fix_cmake_global_defaults(cudf::cudf) + # Make sure consumers of cuspatial can see cudf::cudftestutil + fix_cmake_global_defaults(cudf::cudftestutil) +endfunction() + +set(CUSPATIAL_MIN_VERSION_cudf "${CUSPATIAL_VERSION_MAJOR}.${CUSPATIAL_VERSION_MINOR}") + +find_and_configure_cudf(${CUSPATIAL_MIN_VERSION_cudf}) diff --git a/cpp/src/io/shp/polygon_shapefile_reader.cpp b/cpp/src/io/shp/polygon_shapefile_reader.cpp index 505b71f71..573f266a4 100644 --- a/cpp/src/io/shp/polygon_shapefile_reader.cpp +++ b/cpp/src/io/shp/polygon_shapefile_reader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,7 +140,7 @@ read_polygon_shapefile(std::string const& filename) std::vector xs; std::vector ys; - int num_features = read_layer(dataset_layer, feature_lengths, ring_lengths, xs, ys); + read_layer(dataset_layer, feature_lengths, ring_lengths, xs, ys); feature_lengths.shrink_to_fit(); ring_lengths.shrink_to_fit(); diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 9a12b5f8d..245d6e6b8 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2019-2020, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, 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,143 +14,80 @@ # limitations under the License. #============================================================================= -if(NOT CMAKE_CUDA_COMPILER) - message(SEND_ERROR "CMake cannot locate a CUDA compiler") -endif() - -################################################################################################### -# - common test utils ----------------------------------------------------------------------------- - -find_library(CUDFTESTUTIL_LIBRARY "libcudftestutil.a" - HINTS "$ENV{CUDF_ROOT}/lib") - -message(STATUS "CUDFTESTUTIL: CUDFTESTUTIL_LIBRARY set to ${CUDFTESTUTIL_LIBRARY}") - -add_library(cudftestutil STATIC IMPORTED ${CUDFTESTUTIL_LIBRARY}) - -if (CUDFTESTUTIL_LIBRARY) - set_target_properties(cudftestutil PROPERTIES IMPORTED_LOCATION ${CUDFTESTUTIL_LIBRARY}) -endif (CUDFTESTUTIL_LIBRARY) - ################################################################################################### # - compiler function ----------------------------------------------------------------------------- -function(ConfigureTest CMAKE_TEST_NAME CMAKE_TEST_SRC) - add_executable(${CMAKE_TEST_NAME} - ${CMAKE_TEST_SRC}) - set_target_properties(${CMAKE_TEST_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - # By default the linker doesn't transitively add `DT_NEEDED` entries in executables like it does - # for shared libraries, so to work around current libcudf build behavior we're adding the linker - # flag - target_link_libraries(${CMAKE_TEST_NAME} "-Wl,--copy-dt-needed-entries") - target_link_libraries(${CMAKE_TEST_NAME} gmock gtest gmock_main gtest_main pthread cuspatial - cudftestutil) - if(USE_NVTX) - target_link_libraries(${CMAKE_TEST_NAME} ${NVTX_LIBRARY}) - endif(USE_NVTX) - set_target_properties(${CMAKE_TEST_NAME} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/gtests") +function(ConfigureTest CMAKE_TEST_NAME) + add_executable(${CMAKE_TEST_NAME} ${ARGN}) + target_compile_options(${CMAKE_TEST_NAME} + PRIVATE "$<$:${CUSPATIAL_CXX_FLAGS}>" + "$<$:${CUSPATIAL_CUDA_FLAGS}>") + target_include_directories(${CMAKE_TEST_NAME} + PRIVATE "$" + "$") + set_target_properties(${CMAKE_TEST_NAME} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$") + target_link_libraries(${CMAKE_TEST_NAME} GTest::gtest_main GTest::gmock_main cudf::cudftestutil cuspatial) add_test(NAME ${CMAKE_TEST_NAME} COMMAND ${CMAKE_TEST_NAME}) endfunction(ConfigureTest) ################################################################################################### -# - include paths --------------------------------------------------------------------------------- - -include_directories("${THRUST_INCLUDE_DIR}" - "${LIBCUDACXX_INCLUDE_DIR}") - -if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) - include_directories("${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}") -endif() - -include_directories("${CMAKE_BINARY_DIR}/include" - "${CMAKE_SOURCE_DIR}/include" - "${CMAKE_SOURCE_DIR}" - "${CMAKE_SOURCE_DIR}/src" - "${GTEST_INCLUDE_DIR}" - "${RMM_INCLUDE}" - "${CUDF_INCLUDE}") - +### test sources ################################################################################## ################################################################################################### -# - library paths --------------------------------------------------------------------------------- - -link_directories("${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}" # CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES is an undocumented/unsupported variable containing the link directories for nvcc - "${CMAKE_BINARY_DIR}" - "${CONDA_LINK_DIRS}" - "${GTEST_LIBRARY_DIR}") -set(CARTESIAN_PRODUCT_GROUP_INDEX_ITERATOR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/cartesian_product_group_index_iterator_test.cu") -ConfigureTest(CARTESIAN_PRODUCT_GROUP_INDEX_ITERATOR_TEST "${CARTESIAN_PRODUCT_GROUP_INDEX_ITERATOR_TEST_SRC}") +ConfigureTest(CARTESIAN_PRODUCT_GROUP_INDEX_ITERATOR_TEST + spatial/cartesian_product_group_index_iterator_test.cu) -set(CUBIC_SPLINE_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/interpolate/cubic_spline_test.cpp") - ConfigureTest(CUBIC_SPLINE_TEST "${CUBIC_SPLINE_TEST_SRC}") + ConfigureTest(CUBIC_SPLINE_TEST + interpolate/cubic_spline_test.cpp) -set(COORDINATE_TRANSFORM_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/coordinate_transform_test.cu") -ConfigureTest(COORDINATE_TRANSFORM_TEST "${COORDINATE_TRANSFORM_TEST_SRC}") +ConfigureTest(COORDINATE_TRANSFORM_TEST + spatial/coordinate_transform_test.cu) -set(HAVERSINE_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/haversine_test.cpp") -ConfigureTest(HAVERSINE_TEST "${HAVERSINE_TEST_SRC}") +ConfigureTest(HAVERSINE_TEST + spatial/haversine_test.cpp) -set(HAUSDORFF_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/hausdorff_test.cpp") -ConfigureTest(HAUSDORFF_TEST "${HAUSDORFF_TEST_SRC}") +ConfigureTest(HAUSDORFF_TEST + spatial/hausdorff_test.cpp) -set(JOIN_POINT_IN_POLYGON_SMALL_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/join/point_in_polygon_test_small.cpp") -ConfigureTest(JOIN_POINT_IN_POLYGON_SMALL_TEST "${JOIN_POINT_IN_POLYGON_SMALL_TEST_SRC}") +ConfigureTest(JOIN_POINT_IN_POLYGON_SMALL_TEST + join/point_in_polygon_test_small.cpp) -set(JOIN_POINT_IN_POLYGON_LARGE_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/join/point_in_polygon_test_large.cpp") -ConfigureTest(JOIN_POINT_IN_POLYGON_LARGE_TEST "${JOIN_POINT_IN_POLYGON_LARGE_TEST_SRC}") +ConfigureTest(JOIN_POINT_IN_POLYGON_LARGE_TEST + join/point_in_polygon_test_large.cpp) -set(JOIN_POINT_TO_POLYLINE_SMALL_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/join/point_to_nearest_polyline_test_small.cpp") -ConfigureTest(JOIN_POINT_TO_POLYLINE_SMALL_TEST "${JOIN_POINT_TO_POLYLINE_SMALL_TEST_SRC}") +ConfigureTest(JOIN_POINT_TO_POLYLINE_SMALL_TEST + join/point_to_nearest_polyline_test_small.cpp) -set(POINT_IN_POLYGON_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/point_in_polygon_test.cpp") -ConfigureTest(POINT_IN_POLYGON_TEST "${POINT_IN_POLYGON_TEST_SRC}") +ConfigureTest(POINT_IN_POLYGON_TEST + spatial/point_in_polygon_test.cpp) -set(POINT_QUADTREE_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/indexing/point_quadtree_test.cu") -ConfigureTest(POINT_QUADTREE_TEST "${POINT_QUADTREE_TEST_SRC}") +ConfigureTest(POINT_QUADTREE_TEST + indexing/point_quadtree_test.cu) -set(POLYLINE_BBOX_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/polyline_bbox_test.cu") -ConfigureTest(POLYLINE_BBOX_TEST "${POLYLINE_BBOX_TEST_SRC}") +ConfigureTest(POLYLINE_BBOX_TEST + spatial/polyline_bbox_test.cu) -set(POLYGON_BBOX_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial/polygon_bbox_test.cu") -ConfigureTest(POLYGON_BBOX_TEST "${POLYGON_BBOX_TEST_SRC}") +ConfigureTest(POLYGON_BBOX_TEST + spatial/polygon_bbox_test.cu) -set(SHAPEFILE_READER_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/io/shp/polygon_shapefile_reader_test.cpp") -ConfigureTest(SHAPEFILE_READER_TEST "${SHAPEFILE_READER_TEST_SRC}") +ConfigureTest(SHAPEFILE_READER_TEST + io/shp/polygon_shapefile_reader_test.cpp) -set(QUADTREE_POLYGON_FILTERING_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/join/quadtree_polygon_filtering_test.cu") -ConfigureTest(QUADTREE_POLYGON_FILTERING_TEST "${QUADTREE_POLYGON_FILTERING_SRC}") +ConfigureTest(QUADTREE_POLYGON_FILTERING_TEST + join/quadtree_polygon_filtering_test.cu) -set(QUADTREE_POLYLINE_FILTERING_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/join/quadtree_polyline_filtering_test.cu") -ConfigureTest(QUADTREE_POLYLINE_FILTERING_TEST "${QUADTREE_POLYLINE_FILTERING_SRC}") +ConfigureTest(QUADTREE_POLYLINE_FILTERING_TEST + join/quadtree_polyline_filtering_test.cu) -set(TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_SRC -"${CMAKE_CURRENT_SOURCE_DIR}/trajectory/test_trajectory_distances_and_speeds.cu") -ConfigureTest(TRAJECTORY_DISTANCES_AND_SPEEDS_TEST "${TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_SRC}") +ConfigureTest(TRAJECTORY_DISTANCES_AND_SPEEDS_TEST + trajectory/test_trajectory_distances_and_speeds.cu) -set(DERIVE_TRAJECTORIES_TEST_SRC -"${CMAKE_CURRENT_SOURCE_DIR}/trajectory/test_derive_trajectories.cu") -ConfigureTest(DERIVE_TRAJECTORIES_TEST "${DERIVE_TRAJECTORIES_TEST_SRC}") +ConfigureTest(DERIVE_TRAJECTORIES_TEST + trajectory/test_derive_trajectories.cu) -set(TRAJECTORY_BOUNDING_BOXES_TEST_SRC -"${CMAKE_CURRENT_SOURCE_DIR}/trajectory/test_trajectory_bounding_boxes.cu") -ConfigureTest(TRAJECTORY_BOUNDING_BOXES_TEST "${TRAJECTORY_BOUNDING_BOXES_TEST_SRC}") +ConfigureTest(TRAJECTORY_BOUNDING_BOXES_TEST + trajectory/test_trajectory_bounding_boxes.cu) -set(SPATIAL_WINDOW_POINT_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/spatial_window/spatial_window_test.cpp") -ConfigureTest(SPATIAL_WINDOW_POINT_TEST "${SPATIAL_WINDOW_POINT_TEST_SRC}") +ConfigureTest(SPATIAL_WINDOW_POINT_TEST + spatial_window/spatial_window_test.cpp) diff --git a/cpp/tests/spatial/haversine_test.cpp b/cpp/tests/spatial/haversine_test.cpp index 771e3a11f..73cc4922d 100644 --- a/cpp/tests/spatial/haversine_test.cpp +++ b/cpp/tests/spatial/haversine_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. + * Copyright (c) 2020-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,8 +57,6 @@ TYPED_TEST(HaversineTest, Zero) { using T = TypeParam; - auto const count = 3; - auto a_lon = fixed_width_column_wrapper({0}); auto a_lat = fixed_width_column_wrapper({0}); auto b_lon = fixed_width_column_wrapper({0}); @@ -75,8 +73,6 @@ TYPED_TEST(HaversineTest, EquivalentPoints) { using T = TypeParam; - auto const count = 3; - auto a_lon = fixed_width_column_wrapper({-180, 180}); auto a_lat = fixed_width_column_wrapper({0, 30}); auto b_lon = fixed_width_column_wrapper({180, -180}); diff --git a/python/cuspatial/setup.py b/python/cuspatial/setup.py index 75f2633a7..343a0547f 100644 --- a/python/cuspatial/setup.py +++ b/python/cuspatial/setup.py @@ -48,7 +48,7 @@ os.path.join(CUSPATIAL_ROOT, "_deps/libcudacxx-src/include"), os.path.join( os.path.dirname(sysconfig.get_path("include")), - "libcuspatial/libcudacxx", + "libcudf/libcudacxx", ), os.path.dirname(sysconfig.get_path("include")), np.get_include(),