Skip to content

Commit cc961f4

Browse files
gcuendet-cognexgcuendet
authored andcommitted
Fix Cudnn finder
Signed-off-by: Gabriel Cuendet <[email protected]>
1 parent e55b83e commit cc961f4

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

cmake/Modules/FindcuDNN.cmake

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -182,56 +182,62 @@ if(cuDNN_INCLUDE_DIRS)
182182
endif()
183183
endif()
184184

185+
# pytorch compatibility layer
186+
set(CUDNN_LIBRARY_PATH ${cuDNN_LINK_LIBRARY})
187+
set(CUDNN_INCLUDE_PATH ${cuDNN_INCLUDE_DIRS})
188+
185189
find_package_handle_standard_args(cuDNN
186190
REQUIRED_VARS cuDNN_LINK_LIBRARY cuDNN_INCLUDE_DIRS
187191
VERSION_VAR cuDNN_VERSION)
188192

189193
mark_as_advanced(cuDNN_LINK_LIBRARY cuDNN_INCLUDE_DIRS cuDNN_DLL_LIBRARY)
190194

191195
if(cuDNN_FOUND)
192-
add_library(cuDNN::cuDNN SHARED IMPORTED)
193-
if(WIN32)
194-
set_target_properties(cuDNN::cuDNN
195-
PROPERTIES
196-
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
197-
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
198-
IMPORTED_LOCATION "${cuDNN_DLL_LIBRARY}"
199-
IMPORTED_IMPLIB "${cuDNN_LINK_LIBRARY}"
200-
)
201-
else(WIN32)
202-
set_target_properties(cuDNN::cuDNN
203-
PROPERTIES
204-
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
205-
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
206-
IMPORTED_LOCATION "${cuDNN_LINK_LIBRARY}"
207-
)
208-
endif(WIN32)
209-
if(cuDNN_VERSION_MAJOR VERSION_GREATER 8 OR cuDNN_VERSION_MAJOR VERSION_EQUAL 8)
210-
macro(create_cudnn_target cudnn_target_name)
211-
string(TOUPPER ${cudnn_target_name} target_infix)
212-
add_library(cuDNN::${cudnn_target_name} SHARED IMPORTED)
213-
if(WIN32)
214-
set_target_properties(cuDNN::${cudnn_target_name}
215-
PROPERTIES
216-
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
217-
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
218-
IMPORTED_LOCATION "${cuDNN_${target_infix}_DLL_LIBRARY}"
219-
IMPORTED_IMPLIB "${cuDNN_${target_infix}_LINK_LIBRARY}"
220-
)
221-
else(WIN32)
196+
if(NOT TARGET cuDNN::cuDNN)
197+
add_library(cuDNN::cuDNN SHARED IMPORTED)
198+
if(WIN32)
199+
set_target_properties(cuDNN::cuDNN
200+
PROPERTIES
201+
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
202+
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
203+
IMPORTED_LOCATION "${cuDNN_DLL_LIBRARY}"
204+
IMPORTED_IMPLIB "${cuDNN_LINK_LIBRARY}"
205+
)
206+
else(WIN32)
207+
set_target_properties(cuDNN::cuDNN
208+
PROPERTIES
209+
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
210+
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
211+
IMPORTED_LOCATION "${cuDNN_LINK_LIBRARY}"
212+
)
213+
endif(WIN32)
214+
if(cuDNN_VERSION_MAJOR VERSION_GREATER 8 OR cuDNN_VERSION_MAJOR VERSION_EQUAL 8)
215+
macro(create_cudnn_target cudnn_target_name)
216+
string(TOUPPER ${cudnn_target_name} target_infix)
217+
add_library(cuDNN::${cudnn_target_name} SHARED IMPORTED)
218+
if(WIN32)
219+
set_target_properties(cuDNN::${cudnn_target_name}
220+
PROPERTIES
221+
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
222+
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
223+
IMPORTED_LOCATION "${cuDNN_${target_infix}_DLL_LIBRARY}"
224+
IMPORTED_IMPLIB "${cuDNN_${target_infix}_LINK_LIBRARY}"
225+
)
226+
else(WIN32)
222227
set_target_properties(cuDNN::${cudnn_target_name}
223228
PROPERTIES
224229
IMPORTED_LINK_INTERFACE_LANGUAGE "C"
225230
INTERFACE_INCLUDE_DIRECTORIES "${cuDNN_INCLUDE_DIRS}"
226231
IMPORTED_LOCATION "${cuDNN_${target_infix}_LINK_LIBRARY}"
227232
)
228-
endif(WIN32)
229-
endmacro()
230-
create_cudnn_target(adv_infer)
231-
create_cudnn_target(adv_train)
232-
create_cudnn_target(cnn_infer)
233-
create_cudnn_target(cnn_train)
234-
create_cudnn_target(ops_infer)
235-
create_cudnn_target(ops_train)
236-
endif()
237-
endif(cuDNN_FOUND)
233+
endif(WIN32)
234+
endmacro()
235+
create_cudnn_target(adv_infer)
236+
create_cudnn_target(adv_train)
237+
create_cudnn_target(cnn_infer)
238+
create_cudnn_target(cnn_train)
239+
create_cudnn_target(ops_infer)
240+
create_cudnn_target(ops_train)
241+
endif()
242+
endif(NOT TARGET cuDNN::cuDNN)
243+
endif(cuDNN_FOUND)

0 commit comments

Comments
 (0)