Link LazyLinalg with cusolver statically when needed (#79324)
By copy-n-pasting the static linking logic from `libtorch_cuda` if
lazylinalg is not enabled
Pull Request resolved: https://github.com/pytorch/pytorch/pull/79324
Approved by: https://github.com/atalman
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index ef859e1..4c97643 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -985,8 +985,17 @@
target_link_libraries(torch_cuda_linalg PRIVATE
torch_cpu
torch_cuda
- ${CUDA_cusolver_LIBRARY}
)
+ if($ENV{ATEN_STATIC_CUDA})
+ target_link_libraries(torch_cuda_linalg PRIVATE
+ ${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcusolver_static.a
+ ${CUDA_TOOLKIT_ROOT_DIR}/lib64/liblapack_static.a # needed for libcusolver_static
+ )
+ else()
+ target_link_libraries(torch_cuda_linalg PRIVATE
+ ${CUDA_cusolver_LIBRARY}
+ )
+ endif()
# NS: TODO, is this really necessary?
if(USE_MAGMA AND CAFFE2_STATIC_LINK_CUDA)
target_link_libraries(torch_cuda_linalg PRIVATE