Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-vendor CMake dependencies and use shared libraries #753

Draft
wants to merge 25 commits into
base: branch-24.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dcb3050
Support both conda and source installation for boost
gigony Jul 27, 2024
3a8c64e
Remove boost dependency
gigony Jul 29, 2024
dfba773
Support both conda and source installation for fmt
gigony Jul 29, 2024
23a535b
Support both conda and source installation for nlohmann_json
gigony Jul 29, 2024
7aee973
Support both conda and source installation for libabseil
gigony Jul 29, 2024
e3d1925
Support both conda and source installation for nvtx3
gigony Jul 29, 2024
01c12b4
Support both conda and source installation for taskflow
gigony Jul 29, 2024
b7572bf
Support both conda and source installation for pybind11
gigony Jul 30, 2024
988cf45
Support both conda and source installation for pybind11_json
gigony Jul 30, 2024
dda171a
Update libcuckoo to 0.3.1
gigony Jul 30, 2024
7e85e5f
Update catch2 to 3.6.0
gigony Jul 31, 2024
7b853e4
Remove workarounds for nvcc errors with -std=c++17
gigony Jul 31, 2024
df4389a
Do not call catch_discover_tests() in CMakeLists.txt
gigony Jul 31, 2024
850fb2a
Add a comment on pybind11 in run script
gigony Jul 31, 2024
1286fbe
Support both conda and source installation for cli11
gigony Jul 31, 2024
568eb40
Update CONTRIBUTING guide
gigony Jul 31, 2024
dd644c8
Update dependencies
gigony Jul 31, 2024
a2b2a17
Remove rmm.cmake
gigony Jul 31, 2024
55f077f
Update cucim dependencies (python)
gigony Aug 1, 2024
6785f4c
Fix abseil.cmake for building from source code
gigony Aug 1, 2024
e0dad71
Fix boost-header-only.cmake to work with Boost v1.85.0
gigony Aug 1, 2024
4ddd932
Add libabseil dependency to run
gigony Aug 1, 2024
03127d2
Build with CXX11 ABI only
gigony Aug 1, 2024
f5be43c
Reduce the shared memory size in the test case to avoid the error
gigony Aug 1, 2024
20ff997
Test shared memory cache with reduced size
gigony Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ option(CUCIM_STATIC_GDS "Use static cufile library" OFF)
option(CUCIM_SUPPORT_CUDA "Support CUDA" ON)
option(CUCIM_SUPPORT_NVTX "Support NVTX" ON)

# Setup CXX11 ABI
# : Adds CXX11 ABI definition to the compiler command line for targets in the current directory,
# whether added before or after this command is invoked, and for the ones in sub-directories added after.
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) # TODO: create two library, one with CXX11 ABI and one without it.

################################################################################
# Define basic dependencies
Expand All @@ -122,7 +118,7 @@ superbuild_depend(googlebenchmark)
superbuild_depend(openslide)
superbuild_depend(catch2)
superbuild_depend(cli11)
superbuild_depend(json)
superbuild_depend(nlohmann_json)
superbuild_depend(libcuckoo)
superbuild_depend(boost-header-only)
superbuild_depend(nvtx3)
Expand Down Expand Up @@ -154,10 +150,10 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/examples/cpp/CMakeLists.txt.examples.re
################################################################################
set(INSTALL_TARGETS
${CUCIM_PACKAGE_NAME}
fmt-header-only
cucim_benchmarks
)


