diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bfd419a66..910865fd2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,27 +1,37 @@ repos: - - repo: https://github.com/timothycrosley/isort - rev: 5.0.4 - hooks: - - id: isort - - repo: https://github.com/ambv/black - rev: stable - hooks: - - id: black - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.1 - hooks: - - id: flake8 - alias: flake8 - name: flake8 - args: ["--config=python/.flake8"] - types: [python] - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.1 - hooks: - - id: flake8 - alias: flake8-cython - name: flake8-cython - args: ["--config=python/.flake8.cython"] - types: [cython] + - repo: https://github.com/timothycrosley/isort + rev: 5.0.7 + hooks: + - id: isort + - repo: https://github.com/ambv/black + rev: 19.10b0 + hooks: + - id: black + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.3 + hooks: + - id: flake8 + alias: flake8 + name: flake8 + args: ["--config=python/.flake8"] + types: [python] + - id: flake8 + alias: flake8-cython + name: flake8-cython + args: ["--config=python/.flake8.cython"] + types: [cython] + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.11 + hooks: + - id: cmake-format + name: cmake-format + args: ["--config-files", "cmake/config.json", "--in-place", "--"] + types: [file] # override `types: [cmake]` + files: \.(cmake(\.in)?)$|CMakeLists\.txt + - id: cmake-lint + args: ["--config-files", "cmake/config.json", "--"] + types: [file] # override `types: [cmake]` + files: \.(cmake(\.in)?)$|CMakeLists\.txt + default_language_version: - python: python3 + python: python3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ae6b0852..dc5384e09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ## Improvements +- PR #604 CMake target cleanup, formatting, linting - PR #599 Make the arena memory resource work better with the producer/consumer mode - PR #612 Drop old Python `device_array*` API - PR #603 Always test both legacy and per-thread default stream diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d03d803..6b5099205 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,166 +1,130 @@ -#============================================================================= +# ============================================================================= # Copyright (c) 2018, 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 +# 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 +# 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. -#============================================================================= -cmake_minimum_required(VERSION 3.17...3.18 FATAL_ERROR) +# 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. +# ============================================================================= +cmake_minimum_required(VERSION 3.18...3.18 FATAL_ERROR) -project(RMM VERSION 0.17.0 LANGUAGES C CXX CUDA) +project( + RMM + VERSION 0.17.0 + LANGUAGES CXX) -include(cmake/CPM.cmake) +include(cmake/Modules/CPM.cmake) +include(cmake/Modules/RMM_thirdparty.cmake) -################################################################################################### -# - build type +# build type # Set a default build type if none was specified set(DEFAULT_BUILD_TYPE "Release") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.") - set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE - STRING "Choose the type of build." FORCE) + message(STATUS "RMM: Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.") + set(CMAKE_BUILD_TYPE + "${DEFAULT_BUILD_TYPE}" + CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" + "RelWithDebInfo") endif() -################################################################################################### -# - compiler options - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=deprecated-declarations") -endif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - -################################################################################################### -# - build options +# build options option(BUILD_TESTS "Configure CMake to build tests" ON) option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF) -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) - # cudart can be statically linked or dynamically linked the python ecosystem wants dynamic linking option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF) -################################################################################################### # find packages we depend on find_package(CUDAToolkit REQUIRED) -################################################################################################### -# cmake modules - -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) - -################################################################################################### -# third-party dependencies - -include(RMM_thirdparty) - -################################################################################################### # library targets add_library(rmm INTERFACE) add_library(rmm::rmm ALIAS rmm) -target_include_directories(rmm INTERFACE - "$" - "$" - ) +target_include_directories(rmm INTERFACE "$" + "$") if(CUDA_STATIC_RUNTIME) - message(STATUS "Enabling static linking of cudart") + message(STATUS "RMM: Enabling static linking of cudart") target_link_libraries(rmm INTERFACE CUDA::cudart_static) else() target_link_libraries(rmm INTERFACE CUDA::cudart) endif(CUDA_STATIC_RUNTIME) -target_link_libraries(rmm INTERFACE rmm::Thrust spdlog::spdlog_header_only ${CMAKE_DL_LIBS}) +target_link_libraries(rmm INTERFACE rmm::Thrust) +target_link_libraries(rmm INTERFACE spdlog::spdlog_header_only) +target_compile_features(rmm INTERFACE cxx_std_14 cuda_std_14) -################################################################################################### -# Set logging level. Must go before including gtests and benchmarks. +# Set logging level. Must go before including gtests and benchmarks. -set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.") +set(RMM_LOGGING_LEVEL + "INFO" + CACHE STRING "Choose the logging level.") # Set the possible values of build type for cmake-gui -set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS - "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF") -message(STATUS "RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.") +set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" + "CRITICAL" "OFF") +message(STATUS "RMM: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'") -################################################################################################### -# add gtest +# optionally build tests if(BUILD_TESTS) - include(CTest) - add_subdirectory(tests) + enable_testing() + add_subdirectory(tests) endif(BUILD_TESTS) -################################################################################################### # add google benchmark if(BUILD_BENCHMARKS) add_subdirectory(benchmarks) endif(BUILD_BENCHMARKS) -################################################################################################### # install targets include(GNUInstallDirs) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/rmm) -install(TARGETS rmm - EXPORT rmm-targets) +install(TARGETS rmm EXPORT rmm-targets) -install(DIRECTORY include/rmm - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY include/rmm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) include(CMakePackageConfigHelpers) -configure_package_config_file( - cmake/rmm-config.cmake.in - ${RMM_BINARY_DIR}/rmm-config.cmake - INSTALL_DESTINATION ${INSTALL_CONFIGDIR} - ) - -write_basic_package_version_file( - ${RMM_BINARY_DIR}/rmm-config-version.cmake - COMPATIBILITY SameMinorVersion - ) - -install(EXPORT rmm-targets +configure_package_config_file(cmake/rmm-config.cmake.in ${RMM_BINARY_DIR}/rmm-config.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR}) + +write_basic_package_version_file(${RMM_BINARY_DIR}/rmm-config-version.cmake + COMPATIBILITY SameMinorVersion) + +install( + EXPORT rmm-targets FILE rmm-targets.cmake NAMESPACE rmm:: - DESTINATION ${INSTALL_CONFIGDIR} - ) - -install(FILES - ${RMM_BINARY_DIR}/rmm-config.cmake - ${RMM_BINARY_DIR}/rmm-config-version.cmake - ${RMM_SOURCE_DIR}/cmake/install/FindThrust.cmake - DESTINATION ${INSTALL_CONFIGDIR} - ) - -################################################################################################### -# make documentation + DESTINATION ${INSTALL_CONFIGDIR}) + +install(FILES ${RMM_BINARY_DIR}/rmm-config.cmake ${RMM_BINARY_DIR}/rmm-config-version.cmake + ${RMM_SOURCE_DIR}/cmake/install/FindThrust.cmake DESTINATION ${INSTALL_CONFIGDIR}) -add_custom_command(OUTPUT RMM_DOXYGEN - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen - COMMAND doxygen Doxyfile - VERBATIM) +# make documentation -add_custom_target(rmm_doc DEPENDS RMM_DOXYGEN) +add_custom_command( + OUTPUT RMM_DOXYGEN + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen + COMMAND doxygen Doxyfile + VERBATIM + COMMENT "Custom command for RMM doxygen docs") + +add_custom_target( + rmm_doc + DEPENDS RMM_DOXYGEN + COMMENT "Target for the custom command to build the RMM doxygen docs") diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b9ab823b7..3ff79215d 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,72 +1,91 @@ -#============================================================================= +# ============================================================================= # Copyright (c) 2018-2020, 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 +# 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 +# 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. -#============================================================================= -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +# 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. +# ============================================================================= -project(RMM_BENCHS LANGUAGES C CXX CUDA) +# Fetch Google Benchmark -option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF) +CPMFindPackage( + NAME benchmark + GITHUB_REPOSITORY google/benchmark + VERSION 1.5.2 + GIT_SHALLOW TRUE + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" "BENCHMARK_ENABLE_INSTALL OFF") + +# Auto-detect available GPU compute architectures -################################################################################################### -# - compiler function +include(${RMM_SOURCE_DIR}/cmake/Modules/SetGPUArchs.cmake) +message(STATUS "RMM: Building benchmarks with GPU Architectures: ${CMAKE_CUDA_ARCHITECTURES}") -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) - target_include_directories(${CMAKE_BENCH_NAME} PRIVATE "$") - - target_link_libraries(${CMAKE_BENCH_NAME} benchmark::benchmark pthread rmm) +# Build options - set_target_properties(${CMAKE_BENCH_NAME} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${RMM_BINARY_DIR}/gbenchmarks") - - target_compile_definitions(${CMAKE_BENCH_NAME} PUBLIC - "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}") +enable_language(CUDA) + +option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF) +option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF) + +if(PER_THREAD_DEFAULT_STREAM) + message(STATUS "RMM: Building benchmarks with per-thread default stream") +endif(PER_THREAD_DEFAULT_STREAM) + +# compiler function + +# This function takes in a benchmark name and benchmark source and handles setting all of the +# associated properties and linking to build the benchmark +function(ConfigureBench BENCH_NAME BENCH_SRC) + add_executable(${BENCH_NAME} ${BENCH_SRC} + "${CMAKE_CURRENT_SOURCE_DIR}/synchronization/synchronization.cpp") + target_include_directories(${BENCH_NAME} PRIVATE "$") + set_target_properties( + ${BENCH_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE ON + RUNTIME_OUTPUT_DIRECTORY "$" + CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") + target_link_libraries(${BENCH_NAME} benchmark::benchmark pthread rmm) + target_compile_definitions(${BENCH_NAME} + PUBLIC "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}") if(PER_THREAD_DEFAULT_STREAM) - message(STATUS "Using per-thread default stream for ${CMAKE_BENCH_NAME}") - target_compile_definitions(${CMAKE_BENCH_NAME} PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM) + target_compile_definitions(${BENCH_NAME} PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM) endif(PER_THREAD_DEFAULT_STREAM) + + target_compile_options(${BENCH_NAME} PUBLIC $<$:-Werror + -Wno-error=deprecated-declarations>) + if(DISABLE_DEPRECATION_WARNING) + target_compile_options(${BENCH_NAME} PUBLIC $<$:-Xcompiler + -Wno-deprecated-declarations>) + target_compile_options(${BENCH_NAME} + PUBLIC $<$:-Wno-deprecated-declarations>) + endif(DISABLE_DEPRECATION_WARNING) + endfunction(ConfigureBench) -################################################################################################### -### benchmark sources ############################################################################# -################################################################################################### +# benchmark sources -################################################################################################### -# - random allocations benchmark +# random allocations benchmark set(RANDOM_ALLOCATIONS_BENCH_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/random_allocations/random_allocations.cpp") + "${CMAKE_CURRENT_SOURCE_DIR}/random_allocations/random_allocations.cpp") ConfigureBench(RANDOM_ALLOCATIONS_BENCH "${RANDOM_ALLOCATIONS_BENCH_SRC}") -################################################################################################### -# - replay benchmark +# replay benchmark -set(REPLAY_BENCH_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/replay/replay.cpp") +set(REPLAY_BENCH_SRC "${CMAKE_CURRENT_SOURCE_DIR}/replay/replay.cpp") ConfigureBench(REPLAY_BENCH "${REPLAY_BENCH_SRC}") -################################################################################################### -# - uvector benchmark +# uvector benchmark -set(UVECTOR_BENCH_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/device_uvector/device_uvector_bench.cu") +set(UVECTOR_BENCH_SRC "${CMAKE_CURRENT_SOURCE_DIR}/device_uvector/device_uvector_bench.cu") ConfigureBench(UVECTOR_BENCH "${UVECTOR_BENCH_SRC}") diff --git a/ci/checks/style.sh b/ci/checks/style.sh index 50669ea14..001afeb6f 100644 --- a/ci/checks/style.sh +++ b/ci/checks/style.sh @@ -33,6 +33,34 @@ FLAKE_CYTHON_RETVAL=$? CLANG_FORMAT=`python scripts/run-clang-format.py 2>&1` CLANG_FORMAT_RETVAL=$? +# Run cmake-format / cmake-lint and get results/return code +CMAKE_FILES=(`find | grep -E "^.*\.cmake(\.in)?$|^.*/CMakeLists.txt$"`) + +CMAKE_FORMATS=() +CMAKE_FORMAT_RETVAL=0 + +CMAKE_LINTS=() +CMAKE_LINT_RETVAL=0 + + +for cmake_file in "${CMAKE_FILES[@]}"; do + cmake-format --in-place --config-files cmake/config.json -- ${cmake_file} + TMP_CMAKE_FORMAT=`git diff --color --exit-code -- ${cmake_file}` + TMP_CMAKE_FORMAT_RETVAL=$? + if [ "$TMP_CMAKE_FORMAT_RETVAL" != "0" ]; then + CMAKE_FORMAT_RETVAL=1 + CMAKE_FORMATS+=("$TMP_CMAKE_FORMAT") + fi + + TMP_CMAKE_LINT=`cmake-lint --config-files cmake/config.json -- ${cmake_file}` + TMP_CMAKE_LINT_RETVAL=$? + if [ "$TMP_CMAKE_LINT_RETVAL" != "0" ]; then + CMAKE_LINT_RETVAL=1 + CMAKE_LINTS+=("$TMP_CMAKE_LINT") + fi +done + + # Output results if failure otherwise show pass if [ "$ISORT_RETVAL" != "0" ]; then echo -e "\n\n>>>> FAILED: isort style check; begin output\n\n" @@ -74,7 +102,29 @@ else echo -e "\n\n>>>> PASSED: clang format check\n\n" fi -RETVALS=($ISORT_RETVAL $BLACK_RETVAL $FLAKE_RETVAL $FLAKE_CYTHON_RETVAL $CLANG_FORMAT_RETVAL) +if [ "$CMAKE_FORMAT_RETVAL" != "0" ]; then + echo -e "\n\n>>>> FAILED: cmake format check; begin output\n\n" + for CMAKE_FORMAT in "${CMAKE_FORMATS[@]}"; do + echo -e "$CMAKE_FORMAT" + echo -e "\n" + done + echo -e "\n\n>>>> FAILED: cmake format check; end output\n\n" +else + echo -e "\n\n>>>> PASSED: cmake format check\n\n" +fi + +if [ "$CMAKE_LINT_RETVAL" != "0" ]; then + echo -e "\n\n>>>> FAILED: cmake lint check; begin output\n\n" + for CMAKE_LINT in "${CMAKE_LINTS[@]}"; do + echo -e "$CMAKE_LINT" + echo -e "\n" + done + echo -e "\n\n>>>> FAILED: cmake lint check; end output\n\n" +else + echo -e "\n\n>>>> PASSED: cmake lint check\n\n" +fi + +RETVALS=($ISORT_RETVAL $BLACK_RETVAL $FLAKE_RETVAL $FLAKE_CYTHON_RETVAL $CLANG_FORMAT_RETVAL $CMAKE_FORMAT_RETVAL $CMAKE_LINT_RETVAL) IFS=$'\n' RETVAL=`echo "${RETVALS[*]}" | sort -nr | head -n1` diff --git a/ci/gpu/build.sh b/ci/gpu/build.sh index 6ca583d48..02f7845e4 100755 --- a/ci/gpu/build.sh +++ b/ci/gpu/build.sh @@ -78,7 +78,7 @@ if [[ -z "$PROJECT_FLASH" || "$PROJECT_FLASH" == "0" ]]; then cd "${WORKSPACE}/build" GTEST_OUTPUT="xml:${WORKSPACE}/test-results/" make -j${PARALLEL_LEVEL} test - gpuci_logger "Python py.test for librmm_cffi" + gpuci_logger "Running rmm pytests..." cd $WORKSPACE/python py.test --cache-clear --basetemp=${WORKSPACE}/rmm-cuda-tmp --junitxml=${WORKSPACE}/test-results/junit-rmm.xml -v --cov-config=.coveragerc --cov=rmm --cov-report=xml:${WORKSPACE}/python/rmm-coverage.xml --cov-report term fi diff --git a/cmake/CPM.cmake b/cmake/Modules/CPM.cmake similarity index 78% rename from cmake/CPM.cmake rename to cmake/Modules/CPM.cmake index 60a9fe022..162edcba2 100644 --- a/cmake/CPM.cmake +++ b/cmake/Modules/CPM.cmake @@ -10,10 +10,10 @@ endif() if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) message(STATUS "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} - ) + file( + DOWNLOAD + https://raw.githubusercontent.com/TheLartians/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake + ${CPM_DOWNLOAD_LOCATION}) endif() include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/Modules/EvalGPUArchs.cmake b/cmake/Modules/EvalGPUArchs.cmake new file mode 100644 index 000000000..c3afb8797 --- /dev/null +++ b/cmake/Modules/EvalGPUArchs.cmake @@ -0,0 +1,62 @@ +# Copyright (c) 2019-2020, 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. + +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} + " +#include +#include +#include +using namespace std; +int main(int argc, char** argv) { + set archs; + int nDevices; + if((cudaGetDeviceCount(&nDevices) == cudaSuccess) && (nDevices > 0)) { + for(int dev=0;dev= 1.10.0 provides a cmake config file -- use it if it exists - FIND_PACKAGE_ARGUMENTS "CONFIG" - ) - - if (GTest_ADDED) - add_library(GTest::gtest ALIAS gtest) - add_library(GTest::gmock ALIAS gmock) - add_library(GTest::gtest_main ALIAS gtest_main) - add_library(GTest::gmock_main ALIAS gmock_main) - endif() -endif() - -################################################################################################### -# - googlebenchmark ------------------------------------------------------------------------------- - -if (BUILD_BENCHMARKS) - CPMFindPackage( - NAME benchmark - GITHUB_REPOSITORY google/benchmark - VERSION 1.5.2 - GIT_SHALLOW TRUE - OPTIONS - "BENCHMARK_ENABLE_TESTING OFF" - "BENCHMARK_ENABLE_INSTALL OFF" - ) -endif() diff --git a/cmake/config.json b/cmake/config.json new file mode 100644 index 000000000..fa3f769cc --- /dev/null +++ b/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/cmake/install/FindThrust.cmake b/cmake/install/FindThrust.cmake index 8daebd0b2..d18216d06 100644 --- a/cmake/install/FindThrust.cmake +++ b/cmake/install/FindThrust.cmake @@ -1,33 +1,30 @@ - # FindThrust # --------- # # Try to find Thrust # -# Uses Thrust_ROOT in the cache variables or in the environment as a hint -# where to search +# Uses Thrust_ROOT in the cache variables or in the environment as a hint where to search # # IMPORTED Targets # ^^^^^^^^^^^^^^^^ # -# This module defines a basic `thrust_create_target` function as provided -# otherwise by the newer Thrust >= 1.9.10 included configs. +# This module defines a basic `thrust_create_target` function as provided otherwise by the newer +# Thrust >= 1.9.10 included configs. # # Result Variables # ^^^^^^^^^^^^^^^^ # # This module defines the following variables: -# -# ``Thrust_FOUND`` -# system has Thrust -# ``Thrust_INCLUDE_DIRS`` -# the Thrust include directories +# ~~~ +# ``Thrust_FOUND`` system has Thrust +# ``Thrust_INCLUDE_DIRS`` the Thrust include directories +# ~~~ include(FindPackageHandleStandardArgs) # try to find Thrust via installed config first find_package(Thrust QUIET CONFIG) -if (Thrust_FOUND) +if(Thrust_FOUND) find_package_handle_standard_args(Thrust CONFIG_MODE) return() endif() @@ -36,7 +33,8 @@ cmake_minimum_required(VERSION 3.17..3.18 FATAL_ERROR) find_dependency(CUDAToolkit) -find_path(Thrust_INCLUDE_DIRS +find_path( + Thrust_INCLUDE_DIRS NAMES thrust/version.h HINTS ${CUDAToolkit_INCLUDE_DIRS}) @@ -47,18 +45,19 @@ math(EXPR minor "(${CMAKE_MATCH_1} / 100) % 1000") math(EXPR subminor "${CMAKE_MATCH_1} % 100") set(Thrust_VERSION "${major}.${minor}.${subminor}") -find_package_handle_standard_args(Thrust +find_package_handle_standard_args( + Thrust REQUIRED_VARS Thrust_INCLUDE_DIRS VERSION_VAR Thrust_VERSION) -if (Thrust_FOUND) +if(Thrust_FOUND) + # Create wrapper function to handle situation where we can't use a regular IMPORTED INTERFACE + # target since that'll use -isystem, leading to the wrong search order with nvcc function(thrust_create_target tgt) if(NOT TARGET ${tgt}) - # can't use a regular IMPORTED INTERFACE target since that'll - # use -isystem, leading to the wrong search order with nvcc add_library(thrust_internal INTERFACE) - set_target_properties(thrust_internal PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Thrust_INCLUDE_DIRS}") + set_target_properties(thrust_internal PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${Thrust_INCLUDE_DIRS}") add_library(${tgt} ALIAS thrust_internal) endif() endfunction() diff --git a/cmake/rmm-config.cmake.in b/cmake/rmm-config.cmake.in index b7dca8e11..06006d5fd 100644 --- a/cmake/rmm-config.cmake.in +++ b/cmake/rmm-config.cmake.in @@ -1,4 +1,3 @@ - @PACKAGE_INIT@ cmake_minimum_required(VERSION 3.17) @@ -18,7 +17,6 @@ thrust_create_target(rmm::Thrust FROM_OPTIONS) set(CMAKE_MODULE_PATH ${_save_CMAKE_MODULE_PATH}) - include("${CMAKE_CURRENT_LIST_DIR}/rmm-targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/rmm-config-version.cmake") diff --git a/conda/environments/rmm_dev_cuda10.1.yml b/conda/environments/rmm_dev_cuda10.1.yml index db2e86135..fc8be856e 100644 --- a/conda/environments/rmm_dev_cuda10.1.yml +++ b/conda/environments/rmm_dev_cuda10.1.yml @@ -5,7 +5,11 @@ channels: dependencies: - clang=8.0.1 - clang-tools=8.0.1 -- cmake>=3.14 +- cmake>=3.18 +- cmake-format=0.6.11 +- flake8=3.8.3 +- black=19.10 +- isort=5.0.7 - python>=3.6,<3.8 - numba>=0.49 - numpy diff --git a/conda/environments/rmm_dev_cuda10.2.yml b/conda/environments/rmm_dev_cuda10.2.yml index 8d9a2317b..6bf142338 100644 --- a/conda/environments/rmm_dev_cuda10.2.yml +++ b/conda/environments/rmm_dev_cuda10.2.yml @@ -5,7 +5,11 @@ channels: dependencies: - clang=8.0.1 - clang-tools=8.0.1 -- cmake>=3.14 +- cmake>=3.18 +- cmake-format=0.6.11 +- flake8=3.8.3 +- black=19.10 +- isort=5.0.7 - python>=3.6,<3.8 - numba>=0.49 - numpy diff --git a/conda/environments/rmm_dev_cuda11.0.yml b/conda/environments/rmm_dev_cuda11.0.yml index 5d202c18e..ef2d5b6c7 100644 --- a/conda/environments/rmm_dev_cuda11.0.yml +++ b/conda/environments/rmm_dev_cuda11.0.yml @@ -5,7 +5,11 @@ channels: dependencies: - clang=8.0.1 - clang-tools=8.0.1 -- cmake>=3.14 +- cmake>=3.18 +- cmake-format=0.6.11 +- flake8=3.8.3 +- black=19.10 +- isort=5.0.7 - python>=3.6,<3.8 - numba>=0.49 - numpy diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1c62a130e..fee089db8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,151 +1,146 @@ -#============================================================================= +# ============================================================================= # Copyright (c) 2018-2020, 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 +# 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 +# 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. -#============================================================================= -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +# 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. +# ============================================================================= -project(RMM_TESTS LANGUAGES C CXX CUDA) +include(CTest) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Fetch GTest -set(CMAKE_CUDA_STANDARD 14) -set(CMAKE_CUDA_STANDARD_REQUIRED ON) +CPMFindPackage( + NAME GTest + GITHUB_REPOSITORY google/googletest + GIT_TAG release-1.10.0 + VERSION 1.10.0 + GIT_SHALLOW TRUE + OPTIONS "INSTALL_GTEST OFF" + # googletest >= 1.10.0 provides a cmake config file -- use it if it exists + FIND_PACKAGE_ARGUMENTS "CONFIG") -################################################################################################### -# - compiler function +if(GTest_ADDED) + add_library(GTest::gtest ALIAS gtest) + add_library(GTest::gmock ALIAS gmock) + add_library(GTest::gtest_main ALIAS gtest_main) + add_library(GTest::gmock_main ALIAS gmock_main) +endif() -function(ConfigureTestInternal 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) - target_include_directories(${CMAKE_TEST_NAME} PRIVATE "$") +# Auto-detect available GPU compute architectures - target_link_libraries(${CMAKE_TEST_NAME} GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main - pthread rmm) - - set_target_properties(${CMAKE_TEST_NAME} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${RMM_BINARY_DIR}/gtests") +include(${RMM_SOURCE_DIR}/cmake/Modules/SetGPUArchs.cmake) +message(STATUS "RMM: Building tests with GPU Architectures: ${CMAKE_CUDA_ARCHITECTURES}") + +enable_language(CUDA) + +# Build options + +option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF) - target_compile_definitions(${CMAKE_TEST_NAME} PUBLIC - "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}") +# compiler function - add_test(NAME ${CMAKE_TEST_NAME} COMMAND ${CMAKE_TEST_NAME}) +# This function takes in a test name and test source and handles setting all of the associated +# properties and linking to build the test +function(ConfigureTestInternal TEST_NAME TEST_SRC) + add_executable(${TEST_NAME} "${TEST_SRC}") + target_include_directories(${TEST_NAME} PRIVATE "$") + target_link_libraries(${TEST_NAME} GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main + pthread rmm) + set_target_properties( + ${TEST_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE ON + RUNTIME_OUTPUT_DIRECTORY "$" + CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") + target_compile_definitions(${TEST_NAME} + PUBLIC "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}") + target_compile_options(${TEST_NAME} PUBLIC $<$:-Werror + -Wno-error=deprecated-declarations>) + + if(DISABLE_DEPRECATION_WARNING) + target_compile_options(${TEST_NAME} PUBLIC $<$:-Xcompiler + -Wno-deprecated-declarations>) + target_compile_options(${TEST_NAME} + PUBLIC $<$:-Wno-deprecated-declarations>) + endif(DISABLE_DEPRECATION_WARNING) + + add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) endfunction(ConfigureTestInternal) -function(ConfigureTest CMAKE_TEST_NAME CMAKE_TEST_SRC) +# Wrapper around `ConfigureTestInternal` that builds tests both with and without per thread default +# stream +function(ConfigureTest TEST_NAME TEST_SRC) # Test with legacy default stream. - ConfigureTestInternal("${CMAKE_TEST_NAME}" "${CMAKE_TEST_SRC}") + ConfigureTestInternal("${TEST_NAME}" "${TEST_SRC}") # Test with per-thread default stream. - string(REGEX REPLACE "_TEST$" "_PTDS_TEST" CMAKE_PTDS_TEST_NAME "${CMAKE_TEST_NAME}") - ConfigureTestInternal("${CMAKE_PTDS_TEST_NAME}" "${CMAKE_TEST_SRC}") - target_compile_definitions("${CMAKE_PTDS_TEST_NAME}" PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM) + string(REGEX REPLACE "_TEST$" "_PTDS_TEST" PTDS_TEST_NAME "${TEST_NAME}") + ConfigureTestInternal("${PTDS_TEST_NAME}" "${TEST_SRC}") + target_compile_definitions("${PTDS_TEST_NAME}" PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM) endfunction(ConfigureTest) -################################################################################################### -### test sources ################################################################################## -################################################################################################### +# test sources -################################################################################################### -# - device mr tests +# device mr tests -set(DEVICE_MR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/mr_tests.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/mr_multithreaded_tests.cpp") - +set(DEVICE_MR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/mr_tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/mr_multithreaded_tests.cpp") ConfigureTest(DEVICE_MR_TEST "${DEVICE_MR_TEST_SRC}") -################################################################################################### -# - pool mr tests +# pool mr tests -set(POOL_MR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/pool_mr_tests.cpp") - +set(POOL_MR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/pool_mr_tests.cpp") ConfigureTest(POOL_MR_TEST "${POOL_MR_TEST_SRC}") -################################################################################################### -# - thrust allocator tests +# thrust allocator tests -set(THRUST_ALLOCATOR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/thrust_allocator_tests.cu") - +set(THRUST_ALLOCATOR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/thrust_allocator_tests.cu") ConfigureTest(THRUST_ALLOCATOR_TEST "${THRUST_ALLOCATOR_TEST_SRC}") -################################################################################################### -# - tracking adaptor tests +# tracking adaptor tests -set(TRACKING_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/tracking_mr_tests.cpp") +set(TRACKING_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/tracking_mr_tests.cpp") ConfigureTest(TRACKING_TEST "${TRACKING_TEST_SRC}") -################################################################################################### -# - limiting adaptor tests - -set(LIMITING_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/limiting_mr_tests.cpp") +# limiting adaptor tests +set(LIMITING_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/device/limiting_mr_tests.cpp") ConfigureTest(LIMITING_TEST "${LIMITING_TEST_SRC}") -################################################################################################### -# - host mr tests - -set(HOST_MR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/mr/host/mr_tests.cpp") +# host mr tests -ConfigureTest(HOST_MR_TEST "${HOST_MR_TEST_SRC}") +set(HOST_MR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/mr/host/mr_tests.cpp") +ConfigureTest(HOST_MR_TEST "${HOST_MR_TEST_SRC}") -################################################################################################### -# - cuda stream tests +# cuda stream tests -set(CUDA_STREAM_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/cuda_stream_tests.cpp") +set(CUDA_STREAM_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/cuda_stream_tests.cpp") ConfigureTest(CUDA_STREAM_TEST "${CUDA_STREAM_TEST_SRC}") -################################################################################################### -# - device buffer tests - -set(BUFFER_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/device_buffer_tests.cu") +# device buffer tests +set(BUFFER_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/device_buffer_tests.cu") ConfigureTest(DEVICE_BUFFER_TEST "${BUFFER_TEST_SRC}") -################################################################################################### -# - device scalar tests - -set(SCALAR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/device_scalar_tests.cpp") +# device scalar tests +set(SCALAR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/device_scalar_tests.cpp") ConfigureTest(DEVICE_SCALAR_TEST "${SCALAR_TEST_SRC}") -################################################################################################### -# - logger tests - -set(LOGGER_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/logger_tests.cpp") +# logger tests +set(LOGGER_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/logger_tests.cpp") ConfigureTest(LOGGER_TEST "${LOGGER_TEST_SRC}") -################################################################################################### -# - uvector tests - -set(DEVICE_UVECTOR_TEST_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/device_uvector_tests.cpp") +# uvector tests +set(DEVICE_UVECTOR_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/device_uvector_tests.cpp") ConfigureTest(DEVICE_UVECTOR_TEST "${DEVICE_UVECTOR_TEST_SRC}") - -################################################################################################### - -enable_testing()