Skip to content

Commit

Permalink
Improve the python CMake functionality to speed up the configure step (
Browse files Browse the repository at this point in the history
…nv-morpheus#754)

This is the corresponding update to incorporate changes from nv-morpheus/utilities#17.

Summary of changes:

1. This reorganizes the python CMake checks so they only get executed once (handled in utilities). Significantly speeding up the configure step.
1. Makes the CMake variable names consistent (breaking change)
   1. For example, `MORPHEUS_BUILD_PYTHON_STUBS` -> `MORPHEUS_PYTHON_BUILD_STUBS`
1. Removes extra cmake code that is now handled by utilities

Authors:
  - Michael Demoret (https://github.com/mdemoret-nv)

Approvers:
  - Christopher Harris (https://github.com/cwharris)

URL: nv-morpheus#754
  • Loading branch information
mdemoret-nv authored Mar 16, 2023
1 parent b358fde commit 1493694
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 103 deletions.
26 changes: 15 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

list(APPEND CMAKE_MESSAGE_CONTEXT "morpheus")

# Global options
# Global options (Keep sorted!)
option(BUILD_SHARED_LIBS "Default value for whether or not to build shared or static libraries" ON)
option(MORPHEUS_BUILD_BENCHMARKS "Whether or not to build benchmarks" OFF)
option(MORPHEUS_BUILD_DOCS "Enable building of API documentation" OFF)
option(MORPHEUS_BUILD_EXAMPLES "Whether or not to build examples" OFF)
option(MORPHEUS_BUILD_TESTS "Whether or not to build tests" OFF)
option(MORPHEUS_BUILD_PYTHON_STUBS "Whether or not to generated .pyi stub files for C++ Python modules. Disable to avoid requiring loading the NVIDIA GPU Driver during build" ON)
option(MORPHEUS_BUILD_PYTHON_WHEEL "Whether or not to build the morpheus .whl file" OFF)
option(MORPHEUS_ENABLE_DEBUG_INFO "Enable printing debug information" OFF)
option(MORPHEUS_PYTHON_BUILD_STUBS "Whether or not to generated .pyi stub files for C++ Python modules. Disable to avoid requiring loading the NVIDIA GPU Driver during build" ON)
option(MORPHEUS_PYTHON_BUILD_WHEEL "Whether or not to build the morpheus .whl file" OFF)
option(MORPHEUS_PYTHON_INPLACE_BUILD "Whether or not to copy built python modules back to the source tree for debug purposes." OFF)
option(MORPHEUS_PYTHON_PERFORM_INSTALL "Whether or not to automatically `pip install` any built python library. WARNING: This may overwrite any existing installation of the same name." OFF)
option(MORPHEUS_USE_CCACHE "Enable caching compilation results with ccache" OFF)
option(MORPHEUS_USE_CLANG_TIDY "Enable running clang-tidy as part of the build process" OFF)
option(MORPHEUS_USE_CONDA "Enables finding dependencies via conda instead of vcpkg.
Note: This will disable vcpkg. All dependencies must be installed first in the conda environment" OFF)
option(MORPHEUS_USE_CONDA "Enables finding dependencies via conda instead of vcpkg. Note: This will disable vcpkg. All dependencies must be installed first in the conda environment" OFF)
option(MORPHEUS_USE_IWYU "Enable running include-what-you-use as part of the build process" OFF)
option(MORPHEUS_BUILD_DOCS "Enable building of API documentation" OFF)

set(MORPHEUS_PY_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/wheel" CACHE STRING "Location to install the python directory")

set(MORPHEUS_RAPIDS_VERSION "22.10" CACHE STRING "Sets default versions for RAPIDS libraries.")
Expand Down Expand Up @@ -116,15 +118,17 @@ if("${CMAKE_EXECUTABLE_SUFFIX}" STREQUAL "")
set(CMAKE_EXECUTABLE_SUFFIX ".x")
endif()

# Create a custom target to allow preparing for style checks
add_custom_target(${PROJECT_NAME}_style_checks
COMMENT "Building dependencies for style checks"
)


##################################
##### Morpheus Python Setup ######
##################################

# Create a custom target to allow preparing for style checks
add_custom_target(${PROJECT_NAME}_style_checks
COMMENT "Building dependencies for style checks"
)
morpheus_utils_python_configure()

# Include the main morpheus code
morpheus_utils_create_python_package(morpheus
Expand All @@ -139,7 +143,7 @@ if(MORPHEUS_PYTHON_INPLACE_BUILD)
list(APPEND extra_args "IS_INPLACE")
endif()

if(MORPHEUS_BUILD_PYTHON_WHEEL)
if(MORPHEUS_PYTHON_BUILD_WHEEL)
list(APPEND extra_args "BUILD_WHEEL")
endif()

Expand Down
2 changes: 1 addition & 1 deletion ci/conda/recipes/morpheus/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ outputs:
# Note: Setting a default value here will overwrite the value from the
# shell! Defaults should be set in the run_conda_build.sh script
- CMAKE_CUDA_ARCHITECTURES
- MORPHEUS_BUILD_PYTHON_STUBS
- MORPHEUS_PYTHON_BUILD_STUBS
- MORPHEUS_CACHE_DIR
- PARALLEL_LEVEL
run_exports:
Expand Down
4 changes: 2 additions & 2 deletions ci/conda/recipes/morpheus/morpheus_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib ${CMAKE_ARGS}"
CMAKE_ARGS="-DBUILD_SHARED_LIBS=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_USE_CONDA=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_USE_CCACHE=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_BUILD_PYTHON_STUBS=${MORPHEUS_BUILD_PYTHON_STUBS=-"ON"} ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_PYTHON_BUILD_STUBS=${MORPHEUS_PYTHON_BUILD_STUBS=-"ON"} ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_PYTHON_INPLACE_BUILD=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_BUILD_PYTHON_WHEEL=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DMORPHEUS_PYTHON_BUILD_WHEEL=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON ${CMAKE_ARGS}"
CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES=-"all"} ${CMAKE_ARGS}"
CMAKE_ARGS="-DPython_EXECUTABLE=${PYTHON} ${CMAKE_ARGS}"
Expand Down
2 changes: 1 addition & 1 deletion ci/conda/recipes/run_conda_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export MORPHEUS_ROOT=${MORPHEUS_ROOT:-$(git rev-parse --show-toplevel)}

# Export script_env variables that must be set for conda build
export CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES:-"ALL"}
export MORPHEUS_BUILD_PYTHON_STUBS=${MORPHEUS_BUILD_PYTHON_STUBS:-"ON"}
export MORPHEUS_PYTHON_BUILD_STUBS=${MORPHEUS_PYTHON_BUILD_STUBS:-"ON"}
export MORPHEUS_CACHE_DIR=${MORPHEUS_CACHE_DIR:-"${MORPHEUS_ROOT}/.cache"}
export PARALLEL_LEVEL=${PARALLEL_LEVEL:-$(nproc)}

Expand Down
2 changes: 1 addition & 1 deletion ci/scripts/github/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rapids-logger "Configuring cmake for Morpheus"
git submodule update --init --recursive
cmake -B build -G Ninja ${CMAKE_BUILD_ALL_FEATURES} \
-DCCACHE_PROGRAM_PATH=$(which sccache) \
-DMORPHEUS_BUILD_PYTHON_WHEEL=ON \
-DMORPHEUS_PYTHON_BUILD_WHEEL=ON \
-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON .

rapids-logger "Building Morpheus"
Expand Down
2 changes: 1 addition & 1 deletion ci/scripts/github/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export SCCACHE_REGION="us-east-2"
export SCCACHE_IDLE_TIMEOUT=32768
#export SCCACHE_LOG=debug

export CMAKE_BUILD_ALL_FEATURES="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON -DMORPHEUS_CUDA_ARCHITECTURES=60;70;75;80 -DMORPHEUS_BUILD_BENCHMARKS=ON -DMORPHEUS_BUILD_EXAMPLES=ON -DMORPHEUS_BUILD_TESTS=ON -DMORPHEUS_USE_CONDA=ON -DMORPHEUS_PYTHON_INPLACE_BUILD=OFF -DMORPHEUS_BUILD_PYTHON_STUBS=ON -DMORPHEUS_USE_CCACHE=ON"
export CMAKE_BUILD_ALL_FEATURES="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON -DMORPHEUS_CUDA_ARCHITECTURES=60;70;75;80 -DMORPHEUS_BUILD_BENCHMARKS=ON -DMORPHEUS_BUILD_EXAMPLES=ON -DMORPHEUS_BUILD_TESTS=ON -DMORPHEUS_USE_CONDA=ON -DMORPHEUS_PYTHON_INPLACE_BUILD=OFF -DMORPHEUS_PYTHON_BUILD_STUBS=ON -DMORPHEUS_USE_CCACHE=ON"

export FETCH_STATUS=0

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ RUN --mount=type=cache,id=workspace_cache,target=/workspace/.cache,sharing=locke
source activate base &&\
# Need to get around recent versions of git locking paths until they are deemed safe
git config --global --add safe.directory "*" &&\
MORPHEUS_BUILD_PYTHON_STUBS=OFF CONDA_BLD_PATH=/opt/conda/conda-bld CONDA_ARGS="--no-test" ./ci/conda/recipes/run_conda_build.sh morpheus
MORPHEUS_PYTHON_BUILD_STUBS=OFF CONDA_BLD_PATH=/opt/conda/conda-bld CONDA_ARGS="--no-test" ./ci/conda/recipes/run_conda_build.sh morpheus

# sid_visualization is a submodule we need to init
RUN git submodule update --init --recursive
Expand Down
2 changes: 1 addition & 1 deletion external/utilities
Submodule utilities updated 30 files
+30 −0 cmake/morpheus_utils/environment_config/cpm/register_api.cmake
+3 −5 cmake/morpheus_utils/environment_config/rapids_cmake/register_api.cmake
+0 −2 cmake/morpheus_utils/environment_config/register_api.cmake
+2 −2 cmake/morpheus_utils/package_config/boost/Configure_boost.cmake
+1 −1 cmake/morpheus_utils/package_config/cudf/Configure_cudf.cmake
+0 −29 cmake/morpheus_utils/package_config/ensure_cpm_init.cmake
+1 −1 cmake/morpheus_utils/package_config/expected/Configure_expected.cmake
+1 −1 cmake/morpheus_utils/package_config/glog/Configure_glog.cmake
+1 −1 cmake/morpheus_utils/package_config/hwloc/Configure_hwloc.cmake
+1 −1 cmake/morpheus_utils/package_config/libcudacxx/Configure_libcudacxx.cmake
+1 −1 cmake/morpheus_utils/package_config/matx/Configure_matx.cmake
+4 −2 cmake/morpheus_utils/package_config/mrc/Configure_mrc.cmake
+1 −1 cmake/morpheus_utils/package_config/prometheus/Configure_prometheus.cmake
+2 −1 cmake/morpheus_utils/package_config/pybind11/Configure_pybind11.cmake
+1 −1 cmake/morpheus_utils/package_config/rdkafka/Configure_rdkafka.cmake
+9 −0 cmake/morpheus_utils/package_config/register_api.cmake
+1 −1 cmake/morpheus_utils/package_config/rmm/Configure_rmm.cmake
+1 −1 cmake/morpheus_utils/package_config/rxcpp/Configure_rxcpp.cmake
+1 −1 cmake/morpheus_utils/package_config/taskflow/Configure_taskflow.cmake
+1 −2 cmake/morpheus_utils/package_config/triton_client/Configure_triton_client.cmake
+1 −1 cmake/morpheus_utils/package_config/ucx/Configure_ucx.cmake
+68 −0 cmake/morpheus_utils/python/configure.cmake
+26 −0 cmake/morpheus_utils/python/ensure_cython.cmake
+24 −0 cmake/morpheus_utils/python/ensure_pybind11.cmake
+32 −12 cmake/morpheus_utils/python/ensure_python3.cmake
+37 −0 cmake/morpheus_utils/python/ensure_sk_build.cmake
+22 −8 cmake/morpheus_utils/python/pip_gen_depfile.py
+0 −70 cmake/morpheus_utils/python/python_config_macros.cmake
+47 −19 cmake/morpheus_utils/python/python_module_tools.cmake
+26 −7 cmake/morpheus_utils/python/register_api.cmake
11 changes: 0 additions & 11 deletions morpheus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,9 @@

list(APPEND CMAKE_MESSAGE_CONTEXT "morpheus")

option(MORPHEUS_PYTHON_INPLACE_BUILD
"Whether or not to copy built python modules back to the source tree for debug purposes." OFF)
option(MORPHEUS_PYTHON_PERFORM_INSTALL
"Whether or not to automatically `pip install` any built python library. WARNING: This may overwrite any existing installation of the same name." OFF)
option(MORPHEUS_BUILD_PYTHON_STUBS
"Whether or not to generate stubs for python files." ON)

morpheus_utils_python_modules_ensure_loaded()

# Save the root of the python for relative paths
set(MORPHEUS_PY_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)

# Determine the install directory for built modules

add_subdirectory(_lib)


Expand Down
10 changes: 3 additions & 7 deletions morpheus/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
# =============================================================================
list(APPEND CMAKE_MESSAGE_CONTEXT "_lib")

find_package(pybind11 REQUIRED)

if(MORPHEUS_PYTHON_INPLACE_BUILD)
message(STATUS "Performing inplace build for Python modules and library dependencies. Use `pip install -e .`\
from the root folder to install Morpheus.")
endif()

########### morpheus ###########
set(MORPHEUS_LIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR})

Expand All @@ -33,6 +26,9 @@ include(cmake/libraries/cudf_helpers.cmake)
include(cmake/libraries/morpheus.cmake)

########### py_morpheus ########
# Set the default link targets to avoid repeating this
morpheus_utils_python_package_set_default_link_targets(morpheus mrc::pymrc)

#----------morpheus._lib.stages---------
include(cmake/python_modules/stages.cmake)

Expand Down
6 changes: 0 additions & 6 deletions morpheus/_lib/cmake/libraries/cuda_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ set_target_properties(
target_include_directories(cuda_utils_objs
PUBLIC
"${MORPHEUS_LIB_ROOT}/include"
cudf::cudf
matx::matx
mrc::pymrc
)

target_link_libraries(cuda_utils_objs
Expand Down Expand Up @@ -83,14 +80,11 @@ set_target_properties(cuda_utils
PROPERTIES OUTPUT_NAME ${PROJECT_NAME}_utils
)

message(STATUS " Install dest: (cuda_utils) ${MORPHEUS_LIB_INSTALL_DIR}")
install(
TARGETS
cuda_utils
EXPORT
${PROJECT_NAME}-exports
LIBRARY DESTINATION
"${MORPHEUS_LIB_INSTALL_DIR}"
COMPONENT Wheel
)

Expand Down
12 changes: 1 addition & 11 deletions morpheus/_lib/cmake/libraries/cudf_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
# the License.
# =============================================================================

morpheus_utils_add_cython_library(
morpheus_add_cython_library(
cudf_helpers
MODULE_ROOT
"${MORPHEUS_LIB_ROOT}"
PYX_FILE
"${MORPHEUS_LIB_ROOT}/cudf_helpers.pyx"
INCLUDE_DIRS
"${MORPHEUS_LIB_ROOT}/include"
LINK_TARGETS
cuda_utils
OUTPUT_TARGET
cudf_helpers_target
INSTALL_DEST
${MORPHEUS_LIB_INSTALL_DIR}
)

# This target generates headers used by other parts of the code base.
Expand All @@ -42,7 +36,3 @@ set_target_properties(
CXX_INCLUDE_WHAT_YOU_USE ""
EXPORT_COMPILE_COMMANDS OFF
)

if (MORPHEUS_PYTHON_INPLACE_BUILD)
morpheus_utils_inplace_build_copy(${cudf_helpers_target} ${MORPHEUS_LIB_ROOT})
endif()
4 changes: 1 addition & 3 deletions morpheus/_lib/cmake/libraries/morpheus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,16 @@ target_link_libraries(morpheus
target_include_directories(morpheus
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

set_target_properties(morpheus PROPERTIES CXX_VISIBILITY_PRESET hidden)

message(STATUS " Install dest: (morpheus) ${MORPHEUS_LIB_INSTALL_DIR}")
install(
TARGETS
morpheus
EXPORT
${PROJECT_NAME}-exports
LIBRARY DESTINATION
"${MORPHEUS_LIB_INSTALL_DIR}"
COMPONENT Wheel
)

Expand Down
17 changes: 1 addition & 16 deletions morpheus/_lib/cmake/python_modules/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,8 @@
# the License.
# =============================================================================

morpheus_utils_add_pybind11_module(
morpheus_add_pybind11_module(
common
MODULE_ROOT
"${MORPHEUS_LIB_ROOT}"
SOURCE_FILES
"${MORPHEUS_LIB_ROOT}/src/python_modules/common.cpp"
INCLUDE_DIRS
"${MORPHEUS_LIB_ROOT}/include"
LINK_TARGETS
morpheus
mrc::pymrc
OUTPUT_TARGET
common_target
INSTALL_DEST
${MORPHEUS_LIB_INSTALL_DIR}
)

if(MORPHEUS_PYTHON_INPLACE_BUILD)
morpheus_utils_inplace_build_copy(${common_target} ${MORPHEUS_LIB_ROOT})
endif()
15 changes: 0 additions & 15 deletions morpheus/_lib/cmake/python_modules/messages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@

morpheus_utils_add_pybind11_module(
messages
MODULE_ROOT
"${MORPHEUS_LIB_ROOT}"
SOURCE_FILES
"${MORPHEUS_LIB_ROOT}/src/python_modules/messages.cpp"
INCLUDE_DIRS
"${MORPHEUS_LIB_ROOT}/include"
LINK_TARGETS
morpheus
mrc::pymrc
OUTPUT_TARGET
messages_target
INSTALL_DEST
${MORPHEUS_LIB_INSTALL_DIR}
)

if(MORPHEUS_PYTHON_INPLACE_BUILD)
morpheus_utils_inplace_build_copy(${messages_target} ${MORPHEUS_LIB_ROOT})
endif()
15 changes: 0 additions & 15 deletions morpheus/_lib/cmake/python_modules/stages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@

morpheus_utils_add_pybind11_module(
stages
MODULE_ROOT
"${MORPHEUS_LIB_ROOT}"
SOURCE_FILES
"${MORPHEUS_LIB_ROOT}/src/python_modules/stages.cpp"
INCLUDE_DIRS
"${MORPHEUS_LIB_ROOT}/include"
LINK_TARGETS
morpheus
mrc::pymrc
OUTPUT_TARGET
stages_target
INSTALL_DEST
${MORPHEUS_LIB_INSTALL_DIR}
)

if(MORPHEUS_PYTHON_INPLACE_BUILD)
morpheus_utils_inplace_build_copy(${stages_target} ${MORPHEUS_LIB_ROOT})
endif()

0 comments on commit 1493694

Please sign in to comment.