Skip to content

Commit cdd2c2f

Browse files
committed
Add vcpkg mkl
1 parent 0030847 commit cdd2c2f

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

.github/workflows/vcpkg.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
# Exclude test_sumProduct and test_sumProduct_chain from pytest on windows.
3232
# These tests should be fixed for windows.
3333
pytest_extra_flags: -k "not test_sumProduct"
34+
additional_vcpkg_ports: intel-mkl
3435
- os: ubuntu-latest
3536
triplet: x64-linux-release
3637
build_type: Release
@@ -40,6 +41,8 @@ jobs:
4041
# vcpkg compile external metis, while test are configured to use vendored metis.
4142
# Need to debug and fix it.
4243
ctest_extra_flags: -E "testFindSeparator"
44+
additional_vcpkg_ports: intel-mkl
45+
cxxflags: -DCMAKE_CXX_FLAGS="-Wno-error=maybe-uninitialized"
4346
- os: macos-latest
4447
triplet: arm64-osx-release
4548
build_type: Release
@@ -106,6 +109,7 @@ jobs:
106109
tbb
107110
pybind11
108111
geographiclib
112+
${{ matrix.additional_vcpkg_ports }}
109113
110114
- name: copy files for hash
111115
shell: bash
@@ -136,7 +140,18 @@ jobs:
136140
if: success()
137141
shell: bash
138142
run: |
139-
export CL=-openmp
143+
# This is due an warning as error found in linux gtsam code:
144+
# In file included from include/Eigen/Core:370,
145+
# from include/Eigen/Dense:1,
146+
# from gtsam/base/OptionalJacobian.h:24,
147+
# from gtsam/base/Matrix.h:27,
148+
# from gtsam/linear/GaussianFactor.h:24,
149+
# from gtsam/linear/HessianFactor.h:21,
150+
# from gtsam/linear/HessianFactor.cpp:18:
151+
# In static member function ‘static void Eigen::internal::selfadjoint_matrix_vector_product<double, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, 0>::run(Index, const double*, Index, const double*, double*, double) [with Index = long int; int StorageOrder = 1; int UpLo = 1; bool ConjugateLhs = false; bool ConjugateRhs = false]’,
152+
# inlined from ‘static void Eigen::internal::selfadjoint_product_impl<Lhs, LhsMode, false, Rhs, 0, true>::run(Dest&, const Lhs&, const Rhs&, const Scalar&) [with Dest = Eigen::Transpose<Eigen::Matrix<double, 1, -1> >; Lhs = Eigen::Transpose<const Eigen::Block<const Eigen::Matrix<double, -1, -1>, -1, -1, false> >; int LhsMode = 1; Rhs = Eigen::Transpose<const Eigen::Transpose<const Eigen::Matrix<double, -1, 1> > >]’ at include/Eigen/src/Core/products/SelfadjointMatrixVector.h:229:7:
153+
# include/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h:69:1: error: ‘result’ may be used uninitialized [-Werror=maybe-uninitialized]
154+
# 69 | EIGEN_BLAS_SYMV_SPECIALIZE(double)
140155
141156
cmake . -B build -G Ninja \
142157
-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake \
@@ -155,8 +170,11 @@ jobs:
155170
-DGTSAM_USE_SYSTEM_METIS=ON \
156171
-DGTSAM_USE_SYSTEM_PYBIND=ON \
157172
-DGTSAM_SUPPORT_NESTED_DISSECTION=ON \
173+
-DGTSAM_WITH_EIGEN_MKL=ON \
174+
-DGTSAM_WITH_EIGEN_MKL_OPENMP=ON \
158175
-DCTEST_EXTRA_ARGS='${{ matrix.ctest_extra_flags }}' \
159-
-DPYTEST_EXTRA_ARGS='${{ matrix.pytest_extra_flags }}'
176+
-DPYTEST_EXTRA_ARGS='${{ matrix.pytest_extra_flags }}' \
177+
${{ matrix.cxxflags }}
160178
161179
- name: cmake build
162180
shell: bash
@@ -174,4 +192,7 @@ jobs:
174192
- name: Run tests
175193
shell: bash
176194
run: |
195+
VCPKG_BASH_PATH="${VCPKG_INSTALLATION_ROOT//\\//}" # backslashes -> slashes
196+
VCPKG_BASH_PATH="/${VCPKG_BASH_PATH/:/}" # drop colon, add leading /
197+
export PATH="$PATH:$VCPKG_BASH_PATH/installed/${{ matrix.triplet }}/bin"
177198
cmake --build build --config ${{ matrix.build_type }} --target check

cmake/FindMKL.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
# OPEN - Open MPI library
2222
# SGI - SGI MPT Library
2323

