# Copyright 2024 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Using single threaded Intel(R) MKL to minimize the interference with SVS ThreadPool set(MKL_THREADING sequential) # As a side-effect of `find_package`, the variable `MKL_ROOT` will be defined. # This helps us find the custom shared-object building if needed. find_package(MKL CONFIG REQUIRED) # The custom Intel(R) MKL flow uses MKL's builder utility to create a small shared-library with # just the symbols used by SVS. # # The resulting object and linking are portable and should be suitable for distribution. if (SVS_EXPERIMENTAL_BUILD_CUSTOM_MKL) set(SVS_MKL_CUSTOM_LIBRARY_NAME libsvs_mkl) set(SVS_MKL_CUSTOM_SO_NAME ${SVS_MKL_CUSTOM_LIBRARY_NAME}.so) set(SVS_MKL_CUSTOM_FULL_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SVS_MKL_CUSTOM_SO_NAME}) # Find where the makefile is. # It can exist in one of several paths. # # For 2023 Intel(R) MKL flavors, it is found at "MKL_ROOT/tools/builder" # For 2024 Intel(R) MKL - it is a "MKL_ROOT/share/mkl/tool/builder" # # Don't seach CMake defaults - "makefile" is a common enough name that we might find # an incorrect version if we include the default search paths. find_path( SVS_MKL_BUILDER makefile PATHS "${MKL_ROOT}/tools/builder" "${MKL_ROOT}/share/mkl/tools/builder" NO_DEFAULT_PATH REQUIRED ) if (SVS_EXPERIMENTAL_ENABLE_IVF) set(mkl_functions_file ${CMAKE_CURRENT_LIST_DIR}/mkl_functions_ivf) else() set(mkl_functions_file ${CMAKE_CURRENT_LIST_DIR}/mkl_functions) endif() # This command creates the custom shared-object that will be linked to. add_custom_command( OUTPUT ${SVS_MKL_CUSTOM_FULL_PATH} COMMAND "make" "-C" "${SVS_MKL_BUILDER}" "libintel64" "interface=ilp64" "threading=sequential" "export=${mkl_functions_file}" "MKLROOT=${MKL_ROOT}" "name=${CMAKE_CURRENT_BINARY_DIR}/${SVS_MKL_CUSTOM_LIBRARY_NAME}" ) # Create a target for the newly created shared object. add_custom_target(svs_mkl_target DEPENDS ${SVS_MKL_CUSTOM_FULL_PATH}) # Create an imported object for the custom Intel(R) MKL library - configure it to depend on # the custom library built. add_library(svs_mkl SHARED IMPORTED) add_dependencies(svs_mkl svs_mkl_target) set_target_properties( svs_mkl PROPERTIES IMPORTED_LOCATION ${SVS_MKL_CUSTOM_FULL_PATH} IMPORTED_NO_SONAME TRUE INTERFACE_COMPILE_OPTIONS $ INTERFACE_INCLUDE_DIRECTORIES $ ) target_link_libraries(${SVS_LIB} INTERFACE svs_mkl) # Ensure that the custom Intel(R) MKL library is bundled with the rest of the library. include(GNUInstallDirs) install(IMPORTED_RUNTIME_ARTIFACTS svs_mkl LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) elseif(NOT SVS_EXPERIMENTAL_LINK_STATIC_MKL) target_compile_options( ${SVS_LIB} INTERFACE $ ) target_include_directories( ${SVS_LIB} INTERFACE $ ) target_link_libraries(${SVS_LIB} INTERFACE $) endif()