install(TARGETS ${INSTALL_TARGETS}
EXPORT ${CUCIM_PACKAGE_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down Expand Up @@ -207,11 +203,15 @@ install(DIRECTORY

# Copy 3rdparty headers
install(DIRECTORY
${deps-fmt_SOURCE_DIR}/include/
${deps-nvtx3_SOURCE_DIR}/c/include/
${deps-nvtx3_SOURCE_DIR}/cpp/include/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${CUCIM_PACKAGE_NAME}/3rdparty)
${fmt_INCLUDE_DIR}/fmt/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${CUCIM_PACKAGE_NAME}/3rdparty/fmt
)
install(DIRECTORY
${nvtx3_INCLUDE_DIR}/nvtx3/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${CUCIM_PACKAGE_NAME}/3rdparty/nvtx3
)

set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE ${CUCIM_PACKAGE_NAME})
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ Note that `./conda/environments/all_cuda-118_arch-x86_64.yaml` is currently set
If you want to change the version of gcc or CUDA toolkit package, please update `./conda/environments/all_cuda-118_arch-x86_64.yaml` before executing the following commands.

```bash
conda env create -n cucim -f ./conda/environments/all_cuda-118_arch-x86_64.yaml
mamba env create -n cucim -f conda/environments/all_cuda-125_arch-x86_64.yaml
# activate the environment
conda activate cucim
mamba activate cucim
```

### Building `libcucim` and install `cucim` (python bindings):
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -26,8 +26,6 @@ set_target_properties(cucim_benchmarks
CXX_EXTENSIONS NO
)
target_compile_features(cucim_benchmarks PRIVATE ${CUCIM_REQUIRED_FEATURES})
# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'`
target_compile_options(cucim_benchmarks PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Werror -Wall -Wextra>)
target_compile_definitions(cucim_benchmarks
PUBLIC
CUCIM_VERSION=${PROJECT_VERSION}
Expand Down Expand Up @@ -59,8 +57,6 @@ set_target_properties(cucim_primitives_benchmarks
CXX_EXTENSIONS NO
)
target_compile_features(cucim_primitives_benchmarks PRIVATE ${CUCIM_REQUIRED_FEATURES})
# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'`
target_compile_options(cucim_primitives_benchmarks PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Werror -Wall -Wextra>)
target_link_libraries(cucim_primitives_benchmarks
PRIVATE
${CUCIM_PACKAGE_NAME}
Expand Down
10 changes: 10 additions & 0 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ channels:
- conda-forge
- nvidia
dependencies:
- boost-cpp
- c-compiler
- catch2
- cli11
- click
- cmake>=3.26.4,!=3.30.0
- cuda-version=11.8
- cudatoolkit
- cupy>=12.0.0
- cxx-compiler
- fmt
- gcc_linux-64=11.*
- imagecodecs>=2021.6.8
- ipython
- jbig
- lazy_loader>=0.1
- libabseil
- libcufile-dev=1.4.0.31
- libcufile=1.4.0.31
- libnvjpeg-dev=11.6.0.55
Expand All @@ -26,14 +31,18 @@ dependencies:
- matplotlib-base
- nbsphinx
- ninja
- nlohmann_json
- numpy>=1.23.4,<3.0a0
- numpydoc>=1.5
- nvcc_linux-64=11.8
- nvtx-c >=3.1.0
- openslide-python>=1.3.0
- pip
- pooch>=1.6.0
- pre-commit
- psutil>=5.8.0
- pybind11
- pybind11_json
- pydata-sphinx-theme
- pytest-cov>=2.12.1
- pytest-lazy-fixtures>=1.0.0
Expand All @@ -46,6 +55,7 @@ dependencies:
- scipy>=1.6.0
- sphinx<6
- sysroot_linux-64==2.17
- taskflow
- tifffile>=2022.7.28
- xz
- yasm
Expand Down
10 changes: 10 additions & 0 deletions conda/environments/all_cuda-125_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,42 @@ channels:
- conda-forge
- nvidia
dependencies:
- boost-cpp
- c-compiler
- catch2
- cli11
- click
- cmake>=3.26.4,!=3.30.0
- cuda-cudart-dev
- cuda-nvcc
- cuda-version=12.5
- cupy>=12.0.0
- cxx-compiler
- fmt
- gcc_linux-64=11.*
- imagecodecs>=2021.6.8
- ipython
- jbig
- lazy_loader>=0.1
- libabseil
- libcufile-dev
- libnvjpeg-dev
- libnvjpeg-static
- libwebp-base
- matplotlib-base
- nbsphinx
- ninja
- nlohmann_json
- numpy>=1.23.4,<3.0a0
- numpydoc>=1.5
- nvtx-c >=3.1.0
- openslide-python>=1.3.0
- pip
- pooch>=1.6.0
- pre-commit
- psutil>=5.8.0
- pybind11
- pybind11_json
- pydata-sphinx-theme
- pytest-cov>=2.12.1
- pytest-lazy-fixtures>=1.0.0
Expand All @@ -45,6 +54,7 @@ dependencies:
- scipy>=1.6.0
- sphinx<6
- sysroot_linux-64==2.17
- taskflow
- tifffile>=2022.7.28
- xz
- yasm
Expand Down
4 changes: 4 additions & 0 deletions conda/recipes/cucim/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ requirements:
- cuda-cudart-dev
{% endif %}
- cupy >=12.0.0
- fmt
- libcucim ={{ version }}
- nlohmann_json
- pybind11
- pybind11_json
- python
- rapids-build-backend >=0.3.0,<0.4.0.dev0
- scikit-image >=0.19.0,<0.25.0a0
Expand Down
10 changes: 10 additions & 0 deletions conda/recipes/libcucim/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,19 @@ requirements:
- libnvjpeg-dev
- libnvjpeg-static
{% endif %}
- boost-cpp
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
- catch2
- cli11
- fmt
- jbig
- libabseil
- libwebp-base
- nvtx-c >=3.1.0
- nlohmann_json
- openslide
- pybind11
- pybind11_json
- taskflow
- xz
- zlib
- zstd
Expand All @@ -92,6 +101,7 @@ requirements:
- libnvjpeg
{% endif %}
- {{ pin_compatible('libwebp-base', max_pin='x.x') }}
- libabseil
- jbig
- xz
- zlib
Expand Down
13 changes: 3 additions & 10 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -128,11 +128,6 @@ set_target_properties(${CUCIM_PACKAGE_NAME}
# Note: Looks like the following line causes error on CMake 3.18.4 (it is working on 3.18.2). Keeping it for now.
set(CUCIM_REQUIRED_FEATURES cxx_std_17)
target_compile_features(${CUCIM_PACKAGE_NAME} PRIVATE ${CUCIM_REQUIRED_FEATURES})
# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'`
target_compile_options(${CUCIM_PACKAGE_NAME}
PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-Werror -Wall -Wextra>
)
target_compile_definitions(${CUCIM_PACKAGE_NAME}
PUBLIC
CUCIM_VERSION=${PROJECT_VERSION}
Expand All @@ -144,23 +139,21 @@ target_compile_definitions(${CUCIM_PACKAGE_NAME}
CUCIM_STATIC_GDS=$<BOOL:${CUCIM_STATIC_GDS}>
CUCIM_SUPPORT_CUDA=$<BOOL:${CUCIM_SUPPORT_CUDA}>
CUCIM_SUPPORT_NVTX=$<BOOL:${CUCIM_SUPPORT_NVTX}>
_GLIBCXX_USE_CXX11_ABI=0 # TODO: create two library, one with CXX11 ABI and one without it.
)

# Link libraries
target_link_libraries(${CUCIM_PACKAGE_NAME}
PUBLIC
${CMAKE_DL_LIBS}
Threads::Threads # -lpthread
$<BUILD_INTERFACE:deps::fmt>
$<INSTALL_INTERFACE:cucim::fmt-header-only>
deps::fmt
PRIVATE
CUDA::cudart
deps::abseil
deps::gds
deps::libcuckoo
deps::boost-header-only
deps::json
deps::nlohmann_json
deps::nvtx3
deps::taskflow
)
Expand Down
68 changes: 43 additions & 25 deletions cpp/cmake/deps/abseil.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -14,31 +14,49 @@
#

if (NOT TARGET deps::abseil)
FetchContent_Declare(
deps-abseil
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG 20200225.2
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(deps-abseil)
if (NOT deps-abseil_POPULATED)
message(STATUS "Fetching abseil sources")
FetchContent_Populate(deps-abseil)
message(STATUS "Fetching abseil sources - done")
endif ()
set(Abseil_VERSION 20240116.2)

# Create static library
cucim_set_build_shared_libs(OFF)
set(BUILD_TESTING FALSE) # Disable BUILD_TESTING (cmake-build-debug/_deps/deps-abseil-src/CMakeLists.txt:97)
add_subdirectory(${deps-abseil_SOURCE_DIR} ${deps-abseil_BINARY_DIR} EXCLUDE_FROM_ALL)
if (DEFINED ENV{CONDA_PREFIX})
find_package(absl REQUIRED)
if (NOT absl_FOUND)
message(FATAL_ERROR "fmt package not found in conda environment")
endif()

# Set PIC to prevent the following error message
# : /usr/bin/ld: ../lib/libabsl_strings.a(escaping.cc.o): relocation R_X86_64_PC32 against symbol `_ZN4absl14lts_2020_02_2516numbers_internal8kHexCharE' can not be used when making a shared object; recompile with -fPIC
set_target_properties(absl_strings absl_strings_internal absl_int128 absl_raw_logging_internal PROPERTIES POSITION_INDEPENDENT_CODE ON)
cucim_restore_build_shared_libs()
add_library(deps::abseil ALIAS absl::strings)
get_target_property(abseil_INCLUDE_DIR absl::strings INTERFACE_INCLUDE_DIRECTORIES)

add_library(deps::abseil INTERFACE IMPORTED GLOBAL)
target_link_libraries(deps::abseil INTERFACE absl::strings)
set(deps-abseil_SOURCE_DIR ${deps-abseil_SOURCE_DIR} CACHE INTERNAL "" FORCE)
mark_as_advanced(deps-abseil_SOURCE_DIR)
set(abseil_INCLUDE_DIR ${abseil_INCLUDE_DIR} CACHE INTERNAL "" FORCE)
mark_as_advanced(abseil_INCLUDE_DIR)
else()
# Fallback to fetching Abseil sources
FetchContent_Declare(
deps-abseil
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG ${Abseil_VERSION}
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(deps-abseil)
if (NOT deps-abseil_POPULATED)
message(STATUS "Fetching abseil sources")
# TODO: use FetchContent_MakeAvailable (with EXCLUDE_FROM_ALL option in FetchContent_Declare) when CMake 3.30 is minimum required
# (https://cmake.org/cmake/help/latest/policy/CMP0169.html#policy:CMP0169)
FetchContent_Populate(deps-abseil)
message(STATUS "Fetching abseil sources - done")
endif ()

# Create static library
cucim_set_build_shared_libs(OFF)
set(BUILD_TESTING FALSE) # Disable BUILD_TESTING (cmake-build-debug/_deps/deps-abseil-src/CMakeLists.txt:97)
add_subdirectory(${deps-abseil_SOURCE_DIR} ${deps-abseil_BINARY_DIR} EXCLUDE_FROM_ALL)

# Set PIC to prevent the following error message
# : /usr/bin/ld: ../lib/libabsl_strings.a(escaping.cc.o): relocation R_X86_64_PC32 against symbol `_ZN4absl14lts_2020_02_2516numbers_internal8kHexCharE' can not be used when making a shared object; recompile with -fPIC
set_target_properties(absl_strings absl_strings_internal absl_int128 absl_raw_logging_internal PROPERTIES POSITION_INDEPENDENT_CODE ON)
cucim_restore_build_shared_libs()

add_library(deps::abseil INTERFACE IMPORTED GLOBAL)
target_link_libraries(deps::abseil INTERFACE absl::strings)
set(abseil_INCLUDE_DIR ${deps-deps-abseil_SOURCE_DIR} CACHE INTERNAL "" FORCE)
mark_as_advanced(abseil_INCLUDE_DIR)
endif()
endif ()
Loading
Loading