Skip to content

Commit

Permalink
Refine cmake based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CuiYifeng committed Jul 8, 2024
1 parent 2d0aabe commit 55211f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
40 changes: 34 additions & 6 deletions cmake/Modules/FindoneMKL.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
set(ONEMKL_FOUND FALSE)

set(ONEMKL_LIBRARIES)

set(ONEMKL_DEFAULT_DIR "/opt/intel/oneapi/mkl/latest")
if(DEFINED ENV{MKLROOT})
SET(INTEL_MKL_DIR $ENV{MKLROOT})
else()
SET(INTEL_MKL_DIR "/opt/intel/oneapi/mkl/latest")
set(ONEMKL_ROOT $ENV{MKLROOT})
elseif(EXISTS "${ONEMKL_DEFAULT_DIR}")
set(ONEMKL_ROOT "${ONEMKL_DEFAULT_DIR}")
endif()

if(NOT ONEMKL_ROOT)
message(WARNING "Cannot find oneMKL in ENV{MKLROOT} or default path, please setup oneMKL before building!!")
return()
endif()

find_file(
ONEMKL_INCLUDE_DIR
NAMES include
HINTS ${ONEMKL_ROOT}
NO_DEFAULT_PATH
)

find_file(
ONEMKL_LIB_DIR
NAMES lib
HINTS ${ONEMKL_ROOT}
NO_DEFAULT_PATH
)

if((NOT ONEMKL_INCLUDE_DIR) OR (NOT ONEMKL_LIB_DIR))
message(WARNING "oneMKL sdk is incomplete!!")
return()
endif()

set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}
"${INTEL_MKL_DIR}/include")
"${ONEMKL_INCLUDE_DIR}")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
"${INTEL_MKL_DIR}/lib")
"${ONEMKL_LIB_DIR}")

set(MKL_LIB_NAMES "mkl_intel_lp64" "mkl_gnu_thread" "mkl_core" "mkl_sycl_dft")

foreach(LIB_NAME IN LISTS MKL_LIB_NAMES)
find_library(
${LIB_NAME}_library
NAMES ${LIB_NAME}
HINTS ${INTEL_MKL_DIR}/lib
HINTS ${ONEMKL_LIB_DIR}
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
)
list(APPEND ONEMKL_LIBRARIES ${${LIB_NAME}_library})
endforeach()

set(ONEMKL_FOUND TRUE)
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ if(CLANG_FORMAT)
endif()

find_package(oneMKL)
if(NOT ONEMKL_FOUND)
message(FATAL_ERROR "Can NOT find ONEMKL cmake helpers module!")
endif()

target_link_libraries(torch_xpu_ops INTERFACE ${ONEMKL_LIBRARIES})

0 comments on commit 55211f9

Please sign in to comment.