Skip to content

Commit e464cab

Browse files
committed
Improve support for MKL
1 parent fe13875 commit e464cab

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

dynadjust/CMakeLists.txt

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cmake_minimum_required(VERSION 3.15)
22
project(dynadjust VERSION 1.2.9)
33

4-
option(BUILD_TESTING "Enable testing" OFF)
4+
option(BUILD_TESTING "Enable testing" ON)
55
option(BUILD_STATIC "Build static binaries in the 'static' directory" OFF)
6-
option(USE_MKL "Use Intel MKL (Linux and Windows)" OFF)
6+
option(USE_MKL "Use Intel MKL (Linux and Windows)" ON)
77
option(USE_OPENMP_MAC "Use OpenMP on macOS (requires `brew install libomp`)" OFF)
88
option(ILP64 "Use ILP64 Interface for BLAS and LAPACK" OFF)
99

10-
set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
10+
set(CMAKE_DISABLE_PRECOMPILE_HEADERS OFF)
1111

1212
# Fix Boost 1.70+ issue with CMake 3.14+
1313
if(POLICY CMP0167)
@@ -279,25 +279,44 @@ if(APPLE)
279279
endif()
280280
list(APPEND DNA_LIBRARIES ${ACCELERATE_LIB})
281281

282-
elseif(WIN32)
282+
elseif (WIN32)
283+
message(STATUS "Looking for BLAS and LAPACK on Windows (BLA_VENDOR=${BLA_VENDOR})")
283284
if (USE_MKL)
284285
add_compile_options("-DUSE_MKL")
285286
if (ILP64)
286287
set(BLA_VENDOR "Intel10_64ilp" CACHE STRING "Force MKL" FORCE)
287288
else()
288289
set(BLA_VENDOR "Intel10_64lp" CACHE STRING "Force MKL" FORCE)
289290
endif()
290-
else()
291-
set(BLA_VENDOR "OpenBLAS" CACHE STRING "Force OpenBLAS" FORCE)
292-
endif()
293291

294-
message(STATUS "Looking for BLAS and LAPACK on Windows (BLA_VENDOR=${BLA_VENDOR})")
292+
message(STATUS "BLA_VENDOR=${BLA_VENDOR}")
293+
294+
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKL_ROOT})
295+
set (BLAS_LIBRARIES, ${MKL_REQUESTED_LIBRARIES})
296+
set(BLAS_INCLUDE_DIRS, ${MKL_INCLUDE})
297+
message(STATUS "MKL_INCLUDE=${MKL_INCLUDE}")
298+
message(STATUS "MKL_LIB_DIR=${MKL_ROOT}/lib")
299+
message(STATUS "DLL_EXT=${DLL_EXT}")
300+
include_directories(${MKL_INCLUDE})
301+
link_directories("${MKL_ROOT}/lib")
302+
303+
foreach(lib ${MKL_REQUESTED_LIBRARIES})
304+
get_filename_component(libname ${lib} NAME_WLE)
305+
list(APPEND MKL_REQUESTED_DLL_LIBRARIES "${libname}_dll")
306+
endforeach()
295307

296-
find_package(BLAS REQUIRED)
297-
add_link_options(${BLAS_LINKER_FLAGS})
298-
message(STATUS "BLAS_LINKER_FLAGS=${BLAS_LINKER_FLAGS}")
299-
message(STATUS "BLAS_LIBRARIES=${BLAS_LIBRARIES}")
300-
list(APPEND DNA_LIBRARIES ${BLAS_LIBRARIES})
308+
message(STATUS "MKL_REQUESTED_DLL_LIBRARIES=${MKL_REQUESTED_DLL_LIBRARIES}")
309+
310+
list(APPEND DNA_LIBRARIES ${MKL_REQUESTED_DLL_LIBRARIES})
311+
else()
312+
set(BLA_VENDOR "OpenBLAS" CACHE STRING "Force OpenBLAS" FORCE)
313+
find_package(BLAS REQUIRED)
314+
add_link_options(${BLAS_LINKER_FLAGS})
315+
message(STATUS "BLAS_LINKER_FLAGS=${BLAS_LINKER_FLAGS}")
316+
message(STATUS "BLAS_LIBRARIES=${BLAS_LIBRARIES}")
317+
list(APPEND DNA_LIBRARIES ${BLAS_LIBRARIES})
318+
endif()
319+
301320

