Skip to content

Commit dbab9b7

Browse files
gujinghuifacebook-github-bot
authored andcommitted
seperate mkl, mklml, and mkldnn (pytorch#12170)
Summary: 1. Remove avx2 support in mkldnn 2. Seperate mkl, mklml, and mkldnn 3. Fix convfusion test case Pull Request resolved: pytorch#12170 Reviewed By: yinghai Differential Revision: D10207126 Pulled By: orionr fbshipit-source-id: 1e62eb47943f426a89d57e2d2606439f2b04fd51
1 parent bb96b66 commit dbab9b7

40 files changed

+277
-364
lines changed

.jenkins/pytorch/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ test_aten() {
109109

110110
${SUDO} ln -s "$TORCH_LIB_PATH"/libc10* build/bin
111111
${SUDO} ln -s "$TORCH_LIB_PATH"/libcaffe2* build/bin
112+
${SUDO} ln -s "$TORCH_LIB_PATH"/libmkldnn* build/bin
112113
${SUDO} ln -s "$TORCH_LIB_PATH"/libnccl* build/bin
113114

114115
ls build/bin

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ option(USE_TENSORRT "Using Nvidia TensorRT library" OFF)
117117
option(USE_ZMQ "Use ZMQ" OFF)
118118
option(USE_ZSTD "Use ZSTD" OFF)
119119
option(USE_MKLDNN "Use MKLDNN" OFF)
120-
option(USE_IDEEP "Use IDEEP interface in MKL BLAS" ON)
121-
option(USE_MKLML "Use MKLML interface in MKL BLAS" ON)
122120
option(USE_DISTRIBUTED "Use distributed" ON)
123121
cmake_dependent_option(
124122
USE_MPI "Use MPI for Caffe2. Only available if USE_DISTRIBUTED is on." ON
@@ -150,8 +148,7 @@ if (BUILD_ATEN_ONLY)
150148
set(USE_NNPACK OFF)
151149
set(USE_NUMPY OFF)
152150
set(USE_OPENCV OFF)
153-
set(USE_IDEEP OFF)
154-
set(USE_MKLML OFF)
151+
set(USE_MKLDNN OFF)
155152
set(USE_DISTRIBUTED OFF)
156153
set(USE_LMDB OFF)
157154
endif()

caffe2/contrib/ideep/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
if(USE_MKL AND USE_IDEEP AND CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
1+
if(CAFFE2_USE_MKLDNN)
22
message(STATUS "Including IDEEP operators")
33

44
# ---[ CPU files.
5-
file(GLOB_RECURSE avx2_srcs *.cc)
5+
file(GLOB_RECURSE tmp *.cc)
6+
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${tmp})
67
# exclude test files and gpu files
78
file(GLOB_RECURSE tmp *_test.cc)
8-
exclude(avx2_srcs "${avx2_srcs}" ${tmp})
9+
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${tmp})
910

10-
add_library(Caffe2_ideep_operators OBJECT ${avx2_srcs})
11-
add_dependencies(Caffe2_ideep_operators Caffe2_PROTO)
12-
set_target_properties(Caffe2_ideep_operators PROPERTIES COMPILE_FLAGS "-mavx2")
11+
# ---[ CPU test files - currently none but just to be safe
12+
file(GLOB_RECURSE tmp *_test.cc)
13+
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} ${tmp})
1314

1415
# ---[ Send the lists to the parent scope.
15-
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS}
16-
$<TARGET_OBJECTS:Caffe2_ideep_operators>)
1716
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
17+
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)
1818
else()
1919
message(STATUS "Excluding ideep operators as we are not using ideep")
2020
endif()

caffe2/contrib/warpctc/ctc_op.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "caffe2/core/context_gpu.h"
33
#include "caffe2/core/operator.h"
44

5-
#ifdef CAFFE2_USE_IDEEP
5+
#ifdef CAFFE2_USE_MKLDNN
66
#include <caffe2/ideep/operators/operator_fallback_ideep.h>
77
#include <caffe2/ideep/utils/ideep_operator.h>
88
#endif
@@ -25,7 +25,7 @@ REGISTER_CPU_OPERATOR(CTC, CTCOp<float, CPUContext>);
2525
OPERATOR_SCHEMA(CTC).NumInputs(3, 4).NumOutputs(2, 3);
2626
// .EnforceInputOutputGradient({{0, 0}});
2727

28-
#ifdef CAFFE2_USE_IDEEP
28+
#ifdef CAFFE2_USE_MKLDNN
2929
REGISTER_IDEEP_OPERATOR(CTC, IDEEPFallbackOp<CTCOp<float, CPUContext>>);
3030
#endif
3131

