Skip to content

Commit

Permalink
Merge branch 'mkl-find' into 'master'
Browse files Browse the repository at this point in the history
[cmake] Refactored MKL find logic to use CONFIG mode

See merge request ogs/ogs!4789
  • Loading branch information
bilke committed Nov 10, 2023
2 parents ca441a9 + dffad4e commit 29e136f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 395 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ if(MSVC)
endif()

option(OGS_USE_MKL "Use Intel MKL" OFF)
if(OGS_USE_MKL)
option(MKL_USE_parallel "Use MKL parallel" True)
option(MKL_USE_sdl "Single Dynamic Library or static/dynamic" False)
set(MKL_USE_interface
"lp64"
CACHE
STRING
"for Intel(R)64 compatible arch: ilp64/lp64 or for ia32 arch: cdecl/stdcall"
)
endif()

# Eigen
option(OGS_USE_EIGEN_UNSUPPORTED "Use Eigen unsupported modules" ON)
Expand Down
8 changes: 1 addition & 7 deletions MathLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,14 @@ target_link_libraries(
$<$<BOOL:${OGS_USE_LIS}>:${LIS_LIBRARIES}>
$<$<BOOL:${OGS_USE_CVODE}>:CVODE::CVODE>
$<$<BOOL:${OGS_USE_PETSC}>:petsc>
$<$<BOOL:${OGS_USE_MKL}>:MKL::MKL>
Eigen3::Eigen
$<$<TARGET_EXISTS:OpenMP::OpenMP_CXX>:OpenMP::OpenMP_CXX>
)

if(OGS_USE_LIS)
target_include_directories(MathLib PUBLIC ${LIS_INCLUDE_DIR})
endif()
if(OGS_USE_MKL)
target_include_directories(MathLib PUBLIC ${MKL_INCLUDE_DIR})
target_link_libraries(MathLib PUBLIC ${MKL_LIBRARIES})
target_link_options(MathLib PUBLIC ${MKL_LINK_FLAGS})
target_compile_definitions(MathLib PUBLIC ${MKL_DEFINITIONS})
target_link_directories(MathLib PUBLIC ${MKL_LIBRARY_DIR})
endif()

target_compile_definitions(
MathLib
Expand Down
31 changes: 20 additions & 11 deletions scripts/ci/extends/vs2019-environment.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
.load_vs2019_env: &load_vs2019_env
- |
pushd $env:VS160COMNTOOLS
cmd /c "VsDevCmd.bat -arch=amd64 -host_arch=amd64&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
Write-Host "`nVisual Studio Command Prompt variables set." -ForegroundColor Yellow
.vs2019-environment:
before_script:
# Load VS environment
- |
pushd $env:VS160COMNTOOLS
cmd /c "VsDevCmd.bat -arch=amd64 -host_arch=amd64&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
Write-Host "`nVisual Studio Command Prompt variables set." -ForegroundColor Yellow
- *load_vs2019_env

.vs2019-mkl-environment:
before_script:
- *load_vs2019_env
# Load MKL environment
- '& "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"'
- $env:PATH += ";C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler"
2 changes: 2 additions & 0 deletions scripts/ci/jobs/build-linux-arch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build linux arch:
CMAKE_ARGS: >-
-DBUILD_SHARED_LIBS=ON
-DOGS_USE_MKL=ON
before_script:
- source /opt/intel/oneapi/setvars.sh
2 changes: 1 addition & 1 deletion scripts/ci/jobs/build-win.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build win:
extends:
- .template-build-win
- .vs2019-environment
- .vs2019-mkl-environment
variables:
CHECK_WARNINGS: "true"
CMAKE_PRESET: release
Expand Down
37 changes: 28 additions & 9 deletions scripts/cmake/Find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,42 @@ if(NOT (OGS_USE_PETSC AND OGS_USE_MKL) OR OGS_USE_PETSC_MKL_EIGEN_OPENMP)
find_package(OpenMP COMPONENTS C CXX)
endif()

# blas / lapack
# blas / lapack / MKL
if(OGS_USE_MKL)
if("${MKL_USE_interface}" STREQUAL "lp64")
if(APPLE)
set(_mac_ld_prefix "DY")
endif()
if(NOT DEFINED ENV{MKLROOT} OR (NOT "$ENV{${_mac_ld_prefix}LD_LIBRARY_PATH}"
MATCHES "intel" AND NOT WIN32)
)
message(
FATAL_ERROR
"OGS_USE_MKL was used but it seems that you did not source the MKL environment. "
"Typically you can run `source /opt/intel/oneapi/setvars.sh` before running CMake."
)
endif()
set(MKL_INTERFACE
"lp64"
CACHE
STRING
"for Intel(R)64 compatible arch: ilp64/lp64 or for ia32 arch: cdecl/stdcall"
)
if("${MKL_INTERFACE}" STREQUAL "lp64")
set(BLA_VENDOR Intel10_64lp)
elseif("${MKL_USE_interface}" STREQUAL "ilp64")
elseif("${MKL_INTERFACE}" STREQUAL "ilp64")
set(BLA_VENDOR Intel10_64ilp)
endif()
if(NOT WIN32 AND NOT APPLE)
set(CMAKE_REQUIRE_FIND_PACKAGE_BLAS TRUE)
set(CMAKE_REQUIRE_FIND_PACKAGE_LAPACK TRUE)
endif()
endif()
find_package(BLAS)
find_package(LAPACK)

if(OGS_USE_MKL)
find_package(MKL REQUIRED)
find_file(MKL_SETVARS setvars.sh PATHS ${MKL_ROOT_DIR} ${MKL_ROOT_DIR}/..
${MKL_ROOT_DIR}/../..
NO_DEFAULT_PATH
)
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
find_file(MKL_SETVARS setvars.sh PATHS ${MKL_ROOT}/../.. NO_DEFAULT_PATH)
endif()

# Check MPI package
Expand Down Expand Up @@ -134,7 +153,7 @@ function(printMKLUsage)
if(WIN32)
message(
STATUS
"NOTE: Please add the MKL redist directory to your PATH environment variable!\nE.g. with: set PATH=%PATH%;${MKL_ROOT_DIR}/redist/intel64"
"NOTE: In addition to loading the oneAPI setvars.bat file please also add this to your PATH C:\\Program Files (x86)\\Intel\\oneAPI\\compiler\\latest\\windows\\redist\\intel64_win\\compiler"
)
else()
message(
Expand Down
Loading

0 comments on commit 29e136f

Please sign in to comment.