302321
if (NOT USE_MKL)
303322
set(BLA_VENDOR "Generic" CACHE STRING "Force Generic" FORCE)
@@ -311,7 +330,7 @@ elseif(WIN32)
311330
list(APPEND DNA_LIBRARIES ${LAPACK_LIBRARIES})
312331
endif()
313332

314-
if(NOT USE_MKL)
333+
if (NOT USE_MKL)
315334
# Find OpenBLAS package which should set include directories
316335
find_package(OpenBLAS CONFIG QUIET)
317336
if(OpenBLAS_FOUND)
@@ -379,7 +398,8 @@ elseif(UNIX)
379398
list(APPEND DNA_LIBRARIES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
380399
endif()
381400
endif()
382-
401+
else()
402+
message(STATUS "Here is something dandy")
383403
endif()
384404

385405
message(STATUS "DynAdjust library dependencies: ${DNA_LIBRARIES}")

dynadjust/CMakePresets.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"configurePresets": [
66
{
7-
"name": "vs-x64",
7+
"name": "vs-x64-openblas",
88
"displayName": "VS2022 x64 (vcpkg)",
99
"generator": "Visual Studio 17 2022",
1010
"architecture": { "value": "x64" },
@@ -13,15 +13,34 @@
1313
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
1414
"VCPKG_TARGET_TRIPLET": "x64-windows"
1515
}
16+
},
17+
{
18+
"name": "vs-x64-mkl",
19+
"displayName": "VS2022 x64 (vcpkg)",
20+
"generator": "Visual Studio 17 2022",
21+
"architecture": { "value": "x64" },
22+
"binaryDir": "${sourceParentDir}/build/",
23+
"cacheVariables": {
24+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
25+
"VCPKG_TARGET_TRIPLET": "x64-windows",
26+
"CMAKE_PREFIX_PATH": "C:\\Program Files (x86)\\Intel\\oneAPI\\mkl\\2025.2\\lib\\cmake\\mkl;$env{CMAKE_PREFIX_PATH}",
27+
"USE_MKL": "ON",
28+
"MKL_ARCH": "intel64",
29+
"MKL_MPI": "intelmpi",
30+
"MKL_LINK": "dynamic",
31+
"MKL_INTERFACE": "lp64",
32+
"ENABLE_SCALAPACK": "True",
33+
"BLA_VENDOR": "Intel10_64lp"
34+
}
1635
}
1736
],
1837

1938
"buildPresets": [
20-
{ "name": "build-debug", "configurePreset": "vs-x64", "configuration": "Debug" },
21-
{ "name": "build-release", "configurePreset": "vs-x64", "configuration": "Release" }
39+
{ "name": "build-debug", "configurePreset": "vs-x64-mkl", "configuration": "Debug" },
40+
{ "name": "build-release", "configurePreset": "vs-x64-mkl", "configuration": "Release" }
2241
],
2342

2443
"testPresets": [
25-
{ "name": "ctest", "configurePreset": "vs-x64", "configuration": "Debug" }
44+
{ "name": "ctest", "configurePreset": "vs-x64-mkl", "configuration": "Debug" }
2645
]
2746
}

dynadjust/include/config/dnaversion.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ const char* const __dynadjust_app_name__ = "dynadjust";
125125

126126
#if defined(__APPLE__) // Apple Accelerate framework // (-DACCELERATE_LAPACK_ILP64=1 for ILP64)
127127
#define __LINEAR_ALGEBRA_LIB__ "OpenBLAS"
128-
#elif (defined(_WIN32) && !defined(MKL_ILP64) && !defined(MKL_LP64)) // Windows - No LAPACKE and no MKL
128+
#elif (defined(_WIN32) && !defined(USE_MKL)) // Windows - No LAPACKE and no MKL
129129
#define __LINEAR_ALGEBRA_LIB__ "OpenBLAS"
130-
#elif (defined(MKL_ILP64) || defined(MKL_LP64)) // Linux or Windows - Intel MKL with ILP64
130+
#elif (defined(_WIN32) && defined(USE_MKL)) // Linux or Windows - Intel MKL with ILP64
131131
#define __LINEAR_ALGEBRA_LIB__ "Intel MKL"
132132
#else // LAPACKE fall back
133133
#define __LINEAR_ALGEBRA_LIB__ "OpenBLAS"

0 commit comments

Comments
 (0)