caffe2/core/macros.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static_assert(
4040
#cmakedefine CAFFE2_USE_GOOGLE_GLOG
4141
#cmakedefine CAFFE2_USE_LITE_PROTO
4242
#cmakedefine CAFFE2_USE_MKL
43-
#cmakedefine CAFFE2_USE_IDEEP
43+
#cmakedefine CAFFE2_USE_MKLDNN
4444
#cmakedefine CAFFE2_USE_NVTX
4545
#cmakedefine CAFFE2_USE_TRT
4646
#cmakedefine CAFFE2_DISABLE_NUMA
@@ -76,6 +76,7 @@ static_assert(
7676
{"USE_EIGEN_FOR_BLAS", "${CAFFE2_USE_EIGEN_FOR_BLAS}"}, \
7777
{"USE_LITE_PROTO", "${CAFFE2_USE_LITE_PROTO}"}, \
7878
{"USE_MKL", "${CAFFE2_USE_MKL}"}, \
79+
{"USE_MKLDNN", "${CAFFE2_USE_MKLDNN}"}, \
7980
{"USE_NVTX", "${CAFFE2_USE_NVTX}"}, \
8081
{"USE_TRT", "${CAFFE2_USE_TRT}"}, \
8182
{"DISABLE_NUMA", "${CAFFE2_DISABLE_NUMA}"}, \

caffe2/ideep/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
if(USE_MKL AND USE_IDEEP AND CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
1+
if(CAFFE2_USE_MKLDNN)
22
message(STATUS "Including IDEEP operators")
33

44
# ---[ CPU files.
5-
file(GLOB_RECURSE avx2_srcs *.cc)
5+
file(GLOB_RECURSE tmp *.cc)
6+
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${tmp})
67
# exclude test files and gpu files
78
file(GLOB_RECURSE tmp *_test.cc)
8-
exclude(avx2_srcs "${avx2_srcs}" ${tmp})
9+
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${tmp})
910

10-
add_library(Caffe2_ideep_operators OBJECT ${avx2_srcs})
11-
add_dependencies(Caffe2_ideep_operators Caffe2_PROTO)
12-
set_target_properties(Caffe2_ideep_operators PROPERTIES COMPILE_FLAGS "-mavx2")
11+
# ---[ CPU test files - currently none but just to be safe
12+
file(GLOB_RECURSE tmp *_test.cc)
13+
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} ${tmp})
1314

1415
# ---[ Send the lists to the parent scope.
15-
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS}
16-
$<TARGET_OBJECTS:Caffe2_ideep_operators>)
1716
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
17+
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)
1818
else()
1919
message(STATUS "Excluding ideep operators as we are not using ideep")
2020
endif()

caffe2/operators/atomic_ops.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "caffe2/core/context.h"
33
#include "caffe2/core/operator.h"
44

