From dcb3050ae3368f75ba2e7e6bf28d21cc7e4786d4 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Fri, 26 Jul 2024 19:03:09 -0700 Subject: [PATCH 01/25] Support both conda and source installation for boost Signed-off-by: Gigon Bae --- cpp/cmake/deps/boost-header-only.cmake | 144 +++++++++++++++++-------- 1 file changed, 102 insertions(+), 42 deletions(-) diff --git a/cpp/cmake/deps/boost-header-only.cmake b/cpp/cmake/deps/boost-header-only.cmake index 67624a201..290eeaac2 100644 --- a/cpp/cmake/deps/boost-header-only.cmake +++ b/cpp/cmake/deps/boost-header-only.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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 @@ -14,57 +14,117 @@ # if (NOT TARGET deps::boost-header-only) - set(Boost_VERSION 1.75.0) + set(Boost_VERSION 1.85.0) set(boost_component_list "interprocess" "config" "intrusive" "move" "assert" "static_assert" "container" "core" "date_time" "smart_ptr" "throw_exception" "utility" "type_traits" "numeric/conversion" "mpl" "preprocessor" "container_hash" "integer" "detail") - FetchContent_Declare( - deps-boost-header-only - GIT_REPOSITORY https://github.com/boostorg/boost.git - GIT_TAG boost-${Boost_VERSION} - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-boost-header-only) - if (NOT deps-boost-header-only_POPULATED) - message(STATUS "Fetching boost-header-only sources") - FetchContent_Populate(deps-boost-header-only) - message(STATUS "Fetching boost-header-only sources - done") + if (DEFINED ENV{CONDA_PREFIX}) + # Use boost headers from conda environment + find_path(boost_INCLUDE_DIR + NAMES boost/version.hpp + HINTS $ENV{CONDA_PREFIX}/include + ) + if (NOT boost_INCLUDE_DIR) + message(FATAL_ERROR "boost headers not found in conda environment") + endif() + + # Apply patch for boost-header-only message(STATUS "Applying patch for boost-header-only") find_package(Git) + if(Git_FOUND OR GIT_FOUND) - execute_process( - COMMAND bash -c "${GIT_EXECUTABLE} reset HEAD --hard && ${GIT_EXECUTABLE} apply ${CMAKE_CURRENT_LIST_DIR}/boost-header-only.patch" - WORKING_DIRECTORY "${deps-boost-header-only_SOURCE_DIR}/libs/interprocess" - RESULT_VARIABLE exec_result - ERROR_VARIABLE exec_error - ERROR_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE exec_output - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(exec_result EQUAL 0) - message(STATUS "Applying patch for boost-header-only - done") + # Check if the patch is already applied + file(READ "${boost_INCLUDE_DIR}/boost/interprocess/mem_algo/rbtree_best_fit.hpp" file_content) + if("${file_content}" MATCHES "cuCIM patch") + message(STATUS "Patch for boost-header-only is already applied") else() - message(STATUS "Applying patch for boost-header-only - failed") - message(FATAL_ERROR "${exec_output}\n${exec_error}") + execute_process( + COMMAND bash -c "${GIT_EXECUTABLE} apply --whitespace=nowarn ${CMAKE_CURRENT_LIST_DIR}/boost-header-only.patch" + WORKING_DIRECTORY "${boost_INCLUDE_DIR}/.." # Assuming the patch is relative to the include directory + RESULT_VARIABLE exec_result + ERROR_VARIABLE exec_error + ERROR_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE exec_output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(exec_result EQUAL 0) + message(STATUS "Applying patch for boost-header-only - done") + else() + message(STATUS "Applying patch for boost-header-only - failed") + message(STATUS "${exec_output}\n${exec_error}") + endif() endif() + endif() + + add_library(deps::boost-header-only INTERFACE IMPORTED GLOBAL) + + unset(boost_include_string) + # Create a list of components + foreach(item IN LISTS boost_component_list) + set(boost_include_string "${boost_include_string}" "${boost_INCLUDE_DIR}") + endforeach(item) + + set_target_properties(deps::boost-header-only PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES + "${boost_include_string}" + INTERFACE_COMPILE_DEFINITIONS + BOOST_DATE_TIME_NO_LIB=1 + ) + + set(boost_INCLUDE_DIR ${boost_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(boost_INCLUDE_DIR) + else() + # Fallback to fetching Boost sources + FetchContent_Declare( + deps-boost-header-only + GIT_REPOSITORY https://github.com/boostorg/boost.git + GIT_TAG boost-${Boost_VERSION} + GIT_SHALLOW TRUE + ) + + FetchContent_GetProperties(deps-boost-header-only) + if (NOT deps-boost-header-only_POPULATED) + message(STATUS "Fetching boost-header-only sources") + FetchContent_MakeAvailable(deps-boost-header-only) + message(STATUS "Fetching boost-header-only sources - done") + + message(STATUS "Applying patch for boost-header-only") + find_package(Git) + if(Git_FOUND OR GIT_FOUND) + execute_process( + COMMAND bash -c "${GIT_EXECUTABLE} reset HEAD --hard && ${GIT_EXECUTABLE} apply ${CMAKE_CURRENT_LIST_DIR}/boost-header-only.patch" + WORKING_DIRECTORY "${deps-boost-header-only_SOURCE_DIR}/libs/interprocess" + RESULT_VARIABLE exec_result + ERROR_VARIABLE exec_error + ERROR_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE exec_output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(exec_result EQUAL 0) + message(STATUS "Applying patch for boost-header-only - done") + else() + message(STATUS "Applying patch for boost-header-only - failed") + message(FATAL_ERROR "${exec_output}\n${exec_error}") + endif() + endif () endif () - endif () - add_library(deps::boost-header-only INTERFACE IMPORTED GLOBAL) + add_library(deps::boost-header-only INTERFACE IMPORTED GLOBAL) - unset(boost_include_string) - # Create a list of components - foreach(item IN LISTS boost_component_list) - set(boost_include_string "${boost_include_string}" "${deps-boost-header-only_SOURCE_DIR}/libs/${item}/include") - endforeach(item) - # https://www.boost.org/doc/libs/1_75_0/doc/html/interprocess.html#interprocess.intro.introduction_building_interprocess - set_target_properties(deps::boost-header-only PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES - "${boost_include_string}" - INTERFACE_COMPILE_DEFINITIONS - BOOST_DATE_TIME_NO_LIB=1 - ) + unset(boost_include_string) + # Create a list of components + foreach(item IN LISTS boost_component_list) + set(boost_include_string "${boost_include_string}" "${deps-boost-header-only_SOURCE_DIR}/libs/${item}/include") + endforeach(item) + # https://www.boost.org/doc/libs/1_75_0/doc/html/interprocess.html#interprocess.intro.introduction_building_interprocess + set_target_properties(deps::boost-header-only PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES + "${boost_include_string}" + INTERFACE_COMPILE_DEFINITIONS + BOOST_DATE_TIME_NO_LIB=1 + ) - set(deps-boost-header-only_SOURCE_DIR ${deps-boost-header-only_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-boost-header-only_SOURCE_DIR) + set(boost_INCLUDE_DIR ${deps-boost-header-only_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(boost_INCLUDE_DIR) + endif() endif () From 3a8c64ec6c8dc5dac49d67bb60864356b0902242 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 11:16:42 -0700 Subject: [PATCH 02/25] Remove boost dependency Signed-off-by: Gigon Bae --- cpp/cmake/deps/boost.cmake | 75 ------------------- .../cucim.kit.cuslide/cmake/deps/boost.cmake | 75 ------------------- 2 files changed, 150 deletions(-) delete mode 100644 cpp/cmake/deps/boost.cmake delete mode 100644 cpp/plugins/cucim.kit.cuslide/cmake/deps/boost.cmake diff --git a/cpp/cmake/deps/boost.cmake b/cpp/cmake/deps/boost.cmake deleted file mode 100644 index 3fb6db1e9..000000000 --- a/cpp/cmake/deps/boost.cmake +++ /dev/null @@ -1,75 +0,0 @@ -# -# 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. -# 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. -# - -if (NOT TARGET deps::boost) - set(Boost_VERSION 1.75.0) - set(Boost_BUILD_COMPONENTS container) - set(Boost_BUILD_OPTIONS "threading=multi cxxflags=-fPIC runtime-link=static variant=release link=static address-model=64 --layout=system") - set(Boost_COMPILE_DEFINITIONS - BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 - BOOST_ALL_NO_LIB=1 - BOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT=1 - CACHE INTERNAL "Boost compile definitions") - - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_MULTITHREADED ON) - set(Boost_USE_STATIC_RUNTIME ON) - - foreach(component_name ${Boost_BUILD_COMPONENTS}) - list(APPEND Boost_BUILD_VARIANTS --with-${component_name}) - endforeach() - - FetchContent_Declare( - deps-boost - GIT_REPOSITORY https://github.com/boostorg/boost.git - GIT_TAG boost-${Boost_VERSION} - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-boost) - if (NOT deps-boost_POPULATED) - message(STATUS "Fetching boost sources") - FetchContent_Populate(deps-boost) - message(STATUS "Fetching boost sources - done") - endif () - - if (deps-boost_POPULATED AND NOT EXISTS "${deps-boost_BINARY_DIR}/install") - include(ProcessorCount) - ProcessorCount(PROCESSOR_COUNT) - - execute_process(COMMAND /bin/bash -c "./bootstrap.sh --prefix=${deps-boost_BINARY_DIR}/install && ./b2 install --build-dir=${deps-boost_BINARY_DIR}/build --stagedir=${deps-boost_BINARY_DIR}/stage -j${PROCESSOR_COUNT} ${Boost_BUILD_VARIANTS} ${Boost_BUILD_OPTIONS}" - WORKING_DIRECTORY ${deps-boost_SOURCE_DIR} - COMMAND_ECHO STDOUT - RESULT_VARIABLE Boost_BUILD_RESULT) - if(NOT Boost_BUILD_RESULT EQUAL "0") - message(FATAL_ERROR "boost library build failed with ${Boost_BUILD_RESULT}, please checkout the boost module configurations") - endif() - endif() - - find_package(Boost 1.75 CONFIG REQUIRED COMPONENTS ${Boost_BUILD_COMPONENTS} - HINTS ${deps-boost_BINARY_DIR}/install) # /lib/cmake/Boost-${Boost_VERSION} - - message(STATUS "Boost version: ${Boost_VERSION}") - - add_library(deps::boost INTERFACE IMPORTED GLOBAL) - - set_target_properties(deps::boost PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${Boost_COMPILE_DEFINITIONS}" - INTERFACE_LINK_LIBRARIES "${Boost_LIBRARIES}" - ) - - set(deps-boost_SOURCE_DIR ${deps-boost_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-boost_SOURCE_DIR) -endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/boost.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/boost.cmake deleted file mode 100644 index 3fb6db1e9..000000000 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/boost.cmake +++ /dev/null @@ -1,75 +0,0 @@ -# -# 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. -# 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. -# - -if (NOT TARGET deps::boost) - set(Boost_VERSION 1.75.0) - set(Boost_BUILD_COMPONENTS container) - set(Boost_BUILD_OPTIONS "threading=multi cxxflags=-fPIC runtime-link=static variant=release link=static address-model=64 --layout=system") - set(Boost_COMPILE_DEFINITIONS - BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 - BOOST_ALL_NO_LIB=1 - BOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT=1 - CACHE INTERNAL "Boost compile definitions") - - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_MULTITHREADED ON) - set(Boost_USE_STATIC_RUNTIME ON) - - foreach(component_name ${Boost_BUILD_COMPONENTS}) - list(APPEND Boost_BUILD_VARIANTS --with-${component_name}) - endforeach() - - FetchContent_Declare( - deps-boost - GIT_REPOSITORY https://github.com/boostorg/boost.git - GIT_TAG boost-${Boost_VERSION} - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-boost) - if (NOT deps-boost_POPULATED) - message(STATUS "Fetching boost sources") - FetchContent_Populate(deps-boost) - message(STATUS "Fetching boost sources - done") - endif () - - if (deps-boost_POPULATED AND NOT EXISTS "${deps-boost_BINARY_DIR}/install") - include(ProcessorCount) - ProcessorCount(PROCESSOR_COUNT) - - execute_process(COMMAND /bin/bash -c "./bootstrap.sh --prefix=${deps-boost_BINARY_DIR}/install && ./b2 install --build-dir=${deps-boost_BINARY_DIR}/build --stagedir=${deps-boost_BINARY_DIR}/stage -j${PROCESSOR_COUNT} ${Boost_BUILD_VARIANTS} ${Boost_BUILD_OPTIONS}" - WORKING_DIRECTORY ${deps-boost_SOURCE_DIR} - COMMAND_ECHO STDOUT - RESULT_VARIABLE Boost_BUILD_RESULT) - if(NOT Boost_BUILD_RESULT EQUAL "0") - message(FATAL_ERROR "boost library build failed with ${Boost_BUILD_RESULT}, please checkout the boost module configurations") - endif() - endif() - - find_package(Boost 1.75 CONFIG REQUIRED COMPONENTS ${Boost_BUILD_COMPONENTS} - HINTS ${deps-boost_BINARY_DIR}/install) # /lib/cmake/Boost-${Boost_VERSION} - - message(STATUS "Boost version: ${Boost_VERSION}") - - add_library(deps::boost INTERFACE IMPORTED GLOBAL) - - set_target_properties(deps::boost PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${Boost_COMPILE_DEFINITIONS}" - INTERFACE_LINK_LIBRARIES "${Boost_LIBRARIES}" - ) - - set(deps-boost_SOURCE_DIR ${deps-boost_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-boost_SOURCE_DIR) -endif () From dfba773ea4ce4ac127ce77e45c2c212d7d69e556 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 10:07:01 -0700 Subject: [PATCH 03/25] Support both conda and source installation for fmt Signed-off-by: Gigon Bae --- CMakeLists.txt | 4 +- cpp/CMakeLists.txt | 3 +- cpp/cmake/deps/fmt.cmake | 75 +++++++++++------ cpp/cmake/deps/googletest.cmake | 2 + cpp/include/cucim/util/cuda.h | 8 +- .../cucim.kit.cumed/cmake/deps/fmt.cmake | 80 +++++++++++++------ .../cmake/deps/googletest.cmake | 4 +- .../cucim.kit.cuslide/cmake/deps/fmt.cmake | 80 +++++++++++++------ .../cmake/deps/googletest.cmake | 2 + cpp/src/cache/image_cache_per_process.cpp | 5 +- cpp/src/cuimage.cpp | 7 +- cpp/src/loader/thread_batch_data_loader.cpp | 7 +- python/cmake/deps/fmt.cmake | 75 +++++++++++------ 13 files changed, 235 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff7e7ca8e..778f2ca13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,10 +154,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} @@ -207,7 +207,7 @@ install(DIRECTORY # Copy 3rdparty headers install(DIRECTORY - ${deps-fmt_SOURCE_DIR}/include/ + ${fmt_INCLUDE_DIR} ${deps-nvtx3_SOURCE_DIR}/c/include/ ${deps-nvtx3_SOURCE_DIR}/cpp/include/ DESTINATION diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 67409a699..36c3c1d64 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -152,8 +152,7 @@ target_link_libraries(${CUCIM_PACKAGE_NAME} PUBLIC ${CMAKE_DL_LIBS} Threads::Threads # -lpthread - $ - $ + deps::fmt PRIVATE CUDA::cudart deps::abseil diff --git a/cpp/cmake/deps/fmt.cmake b/cpp/cmake/deps/fmt.cmake index ef2797e18..aeee5022d 100644 --- a/cpp/cmake/deps/fmt.cmake +++ b/cpp/cmake/deps/fmt.cmake @@ -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 @@ -14,30 +14,57 @@ # if (NOT TARGET deps::fmt) - FetchContent_Declare( - deps-fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 7.0.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-fmt) - if (NOT deps-fmt_POPULATED) - message(STATUS "Fetching fmt sources") - FetchContent_Populate(deps-fmt) - message(STATUS "Fetching fmt sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(fmt REQUIRED) + if (NOT fmt_FOUND) + message(FATAL_ERROR "fmt package not found in conda environment") + endif () + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) - # Create static library - cucim_set_build_shared_libs(OFF) - add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + set(fmt_INCLUDE_DIR ${fmt_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-fmt) + if (NOT deps-fmt_POPULATED) + message(STATUS "Fetching fmt 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-fmt) + message(STATUS "Fetching fmt sources - done") + endif () - # Set PIC to prevent the following error message - # : /usr/bin/ld: ../lib/libfmtd.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC - set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) - cucim_restore_build_shared_libs() + # Create static library + cucim_set_build_shared_libs(OFF) + add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + cucim_restore_build_shared_libs() - add_library(deps::fmt INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::fmt INTERFACE fmt::fmt-header-only) - set(deps-fmt_SOURCE_DIR ${deps-fmt_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-fmt_SOURCE_DIR) + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) + + set(fmt_INCLUDE_DIR ${deps-fmt_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + endif () endif () diff --git a/cpp/cmake/deps/googletest.cmake b/cpp/cmake/deps/googletest.cmake index f85dd85b6..a607b5954 100644 --- a/cpp/cmake/deps/googletest.cmake +++ b/cpp/cmake/deps/googletest.cmake @@ -23,6 +23,8 @@ if (NOT TARGET deps::googletest) FetchContent_GetProperties(deps-googletest) if (NOT deps-googletest_POPULATED) message(STATUS "Fetching googletest 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-googletest) message(STATUS "Fetching googletest sources - done") endif () diff --git a/cpp/include/cucim/util/cuda.h b/cpp/include/cucim/util/cuda.h index 12f161f1e..08728fc4d 100644 --- a/cpp/include/cucim/util/cuda.h +++ b/cpp/include/cucim/util/cuda.h @@ -28,7 +28,7 @@ if (cudaSuccess != cuda_status) \ { \ fmt::print(stderr, "[Error] CUDA Runtime call {} in line {} of file {} failed with '{}' ({}).\n", #stmt, \ - __LINE__, __FILE__, cudaGetErrorString(cuda_status), cuda_status); \ + __LINE__, __FILE__, cudaGetErrorString(cuda_status), static_cast(cuda_status)); \ } \ } @@ -39,7 +39,7 @@ { \ throw std::runtime_error( \ fmt::format("[Error] CUDA Runtime call {} in line {} of file {} failed with '{}' ({}).\n", #stmt, \ - __LINE__, __FILE__, cudaGetErrorString(cuda_status), cuda_status)); \ + __LINE__, __FILE__, cudaGetErrorString(cuda_status), static_cast(cuda_status))); \ } \ } @@ -49,7 +49,7 @@ if (_nvjpeg_status != NVJPEG_STATUS_SUCCESS) \ { \ fmt::print("[Error] NVJPEG call {} in line {} of file {} failed with the error code {}.\n", #stmt, \ - __LINE__, __FILE__, _nvjpeg_status)); \ + __LINE__, __FILE__, static_cast(_nvjpeg_status)); \ } \ } @@ -60,7 +60,7 @@ { \ throw std::runtime_error( \ fmt::format("[Error] NVJPEG call {} in line {} of file {} failed with the error code {}.\n", #stmt, \ - __LINE__, __FILE__, _nvjpeg_status)); \ + __LINE__, __FILE__, static_cast(_nvjpeg_status))); \ } \ } diff --git a/cpp/plugins/cucim.kit.cumed/cmake/deps/fmt.cmake b/cpp/plugins/cucim.kit.cumed/cmake/deps/fmt.cmake index cdf40f061..aeee5022d 100644 --- a/cpp/plugins/cucim.kit.cumed/cmake/deps/fmt.cmake +++ b/cpp/plugins/cucim.kit.cumed/cmake/deps/fmt.cmake @@ -1,42 +1,70 @@ -# Apache License, Version 2.0 -# Copyright 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 # -# 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. +# if (NOT TARGET deps::fmt) - FetchContent_Declare( - deps-fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 7.0.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-fmt) - if (NOT deps-fmt_POPULATED) - message(STATUS "Fetching fmt sources") - FetchContent_Populate(deps-fmt) - message(STATUS "Fetching fmt sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(fmt REQUIRED) + if (NOT fmt_FOUND) + message(FATAL_ERROR "fmt package not found in conda environment") + endif () + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) - # Create static library - cucim_set_build_shared_libs(OFF) - add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) - # Set PIC to prevent the following error message - # : /usr/bin/ld: ../lib/libfmtd.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC - set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) - cucim_restore_build_shared_libs() + set(fmt_INCLUDE_DIR ${fmt_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-fmt) + if (NOT deps-fmt_POPULATED) + message(STATUS "Fetching fmt 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-fmt) + message(STATUS "Fetching fmt sources - done") + endif () - add_library(deps::fmt INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::fmt INTERFACE fmt::fmt-header-only) - set(deps-fmt_SOURCE_DIR ${deps-fmt_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-fmt_SOURCE_DIR) + # Create static library + cucim_set_build_shared_libs(OFF) + add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + cucim_restore_build_shared_libs() + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) + + set(fmt_INCLUDE_DIR ${deps-fmt_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + endif () endif () diff --git a/cpp/plugins/cucim.kit.cumed/cmake/deps/googletest.cmake b/cpp/plugins/cucim.kit.cumed/cmake/deps/googletest.cmake index a9e878601..a607b5954 100644 --- a/cpp/plugins/cucim.kit.cumed/cmake/deps/googletest.cmake +++ b/cpp/plugins/cucim.kit.cumed/cmake/deps/googletest.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 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 @@ -23,6 +23,8 @@ if (NOT TARGET deps::googletest) FetchContent_GetProperties(deps-googletest) if (NOT deps-googletest_POPULATED) message(STATUS "Fetching googletest 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-googletest) message(STATUS "Fetching googletest sources - done") endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/fmt.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/fmt.cmake index 2ca43a98d..aeee5022d 100644 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/fmt.cmake +++ b/cpp/plugins/cucim.kit.cuslide/cmake/deps/fmt.cmake @@ -1,42 +1,70 @@ -# Apache License, Version 2.0 -# Copyright 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 # -# 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. +# if (NOT TARGET deps::fmt) - FetchContent_Declare( - deps-fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 7.0.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-fmt) - if (NOT deps-fmt_POPULATED) - message(STATUS "Fetching fmt sources") - FetchContent_Populate(deps-fmt) - message(STATUS "Fetching fmt sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(fmt REQUIRED) + if (NOT fmt_FOUND) + message(FATAL_ERROR "fmt package not found in conda environment") + endif () + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) - # Create static library - cucim_set_build_shared_libs(OFF) - add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) - # Set PIC to prevent the following error message - # : /usr/bin/ld: ../lib/libfmtd.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC - set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) - cucim_restore_build_shared_libs() + set(fmt_INCLUDE_DIR ${fmt_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-fmt) + if (NOT deps-fmt_POPULATED) + message(STATUS "Fetching fmt 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-fmt) + message(STATUS "Fetching fmt sources - done") + endif () - add_library(deps::fmt INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::fmt INTERFACE fmt::fmt-header-only) - set(deps-fmt_SOURCE_DIR ${deps-fmt_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-fmt_SOURCE_DIR) + # Create static library + cucim_set_build_shared_libs(OFF) + add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + cucim_restore_build_shared_libs() + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) + + set(fmt_INCLUDE_DIR ${deps-fmt_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + endif () endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/googletest.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/googletest.cmake index f85dd85b6..a607b5954 100644 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/googletest.cmake +++ b/cpp/plugins/cucim.kit.cuslide/cmake/deps/googletest.cmake @@ -23,6 +23,8 @@ if (NOT TARGET deps::googletest) FetchContent_GetProperties(deps-googletest) if (NOT deps-googletest_POPULATED) message(STATUS "Fetching googletest 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-googletest) message(STATUS "Fetching googletest sources - done") endif () diff --git a/cpp/src/cache/image_cache_per_process.cpp b/cpp/src/cache/image_cache_per_process.cpp index ca1b2f6f0..682167798 100644 --- a/cpp/src/cache/image_cache_per_process.cpp +++ b/cpp/src/cache/image_cache_per_process.cpp @@ -22,6 +22,7 @@ #include "cucim/util/cuda.h" #include +#include // allows fmt to format std::array, std::vector, etc. namespace std { @@ -79,7 +80,7 @@ PerProcessImageCacheValue::~PerProcessImageCacheValue() case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type)); break; } data = nullptr; @@ -134,7 +135,7 @@ void* PerProcessImageCache::allocate(std::size_t n) case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type_); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type_)); break; } return nullptr; diff --git a/cpp/src/cuimage.cpp b/cpp/src/cuimage.cpp index e4dd435ea..db9f6a1b7 100644 --- a/cpp/src/cuimage.cpp +++ b/cpp/src/cuimage.cpp @@ -25,6 +25,7 @@ # include #endif #include +#include // allows fmt to format std::array, std::vector, etc. #include "cucim/profiler/nvtx3.h" #include "cucim/util/cuda.h" @@ -299,7 +300,7 @@ CuImage::~CuImage() case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type)); break; } } @@ -1231,7 +1232,7 @@ bool CuImage::crop_image(const io::format::ImageReaderRegionRequestDesc& request case cucim::io::DeviceType::kCUDAManaged: case cucim::io::DeviceType::kCPUShared: case cucim::io::DeviceType::kCUDAShared: - throw std::runtime_error(fmt::format("Device type {} not supported!", in_device.type())); + throw std::runtime_error(fmt::format("Device type {} not supported!", static_cast(in_device.type()))); break; } @@ -1443,7 +1444,7 @@ void CuImageIterator::increase_index_() case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type)); break; } diff --git a/cpp/src/loader/thread_batch_data_loader.cpp b/cpp/src/loader/thread_batch_data_loader.cpp index 9aff2d88c..5c827a513 100644 --- a/cpp/src/loader/thread_batch_data_loader.cpp +++ b/cpp/src/loader/thread_batch_data_loader.cpp @@ -20,6 +20,7 @@ #include #include +#include // allows fmt to format std::array, std::vector, etc. #include "cucim/profiler/nvtx3.h" #include "cucim/util/cuda.h" @@ -78,7 +79,7 @@ ThreadBatchDataLoader::ThreadBatchDataLoader(LoadFunc load_func, case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type)); break; } } @@ -112,7 +113,7 @@ ThreadBatchDataLoader::~ThreadBatchDataLoader() case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!", device_type); + fmt::print(stderr, "Device type {} is not supported!", static_cast(device_type)); break; } raster_ptr = nullptr; @@ -243,7 +244,7 @@ uint8_t* ThreadBatchDataLoader::next_data() case io::DeviceType::kCUDAManaged: case io::DeviceType::kCPUShared: case io::DeviceType::kCUDAShared: - fmt::print(stderr, "Device type {} is not supported!\n", device_type); + fmt::print(stderr, "Device type {} is not supported!\n", static_cast(device_type)); break; } diff --git a/python/cmake/deps/fmt.cmake b/python/cmake/deps/fmt.cmake index ef2797e18..aeee5022d 100644 --- a/python/cmake/deps/fmt.cmake +++ b/python/cmake/deps/fmt.cmake @@ -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 @@ -14,30 +14,57 @@ # if (NOT TARGET deps::fmt) - FetchContent_Declare( - deps-fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 7.0.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-fmt) - if (NOT deps-fmt_POPULATED) - message(STATUS "Fetching fmt sources") - FetchContent_Populate(deps-fmt) - message(STATUS "Fetching fmt sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(fmt REQUIRED) + if (NOT fmt_FOUND) + message(FATAL_ERROR "fmt package not found in conda environment") + endif () + + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) - # Create static library - cucim_set_build_shared_libs(OFF) - add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + set(fmt_INCLUDE_DIR ${fmt_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-fmt) + if (NOT deps-fmt_POPULATED) + message(STATUS "Fetching fmt 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-fmt) + message(STATUS "Fetching fmt sources - done") + endif () - # Set PIC to prevent the following error message - # : /usr/bin/ld: ../lib/libfmtd.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC - set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) - cucim_restore_build_shared_libs() + # Create static library + cucim_set_build_shared_libs(OFF) + add_subdirectory(${deps-fmt_SOURCE_DIR} ${deps-fmt_BINARY_DIR} EXCLUDE_FROM_ALL) + cucim_restore_build_shared_libs() - add_library(deps::fmt INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::fmt INTERFACE fmt::fmt-header-only) - set(deps-fmt_SOURCE_DIR ${deps-fmt_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-fmt_SOURCE_DIR) + add_library(deps::fmt INTERFACE IMPORTED GLOBAL) + get_target_property(fmt_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(deps::fmt INTERFACE + "$" + "$" + ) + target_compile_definitions(deps::fmt INTERFACE + FMT_HEADER_ONLY + ) + + set(fmt_INCLUDE_DIR ${deps-fmt_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(fmt_INCLUDE_DIR) + endif () endif () From 23a535bcdeca1550da18177038da27bfd2e80078 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 11:55:28 -0700 Subject: [PATCH 04/25] Support both conda and source installation for nlohmann_json Signed-off-by: Gigon Bae --- CMakeLists.txt | 2 +- cpp/CMakeLists.txt | 2 +- cpp/cmake/deps/json.cmake | 40 -------------- cpp/cmake/deps/nlohmann_json.cmake | 55 +++++++++++++++++++ cpp/plugins/cucim.kit.cuslide/CMakeLists.txt | 4 +- .../cucim.kit.cuslide/cmake/deps/json.cmake | 40 -------------- .../cmake/deps/nlohmann_json.cmake | 55 +++++++++++++++++++ python/CMakeLists.txt | 4 +- python/cmake/deps/json.cmake | 40 -------------- python/cmake/deps/nlohmann_json.cmake | 55 +++++++++++++++++++ 10 files changed, 171 insertions(+), 126 deletions(-) delete mode 100644 cpp/cmake/deps/json.cmake create mode 100644 cpp/cmake/deps/nlohmann_json.cmake delete mode 100644 cpp/plugins/cucim.kit.cuslide/cmake/deps/json.cmake create mode 100644 cpp/plugins/cucim.kit.cuslide/cmake/deps/nlohmann_json.cmake delete mode 100644 python/cmake/deps/json.cmake create mode 100644 python/cmake/deps/nlohmann_json.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 778f2ca13..e2137d229 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,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) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 36c3c1d64..371c3e8c2 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -159,7 +159,7 @@ target_link_libraries(${CUCIM_PACKAGE_NAME} deps::gds deps::libcuckoo deps::boost-header-only - deps::json + deps::nlohmann_json deps::nvtx3 deps::taskflow ) diff --git a/cpp/cmake/deps/json.cmake b/cpp/cmake/deps/json.cmake deleted file mode 100644 index c3f258ee1..000000000 --- a/cpp/cmake/deps/json.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright (c) 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. -# - -if (NOT TARGET deps::json) - FetchContent_Declare( - deps-json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-json) - if (NOT deps-json_POPULATED) - message(STATUS "Fetching json sources") - FetchContent_Populate(deps-json) - message(STATUS "Fetching json sources - done") - endif () - - # Typically you don't care so much for a third party library's tests to be - # run from your own project's code. - set(JSON_BuildTests OFF CACHE INTERNAL "") - - add_subdirectory(${deps-json_SOURCE_DIR} ${deps-json_BINARY_DIR} EXCLUDE_FROM_ALL) - - add_library(deps::json INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::json INTERFACE nlohmann_json::nlohmann_json) - set(deps-json_SOURCE_DIR ${deps-json_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-json_SOURCE_DIR) -endif () diff --git a/cpp/cmake/deps/nlohmann_json.cmake b/cpp/cmake/deps/nlohmann_json.cmake new file mode 100644 index 000000000..00cf0b915 --- /dev/null +++ b/cpp/cmake/deps/nlohmann_json.cmake @@ -0,0 +1,55 @@ +# +# 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 +# +# 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. +# + +if (NOT TARGET deps::nlohmann_json) + if (DEFINED ENV{CONDA_PREFIX}) + find_package(nlohmann_json REQUIRED) + if (NOT nlohmann_json_FOUND) + message(FATAL_ERROR "nlohmann_json package not found in conda environment") + endif() + + add_library(deps::nlohmann_json ALIAS nlohmann_json::nlohmann_json) + + get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + + set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + else() + # Fallback to fetching nlohmann_json sources + FetchContent_Declare( + deps-nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-nlohmann_json) + if (NOT deps-nlohmann_json_POPULATED) + message(STATUS "Fetching nlohmann_json sources") + FetchContent_Populate(deps-nlohmann_json) + message(STATUS "Fetching json sources - done") + endif () + + # Typically you don't care so much for a third party library's tests to be + # run from your own project's code. + set(nlohmann_json_BuildTests OFF CACHE INTERNAL "") + + add_subdirectory(${deps-nlohmann_json_SOURCE_DIR} ${deps-nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::nlohmann_json INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::nlohmann_json INTERFACE nlohmann_json::nlohmann_json) + set(nlohmann_json_INCLUDE_DIR ${deps-nlohmann_json_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + endif() +endif () diff --git a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt index c52c564d8..d5772315a 100644 --- a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt @@ -123,7 +123,7 @@ superbuild_depend(googletest) superbuild_depend(googlebenchmark) superbuild_depend(cli11) superbuild_depend(pugixml) -superbuild_depend(json) +superbuild_depend(nlohmann_json) superbuild_depend(libdeflate) superbuild_depend(nvjpeg) superbuild_depend(libculibos) @@ -228,7 +228,7 @@ target_link_libraries(${CUCIM_PLUGIN_NAME} deps::libopenjpeg deps::libopenjpeg-lcms2 deps::pugixml - deps::json + deps::nlohmann_json deps::libdeflate ) diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/json.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/json.cmake deleted file mode 100644 index c3f258ee1..000000000 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/json.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright (c) 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. -# - -if (NOT TARGET deps::json) - FetchContent_Declare( - deps-json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-json) - if (NOT deps-json_POPULATED) - message(STATUS "Fetching json sources") - FetchContent_Populate(deps-json) - message(STATUS "Fetching json sources - done") - endif () - - # Typically you don't care so much for a third party library's tests to be - # run from your own project's code. - set(JSON_BuildTests OFF CACHE INTERNAL "") - - add_subdirectory(${deps-json_SOURCE_DIR} ${deps-json_BINARY_DIR} EXCLUDE_FROM_ALL) - - add_library(deps::json INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::json INTERFACE nlohmann_json::nlohmann_json) - set(deps-json_SOURCE_DIR ${deps-json_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-json_SOURCE_DIR) -endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/nlohmann_json.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/nlohmann_json.cmake new file mode 100644 index 000000000..00cf0b915 --- /dev/null +++ b/cpp/plugins/cucim.kit.cuslide/cmake/deps/nlohmann_json.cmake @@ -0,0 +1,55 @@ +# +# 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 +# +# 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. +# + +if (NOT TARGET deps::nlohmann_json) + if (DEFINED ENV{CONDA_PREFIX}) + find_package(nlohmann_json REQUIRED) + if (NOT nlohmann_json_FOUND) + message(FATAL_ERROR "nlohmann_json package not found in conda environment") + endif() + + add_library(deps::nlohmann_json ALIAS nlohmann_json::nlohmann_json) + + get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + + set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + else() + # Fallback to fetching nlohmann_json sources + FetchContent_Declare( + deps-nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-nlohmann_json) + if (NOT deps-nlohmann_json_POPULATED) + message(STATUS "Fetching nlohmann_json sources") + FetchContent_Populate(deps-nlohmann_json) + message(STATUS "Fetching json sources - done") + endif () + + # Typically you don't care so much for a third party library's tests to be + # run from your own project's code. + set(nlohmann_json_BuildTests OFF CACHE INTERNAL "") + + add_subdirectory(${deps-nlohmann_json_SOURCE_DIR} ${deps-nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::nlohmann_json INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::nlohmann_json INTERFACE nlohmann_json::nlohmann_json) + set(nlohmann_json_INCLUDE_DIR ${deps-nlohmann_json_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + endif() +endif () diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 70334a980..a21b1df09 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -99,7 +99,7 @@ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) # TODO: create two library, one with ################################################################################ superbuild_depend(pybind11) superbuild_depend(fmt) -superbuild_depend(json) +superbuild_depend(nlohmann_json) superbuild_depend(pybind11_json) ################################################################################ @@ -171,7 +171,7 @@ target_link_libraries(cucim PRIVATE cucim::cucim deps::fmt - deps::json + deps::nlohmann_json deps::pybind11_json ) diff --git a/python/cmake/deps/json.cmake b/python/cmake/deps/json.cmake deleted file mode 100644 index c3f258ee1..000000000 --- a/python/cmake/deps/json.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright (c) 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. -# - -if (NOT TARGET deps::json) - FetchContent_Declare( - deps-json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-json) - if (NOT deps-json_POPULATED) - message(STATUS "Fetching json sources") - FetchContent_Populate(deps-json) - message(STATUS "Fetching json sources - done") - endif () - - # Typically you don't care so much for a third party library's tests to be - # run from your own project's code. - set(JSON_BuildTests OFF CACHE INTERNAL "") - - add_subdirectory(${deps-json_SOURCE_DIR} ${deps-json_BINARY_DIR} EXCLUDE_FROM_ALL) - - add_library(deps::json INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::json INTERFACE nlohmann_json::nlohmann_json) - set(deps-json_SOURCE_DIR ${deps-json_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-json_SOURCE_DIR) -endif () diff --git a/python/cmake/deps/nlohmann_json.cmake b/python/cmake/deps/nlohmann_json.cmake new file mode 100644 index 000000000..00cf0b915 --- /dev/null +++ b/python/cmake/deps/nlohmann_json.cmake @@ -0,0 +1,55 @@ +# +# 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 +# +# 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. +# + +if (NOT TARGET deps::nlohmann_json) + if (DEFINED ENV{CONDA_PREFIX}) + find_package(nlohmann_json REQUIRED) + if (NOT nlohmann_json_FOUND) + message(FATAL_ERROR "nlohmann_json package not found in conda environment") + endif() + + add_library(deps::nlohmann_json ALIAS nlohmann_json::nlohmann_json) + + get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + + set(nlohmann_json_INCLUDE_DIR ${nlohmann_json_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + else() + # Fallback to fetching nlohmann_json sources + FetchContent_Declare( + deps-nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-nlohmann_json) + if (NOT deps-nlohmann_json_POPULATED) + message(STATUS "Fetching nlohmann_json sources") + FetchContent_Populate(deps-nlohmann_json) + message(STATUS "Fetching json sources - done") + endif () + + # Typically you don't care so much for a third party library's tests to be + # run from your own project's code. + set(nlohmann_json_BuildTests OFF CACHE INTERNAL "") + + add_subdirectory(${deps-nlohmann_json_SOURCE_DIR} ${deps-nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::nlohmann_json INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::nlohmann_json INTERFACE nlohmann_json::nlohmann_json) + set(nlohmann_json_INCLUDE_DIR ${deps-nlohmann_json_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nlohmann_json_INCLUDE_DIR) + endif() +endif () From 7aee9732e4ec02d1d4573996df3ab0b4c8a8eeb8 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 13:25:57 -0700 Subject: [PATCH 05/25] Support both conda and source installation for libabseil Signed-off-by: Gigon Bae --- cpp/cmake/deps/abseil.cmake | 58 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/cpp/cmake/deps/abseil.cmake b/cpp/cmake/deps/abseil.cmake index 72b27f2a2..98476217b 100644 --- a/cpp/cmake/deps/abseil.cmake +++ b/cpp/cmake/deps/abseil.cmake @@ -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 @@ -14,31 +14,39 @@ # 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 () + + 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 () From e3d19255c57f9418af8b1c2ffbb1caf0f5bc88bf Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 15:15:51 -0700 Subject: [PATCH 06/25] Support both conda and source installation for nvtx3 Signed-off-by: Gigon Bae --- CMakeLists.txt | 14 +++--- cpp/cmake/deps/nvtx3.cmake | 69 ++++++++++++++++++++---------- cpp/include/cucim/profiler/nvtx3.h | 4 +- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2137d229..68ca8ff9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,11 +207,15 @@ install(DIRECTORY # Copy 3rdparty headers install(DIRECTORY - ${fmt_INCLUDE_DIR} - ${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}) diff --git a/cpp/cmake/deps/nvtx3.cmake b/cpp/cmake/deps/nvtx3.cmake index f079181ab..afb94cfef 100644 --- a/cpp/cmake/deps/nvtx3.cmake +++ b/cpp/cmake/deps/nvtx3.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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 @@ -14,30 +14,53 @@ # if (NOT TARGET deps::nvtx3) - FetchContent_Declare( - deps-nvtx3 - GIT_REPOSITORY https://github.com/NVIDIA/NVTX.git - GIT_TAG 3c98c8425b0376fd8653aac7cfc6a864f3897752 - # GIT_SHALLOW TRUE # TODO (#168): Uncomment this when the official release of nvtx3-cpp is available - ) - FetchContent_GetProperties(deps-nvtx3) - if (NOT deps-nvtx3_POPULATED) - message(STATUS "Fetching nvtx3 sources") - FetchContent_Populate(deps-nvtx3) - message(STATUS "Fetching nvtx3 sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + # Use nvtx3 headers from conda environment + find_path(nvtx3_INCLUDE_DIR + NAMES nvtx3/nvtx3.hpp + HINTS $ENV{CONDA_PREFIX}/include + ) + + if (NOT nvtx3_INCLUDE_DIR) + message(FATAL_ERROR "nvtx3 headers not found in conda environment") + endif () + + add_library(deps::nvtx3 INTERFACE IMPORTED GLOBAL) - # Create shared library - cucim_set_build_shared_libs(ON) # since nvtx3 is header-only library, this may not needed. + set_target_properties(deps::nvtx3 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${nvtx3_INCLUDE_DIR}" + ) + target_link_libraries(deps::nvtx3 INTERFACE ${CMAKE_DL_LIBS}) - set(BUILD_TESTS OFF) - set(BUILD_BENCHMARKS OFF) + set(nvtx3_INCLUDE_DIR ${nvtx3_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(nvtx3_INCLUDE_DIR) + else () + # Fallback to fetching nvtx3 sources + FetchContent_Declare( + deps-nvtx3 + GIT_REPOSITORY https://github.com/NVIDIA/NVTX.git + GIT_TAG v3.1.0 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-nvtx3) + if (NOT deps-nvtx3_POPULATED) + message(STATUS "Fetching nvtx3 sources") + FetchContent_Populate(deps-nvtx3) + message(STATUS "Fetching nvtx3 sources - done") + endif () - add_subdirectory(${deps-nvtx3_SOURCE_DIR}/cpp ${deps-nvtx3_BINARY_DIR} EXCLUDE_FROM_ALL) - cucim_restore_build_shared_libs() + # Create shared library + cucim_set_build_shared_libs(ON) # since nvtx3 is header-only library, this may not needed. - add_library(deps::nvtx3 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::nvtx3 INTERFACE nvtx3-cpp) - set(deps-nvtx3_SOURCE_DIR ${deps-nvtx3_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-nvtx3_SOURCE_DIR) + set(BUILD_TESTS OFF) + set(BUILD_BENCHMARKS OFF) + + add_subdirectory(${deps-nvtx3_SOURCE_DIR}/c ${deps-nvtx3_BINARY_DIR} EXCLUDE_FROM_ALL) + cucim_restore_build_shared_libs() + + add_library(deps::nvtx3 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::nvtx3 INTERFACE nvtx3-cpp) + set(nvtx3_INCLUDE_DIR ${deps-nvtx3_SOURCE_DIR}/c/include CACHE INTERNAL "" FORCE) + mark_as_advanced(nvtx3_INCLUDE_DIR) + endif () endif () diff --git a/cpp/include/cucim/profiler/nvtx3.h b/cpp/include/cucim/profiler/nvtx3.h index e438a305a..b8b259167 100644 --- a/cpp/include/cucim/profiler/nvtx3.h +++ b/cpp/include/cucim/profiler/nvtx3.h @@ -136,8 +136,8 @@ struct domain // Aliases using scoped_range = nvtx3::cucim_scoped_range_in; -using category = nvtx3::named_category; -using message = nvtx3::registered_string; +using category = nvtx3::named_category_in; +using message = nvtx3::registered_string_in; // Category struct category_io From 01c12b4327e6c61f5a19c3820c7a76fe7e2060ab Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 15:43:45 -0700 Subject: [PATCH 07/25] Support both conda and source installation for taskflow Signed-off-by: Gigon Bae --- cpp/cmake/deps/taskflow.cmake | 55 ++++++++++++++++++++----------- cpp/src/concurrent/threadpool.cpp | 2 +- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/cpp/cmake/deps/taskflow.cmake b/cpp/cmake/deps/taskflow.cmake index 147b6f4c3..29db657da 100644 --- a/cpp/cmake/deps/taskflow.cmake +++ b/cpp/cmake/deps/taskflow.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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 @@ -14,26 +14,41 @@ # if (NOT TARGET deps::taskflow) - FetchContent_Declare( - deps-taskflow - GIT_REPOSITORY https://github.com/taskflow/taskflow.git - GIT_TAG v3.2.0 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-taskflow) - if (NOT deps-taskflow_POPULATED) - message(STATUS "Fetching taskflow sources") - FetchContent_Populate(deps-taskflow) - message(STATUS "Fetching taskflow sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(Taskflow REQUIRED) + if (NOT Taskflow_FOUND) + message(FATAL_ERROR "taskflow package not found in conda environment") + endif() + + add_library(deps::taskflow ALIAS Taskflow::Taskflow) + + get_target_property(taskflow_INCLUDE_DIR Taskflow::Taskflow INTERFACE_INCLUDE_DIRECTORIES) - set(TF_BUILD_TESTS OFF) - set(TF_BUILD_EXAMPLES OFF) + set(taskflow_INCLUDE_DIR ${taskflow_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(taskflow_INCLUDE_DIR) + else() + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-taskflow + GIT_REPOSITORY https://github.com/taskflow/taskflow.git + GIT_TAG v3.7.0 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-taskflow) + if (NOT deps-taskflow_POPULATED) + message(STATUS "Fetching taskflow sources") + FetchContent_Populate(deps-taskflow) + message(STATUS "Fetching taskflow sources - done") + endif () - add_subdirectory(${deps-taskflow_SOURCE_DIR} ${deps-taskflow_BINARY_DIR} EXCLUDE_FROM_ALL) + set(TF_BUILD_TESTS OFF) + set(TF_BUILD_EXAMPLES OFF) - add_library(deps::taskflow INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::taskflow INTERFACE Taskflow) - set(deps-taskflow_SOURCE_DIR ${deps-taskflow_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-taskflow_SOURCE_DIR) + add_subdirectory(${deps-taskflow_SOURCE_DIR} ${deps-taskflow_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::taskflow INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::taskflow INTERFACE Taskflow) + set(taskflow_INCLUDE_DIR ${deps-taskflow_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(taskflow_INCLUDE_DIR) + endif () endif () diff --git a/cpp/src/concurrent/threadpool.cpp b/cpp/src/concurrent/threadpool.cpp index 595b40aff..aa7975b2f 100644 --- a/cpp/src/concurrent/threadpool.cpp +++ b/cpp/src/concurrent/threadpool.cpp @@ -56,7 +56,7 @@ ThreadPool::operator bool() const std::future ThreadPool::enqueue(std::function task) { auto future = executor_->async([task]() { task(); }); - return std::move(future); + return future; } void ThreadPool::wait() From b7572bf363a18460020f7444be7aedc6c13c301e Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 17:55:20 -0700 Subject: [PATCH 08/25] Support both conda and source installation for pybind11 Signed-off-by: Gigon Bae --- cpp/cmake/deps/pybind11.cmake | 39 --- cpp/cmake/deps/pybind11_pr4857_4877.patch | 247 ------------------- python/cmake/deps/pybind11.cmake | 56 +++-- python/cmake/deps/pybind11_pr4857_4877.patch | 247 ------------------- 4 files changed, 32 insertions(+), 557 deletions(-) delete mode 100644 cpp/cmake/deps/pybind11.cmake delete mode 100644 cpp/cmake/deps/pybind11_pr4857_4877.patch delete mode 100644 python/cmake/deps/pybind11_pr4857_4877.patch diff --git a/cpp/cmake/deps/pybind11.cmake b/cpp/cmake/deps/pybind11.cmake deleted file mode 100644 index e4ea6f583..000000000 --- a/cpp/cmake/deps/pybind11.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (c) 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. -# - -if (NOT TARGET deps::pybind11) - FetchContent_Declare( - deps-pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.11.1 - GIT_SHALLOW TRUE - PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/pybind11_pr4857_4877.patch" || true - ) - FetchContent_GetProperties(deps-pybind11) - if (NOT deps-pybind11_POPULATED) - message(STATUS "Fetching pybind11 sources") - FetchContent_Populate(deps-pybind11) - message(STATUS "Fetching pybind11 sources - done") - endif () - - # https://pybind11.readthedocs.io/en/stable/compiling.html#configuration-variables - - add_subdirectory(${deps-pybind11_SOURCE_DIR} ${deps-pybind11_BINARY_DIR} EXCLUDE_FROM_ALL) - - add_library(deps::pybind11 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::pybind11 INTERFACE pybind11::module) - set(deps-pybind11_SOURCE_DIR ${deps-pybind11_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-pybind11_SOURCE_DIR) -endif () diff --git a/cpp/cmake/deps/pybind11_pr4857_4877.patch b/cpp/cmake/deps/pybind11_pr4857_4877.patch deleted file mode 100644 index d6abec392..000000000 --- a/cpp/cmake/deps/pybind11_pr4857_4877.patch +++ /dev/null @@ -1,247 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 87ec103..f2f1d19 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -132,6 +132,7 @@ set(PYBIND11_HEADERS - include/pybind11/embed.h - include/pybind11/eval.h - include/pybind11/gil.h -+ include/pybind11/gil_safe_call_once.h - include/pybind11/iostream.h - include/pybind11/functional.h - include/pybind11/numpy.h -diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h -index 31a54c7..8906c1f 100644 ---- a/include/pybind11/detail/common.h -+++ b/include/pybind11/detail/common.h -@@ -118,6 +118,14 @@ - # endif - #endif - -+#if defined(PYBIND11_CPP20) -+# define PYBIND11_CONSTINIT constinit -+# define PYBIND11_DTOR_CONSTEXPR constexpr -+#else -+# define PYBIND11_CONSTINIT -+# define PYBIND11_DTOR_CONSTEXPR -+#endif -+ - // Compiler version assertions - #if defined(__INTEL_COMPILER) - # if __INTEL_COMPILER < 1800 -diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h -index 570a558..da22f48 100644 ---- a/include/pybind11/gil.h -+++ b/include/pybind11/gil.h -@@ -11,6 +11,8 @@ - - #include "detail/common.h" - -+#include -+ - #if defined(WITH_THREAD) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) - # include "detail/internals.h" - #endif -@@ -137,7 +139,9 @@ private: - - class gil_scoped_release { - public: -+ // PRECONDITION: The GIL must be held when this constructor is called. - explicit gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { -+ assert(PyGILState_Check()); - // `get_internals()` must be called here unconditionally in order to initialize - // `internals.tstate` for subsequent `gil_scoped_acquire` calls. Otherwise, an - // initialization race could occur as multiple threads try `gil_scoped_acquire`. -@@ -201,7 +205,11 @@ class gil_scoped_release { - PyThreadState *state; - - public: -- gil_scoped_release() : state{PyEval_SaveThread()} {} -+ // PRECONDITION: The GIL must be held when this constructor is called. -+ gil_scoped_release() { -+ assert(PyGILState_Check()); -+ state = PyEval_SaveThread(); -+ } - gil_scoped_release(const gil_scoped_release &) = delete; - gil_scoped_release &operator=(const gil_scoped_release &) = delete; - ~gil_scoped_release() { PyEval_RestoreThread(state); } -diff --git a/include/pybind11/gil_safe_call_once.h b/include/pybind11/gil_safe_call_once.h -new file mode 100644 -index 0000000..58b90b8 ---- /dev/null -+++ b/include/pybind11/gil_safe_call_once.h -@@ -0,0 +1,90 @@ -+// Copyright (c) 2023 The pybind Community. -+ -+ -+#include "detail/common.h" -+#include "gil.h" -+ -+#include -+#include -+ -+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -+ -+// Use the `gil_safe_call_once_and_store` class below instead of the naive -+// -+// static auto imported_obj = py::module_::import("module_name"); // BAD, DO NOT USE! -+// -+// which has two serious issues: -+// -+// 1. Py_DECREF() calls potentially after the Python interpreter was finalized already, and -+// 2. deadlocks in multi-threaded processes (because of missing lock ordering). -+// -+// The following alternative avoids both problems: -+// -+// PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store storage; -+// auto &imported_obj = storage // Do NOT make this `static`! -+// .call_once_and_store_result([]() { -+// return py::module_::import("module_name"); -+// }) -+// .get_stored(); -+// -+// The parameter of `call_once_and_store_result()` must be callable. It can make -+// CPython API calls, and in particular, it can temporarily release the GIL. -+// -+// `T` can be any C++ type, it does not have to involve CPython API types. -+// -+// The behavior with regard to signals, e.g. `SIGINT` (`KeyboardInterrupt`), -+// is not ideal. If the main thread is the one to actually run the `Callable`, -+// then a `KeyboardInterrupt` will interrupt it if it is running normal Python -+// code. The situation is different if a non-main thread runs the -+// `Callable`, and then the main thread starts waiting for it to complete: -+// a `KeyboardInterrupt` will not interrupt the non-main thread, but it will -+// get processed only when it is the main thread's turn again and it is running -+// normal Python code. However, this will be unnoticeable for quick call-once -+// functions, which is usually the case. -+template -+class gil_safe_call_once_and_store { -+public: -+ // PRECONDITION: The GIL must be held when `call_once_and_store_result()` is called. -+ template -+ gil_safe_call_once_and_store &call_once_and_store_result(Callable &&fn) { -+ if (!is_initialized_) { // This read is guarded by the GIL. -+ // Multiple threads may enter here, because the GIL is released in the next line and -+ // CPython API calls in the `fn()` call below may release and reacquire the GIL. -+ gil_scoped_release gil_rel; // Needed to establish lock ordering. -+ std::call_once(once_flag_, [&] { -+ // Only one thread will ever enter here. -+ gil_scoped_acquire gil_acq; -+ ::new (storage_) T(fn()); // fn may release, but will reacquire, the GIL. -+ is_initialized_ = true; // This write is guarded by the GIL. -+ }); -+ // All threads will observe `is_initialized_` as true here. -+ } -+ // Intentionally not returning `T &` to ensure the calling code is self-documenting. -+ return *this; -+ } -+ -+ // This must only be called after `call_once_and_store_result()` was called. -+ T &get_stored() { -+ assert(is_initialized_); -+ PYBIND11_WARNING_PUSH -+#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5 -+ // Needed for gcc 4.8.5 -+ PYBIND11_WARNING_DISABLE_GCC("-Wstrict-aliasing") -+#endif -+ return *reinterpret_cast(storage_); -+ PYBIND11_WARNING_POP -+ } -+ -+ constexpr gil_safe_call_once_and_store() = default; -+ PYBIND11_DTOR_CONSTEXPR ~gil_safe_call_once_and_store() = default; -+ -+private: -+ alignas(T) char storage_[sizeof(T)] = {}; -+ std::once_flag once_flag_ = {}; -+ bool is_initialized_ = false; -+ // The `is_initialized_`-`storage_` pair is very similar to `std::optional`, -+ // but the latter does not have the triviality properties of former, -+ // therefore `std::optional` is not a viable alternative here. -+}; -+ -+PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) -diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h -index 36077ec..1217c8d 100644 ---- a/include/pybind11/numpy.h -+++ b/include/pybind11/numpy.h -@@ -10,7 +10,10 @@ - #pragma once - - #include "pybind11.h" -+#include "detail/common.h" - #include "complex.h" -+#include "gil_safe_call_once.h" -+#include "pytypes.h" - - #include - #include -@@ -120,6 +123,20 @@ inline numpy_internals &get_numpy_internals() { - return *ptr; - } - -+PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name) { -+ module_ numpy = module_::import("numpy"); -+ str version_string = numpy.attr("__version__"); -+ -+ module_ numpy_lib = module_::import("numpy.lib"); -+ object numpy_version = numpy_lib.attr("NumpyVersion")(version_string); -+ int major_version = numpy_version.attr("major").cast(); -+ -+ /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially -+ became a private module. */ -+ std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core"; -+ return module_::import((numpy_core_path + "." + submodule_name).c_str()); -+} -+ - template - struct same_size { - template -@@ -192,8 +209,8 @@ struct npy_api { - }; - - static npy_api &get() { -- static npy_api api = lookup(); -- return api; -+ PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; -+ return storage.call_once_and_store_result(lookup).get_stored(); - } - - bool PyArray_Check_(PyObject *obj) const { -@@ -263,9 +280,13 @@ private: - }; - - static npy_api lookup() { -- module_ m = module_::import("numpy.core.multiarray"); -+ module_ m = detail::import_numpy_core_submodule("multiarray"); - auto c = m.attr("_ARRAY_API"); - void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), nullptr); -+ if (api_ptr == nullptr) { -+ raise_from(PyExc_SystemError, "FAILURE obtaining numpy _ARRAY_API pointer."); -+ throw error_already_set(); -+ } - npy_api api; - #define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func]; - DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion); -@@ -625,13 +646,14 @@ public: - char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; } - - private: -- static object _dtype_from_pep3118() { -- static PyObject *obj = module_::import("numpy.core._internal") -- .attr("_dtype_from_pep3118") -- .cast() -- .release() -- .ptr(); -- return reinterpret_borrow(obj); -+ static object &_dtype_from_pep3118() { -+ PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; -+ return storage -+ .call_once_and_store_result([]() { -+ return detail::import_numpy_core_submodule("_internal") -+ .attr("_dtype_from_pep3118"); -+ }) -+ .get_stored(); - } - - dtype strip_padding(ssize_t itemsize) { diff --git a/python/cmake/deps/pybind11.cmake b/python/cmake/deps/pybind11.cmake index ab0eab7f8..70c4c7467 100644 --- a/python/cmake/deps/pybind11.cmake +++ b/python/cmake/deps/pybind11.cmake @@ -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 @@ -14,30 +14,38 @@ # if (NOT TARGET deps::pybind11) - FetchContent_Declare( - deps-pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.11.1 - GIT_SHALLOW TRUE - PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/pybind11_pr4857_4877.patch" || true - ) - FetchContent_GetProperties(deps-pybind11) - if (NOT deps-pybind11_POPULATED) - message(STATUS "Fetching pybind11 sources") - FetchContent_Populate(deps-pybind11) - message(STATUS "Fetching pybind11 sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + find_package(pybind11 REQUIRED) + if (NOT pybind11_FOUND) + message(FATAL_ERROR "pybind11 package not found in conda environment") + endif () - # https://pybind11.readthedocs.io/en/stable/compiling.html#configuration-variables - # set(PYBIND11_PYTHON_VERSION 3.6) # It doesn't find python in manylinux2014 image - if (NOT PYTHON_EXECUTABLE) - set(PYTHON_EXECUTABLE /usr/bin/python3) - endif () + add_library(deps::pybind11 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::pybind11 INTERFACE pybind11::module) + get_target_property(pybind11_INCLUDE_DIR pybind11::pybind11_headers INTERFACE_INCLUDE_DIRECTORIES) - add_subdirectory(${deps-pybind11_SOURCE_DIR} ${deps-pybind11_BINARY_DIR} EXCLUDE_FROM_ALL) + set(pybind11_INCLUDE_DIR ${pybind11_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(pybind11_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + GIT_TAG v2.13.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-pybind11) + if (NOT deps-pybind11_POPULATED) + message(STATUS "Fetching pybind11 sources") + FetchContent_Populate(deps-pybind11) + message(STATUS "Fetching pybind11 sources - done") + endif () - add_library(deps::pybind11 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::pybind11 INTERFACE pybind11::module) - set(deps-pybind11_SOURCE_DIR ${deps-pybind11_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-pybind11_SOURCE_DIR) + add_subdirectory(${deps-pybind11_SOURCE_DIR} ${deps-pybind11_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::pybind11 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::pybind11 INTERFACE pybind11::module) + set(deps-pybind11_SOURCE_DIR ${deps-pybind11_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(deps-pybind11_SOURCE_DIR) + endif () endif () diff --git a/python/cmake/deps/pybind11_pr4857_4877.patch b/python/cmake/deps/pybind11_pr4857_4877.patch deleted file mode 100644 index d6abec392..000000000 --- a/python/cmake/deps/pybind11_pr4857_4877.patch +++ /dev/null @@ -1,247 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 87ec103..f2f1d19 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -132,6 +132,7 @@ set(PYBIND11_HEADERS - include/pybind11/embed.h - include/pybind11/eval.h - include/pybind11/gil.h -+ include/pybind11/gil_safe_call_once.h - include/pybind11/iostream.h - include/pybind11/functional.h - include/pybind11/numpy.h -diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h -index 31a54c7..8906c1f 100644 ---- a/include/pybind11/detail/common.h -+++ b/include/pybind11/detail/common.h -@@ -118,6 +118,14 @@ - # endif - #endif - -+#if defined(PYBIND11_CPP20) -+# define PYBIND11_CONSTINIT constinit -+# define PYBIND11_DTOR_CONSTEXPR constexpr -+#else -+# define PYBIND11_CONSTINIT -+# define PYBIND11_DTOR_CONSTEXPR -+#endif -+ - // Compiler version assertions - #if defined(__INTEL_COMPILER) - # if __INTEL_COMPILER < 1800 -diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h -index 570a558..da22f48 100644 ---- a/include/pybind11/gil.h -+++ b/include/pybind11/gil.h -@@ -11,6 +11,8 @@ - - #include "detail/common.h" - -+#include -+ - #if defined(WITH_THREAD) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) - # include "detail/internals.h" - #endif -@@ -137,7 +139,9 @@ private: - - class gil_scoped_release { - public: -+ // PRECONDITION: The GIL must be held when this constructor is called. - explicit gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { -+ assert(PyGILState_Check()); - // `get_internals()` must be called here unconditionally in order to initialize - // `internals.tstate` for subsequent `gil_scoped_acquire` calls. Otherwise, an - // initialization race could occur as multiple threads try `gil_scoped_acquire`. -@@ -201,7 +205,11 @@ class gil_scoped_release { - PyThreadState *state; - - public: -- gil_scoped_release() : state{PyEval_SaveThread()} {} -+ // PRECONDITION: The GIL must be held when this constructor is called. -+ gil_scoped_release() { -+ assert(PyGILState_Check()); -+ state = PyEval_SaveThread(); -+ } - gil_scoped_release(const gil_scoped_release &) = delete; - gil_scoped_release &operator=(const gil_scoped_release &) = delete; - ~gil_scoped_release() { PyEval_RestoreThread(state); } -diff --git a/include/pybind11/gil_safe_call_once.h b/include/pybind11/gil_safe_call_once.h -new file mode 100644 -index 0000000..58b90b8 ---- /dev/null -+++ b/include/pybind11/gil_safe_call_once.h -@@ -0,0 +1,90 @@ -+// Copyright (c) 2023 The pybind Community. -+ -+ -+#include "detail/common.h" -+#include "gil.h" -+ -+#include -+#include -+ -+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -+ -+// Use the `gil_safe_call_once_and_store` class below instead of the naive -+// -+// static auto imported_obj = py::module_::import("module_name"); // BAD, DO NOT USE! -+// -+// which has two serious issues: -+// -+// 1. Py_DECREF() calls potentially after the Python interpreter was finalized already, and -+// 2. deadlocks in multi-threaded processes (because of missing lock ordering). -+// -+// The following alternative avoids both problems: -+// -+// PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store storage; -+// auto &imported_obj = storage // Do NOT make this `static`! -+// .call_once_and_store_result([]() { -+// return py::module_::import("module_name"); -+// }) -+// .get_stored(); -+// -+// The parameter of `call_once_and_store_result()` must be callable. It can make -+// CPython API calls, and in particular, it can temporarily release the GIL. -+// -+// `T` can be any C++ type, it does not have to involve CPython API types. -+// -+// The behavior with regard to signals, e.g. `SIGINT` (`KeyboardInterrupt`), -+// is not ideal. If the main thread is the one to actually run the `Callable`, -+// then a `KeyboardInterrupt` will interrupt it if it is running normal Python -+// code. The situation is different if a non-main thread runs the -+// `Callable`, and then the main thread starts waiting for it to complete: -+// a `KeyboardInterrupt` will not interrupt the non-main thread, but it will -+// get processed only when it is the main thread's turn again and it is running -+// normal Python code. However, this will be unnoticeable for quick call-once -+// functions, which is usually the case. -+template -+class gil_safe_call_once_and_store { -+public: -+ // PRECONDITION: The GIL must be held when `call_once_and_store_result()` is called. -+ template -+ gil_safe_call_once_and_store &call_once_and_store_result(Callable &&fn) { -+ if (!is_initialized_) { // This read is guarded by the GIL. -+ // Multiple threads may enter here, because the GIL is released in the next line and -+ // CPython API calls in the `fn()` call below may release and reacquire the GIL. -+ gil_scoped_release gil_rel; // Needed to establish lock ordering. -+ std::call_once(once_flag_, [&] { -+ // Only one thread will ever enter here. -+ gil_scoped_acquire gil_acq; -+ ::new (storage_) T(fn()); // fn may release, but will reacquire, the GIL. -+ is_initialized_ = true; // This write is guarded by the GIL. -+ }); -+ // All threads will observe `is_initialized_` as true here. -+ } -+ // Intentionally not returning `T &` to ensure the calling code is self-documenting. -+ return *this; -+ } -+ -+ // This must only be called after `call_once_and_store_result()` was called. -+ T &get_stored() { -+ assert(is_initialized_); -+ PYBIND11_WARNING_PUSH -+#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5 -+ // Needed for gcc 4.8.5 -+ PYBIND11_WARNING_DISABLE_GCC("-Wstrict-aliasing") -+#endif -+ return *reinterpret_cast(storage_); -+ PYBIND11_WARNING_POP -+ } -+ -+ constexpr gil_safe_call_once_and_store() = default; -+ PYBIND11_DTOR_CONSTEXPR ~gil_safe_call_once_and_store() = default; -+ -+private: -+ alignas(T) char storage_[sizeof(T)] = {}; -+ std::once_flag once_flag_ = {}; -+ bool is_initialized_ = false; -+ // The `is_initialized_`-`storage_` pair is very similar to `std::optional`, -+ // but the latter does not have the triviality properties of former, -+ // therefore `std::optional` is not a viable alternative here. -+}; -+ -+PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) -diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h -index 36077ec..1217c8d 100644 ---- a/include/pybind11/numpy.h -+++ b/include/pybind11/numpy.h -@@ -10,7 +10,10 @@ - #pragma once - - #include "pybind11.h" -+#include "detail/common.h" - #include "complex.h" -+#include "gil_safe_call_once.h" -+#include "pytypes.h" - - #include - #include -@@ -120,6 +123,20 @@ inline numpy_internals &get_numpy_internals() { - return *ptr; - } - -+PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name) { -+ module_ numpy = module_::import("numpy"); -+ str version_string = numpy.attr("__version__"); -+ -+ module_ numpy_lib = module_::import("numpy.lib"); -+ object numpy_version = numpy_lib.attr("NumpyVersion")(version_string); -+ int major_version = numpy_version.attr("major").cast(); -+ -+ /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially -+ became a private module. */ -+ std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core"; -+ return module_::import((numpy_core_path + "." + submodule_name).c_str()); -+} -+ - template - struct same_size { - template -@@ -192,8 +209,8 @@ struct npy_api { - }; - - static npy_api &get() { -- static npy_api api = lookup(); -- return api; -+ PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; -+ return storage.call_once_and_store_result(lookup).get_stored(); - } - - bool PyArray_Check_(PyObject *obj) const { -@@ -263,9 +280,13 @@ private: - }; - - static npy_api lookup() { -- module_ m = module_::import("numpy.core.multiarray"); -+ module_ m = detail::import_numpy_core_submodule("multiarray"); - auto c = m.attr("_ARRAY_API"); - void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), nullptr); -+ if (api_ptr == nullptr) { -+ raise_from(PyExc_SystemError, "FAILURE obtaining numpy _ARRAY_API pointer."); -+ throw error_already_set(); -+ } - npy_api api; - #define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func]; - DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion); -@@ -625,13 +646,14 @@ public: - char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; } - - private: -- static object _dtype_from_pep3118() { -- static PyObject *obj = module_::import("numpy.core._internal") -- .attr("_dtype_from_pep3118") -- .cast() -- .release() -- .ptr(); -- return reinterpret_borrow(obj); -+ static object &_dtype_from_pep3118() { -+ PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; -+ return storage -+ .call_once_and_store_result([]() { -+ return detail::import_numpy_core_submodule("_internal") -+ .attr("_dtype_from_pep3118"); -+ }) -+ .get_stored(); - } - - dtype strip_padding(ssize_t itemsize) { From 988cf45736385f44c6c16ee2f0a615252fe4f48c Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Mon, 29 Jul 2024 18:14:25 -0700 Subject: [PATCH 09/25] Support both conda and source installation for pybind11_json Signed-off-by: Gigon Bae --- python/cmake/deps/pybind11_json.cmake | 45 ++++++++++++++++++--------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/python/cmake/deps/pybind11_json.cmake b/python/cmake/deps/pybind11_json.cmake index 9313bb0f0..160f02788 100644 --- a/python/cmake/deps/pybind11_json.cmake +++ b/python/cmake/deps/pybind11_json.cmake @@ -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 @@ -14,23 +14,38 @@ # if (NOT TARGET deps::pybind11_json) - FetchContent_Declare( + if (DEFINED ENV{CONDA_PREFIX}) + find_package(pybind11_json REQUIRED) + if (NOT pybind11_json_FOUND) + message(FATAL_ERROR "pybind11_json package not found in conda environment") + endif () + + add_library(deps::pybind11_json INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::pybind11_json INTERFACE pybind11_json) + get_target_property(pybind11_json_INCLUDE_DIR pybind11_json INTERFACE_INCLUDE_DIRECTORIES) + + set(pybind11_json_INCLUDE_DIR ${pybind11_json_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(pybind11_json_INCLUDE_DIR) + else () + # Fallback to fetching pybind11_json sources + FetchContent_Declare( deps-pybind11_json GIT_REPOSITORY https://github.com/pybind/pybind11_json.git - GIT_TAG 0.2.9 + GIT_TAG 0.2.14 GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-pybind11_json) - if (NOT deps-pybind11_json_POPULATED) - message(STATUS "Fetching pybind11_json sources") - FetchContent_Populate(deps-pybind11_json) - message(STATUS "Fetching pybind11_json sources - done") - endif () + ) + FetchContent_GetProperties(deps-pybind11_json) + if (NOT deps-pybind11_json_POPULATED) + message(STATUS "Fetching pybind11_json sources") + FetchContent_Populate(deps-pybind11_json) + message(STATUS "Fetching pybind11_json sources - done") + endif () - add_subdirectory(${deps-pybind11_json_SOURCE_DIR} ${deps-pybind11_json_BINARY_DIR} EXCLUDE_FROM_ALL) + add_subdirectory(${deps-pybind11_json_SOURCE_DIR} ${deps-pybind11_json_BINARY_DIR} EXCLUDE_FROM_ALL) - add_library(deps::pybind11_json INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::pybind11_json INTERFACE pybind11_json) - set(deps-pybind11_json_SOURCE_DIR ${deps-pybind11_json_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-pybind11_json_SOURCE_DIR) + add_library(deps::pybind11_json INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::pybind11_json INTERFACE pybind11_json) + set(pybind11_json_INCLUDE_DIR ${deps-pybind11_json_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(pybind11_json_INCLUDE_DIR) + endif () endif () From dda171af13206c0cb094052096f330b5b453a9a2 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Tue, 30 Jul 2024 11:58:52 -0700 Subject: [PATCH 10/25] Update libcuckoo to 0.3.1 Signed-off-by: Gigon Bae --- cpp/cmake/deps/libcuckoo.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/cmake/deps/libcuckoo.cmake b/cpp/cmake/deps/libcuckoo.cmake index 3089730bc..abf8a85c6 100644 --- a/cpp/cmake/deps/libcuckoo.cmake +++ b/cpp/cmake/deps/libcuckoo.cmake @@ -1,5 +1,5 @@ # Apache License, Version 2.0 -# Copyright 2021 NVIDIA Corporation +# Copyright 2021-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. @@ -17,7 +17,7 @@ if (NOT TARGET deps::libcuckoo) FetchContent_Declare( deps-libcuckoo GIT_REPOSITORY https://github.com/efficient/libcuckoo - GIT_TAG v0.3 + GIT_TAG v0.3.1 GIT_SHALLOW TRUE ) FetchContent_GetProperties(deps-libcuckoo) @@ -59,7 +59,7 @@ if (NOT TARGET deps::libcuckoo) cucim_restore_build_shared_libs() add_library(deps::libcuckoo INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::libcuckoo INTERFACE libcuckoo) + target_link_libraries(deps::libcuckoo INTERFACE libcuckoo::libcuckoo) set(deps-libcuckoo_SOURCE_DIR ${deps-libcuckoo_SOURCE_DIR} CACHE INTERNAL "" FORCE) mark_as_advanced(deps-libcuckoo_SOURCE_DIR) endif () From 7e85e5fae1b198c91e6d60765682cda4191b5828 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:18:59 -0700 Subject: [PATCH 11/25] Update catch2 to 3.6.0 Signed-off-by: Gigon Bae --- cpp/cmake/deps/catch2.cmake | 73 ++++++++++++------- .../cucim.kit.cumed/cmake/deps/catch2.cmake | 73 ++++++++++++------- .../cucim.kit.cuslide/cmake/deps/catch2.cmake | 73 ++++++++++++------- 3 files changed, 144 insertions(+), 75 deletions(-) diff --git a/cpp/cmake/deps/catch2.cmake b/cpp/cmake/deps/catch2.cmake index 4ee4bfabd..699dbe0f5 100644 --- a/cpp/cmake/deps/catch2.cmake +++ b/cpp/cmake/deps/catch2.cmake @@ -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 @@ -14,28 +14,51 @@ # if (NOT TARGET deps::catch2) - FetchContent_Declare( - deps-catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-catch2) - if (NOT deps-catch2_POPULATED) - message(STATUS "Fetching catch2 sources") - FetchContent_Populate(deps-catch2) - message(STATUS "Fetching catch2 sources - done") - endif () - - add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) - - # Include Append catch2's cmake module path so that we can use `include(Catch)`. - # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake - list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) - - add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) - set(deps-catch2_SOURCE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-catch2_SOURCE_DIR) + # Using Catch2 from Conda package has some issues with the CMake integration. + # - [Add C++17 support that "just works" via package managers · Issue #2462 · catchorg/Catch2](https://github.com/catchorg/Catch2/issues/2462) + # - https://stackoverflow.com/a/70320798/16361228 + + # if (DEFINED ENV{CONDA_PREFIX}) + # find_package(Catch2 3 REQUIRED) + # if (NOT Catch2_FOUND) + # message(FATAL_ERROR "Catch2 package not found in conda environment") + # endif () + + # get_target_property(catch2_INCLUDE_DIR Catch2::Catch2 INTERFACE_INCLUDE_DIRECTORIES) + # add_library(deps::catch2 ALIAS Catch2::Catch2) + + # # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + # list(APPEND CMAKE_MODULE_PATH "${catch2_INCLUDE_DIR}/../lib/cmake/Catch2") + # set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + # set(catch2_INCLUDE_DIR ${catch2_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + # mark_as_advanced(catch2_INCLUDE_DIR) + # else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.6.0 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-catch2) + if (NOT deps-catch2_POPULATED) + message(STATUS "Fetching catch2 sources") + FetchContent_Populate(deps-catch2) + message(STATUS "Fetching catch2 sources - done") + endif () + + add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) + + # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) + set(catch2_INCLUDE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(catch2_INCLUDE_DIR) + # endif () endif () diff --git a/cpp/plugins/cucim.kit.cumed/cmake/deps/catch2.cmake b/cpp/plugins/cucim.kit.cumed/cmake/deps/catch2.cmake index 6a35a9c0b..699dbe0f5 100644 --- a/cpp/plugins/cucim.kit.cumed/cmake/deps/catch2.cmake +++ b/cpp/plugins/cucim.kit.cumed/cmake/deps/catch2.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 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 @@ -14,28 +14,51 @@ # if (NOT TARGET deps::catch2) - FetchContent_Declare( - deps-catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-catch2) - if (NOT deps-catch2_POPULATED) - message(STATUS "Fetching catch2 sources") - FetchContent_Populate(deps-catch2) - message(STATUS "Fetching catch2 sources - done") - endif () - - add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) - - # Include Append catch2's cmake module path so that we can use `include(Catch)`. - # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake - list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) - - add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) - set(deps-catch2_SOURCE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-catch2_SOURCE_DIR) + # Using Catch2 from Conda package has some issues with the CMake integration. + # - [Add C++17 support that "just works" via package managers · Issue #2462 · catchorg/Catch2](https://github.com/catchorg/Catch2/issues/2462) + # - https://stackoverflow.com/a/70320798/16361228 + + # if (DEFINED ENV{CONDA_PREFIX}) + # find_package(Catch2 3 REQUIRED) + # if (NOT Catch2_FOUND) + # message(FATAL_ERROR "Catch2 package not found in conda environment") + # endif () + + # get_target_property(catch2_INCLUDE_DIR Catch2::Catch2 INTERFACE_INCLUDE_DIRECTORIES) + # add_library(deps::catch2 ALIAS Catch2::Catch2) + + # # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + # list(APPEND CMAKE_MODULE_PATH "${catch2_INCLUDE_DIR}/../lib/cmake/Catch2") + # set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + # set(catch2_INCLUDE_DIR ${catch2_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + # mark_as_advanced(catch2_INCLUDE_DIR) + # else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.6.0 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-catch2) + if (NOT deps-catch2_POPULATED) + message(STATUS "Fetching catch2 sources") + FetchContent_Populate(deps-catch2) + message(STATUS "Fetching catch2 sources - done") + endif () + + add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) + + # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) + set(catch2_INCLUDE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(catch2_INCLUDE_DIR) + # endif () endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/catch2.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/catch2.cmake index 4ee4bfabd..699dbe0f5 100644 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/catch2.cmake +++ b/cpp/plugins/cucim.kit.cuslide/cmake/deps/catch2.cmake @@ -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 @@ -14,28 +14,51 @@ # if (NOT TARGET deps::catch2) - FetchContent_Declare( - deps-catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-catch2) - if (NOT deps-catch2_POPULATED) - message(STATUS "Fetching catch2 sources") - FetchContent_Populate(deps-catch2) - message(STATUS "Fetching catch2 sources - done") - endif () - - add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) - - # Include Append catch2's cmake module path so that we can use `include(Catch)`. - # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake - list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) - - add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) - set(deps-catch2_SOURCE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-catch2_SOURCE_DIR) + # Using Catch2 from Conda package has some issues with the CMake integration. + # - [Add C++17 support that "just works" via package managers · Issue #2462 · catchorg/Catch2](https://github.com/catchorg/Catch2/issues/2462) + # - https://stackoverflow.com/a/70320798/16361228 + + # if (DEFINED ENV{CONDA_PREFIX}) + # find_package(Catch2 3 REQUIRED) + # if (NOT Catch2_FOUND) + # message(FATAL_ERROR "Catch2 package not found in conda environment") + # endif () + + # get_target_property(catch2_INCLUDE_DIR Catch2::Catch2 INTERFACE_INCLUDE_DIRECTORIES) + # add_library(deps::catch2 ALIAS Catch2::Catch2) + + # # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + # list(APPEND CMAKE_MODULE_PATH "${catch2_INCLUDE_DIR}/../lib/cmake/Catch2") + # set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + # set(catch2_INCLUDE_DIR ${catch2_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + # mark_as_advanced(catch2_INCLUDE_DIR) + # else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.6.0 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-catch2) + if (NOT deps-catch2_POPULATED) + message(STATUS "Fetching catch2 sources") + FetchContent_Populate(deps-catch2) + message(STATUS "Fetching catch2 sources - done") + endif () + + add_subdirectory(${deps-catch2_SOURCE_DIR} ${deps-catch2_BINARY_DIR} EXCLUDE_FROM_ALL) + + # Include Append catch2's cmake module path so that we can use `include(Catch)`. + # https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake + list(APPEND CMAKE_MODULE_PATH "${deps-catch2_SOURCE_DIR}/extras") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) + + add_library(deps::catch2 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::catch2 INTERFACE Catch2::Catch2) + set(catch2_INCLUDE_DIR ${deps-catch2_SOURCE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(catch2_INCLUDE_DIR) + # endif () endif () From 7b853e482869dd46814c7c0e5ac336274bbf9c6d Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:29:45 -0700 Subject: [PATCH 12/25] Remove workarounds for nvcc errors with -std=c++17 Remove workarounds that address the following errors: Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` Signed-off-by: Gigon Bae --- benchmarks/CMakeLists.txt | 6 +----- cpp/CMakeLists.txt | 7 +------ cpp/plugins/cucim.kit.cumed/CMakeLists.txt | 4 +--- cpp/plugins/cucim.kit.cumed/benchmarks/CMakeLists.txt | 4 +--- cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt | 4 +--- cpp/plugins/cucim.kit.cuslide/CMakeLists.txt | 4 +--- cpp/plugins/cucim.kit.cuslide/benchmarks/CMakeLists.txt | 4 +--- cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt | 4 +--- cpp/tests/CMakeLists.txt | 4 +--- examples/cpp/CMakeLists.txt | 4 +--- examples/cpp/CMakeLists.txt.examples.release.in | 4 +--- gds/CMakeLists.txt | 7 +------ 12 files changed, 12 insertions(+), 44 deletions(-) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 0b6fa8d42..b65728046 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -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 @@ -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 $<$:-Werror -Wall -Wextra>) target_compile_definitions(cucim_benchmarks PUBLIC CUCIM_VERSION=${PROJECT_VERSION} @@ -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 $<$:-Werror -Wall -Wextra>) target_link_libraries(cucim_primitives_benchmarks PRIVATE ${CUCIM_PACKAGE_NAME} diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 371c3e8c2..6cdc6ecf2 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -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 @@ -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 - $<$:-Werror -Wall -Wextra> - ) target_compile_definitions(${CUCIM_PACKAGE_NAME} PUBLIC CUCIM_VERSION=${PROJECT_VERSION} diff --git a/cpp/plugins/cucim.kit.cumed/CMakeLists.txt b/cpp/plugins/cucim.kit.cumed/CMakeLists.txt index b1743e70a..fae4049be 100644 --- a/cpp/plugins/cucim.kit.cumed/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cumed/CMakeLists.txt @@ -1,5 +1,5 @@ # Apache License, Version 2.0 -# Copyright 2021 NVIDIA Corporation +# Copyright 2021-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. @@ -163,8 +163,6 @@ set_target_properties(${CUCIM_PLUGIN_NAME} VERSION ${PROJECT_VERSION} ) target_compile_features(${CUCIM_PLUGIN_NAME} PRIVATE cxx_std_17) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(${CUCIM_PLUGIN_NAME} PRIVATE $<$:-Werror -Wall -Wextra>) # Link libraries target_link_libraries(${CUCIM_PLUGIN_NAME} diff --git a/cpp/plugins/cucim.kit.cumed/benchmarks/CMakeLists.txt b/cpp/plugins/cucim.kit.cumed/benchmarks/CMakeLists.txt index ade52265f..70cb98b0e 100644 --- a/cpp/plugins/cucim.kit.cumed/benchmarks/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cumed/benchmarks/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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 @@ -25,8 +25,6 @@ set_target_properties(cumed_benchmarks CXX_EXTENSIONS NO ) target_compile_features(cumed_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(cumed_benchmarks PRIVATE $<$:-Werror -Wall -Wextra>) target_compile_definitions(cumed_benchmarks PUBLIC CUMED_VERSION=${PROJECT_VERSION} diff --git a/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt b/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt index 262c02499..ffe337780 100644 --- a/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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 @@ -32,8 +32,6 @@ set_target_properties(cumed_tests CXX_EXTENSIONS NO ) target_compile_features(cumed_tests PRIVATE ${CUCIM_REQUIRED_FEATURES}) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(cumed_tests PRIVATE $<$:-Werror -Wall -Wextra>) target_compile_definitions(cumed_tests PUBLIC CUMED_VERSION=${PROJECT_VERSION} diff --git a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt index d5772315a..89fea7a33 100644 --- a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt @@ -1,5 +1,5 @@ # Apache License, Version 2.0 -# Copyright 2020-2021 NVIDIA Corporation +# Copyright 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. @@ -210,8 +210,6 @@ set_target_properties(${CUCIM_PLUGIN_NAME} VERSION ${PROJECT_VERSION} ) target_compile_features(${CUCIM_PLUGIN_NAME} PRIVATE cxx_std_17) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(${CUCIM_PLUGIN_NAME} PRIVATE $<$:-Werror -Wall -Wextra>) # Link libraries target_link_libraries(${CUCIM_PLUGIN_NAME} diff --git a/cpp/plugins/cucim.kit.cuslide/benchmarks/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/benchmarks/CMakeLists.txt index 490860c39..447e9b368 100644 --- a/cpp/plugins/cucim.kit.cuslide/benchmarks/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/benchmarks/CMakeLists.txt @@ -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 @@ -26,8 +26,6 @@ set_target_properties(cuslide_benchmarks CXX_EXTENSIONS NO ) target_compile_features(cuslide_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(cuslide_benchmarks PRIVATE $<$:-Werror -Wall -Wextra>) target_compile_definitions(cuslide_benchmarks PUBLIC CUSLIDE_VERSION=${PROJECT_VERSION} diff --git a/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt index 3b9bde713..7b38fb10b 100644 --- a/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt @@ -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 @@ -33,8 +33,6 @@ set_target_properties(cuslide_tests CXX_EXTENSIONS NO ) target_compile_features(cuslide_tests PRIVATE ${CUCIM_REQUIRED_FEATURES}) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(cuslide_tests PRIVATE $<$:-Werror -Wall -Wextra>) target_compile_definitions(cuslide_tests PUBLIC CUSLIDE_VERSION=${PROJECT_VERSION} diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index dfd619b24..133507a4b 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -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 @@ -33,8 +33,6 @@ set_target_properties(cucim_tests CXX_EXTENSIONS NO ) target_compile_features(cucim_tests 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_tests PRIVATE $<$:-Werror -Wall -Wextra>) target_compile_definitions(cucim_tests PUBLIC CUCIM_VERSION=${PROJECT_VERSION} diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 9988e985f..80490ca69 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -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 @@ -26,8 +26,6 @@ set_target_properties(tiff_image CXX_EXTENSIONS NO ) target_compile_features(tiff_image PRIVATE ${CUCIM_REQUIRED_FEATURES}) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(tiff_image PRIVATE $<$:-Werror -Wall -Wextra>) target_link_libraries(tiff_image PRIVATE ${CUCIM_PACKAGE_NAME} diff --git a/examples/cpp/CMakeLists.txt.examples.release.in b/examples/cpp/CMakeLists.txt.examples.release.in index bae629eb7..11d43cbc8 100644 --- a/examples/cpp/CMakeLists.txt.examples.release.in +++ b/examples/cpp/CMakeLists.txt.examples.release.in @@ -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 @@ -69,8 +69,6 @@ set_target_properties(tiff_image CUDA_RUNTIME_LIBRARY Shared ) target_compile_features(tiff_image PRIVATE cxx_std_17 cuda_std_17) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(tiff_image PRIVATE $<$:-Werror -Wall -Wextra>) target_link_libraries(tiff_image PRIVATE cucim::cucim diff --git a/gds/CMakeLists.txt b/gds/CMakeLists.txt index 019f9f891..ca6c8ae26 100644 --- a/gds/CMakeLists.txt +++ b/gds/CMakeLists.txt @@ -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 @@ -45,11 +45,6 @@ set_target_properties(cufile_stub # 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(cufile_stub PRIVATE ${CUCIM_REQUIRED_FEATURES}) -# Use generator expression to avoid `nvcc fatal : Value '-std=c++17' is not defined for option 'Werror'` -target_compile_options(cufile_stub - PRIVATE - $<$:-Werror -Wall -Wextra> - ) ## Link libraries target_link_libraries(cufile_stub From df4389ac7c1e0bdf37875d8363d486162a6bb54a Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:32:59 -0700 Subject: [PATCH 13/25] Do not call catch_discover_tests() in CMakeLists.txt Do not use catch_discover_tests() since it causes a test to be run at build time and somehow it causes a deadlock during the build. Signed-off-by: Gigon Bae --- cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt | 4 +++- cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt | 4 +++- cpp/tests/CMakeLists.txt | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt b/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt index ffe337780..d02d6ad1f 100644 --- a/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cumed/tests/CMakeLists.txt @@ -57,4 +57,6 @@ target_include_directories(cumed_tests include(Catch) # See https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake for other options -catch_discover_tests(cumed_tests) +# Do not use catch_discover_tests() since it causes a test to be run at build time +# and somehow it causes a deadlock during the build. +# catch_discover_tests(cumed_tests) diff --git a/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt index 7b38fb10b..71440d8c9 100644 --- a/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/tests/CMakeLists.txt @@ -60,4 +60,6 @@ target_include_directories(cuslide_tests include(Catch) # See https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake for other options -catch_discover_tests(cuslide_tests) +# Do not use catch_discover_tests() since it causes a test to be run at build time +# and somehow it causes a deadlock during the build. +# catch_discover_tests(cuslide_tests) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 133507a4b..939c5bdfa 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -60,4 +60,6 @@ target_link_libraries(cucim_tests include(Catch) # See https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md#catchcmake-and-catchaddtestscmake for other options -catch_discover_tests(cucim_tests) +# Do not use catch_discover_tests() since it causes a test to be run at build time +# and somehow it causes a deadlock during the build. +# catch_discover_tests(cucim_tests) From 850fb2af3956bfc56946c53b796081a369b3fe73 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:33:52 -0700 Subject: [PATCH 14/25] Add a comment on pybind11 in run script Signed-off-by: Gigon Bae --- run | 1 + 1 file changed, 1 insertion(+) diff --git a/run b/run index 3a8693531..a539dfa08 100755 --- a/run +++ b/run @@ -343,6 +343,7 @@ build_local_cucim_() { local python_library=$(python3 -c "import distutils.sysconfig as sysconfig, os; print(os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('LDLIBRARY')))") local python_include_dir=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") + # https://pybind11.readthedocs.io/en/stable/compiling.html#configuration-variables ${CMAKE_CMD} -S ${source_folder} -B ${build_folder} -G "Unix Makefiles" \ -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \ -DCMAKE_BUILD_TYPE=${build_type_str} \ From 1286fbecd90e975938157b9f3838bbf3365f30c2 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:34:25 -0700 Subject: [PATCH 15/25] Support both conda and source installation for cli11 Signed-off-by: Gigon Bae --- cpp/cmake/deps/cli11.cmake | 60 ++++++++++++------- .../cucim.kit.cumed/cmake/deps/cli11.cmake | 60 ++++++++++++------- .../cucim.kit.cuslide/cmake/deps/cli11.cmake | 60 ++++++++++++------- 3 files changed, 111 insertions(+), 69 deletions(-) diff --git a/cpp/cmake/deps/cli11.cmake b/cpp/cmake/deps/cli11.cmake index 185913c8e..048363106 100644 --- a/cpp/cmake/deps/cli11.cmake +++ b/cpp/cmake/deps/cli11.cmake @@ -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 @@ -14,28 +14,42 @@ # if (NOT TARGET deps::cli11) - FetchContent_Declare( - deps-cli11 - GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git - GIT_TAG v1.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-cli11) - if (NOT deps-cli11_POPULATED) - message(STATUS "Fetching cli11 sources") - FetchContent_Populate(deps-cli11) - message(STATUS "Fetching cli11 sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + # Use cli11 headers from conda environment + find_path(cli11_INCLUDE_DIR + NAMES CLI/CLI.hpp + HINTS $ENV{CONDA_PREFIX}/include + ) - add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + if (NOT cli11_INCLUDE_DIR) + message(FATAL_ERROR "cli11 headers not found in conda environment") + endif () - add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) - set(deps-cli11_SOURCE_DIR ${deps-cli11_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-cli11_SOURCE_DIR) -endif () + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_include_directories(deps::cli11 INTERFACE ${cli11_INCLUDE_DIR}) + + set(cli11_INCLUDE_DIR ${cli11_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-cli11 + GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git + GIT_TAG v2.4.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-cli11) + if (NOT deps-cli11_POPULATED) + message(STATUS "Fetching cli11 sources") + FetchContent_Populate(deps-cli11) + message(STATUS "Fetching cli11 sources - done") + endif () -# Note that library had a failure with nvcc compiler and gcc 9.x headers -# ...c++/9/tuple(553): error: pack "_UElements" does not have the same number of elements as "_Elements" -# __and_...>::value; -# Not using nvcc for main code that uses cli11 solved the issue. + add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) + set(cli11_INCLUDE_DIR ${deps-cli11_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + endif () +endif () diff --git a/cpp/plugins/cucim.kit.cumed/cmake/deps/cli11.cmake b/cpp/plugins/cucim.kit.cumed/cmake/deps/cli11.cmake index 2afb77841..048363106 100644 --- a/cpp/plugins/cucim.kit.cumed/cmake/deps/cli11.cmake +++ b/cpp/plugins/cucim.kit.cumed/cmake/deps/cli11.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 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 @@ -14,28 +14,42 @@ # if (NOT TARGET deps::cli11) - FetchContent_Declare( - deps-cli11 - GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git - GIT_TAG v1.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-cli11) - if (NOT deps-cli11_POPULATED) - message(STATUS "Fetching cli11 sources") - FetchContent_Populate(deps-cli11) - message(STATUS "Fetching cli11 sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + # Use cli11 headers from conda environment + find_path(cli11_INCLUDE_DIR + NAMES CLI/CLI.hpp + HINTS $ENV{CONDA_PREFIX}/include + ) - add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + if (NOT cli11_INCLUDE_DIR) + message(FATAL_ERROR "cli11 headers not found in conda environment") + endif () - add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) - set(deps-cli11_SOURCE_DIR ${deps-cli11_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-cli11_SOURCE_DIR) -endif () + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_include_directories(deps::cli11 INTERFACE ${cli11_INCLUDE_DIR}) + + set(cli11_INCLUDE_DIR ${cli11_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-cli11 + GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git + GIT_TAG v2.4.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-cli11) + if (NOT deps-cli11_POPULATED) + message(STATUS "Fetching cli11 sources") + FetchContent_Populate(deps-cli11) + message(STATUS "Fetching cli11 sources - done") + endif () -# Note that library had a failure with nvcc compiler and gcc 9.x headers -# ...c++/9/tuple(553): error: pack "_UElements" does not have the same number of elements as "_Elements" -# __and_...>::value; -# Not using nvcc for main code that uses cli11 solved the issue. + add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) + set(cli11_INCLUDE_DIR ${deps-cli11_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + endif () +endif () diff --git a/cpp/plugins/cucim.kit.cuslide/cmake/deps/cli11.cmake b/cpp/plugins/cucim.kit.cuslide/cmake/deps/cli11.cmake index 185913c8e..048363106 100644 --- a/cpp/plugins/cucim.kit.cuslide/cmake/deps/cli11.cmake +++ b/cpp/plugins/cucim.kit.cuslide/cmake/deps/cli11.cmake @@ -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 @@ -14,28 +14,42 @@ # if (NOT TARGET deps::cli11) - FetchContent_Declare( - deps-cli11 - GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git - GIT_TAG v1.9.1 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-cli11) - if (NOT deps-cli11_POPULATED) - message(STATUS "Fetching cli11 sources") - FetchContent_Populate(deps-cli11) - message(STATUS "Fetching cli11 sources - done") - endif () + if (DEFINED ENV{CONDA_PREFIX}) + # Use cli11 headers from conda environment + find_path(cli11_INCLUDE_DIR + NAMES CLI/CLI.hpp + HINTS $ENV{CONDA_PREFIX}/include + ) - add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + if (NOT cli11_INCLUDE_DIR) + message(FATAL_ERROR "cli11 headers not found in conda environment") + endif () - add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) - set(deps-cli11_SOURCE_DIR ${deps-cli11_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-cli11_SOURCE_DIR) -endif () + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_include_directories(deps::cli11 INTERFACE ${cli11_INCLUDE_DIR}) + + set(cli11_INCLUDE_DIR ${cli11_INCLUDE_DIR} CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + else () + # Fallback to fetching fmt sources + FetchContent_Declare( + deps-cli11 + GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git + GIT_TAG v2.4.1 + GIT_SHALLOW TRUE + ) + FetchContent_GetProperties(deps-cli11) + if (NOT deps-cli11_POPULATED) + message(STATUS "Fetching cli11 sources") + FetchContent_Populate(deps-cli11) + message(STATUS "Fetching cli11 sources - done") + endif () -# Note that library had a failure with nvcc compiler and gcc 9.x headers -# ...c++/9/tuple(553): error: pack "_UElements" does not have the same number of elements as "_Elements" -# __and_...>::value; -# Not using nvcc for main code that uses cli11 solved the issue. + add_subdirectory(${deps-cli11_SOURCE_DIR} ${deps-cli11_BINARY_DIR} EXCLUDE_FROM_ALL) + + add_library(deps::cli11 INTERFACE IMPORTED GLOBAL) + target_link_libraries(deps::cli11 INTERFACE CLI11::CLI11) + set(cli11_INCLUDE_DIR ${deps-cli11_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) + mark_as_advanced(cli11_INCLUDE_DIR) + endif () +endif () From 568eb40077cd3b32175fd3744a9ac495f1fdc9f3 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 15:35:46 -0700 Subject: [PATCH 16/25] Update CONTRIBUTING guide Signed-off-by: Gigon Bae --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a05dee929..2c5b340eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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): From dd644c8f3640de11acdb69cf73b37cec00b1d72a Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 16:48:57 -0700 Subject: [PATCH 17/25] Update dependencies Signed-off-by: Gigon Bae --- conda/environments/all_cuda-118_arch-x86_64.yaml | 10 ++++++++++ conda/environments/all_cuda-125_arch-x86_64.yaml | 10 ++++++++++ conda/recipes/libcucim/meta.yaml | 9 +++++++++ dependencies.yaml | 12 ++++++++++++ 4 files changed, 41 insertions(+) diff --git a/conda/environments/all_cuda-118_arch-x86_64.yaml b/conda/environments/all_cuda-118_arch-x86_64.yaml index d657617b4..e5c7f3642 100644 --- a/conda/environments/all_cuda-118_arch-x86_64.yaml +++ b/conda/environments/all_cuda-118_arch-x86_64.yaml @@ -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 @@ -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 @@ -46,6 +55,7 @@ dependencies: - scipy>=1.6.0 - sphinx<6 - sysroot_linux-64==2.17 +- taskflow - tifffile>=2022.7.28 - xz - yasm diff --git a/conda/environments/all_cuda-125_arch-x86_64.yaml b/conda/environments/all_cuda-125_arch-x86_64.yaml index a193f5cdd..92d90feee 100644 --- a/conda/environments/all_cuda-125_arch-x86_64.yaml +++ b/conda/environments/all_cuda-125_arch-x86_64.yaml @@ -6,7 +6,10 @@ channels: - conda-forge - nvidia dependencies: +- boost-cpp - c-compiler +- catch2 +- cli11 - click - cmake>=3.26.4,!=3.30.0 - cuda-cudart-dev @@ -14,11 +17,13 @@ dependencies: - 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 @@ -26,13 +31,17 @@ dependencies: - 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 @@ -45,6 +54,7 @@ dependencies: - scipy>=1.6.0 - sphinx<6 - sysroot_linux-64==2.17 +- taskflow - tifffile>=2022.7.28 - xz - yasm diff --git a/conda/recipes/libcucim/meta.yaml b/conda/recipes/libcucim/meta.yaml index b373ffbbe..3be360d5d 100644 --- a/conda/recipes/libcucim/meta.yaml +++ b/conda/recipes/libcucim/meta.yaml @@ -74,10 +74,19 @@ requirements: - libnvjpeg-dev - libnvjpeg-static {% endif %} + - boost-cpp + - catch2 + - cli11 + - fmt - jbig + - libabseil - libwebp-base - nvtx-c >=3.1.0 + - nlohmann_json - openslide + - pybind11 + - pybind11_json + - taskflow - xz - zlib - zstd diff --git a/dependencies.yaml b/dependencies.yaml index 62e2ddefe..d690e65e8 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -101,6 +101,18 @@ dependencies: - output_types: [requirements, pyproject] packages: - wheel + - output_types: [conda] + packages: + - boost-cpp + - catch2 + - cli11 + - fmt + - libabseil + - nvtx-c >=3.1.0 + - nlohmann_json + - pybind11 + - pybind11_json + - taskflow specific: - output_types: conda matrices: From a2b2a170028aa1b1d2da2d074fad664577e6af97 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 16:57:12 -0700 Subject: [PATCH 18/25] Remove rmm.cmake Signed-off-by: Gigon Bae --- cpp/cmake/deps/rmm.cmake | 45 ---------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 cpp/cmake/deps/rmm.cmake diff --git a/cpp/cmake/deps/rmm.cmake b/cpp/cmake/deps/rmm.cmake deleted file mode 100644 index 9363ce188..000000000 --- a/cpp/cmake/deps/rmm.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright (c) 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. -# - -# Note: importing rmm is tricky as it depends on googletest/thrust/spdlog and can conflicts with target names in -# the original project. -# There is a suggestion in CMake but it seems that it takes time to resolve the issue. -# - Namespace support for target names in nested projects: https://gitlab.kitware.com/cmake/cmake/-/issues/16414 - -if (NOT TARGET deps::rmm) - FetchContent_Declare( - deps-rmm - GIT_REPOSITORY https://github.com/rapidsai/rmm.git - GIT_TAG branch-0.17 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(deps-rmm) - if (NOT deps-rmm_POPULATED) - message(STATUS "Fetching rmm sources") - FetchContent_Populate(deps-rmm) - message(STATUS "Fetching rmm sources - done") - endif () - - # Create shared library - cucim_set_build_shared_libs(ON) # Since rmm doesn't use BUILD_SHARED_LIBS, it always build shared library - - add_subdirectory(${deps-rmm_SOURCE_DIR} ${deps-rmm_BINARY_DIR} EXCLUDE_FROM_ALL) - cucim_restore_build_shared_libs() - - add_library(deps::rmm INTERFACE IMPORTED GLOBAL) - target_link_libraries(deps::rmm INTERFACE rmm) - set(deps-rmm_SOURCE_DIR ${deps-rmm_SOURCE_DIR} CACHE INTERNAL "" FORCE) - mark_as_advanced(deps-rmm_SOURCE_DIR) -endif () From 55f077fbf0fe57a95f156f0bb7fcdb60319904b6 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 17:57:02 -0700 Subject: [PATCH 19/25] Update cucim dependencies (python) Signed-off-by: Gigon Bae --- conda/recipes/cucim/meta.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/conda/recipes/cucim/meta.yaml b/conda/recipes/cucim/meta.yaml index 7bd205bb6..4453c28fe 100644 --- a/conda/recipes/cucim/meta.yaml +++ b/conda/recipes/cucim/meta.yaml @@ -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 From 6785f4c652561ae46e742729de8aae1ac97936c9 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 18:47:41 -0700 Subject: [PATCH 20/25] Fix abseil.cmake for building from source code Signed-off-by: Gigon Bae --- cpp/cmake/deps/abseil.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cpp/cmake/deps/abseil.cmake b/cpp/cmake/deps/abseil.cmake index 98476217b..0e3d5b9ef 100644 --- a/cpp/cmake/deps/abseil.cmake +++ b/cpp/cmake/deps/abseil.cmake @@ -44,6 +44,16 @@ if (NOT TARGET 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) From e0dad71f76b5a549a6729c43b0ff570da989985f Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Wed, 31 Jul 2024 23:40:05 -0700 Subject: [PATCH 21/25] Fix boost-header-only.cmake to work with Boost v1.85.0 Signed-off-by: Gigon Bae --- cpp/cmake/deps/boost-header-only.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/cmake/deps/boost-header-only.cmake b/cpp/cmake/deps/boost-header-only.cmake index 290eeaac2..016a2be6c 100644 --- a/cpp/cmake/deps/boost-header-only.cmake +++ b/cpp/cmake/deps/boost-header-only.cmake @@ -15,7 +15,7 @@ if (NOT TARGET deps::boost-header-only) set(Boost_VERSION 1.85.0) - set(boost_component_list "interprocess" "config" "intrusive" "move" "assert" "static_assert" "container" "core" "date_time" "smart_ptr" "throw_exception" "utility" "type_traits" "numeric/conversion" "mpl" "preprocessor" "container_hash" "integer" "detail") + set(boost_component_list "interprocess" "config" "intrusive" "move" "assert" "static_assert" "container" "core" "date_time" "smart_ptr" "throw_exception" "utility" "type_traits" "numeric/conversion" "mpl" "preprocessor" "container_hash" "integer" "detail" "describe" "mp11") if (DEFINED ENV{CONDA_PREFIX}) # Use boost headers from conda environment From 4ddd93293056c26b94a71bb6582bad1b60a248e9 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Thu, 1 Aug 2024 09:53:17 -0700 Subject: [PATCH 22/25] Add libabseil dependency to run Signed-off-by: Gigon Bae --- conda/recipes/libcucim/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/conda/recipes/libcucim/meta.yaml b/conda/recipes/libcucim/meta.yaml index 3be360d5d..5fb7e1ade 100644 --- a/conda/recipes/libcucim/meta.yaml +++ b/conda/recipes/libcucim/meta.yaml @@ -101,6 +101,7 @@ requirements: - libnvjpeg {% endif %} - {{ pin_compatible('libwebp-base', max_pin='x.x') }} + - libabseil - jbig - xz - zlib From 03127d29a28724cf8363601c3a5545f8838f3faf Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Thu, 1 Aug 2024 11:09:14 -0700 Subject: [PATCH 23/25] Build with CXX11 ABI only Signed-off-by: Gigon Bae --- CMakeLists.txt | 4 ---- cpp/CMakeLists.txt | 1 - cpp/include/cucim/io/format/image_format.h | 19 ------------------- cpp/plugins/cucim.kit.cumed/CMakeLists.txt | 4 ---- cpp/plugins/cucim.kit.cuslide/CMakeLists.txt | 4 ---- python/CMakeLists.txt | 4 ---- 6 files changed, 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68ca8ff9b..3ee73f42a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6cdc6ecf2..cb0ce08ee 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -139,7 +139,6 @@ target_compile_definitions(${CUCIM_PACKAGE_NAME} CUCIM_STATIC_GDS=$ CUCIM_SUPPORT_CUDA=$ CUCIM_SUPPORT_NVTX=$ - _GLIBCXX_USE_CXX11_ABI=0 # TODO: create two library, one with CXX11 ABI and one without it. ) # Link libraries diff --git a/cpp/include/cucim/io/format/image_format.h b/cpp/include/cucim/io/format/image_format.h index c83f72dc9..8ef820c69 100644 --- a/cpp/include/cucim/io/format/image_format.h +++ b/cpp/include/cucim/io/format/image_format.h @@ -119,10 +119,6 @@ class EXPORT_VISIBLE ImageMetadata std::array buffer_{}; std::pmr::monotonic_buffer_resource res_{ buffer_.data(), sizeof(buffer_) }; -// manylinux2014 requires gcc4-compatible libstdcxx-abi(gcc is configured with -// '--with-default-libstdcxx-abi=gcc4-compatible', https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html) which -// forces to set _GLIBCXX_USE_CXX11_ABI=0 so std::pmr::string wouldn't be available on CentOS 7. -#if _GLIBCXX_USE_CXX11_ABI std::pmr::string dims_{ &res_ }; std::pmr::vector shape_{ &res_ }; std::pmr::vector channel_names_{ &res_ }; @@ -137,22 +133,7 @@ class EXPORT_VISIBLE ImageMetadata std::pmr::vector level_tile_sizes_{ &res_ }; std::pmr::vector image_names_{ &res_ }; -#else - std::string dims_; - std::pmr::vector shape_{ &res_ }; - std::pmr::vector channel_names_{ &res_ }; - std::pmr::vector spacing_{ &res_ }; - std::pmr::vector spacing_units_{ &res_ }; - std::pmr::vector origin_{ &res_ }; - std::pmr::vector direction_{ &res_ }; - std::string coord_sys_; - std::pmr::vector level_dimensions_{ &res_ }; - std::pmr::vector level_downsamples_{ &res_ }; - std::pmr::vector level_tile_sizes_{ &res_ }; - - std::pmr::vector image_names_{ &res_ }; -#endif // Memory for raw_data and json_data needs to be created with cucim_malloc(); }; diff --git a/cpp/plugins/cucim.kit.cumed/CMakeLists.txt b/cpp/plugins/cucim.kit.cumed/CMakeLists.txt index fae4049be..7aea7bb69 100644 --- a/cpp/plugins/cucim.kit.cumed/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cumed/CMakeLists.txt @@ -105,10 +105,6 @@ include(ExternalProject) # Options ################################################################################ -# 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 dependencies diff --git a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt index 89fea7a33..64e4abc10 100644 --- a/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt +++ b/cpp/plugins/cucim.kit.cuslide/CMakeLists.txt @@ -105,10 +105,6 @@ include(ExternalProject) # Options ################################################################################ -# 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 dependencies diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index a21b1df09..b25a533be 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -89,10 +89,6 @@ include(ExternalProject) # Options ################################################################################ -# 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 dependencies From f5be43c0fe2548d67ac2f09a36423608008f328b Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Thu, 1 Aug 2024 14:55:42 -0700 Subject: [PATCH 24/25] Reduce the shared memory size in the test case to avoid the error Signed-off-by: Gigon Bae --- python/cucim/tests/unit/clara/test_image_cache.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/cucim/tests/unit/clara/test_image_cache.py b/python/cucim/tests/unit/clara/test_image_cache.py index 258e01da4..be651b2a1 100644 --- a/python/cucim/tests/unit/clara/test_image_cache.py +++ b/python/cucim/tests/unit/clara/test_image_cache.py @@ -68,12 +68,12 @@ def test_get_per_process_cache(): def test_get_shared_memory_cache(): from cucim import CuImage - cache = CuImage.cache("shared_memory", memory_capacity=2048) + cache = CuImage.cache("shared_memory", memory_capacity=128) assert int(cache.type) == 2 assert cache.memory_size == 0 # It allocates additional memory - assert cache.memory_capacity > 2**20 * 2048 - assert cache.free_memory > 2**20 * 2048 + assert cache.memory_capacity > 2**20 * 128 + assert cache.free_memory > 2**20 * 128 assert cache.size == 0 assert cache.capacity > 0 assert cache.hit_count == 0 @@ -81,11 +81,11 @@ def test_get_shared_memory_cache(): config = cache.config # Check essential properties - # {'type': 'shared_memory', 'memory_capacity': 2048, 'capacity': 10922, - # 'mutex_pool_capacity': 11117, 'list_padding': 10000, + # {'type': 'shared_memory', 'memory_capacity': 2048, 'capacity': 682, + # 'mutex_pool_capacity': 100003, 'list_padding': 10000, # 'extra_shared_memory_size': 100, 'record_stat': False} assert config["type"] == "shared_memory" - assert config["memory_capacity"] == 2048 + assert config["memory_capacity"] == 128 assert not config["record_stat"] From 20ff9970cc318ed6d6b4ba233c7ec2ff02a20433 Mon Sep 17 00:00:00 2001 From: Gigon Bae Date: Tue, 1 Oct 2024 15:38:21 -0700 Subject: [PATCH 25/25] Test shared memory cache with reduced size It looks like the RAPIDS CI/CD is launching the docker container with a reduced shared memory size. This is causing the shared memory cache to be failed with 'RuntimeError: No space left on device'. Signed-off-by: Gigon Bae --- python/cucim/tests/unit/clara/test_image_cache.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/cucim/tests/unit/clara/test_image_cache.py b/python/cucim/tests/unit/clara/test_image_cache.py index be651b2a1..947539fcf 100644 --- a/python/cucim/tests/unit/clara/test_image_cache.py +++ b/python/cucim/tests/unit/clara/test_image_cache.py @@ -68,12 +68,12 @@ def test_get_per_process_cache(): def test_get_shared_memory_cache(): from cucim import CuImage - cache = CuImage.cache("shared_memory", memory_capacity=128) + cache = CuImage.cache("shared_memory", memory_capacity=32) assert int(cache.type) == 2 assert cache.memory_size == 0 # It allocates additional memory - assert cache.memory_capacity > 2**20 * 128 - assert cache.free_memory > 2**20 * 128 + assert cache.memory_capacity > 2**20 * 32 + assert cache.free_memory > 2**20 * 32 assert cache.size == 0 assert cache.capacity > 0 assert cache.hit_count == 0 @@ -81,11 +81,11 @@ def test_get_shared_memory_cache(): config = cache.config # Check essential properties - # {'type': 'shared_memory', 'memory_capacity': 2048, 'capacity': 682, + # {'type': 'shared_memory', 'memory_capacity': 32, 'capacity': 170, # 'mutex_pool_capacity': 100003, 'list_padding': 10000, # 'extra_shared_memory_size': 100, 'record_stat': False} assert config["type"] == "shared_memory" - assert config["memory_capacity"] == 128 + assert config["memory_capacity"] == 32 assert not config["record_stat"]