Fix finding Intel MKL on Windows, as well as LAPACK, cuDNN and cuSPARSELt (#108040)

Fixes #108039

Intel MKL is now found correctly:

-- MKL libraries: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/intel64/mkl_intel_lp64.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/intel64/mkl_sequential.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/intel64/mkl_core.lib
-- MKL include directory: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/include

and LAPACK too (excerpt from build.ninja):

LINK_LIBRARIES = lib\c10.lib  lib\pthreadpool.lib  lib\cpuinfo.lib  lib\XNNPACK.lib  lib\fbgemm.lib  lib\libittnotify.lib  lib\gloo.lib  lib\foxi_loader.lib  lib\kineto.lib  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_intel_lp64.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_sequential.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_core.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\**mkl_lapack95_lp64.lib**"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_intel_lp64.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_sequential.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_core.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_intel_lp64.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_sequential.lib"  "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\lib\intel64\mkl_core.lib"

cuSPARSELt is also found correctly:

-- Found CUSPARSELT: C:/Program Files/NVIDIA cuSPARSELt/v0.4/lib/cusparseLt.lib

Also cuDNN include directory is properly added for the test target cuda_cudnn_test:

build caffe2\CMakeFiles\cuda_cudnn_test.dir\__\aten\src\ATen\test\cuda_cudnn_test.cpp.obj: CXX_COMPILER__cuda_cudnn_test_RelWithDebInfo C$:\work\Repos\pytorch\aten\src\ATen\test\cuda_cudnn_test.cpp || cmake_object_order_depends_target_cuda_cudnn_test
  DEFINES = ....
  FLAGS = ....
  INCLUDES = -IC:\work\Repos\pytorch\build\aten\src -IC:\work\Repos\pytorch\aten\src ........... -external:IC:\work\Repos\pytorch\third_party\ittapi\include -external:IC:\work\Repos\pytorch\cmake\..\third_party\eigen -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\include" -external:IC:\work\Repos\pytorch\torch\include -external:IC:\work\Repos\pytorch\third_party\ideep\include -external:IC:\work\Repos\pytorch\third_party\googletest\googletest\include -external:IC:\work\Repos\pytorch\third_party\googletest\googletest **-external:I"C:\Program Files\NVIDIA cuDNN\include"** -external:IC:\work\Repos\pytorch\cmake\..\third_party\cudnn_frontend\include -external:W0

Pull Request resolved: https://github.com/pytorch/pytorch/pull/108040
Approved by: https://github.com/ezyang
This commit is contained in:
Andrei Gheorghe
2023-09-08 14:40:58 +00:00
committed by PyTorch MergeBot
parent 366baf690b
commit 2028987bf7
3 changed files with 17 additions and 9 deletions

View File

@ -1738,6 +1738,9 @@ if(BUILD_TEST)
get_filename_component(test_name ${test_src} NAME_WE)
add_executable(${test_name} "${test_src}")
target_link_libraries(${test_name} torch_library gtest_main)
if(USE_CUDNN AND ${test_name} MATCHES "cudnn")
target_link_libraries(${test_name} torch::cudnn)
endif()
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)

View File

@ -29,7 +29,12 @@ find_path(CUSPARSELT_INCLUDE_PATH cusparseLt.h
set(CUSPARSELT_LIBRARY $ENV{CUSPARSELT_LIBRARY} CACHE PATH "Path to the cusparselt library file (e.g., libcusparseLt.so)")
find_library(CUSPARSELT_LIBRARY_PATH libcusparseLt.so
set(CUSPARSELT_LIBRARY_NAME "libcusparseLt.so")
if(MSVC)
set(CUSPARSELT_LIBRARY_NAME "cusparseLt.lib")
endif()
find_library(CUSPARSELT_LIBRARY_PATH ${CUSPARSELT_LIBRARY_NAME}
PATHS ${CUSPARSELT_LIBRARY}
PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64)

View File

@ -37,7 +37,10 @@ IF (WIN32)
SET(DEFAULT_INTEL_COMPILER_DIR
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows")
ENDIF()
SET(DEFAULT_INTEL_MKL_DIR "${INTEL_COMPILER_DIR}/mkl")
SET(DEFAULT_INTEL_MKL_DIR "${DEFAULT_INTEL_COMPILER_DIR}/mkl")
if (EXISTS "${DEFAULT_INTEL_COMPILER_DIR}/mkl/latest")
SET(DEFAULT_INTEL_MKL_DIR "${DEFAULT_INTEL_COMPILER_DIR}/mkl/latest")
endif()
ELSE (WIN32)
SET(DEFAULT_INTEL_COMPILER_DIR "/opt/intel")
SET(DEFAULT_INTEL_MKL_DIR "/opt/intel/mkl")
@ -115,13 +118,6 @@ SET(mklseq)
# Paths
SET(saved_CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH})
SET(saved_CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH})
IF(WIN32)
# Change mklvers and iccvers when we are using MSVC instead of ICC
IF(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
SET(mklvers "${mklvers}_win")
SET(iccvers "${iccvers}_win")
ENDIF()
ENDIF(WIN32)
IF (EXISTS ${INTEL_COMPILER_DIR})
# TODO: diagnostic if dir does not exist
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
@ -404,6 +400,10 @@ IF (MKL_LIBRARIES)
FIND_LIBRARY(MKL_LAPACK_LIBRARIES NAMES "mkl_lapack${mkl64}${mkls}")
MARK_AS_ADVANCED(MKL_LAPACK_LIBRARIES)
ENDIF (NOT MKL_LAPACK_LIBRARIES)
IF (NOT MKL_LAPACK_LIBRARIES)
FIND_LIBRARY(MKL_LAPACK_LIBRARIES NAMES "mkl_lapack95${mkl64}${mkls}")
MARK_AS_ADVANCED(MKL_LAPACK_LIBRARIES)
ENDIF (NOT MKL_LAPACK_LIBRARIES)
IF (NOT MKL_SCALAPACK_LIBRARIES)
FIND_LIBRARY(MKL_SCALAPACK_LIBRARIES NAMES "mkl_scalapack${mkl64}${mkls}")
MARK_AS_ADVANCED(MKL_SCALAPACK_LIBRARIES)