5-
#ifdef CAFFE2_USE_IDEEP
5+
#ifdef CAFFE2_USE_MKLDNN
66
#include <caffe2/ideep/operators/operator_fallback_ideep.h>
77
#include <caffe2/ideep/utils/ideep_operator.h>
88
#endif
@@ -90,7 +90,7 @@ class CheckAtomicBoolOp final : public Operator<CPUContext> {
9090
REGISTER_CPU_OPERATOR(CreateMutex, CreateMutexOp);
9191
REGISTER_CPU_OPERATOR(AtomicFetchAdd, AtomicFetchAddOp);
9292

93-
#ifdef CAFFE2_USE_IDEEP
93+
#ifdef CAFFE2_USE_MKLDNN
9494
REGISTER_IDEEP_OPERATOR(CreateMutex, IDEEPFallbackOp<CreateMutexOp, SkipIndices<0>>);
9595
#endif
9696

caffe2/operators/distance_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "caffe2/operators/distance_op.h"
22
#include "caffe2/utils/eigen_utils.h"
3-
#ifdef CAFFE2_USE_IDEEP
3+
#ifdef CAFFE2_USE_MKLDNN
44
#include <caffe2/ideep/operators/operator_fallback_ideep.h>
55
#include <caffe2/ideep/utils/ideep_operator.h>
66
#endif
@@ -400,7 +400,7 @@ REGISTER_CPU_OPERATOR(L1Distance, L1DistanceOp<float, CPUContext>);
400400
REGISTER_CPU_OPERATOR(
401401
L1DistanceGradient,
402402
L1DistanceGradientOp<float, CPUContext>);
403-
#ifdef CAFFE2_USE_IDEEP
403+
#ifdef CAFFE2_USE_MKLDNN
404404
REGISTER_IDEEP_OPERATOR(
405405
L1DistanceGradient,
406406
IDEEPFallbackOp<L1DistanceGradientOp<float, CPUContext>>);

caffe2/operators/stylizer_ops.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "caffe2/utils/cpu_neon.h"
33
#include "caffe2/utils/math.h"
44

5-
#ifdef CAFFE2_USE_IDEEP
5+
#ifdef CAFFE2_USE_MKLDNN
66
#include <caffe2/ideep/operators/operator_fallback_ideep.h>
77
#include <caffe2/ideep/utils/ideep_operator.h>
88
#endif
@@ -586,7 +586,7 @@ OPERATOR_SCHEMA(BRGNCHWCToPackedInt8BGRAStylizerDeprocess)
586586
.NumInputs(2)
587587
.NumOutputs(1);
588588

589-
#ifdef CAFFE2_USE_IDEEP
589+
#ifdef CAFFE2_USE_MKLDNN
590590
REGISTER_IDEEP_OPERATOR(
591591
BRGNCHWCToPackedInt8BGRAStylizerDeprocess,
592592
IDEEPFallbackOp<BRGNCHWCToPackedInt8BGRAStylizerDeprocessOp, SkipIndices<0>>);

caffe2/opt/optimize_ideep.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "caffe2/opt/converter.h"
33
#include "caffe2/opt/fusion.h"
44

5-
#ifdef CAFFE2_USE_IDEEP
5+
#ifdef CAFFE2_USE_MKLDNN
66
#include "caffe2/ideep/ideep_utils.h"
77
#endif
88

@@ -11,7 +11,7 @@ namespace opt {
1111

1212
using namespace nom;
1313

14-
#ifndef CAFFE2_USE_IDEEP
14+
#ifndef CAFFE2_USE_MKLDNN
1515
void OptimizeForIdeep(
1616
repr::NNModule* nn,
1717
caffe2::Workspace* ws,
@@ -440,7 +440,7 @@ void OptimizeForIdeep(
440440
setPoolingInferenceMode(nn);
441441
}
442442

443-
#endif // CAFFE2_USE_IDEEP
443+
#endif // CAFFE2_USE_MKLDNN
444444

445445
} // namespace opt
446446
} // namespace caffe2

caffe2/python/CMakeLists.txt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ set(Caffe2_CPU_PYTHON_SRCS
66
"/pybind_state_registry.cc"
77
)
88

9+
if(CAFFE2_USE_MKLDNN)
10+
set(Caffe2_CPU_PYTHON_SRCS
11+
${Caffe2_CPU_PYTHON_SRCS}
12+
"/pybind_state_ideep.cc"
13+
)
14+
endif()
15+
916
# ---[ GPU files
1017
set(Caffe2_GPU_PYTHON_SRCS
1118
${Caffe2_CPU_PYTHON_SRCS}
@@ -22,19 +29,6 @@ prepend(Caffe2_CPU_PYTHON_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_CPU_PYTHON_S
2229
prepend(Caffe2_GPU_PYTHON_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_GPU_PYTHON_SRCS})
2330
prepend(Caffe2_HIP_PYTHON_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_HIP_PYTHON_SRCS})
2431

25-
26-
# --[ Some special handling for ideep binding as we need to build with "-mavx2"
27-
if(USE_MKL AND USE_IDEEP AND CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
28-
file(GLOB_RECURSE ideep_srcs *_ideep.cc)
29-
add_library(Caffe2_ideep_pybind OBJECT ${ideep_srcs})
30-
add_dependencies(Caffe2_ideep_pybind Caffe2_PROTO)
31-
set_target_properties(Caffe2_ideep_pybind PROPERTIES COMPILE_FLAGS "-mavx2")
32-
set(Caffe2_CPU_PYTHON_SRCS
33-
${Caffe2_CPU_PYTHON_SRCS}
34-
$<TARGET_OBJECTS:Caffe2_ideep_pybind>
35-
)
36-
endif()
37-
3832
set(Caffe2_CPU_PYTHON_SRCS ${Caffe2_CPU_PYTHON_SRCS} PARENT_SCOPE)
3933
set(Caffe2_GPU_PYTHON_SRCS ${Caffe2_GPU_PYTHON_SRCS} PARENT_SCOPE)
4034
set(Caffe2_HIP_PYTHON_SRCS ${Caffe2_HIP_PYTHON_SRCS} PARENT_SCOPE)

caffe2/python/ideep/LRN_op_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import caffe2.python.ideep_test_util as mu
1313

1414

15-
@unittest.skipIf(not workspace.C.use_ideep, "No IDEEP support.")
15+
@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
1616
class LRNTest(hu.HypothesisTestCase):
1717
@given(input_channels=st.integers(1, 3),
1818
batch_size=st.integers(1, 3),

caffe2/python/ideep/concat_split_op_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _tensor_splits(draw, add_axis=False):
4545
)
4646

4747

48-
@unittest.skipIf(not workspace.C.use_ideep, "No IDEEP support.")
48+
@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
4949
class TestConcatSplitOps(hu.HypothesisTestCase):
5050
@given(tensor_splits=_tensor_splits(),
5151
**mu.gcs)

caffe2/python/ideep/conv_op_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import caffe2.python.ideep_test_util as mu
1515

1616

17-
@unittest.skipIf(not workspace.C.use_ideep, "No IDEEP support.")
17+
@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
1818
class ConvTest(hu.HypothesisTestCase):
1919
@given(stride=st.integers(1, 3),
2020
pad=st.integers(0, 3),

0 commit comments

Comments
 (0)