Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ jobs:
# Exclude test_sumProduct and test_sumProduct_chain from pytest on windows.
# These tests should be fixed for windows.
pytest_extra_flags: -k "not test_sumProduct"
additional_vcpkg_ports: intel-mkl
- os: ubuntu-latest
triplet: x64-linux-release
build_type: Release
test_target: test
binary_cache: /home/runner/.cache/vcpkg/archives
python: python3
additional_vcpkg_ports: intel-mkl
cxxflags: -DCMAKE_CXX_FLAGS="-Wno-error=maybe-uninitialized"
- os: macos-latest
triplet: arm64-osx-release
build_type: Release
Expand Down Expand Up @@ -78,6 +81,14 @@ jobs:
run: |
brew install autoconf automake autoconf-archive

- name: "Install dependencies"
shell: bash
run: |
git -C ${VCPKG_INSTALLATION_ROOT} checkout .
git -C ${VCPKG_INSTALLATION_ROOT} remote add talregev https://github.com/talregev/vcpkg/
git -C ${VCPKG_INSTALLATION_ROOT} pull --rebase --all
git -C ${VCPKG_INSTALLATION_ROOT} switch TalR/mkl

- name: "Install dependencies"
run: >
vcpkg x-set-installed --triplet ${{ matrix.triplet }} --host-triplet ${{ matrix.triplet }}
Expand All @@ -98,6 +109,7 @@ jobs:
eigen3
tbb
pybind11
${{ matrix.additional_vcpkg_ports }}

- name: copy files for hash
shell: bash
Expand Down Expand Up @@ -128,7 +140,10 @@ jobs:
if: success()
shell: bash
run: |
export CL=-openmp
# This is due an warning as error found in linux gtsam code when compile with MKL.
# error: ‘result’ may be used uninitialized [-Werror=maybe-uninitialized]
# staring from from gtsam/linear/HessianFactor.cpp:18
# Remove ${{ matrix.cxxflags }} when you fix the warning in gtsam code.

cmake . -B build -G Ninja \
-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake \
Expand All @@ -147,8 +162,11 @@ jobs:
-DGTSAM_USE_SYSTEM_METIS=OFF \
-DGTSAM_USE_SYSTEM_PYBIND=ON \
-DGTSAM_SUPPORT_NESTED_DISSECTION=ON \
-DGTSAM_WITH_EIGEN_MKL=ON \
-DGTSAM_WITH_EIGEN_MKL_OPENMP=ON \
-DCTEST_EXTRA_ARGS='${{ matrix.ctest_extra_flags }}' \
-DPYTEST_EXTRA_ARGS='${{ matrix.pytest_extra_flags }}'
-DPYTEST_EXTRA_ARGS='${{ matrix.pytest_extra_flags }}' \
${{ matrix.cxxflags }}

- name: cmake build
shell: bash
Expand Down
14 changes: 14 additions & 0 deletions cmake/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
# OPEN - Open MPI library
# SGI - SGI MPT Library

# vcpkg
if(DEFINED VCPKG_INSTALLED_DIR)
find_package(MKL CONFIG)
if(MKL_FOUND)
add_library(mkl-gtsam-if INTERFACE)
target_link_libraries(mkl-gtsam-if INTERFACE MKL::MKL)
set(MKL_LIBRARIES mkl-gtsam-if)
list(APPEND GTSAM_EXPORTED_TARGETS mkl-gtsam-if)
install(TARGETS mkl-gtsam-if EXPORT GTSAM-exports ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
else()

# linux
IF(UNIX AND NOT APPLE)
IF(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
Expand Down Expand Up @@ -267,4 +279,6 @@ find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INCLUDE_DIR MKL_LIBRARIES)
# LINK_DIRECTORIES(${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR}) # hack
#endif()

endif() # end of vcpkg

MARK_AS_ADVANCED(MKL_INCLUDE_DIR MKL_LIBRARIES)
32 changes: 31 additions & 1 deletion cmake/HandleMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ find_package(MKL)

if(MKL_FOUND AND GTSAM_WITH_EIGEN_MKL)
set(GTSAM_USE_EIGEN_MKL 1) # This will go into config.h
set(EIGEN_USE_MKL_ALL 1) # This will go into config.h - it makes Eigen use MKL
if(VCPKG_INSTALLED_DIR)
set(EIGEN_USE_MKL_ALL 0)
add_compile_definitions(EIGEN_USE_BLAS EIGEN_USE_MKL EIGEN_USE_MKL_VML)
else()
set(EIGEN_USE_MKL_ALL 1) # This will go into config.h - it makes Eigen use MKL
endif()
list(APPEND GTSAM_ADDITIONAL_LIBRARIES ${MKL_LIBRARIES})

# --no-as-needed is required with gcc according to the MKL link advisor
Expand All @@ -15,3 +20,28 @@ else()
set(GTSAM_USE_EIGEN_MKL 0)
set(EIGEN_USE_MKL_ALL 0)
endif()

if(WIN32 AND GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
get_target_property(MKL_TARGETS "MKL::MKL" INTERFACE_LINK_LIBRARIES)
set(RUNTIME_DLL_DIRS "")
foreach(MKL_TARGET ${MKL_TARGETS})
if(TARGET ${MKL_TARGET})
get_target_property(MKL_DLL "${MKL_TARGET}" IMPORTED_LOCATION)
if(MKL_DLL)
cmake_path(GET MKL_DLL PARENT_PATH MKL_DLL_DIR)
list (APPEND RUNTIME_DLL_DIRS "${MKL_DLL_DIR}/mkl_*.dll")
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES RUNTIME_DLL_DIRS)
file(GLOB MKL_DLLS CONFIGURE_DEPENDS ${RUNTIME_DLL_DIRS})
list(REMOVE_DUPLICATES MKL_DLLS)
add_custom_target(copy_mkl_dlls
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${MKL_DLLS}"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
COMMAND_EXPAND_LISTS
VERBATIM
)
add_dependencies(check copy_mkl_dlls)
endif()
18 changes: 18 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ if(WIN32)
COMMAND_EXPAND_LISTS
VERBATIM
)
if(GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
ADD_CUSTOM_COMMAND(TARGET ${GTSAM_PYTHON_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${MKL_DLLS}"
"${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam/"
COMMAND_EXPAND_LISTS
VERBATIM
)
endif()
endif()

# Set the path for the GTSAM python module
Expand Down Expand Up @@ -263,6 +272,15 @@ if(GTSAM_UNSTABLE_BUILD_PYTHON)
COMMAND_EXPAND_LISTS
VERBATIM
)
if(GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
ADD_CUSTOM_COMMAND(TARGET ${GTSAM_PYTHON_UNSTABLE_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${MKL_DLLS}"
"${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable/"
COMMAND_EXPAND_LISTS
VERBATIM
)
endif()
endif()

add_custom_target(
Expand Down
Loading