Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
CMake support to link against static Intel MKL
Static linking of Intel MKL is turned off by default.

Note that this however increases binary size of CPU backend by ~200MB and
OpenCL backend by ~100MB, respectively.
  • Loading branch information
9prady9 committed May 6, 2020
commit d79ee873d0a0e4a3fb842c5d84fd797713a8c803
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ option(AF_WITH_NONFREE "Build ArrayFire nonfree algorithms" OFF)
option(AF_WITH_LOGGING "Build ArrayFire with logging support" ON)
option(AF_WITH_STACKTRACE "Add stacktraces to the error messages." ON)
option(AF_CACHE_KERNELS_TO_DISK "Enable caching kernels to disk" ON)
option(AF_WITH_STATIC_MKL "Link against static Intel MKL libraries" OFF)

if(WIN32)
set(AF_STACKTRACE_TYPE "Windbg" CACHE STRING "The type of backtrace features. Windbg(simple), None")
Expand Down Expand Up @@ -311,32 +312,34 @@ install(FILES ${ArrayFire_BINARY_DIR}/cmake/install/ArrayFireConfig.cmake
DESTINATION ${AF_INSTALL_CMAKE_DIR}
COMPONENT cmake)

if((USE_CPU_MKL OR USE_OPENCL_MKL) AND TARGET MKL::Shared AND AF_INSTALL_STANDALONE)
if((USE_CPU_MKL OR USE_OPENCL_MKL) AND AF_INSTALL_STANDALONE)
if(TARGET MKL::ThreadingLibrary)
install(FILES
$<TARGET_FILE:MKL::ThreadingLibrary>
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()

if(NOT WIN32)
if(NOT AF_WITH_STATIC_MKL AND TARGET MKL::Shared)
if(NOT WIN32)
install(FILES
$<TARGET_FILE:MKL::Interface>
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()

install(FILES
$<TARGET_FILE:MKL::Interface>
$<TARGET_FILE:MKL::Shared>
$<TARGET_FILE:MKL::ThreadLayer>
${MKL_RUNTIME_KERNEL_LIBRARIES}

# This variable is used to add tbb.so.2 library because the main lib
# is a linker script and not a symlink so it cant be resolved using
# get_filename_component
${AF_ADDITIONAL_MKL_LIBRARIES}
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()

install(FILES
$<TARGET_FILE:MKL::Shared>
$<TARGET_FILE:MKL::ThreadLayer>
${MKL_RUNTIME_KERNEL_LIBRARIES}

# This variable is used to add tbb.so.2 library because the main lib
# is a linker script and not a symlink so it cant be resolved using
# get_filename_component
${AF_ADDITIONAL_MKL_LIBRARIES}
DESTINATION ${AF_INSTALL_LIB_DIR}
COMPONENT mkl_dependencies)
endif()

# This file will be used to create the config file for the build directory.
Expand Down
4 changes: 3 additions & 1 deletion src/api/unified/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ target_link_libraries(af
if((USE_CPU_MKL OR USE_OPENCL_MKL) AND TARGET MKL::Shared)
target_link_libraries(af
PRIVATE
MKL::Shared)
$<$<BOOL:${AF_WITH_STATIC_MKL}>:MKL::Static>
$<$<NOT:$<BOOL:${AF_WITH_STATIC_MKL}>>:MKL::Shared>
)
endif()


Expand Down
3 changes: 2 additions & 1 deletion src/backend/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ if(USE_CPU_MKL)
cpp_api_interface
afcommon_interface
cpu_sort_by_key
MKL::Shared
$<$<BOOL:${AF_WITH_STATIC_MKL}>:MKL::Static>
$<$<NOT:$<BOOL:${AF_WITH_STATIC_MKL}>>:MKL::Shared>
Threads::Threads
)
else()
Expand Down
4 changes: 3 additions & 1 deletion src/backend/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ if(LAPACK_FOUND OR MKL_Shared_FOUND)

target_link_libraries(afopencl
PRIVATE
MKL::Shared)
$<$<BOOL:${AF_WITH_STATIC_MKL}>:MKL::Static>
$<$<NOT:$<BOOL:${AF_WITH_STATIC_MKL}>>:MKL::Shared>
)
else()
dependency_check(OpenCL_FOUND "OpenCL not found.")

Expand Down