summarylogtreecommitdiffstats
path: root/system-dnnl.diff
blob: 1444d8acaa1e1af81cda4c202fcc8dedf351703f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
diff --git a/cmake/external/dnnl.cmake b/cmake/external/dnnl.cmake
index 6a51a3d5d..a89635210 100644
--- a/cmake/external/dnnl.cmake
+++ b/cmake/external/dnnl.cmake
@@ -26,6 +26,13 @@ elseif(onnxruntime_USE_DNNL AND onnxruntime_DNNL_GPU_RUNTIME STREQUAL "ocl" AND
 endif()
 
 if (onnxruntime_USE_DNNL)
+if (onnxruntime_PREFER_SYSTEM_LIB)
+  # https://oneapi-src.github.io/oneDNN/dev_guide_transition_to_dnnl.html
+  find_package(dnnl CONFIG REQUIRED)
+  add_library(project_dnnl INTERFACE)
+  add_library(dnnl INTERFACE)
+  target_link_libraries(dnnl INTERFACE DNNL::dnnl)
+else ()
   set(DNNL_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/dnnl/src/dnnl/src)
   set(DNNL_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/dnnl/install)
   set(DNNL_LIB_DIR ${DNNL_INSTALL}/${CMAKE_INSTALL_LIBDIR})
@@ -55,3 +62,4 @@ if (onnxruntime_USE_DNNL)
   )
   link_directories(${DNNL_LIB_DIR})
 endif()
+endif()
diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake
index 6bdb2d03c..514faa375 100644
--- a/cmake/onnxruntime_unittests.cmake
+++ b/cmake/onnxruntime_unittests.cmake
@@ -744,10 +744,12 @@ add_custom_command(
 if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
   if (onnxruntime_USE_DNNL)
     list(APPEND onnx_test_libs dnnl)
+    if (NOT onnxruntime_PREFER_SYSTEM_LIB)
     add_custom_command(
       TARGET ${test_data_target} POST_BUILD
       COMMAND ${CMAKE_COMMAND} -E copy ${DNNL_DLL_PATH} $<TARGET_FILE_DIR:${test_data_target}>
       )
+    endif()
   endif()
   if(WIN32)
     if (onnxruntime_USE_TVM)