Skip to content

Commit 1ac58ec

Browse files
committed
Use system mkldnn/onednn
Patch pytorch to use the system mkldnn library from the onednn package rather than building one locally from within ideep submodules. Given that ideep itself is a header-only library, I presume this is what was meant in #108 (comment), and indeed unvendoring onednn seems to improve build time significantly. That said, our onednn package does not support GPU runtime (conda-forge/onednn-feedstock#44) but at least according to my testing, that part of the library was not enabled by our PyTorch builds before (due to missing SYCL). The patch is a bit hacky, and probably needs some polishing before being submitted upstream (and testing on other platforms). Part of issue #108
1 parent 38bbc26 commit 1ac58ec

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

recipe/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export INSTALL_TEST=0
6868
export BUILD_TEST=0
6969

7070
export USE_SYSTEM_SLEEF=1
71+
export USE_SYSTEM_MKLDNN=1
7172
# use our protobuf
7273
export BUILD_CUSTOM_PROTOBUF=OFF
7374
rm -rf $PREFIX/bin/protoc

recipe/meta.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set version = "2.5.1" %}
2-
{% set build = 3 %}
2+
{% set build = 4 %}
33

44
{% if cuda_compiler_version != "None" %}
55
{% set build = build + 200 %}
@@ -36,6 +36,7 @@ source:
3636
- patches/0008-Fix-pickler-error.patch
3737
# https://github.com/pytorch/pytorch/pull/137331
3838
- patches/137331.patch
39+
- patches/0009-Use-system-mkldnn.patch
3940

4041
build:
4142
number: {{ build }}
@@ -138,6 +139,7 @@ requirements:
138139
- llvm-openmp # [osx]
139140
- libabseil
140141
- libprotobuf
142+
- onednn
141143
- sleef
142144
- typing
143145
- libuv
@@ -261,6 +263,7 @@ outputs:
261263
- llvm-openmp # [osx]
262264
- libabseil
263265
- libprotobuf
266+
- onednn
264267
- sleef
265268
- typing
266269
- libuv
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 98593c2d..94a9d63d 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -470,6 +470,7 @@ option(USE_SYSTEM_FXDIV "Use system-provided fxdiv." OFF)
6+
option(USE_SYSTEM_BENCHMARK "Use system-provided google benchmark." OFF)
7+
option(USE_SYSTEM_ONNX "Use system-provided onnx." OFF)
8+
option(USE_SYSTEM_XNNPACK "Use system-provided xnnpack." OFF)
9+
+option(USE_SYSTEM_MKLDNN "Use system-provided mkl-dnn (oneAPI)." OFF)
10+
option(USE_GOLD_LINKER "Use ld.gold to link" OFF)
11+
if(USE_SYSTEM_LIBS)
12+
set(USE_SYSTEM_CPUINFO ON)
13+
@@ -488,6 +489,7 @@ if(USE_SYSTEM_LIBS)
14+
if(USE_NCCL)
15+
set(USE_SYSTEM_NCCL ON)
16+
endif()
17+
+ set(USE_SYSTEM_MKLDNN ON)
18+
endif()
19+
20+
# /Z7 override option When generating debug symbols, CMake default to use the
21+
diff --git a/cmake/Modules/FindMKLDNN.cmake b/cmake/Modules/FindMKLDNN.cmake
22+
index 234d361d..5614f071 100644
23+
--- a/cmake/Modules/FindMKLDNN.cmake
24+
+++ b/cmake/Modules/FindMKLDNN.cmake
25+
@@ -18,6 +18,18 @@ IF(NOT MKLDNN_FOUND)
26+
27+
SET(IDEEP_ROOT "${PROJECT_SOURCE_DIR}/third_party/ideep")
28+
SET(MKLDNN_ROOT "${PROJECT_SOURCE_DIR}/third_party/ideep/mkl-dnn")
29+
+ FIND_PATH(IDEEP_INCLUDE_DIR ideep.hpp PATHS ${IDEEP_ROOT} PATH_SUFFIXES include)
30+
+
31+
+ if(USE_SYSTEM_MKLDNN)
32+
+ FIND_PACKAGE(DNNL REQUIRED)
33+
+ LIST(APPEND MKLDNN_LIBRARIES DNNL::dnnl)
34+
+ LIST(APPEND MKLDNN_INCLUDE_DIR ${IDEEP_INCLUDE_DIR})
35+
+ SET(MKLDNN_FOUND TRUE)
36+
+ # TODO: do we actually need it, or just https://github.com/oneapi-src/oneDNN/pull/2211?
37+
+ ADD_DEFINITIONS(-DDNNL_EXPERIMENTAL_UKERNEL)
38+
+ MESSAGE(STATUS "Found MKL-DNN: SYSTEM")
39+
+ RETURN()
40+
+ endif()
41+
42+
if(USE_XPU) # Build oneDNN GPU library
43+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
44+
@@ -93,7 +105,6 @@ IF(NOT MKLDNN_FOUND)
45+
ENDIF(EXISTS "${MKLDNN_ROOT}/include/oneapi/dnnl/dnnl_ukernel.hpp")
46+
47+
FIND_PACKAGE(BLAS)
48+
- FIND_PATH(IDEEP_INCLUDE_DIR ideep.hpp PATHS ${IDEEP_ROOT} PATH_SUFFIXES include)
49+
FIND_PATH(MKLDNN_INCLUDE_DIR dnnl.hpp dnnl.h dnnl_ukernel.hpp dnnl_ukernel.h PATHS ${MKLDNN_ROOT} PATH_SUFFIXES include/oneapi/dnnl)
50+
IF(NOT MKLDNN_INCLUDE_DIR)
51+
MESSAGE("MKLDNN_INCLUDE_DIR not found")

0 commit comments

Comments
 (0)