24+
# vcpkg
25+
if(DEFINED VCPKG_INSTALLED_DIR)
26+
find_package(MKL CONFIG)
27+
if(MKL_FOUND)
28+
add_library(mkl-gtsam-if INTERFACE)
29+
target_link_libraries(mkl-gtsam-if INTERFACE MKL::MKL)
30+
set(MKL_LIBRARIES mkl-gtsam-if)
31+
list(APPEND GTSAM_EXPORTED_TARGETS mkl-gtsam-if)
32+
install(TARGETS mkl-gtsam-if EXPORT GTSAM-exports ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
33+
endif()
34+
else()
35+
2436
# linux
2537
IF(UNIX AND NOT APPLE)
2638
IF(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
@@ -267,4 +279,6 @@ find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INCLUDE_DIR MKL_LIBRARIES)
267279
# LINK_DIRECTORIES(${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR}) # hack
268280
#endif()
269281

282+
endif() # end of vcpkg
283+
270284
MARK_AS_ADVANCED(MKL_INCLUDE_DIR MKL_LIBRARIES)

cmake/HandleMKL.cmake

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ find_package(MKL)
44

55
if(MKL_FOUND AND GTSAM_WITH_EIGEN_MKL)
66
set(GTSAM_USE_EIGEN_MKL 1) # This will go into config.h
7-
set(EIGEN_USE_MKL_ALL 1) # This will go into config.h - it makes Eigen use MKL
7+
if(VCPKG_INSTALLED_DIR)
8+
set(EIGEN_USE_MKL_ALL 0)
9+
add_compile_definitions(EIGEN_USE_BLAS EIGEN_USE_MKL EIGEN_USE_MKL_VML)
10+
else()
11+
set(EIGEN_USE_MKL_ALL 1) # This will go into config.h - it makes Eigen use MKL
12+
endif()
813
list(APPEND GTSAM_ADDITIONAL_LIBRARIES ${MKL_LIBRARIES})
914

1015
# --no-as-needed is required with gcc according to the MKL link advisor
@@ -15,3 +20,28 @@ else()
1520
set(GTSAM_USE_EIGEN_MKL 0)
1621
set(EIGEN_USE_MKL_ALL 0)
1722
endif()
23+
24+
if(WIN32 AND GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
25+
get_target_property(MKL_TARGETS "MKL::MKL" INTERFACE_LINK_LIBRARIES)
26+
set(RUNTIME_DLL_DIRS "")
27+
foreach(MKL_TARGET ${MKL_TARGETS})
28+
if(TARGET ${MKL_TARGET})
29+
get_target_property(MKL_DLL "${MKL_TARGET}" IMPORTED_LOCATION)
30+
if(MKL_DLL)
31+
cmake_path(GET MKL_DLL PARENT_PATH MKL_DLL_DIR)
32+
list (APPEND RUNTIME_DLL_DIRS "${MKL_DLL_DIR}/mkl_*.dll")
33+
endif()
34+
endif()
35+
endforeach()
36+
list(REMOVE_DUPLICATES RUNTIME_DLL_DIRS)
37+
file(GLOB MKL_DLLS CONFIGURE_DEPENDS ${RUNTIME_DLL_DIRS})
38+
list(REMOVE_DUPLICATES MKL_DLLS)
39+
add_custom_target(copy_mkl_dlls
40+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
41+
"${MKL_DLLS}"
42+
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
43+
COMMAND_EXPAND_LISTS
44+
VERBATIM
45+
)
46+
endif()
47+
add_dependencies(check copy_mkl_dlls)

python/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ if(WIN32)
149149
COMMAND_EXPAND_LISTS
150150
VERBATIM
151151
)
152+
if(GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
153+
ADD_CUSTOM_COMMAND(TARGET ${GTSAM_PYTHON_TARGET} POST_BUILD
154+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
155+
"${MKL_DLLS}"
156+
"${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam/"
157+
COMMAND_EXPAND_LISTS
158+
VERBATIM
159+
)
160+
endif()
152161
endif()
153162

154163
# Set the path for the GTSAM python module
@@ -263,6 +272,15 @@ if(GTSAM_UNSTABLE_BUILD_PYTHON)
263272
COMMAND_EXPAND_LISTS
264273
VERBATIM
265274
)
275+
if(GTSAM_USE_EIGEN_MKL AND DEFINED VCPKG_INSTALLED_DIR)
276+
ADD_CUSTOM_COMMAND(TARGET ${GTSAM_PYTHON_UNSTABLE_TARGET} POST_BUILD
277+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
278+
"${MKL_DLLS}"
279+
"${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable/"
280+
COMMAND_EXPAND_LISTS
281+
VERBATIM
282+
)
283+
endif()
266284
endif()
267285

268286
add_custom_target(

0 commit comments

Comments
 (0)