Skip to content

Commit

Permalink
Making MKL-DNN default build choice (#16474)
Browse files Browse the repository at this point in the history
  • Loading branch information
agramesh1 authored and rmlarsen committed Jan 26, 2018
1 parent 6a75a52 commit e4a628a
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 84 deletions.
6 changes: 3 additions & 3 deletions tensorflow/core/graph/mkl_layout_pass.cc
Expand Up @@ -42,7 +42,7 @@ limitations under the License.

namespace tensorflow {

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

// This pass implements rewriting of graph to support following scenarios:
// (A) Merging nodes in the graph
Expand Down Expand Up @@ -2215,7 +2215,7 @@ Status MklLayoutRewritePass::Run(
return Status::OK();
}

#else // INTEL_MKL_DNN
#else // INTEL_MKL_ML

// This pass implements rewriting of graph to support following scenarios:
// (A) Merging nodes in the graph
Expand Down Expand Up @@ -4325,7 +4325,7 @@ Status MklLayoutRewritePass::Run(

return Status::OK();
}
#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML
} // namespace tensorflow

#endif
6 changes: 3 additions & 3 deletions tensorflow/core/graph/mkl_layout_pass_test.cc
Expand Up @@ -38,7 +38,7 @@ limitations under the License.

namespace tensorflow {

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

namespace {

Expand Down Expand Up @@ -1885,7 +1885,7 @@ BENCHMARK(BM_MklLayoutRewritePass)->Arg(1000)->Arg(10000);

} // namespace

#else // INTEL_MKL_DNN
#else // INTEL_MKL_ML

namespace {

Expand Down Expand Up @@ -3503,7 +3503,7 @@ BENCHMARK(BM_MklLayoutRewritePass)->Arg(1000)->Arg(10000);

} // namespace

#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

} // namespace tensorflow

Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_aggregate_ops.cc
Expand Up @@ -28,7 +28,7 @@ limitations under the License.
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"
using mkldnn::stream;
using mkldnn::sum;
Expand All @@ -37,7 +37,7 @@ using mkldnn::sum;
namespace tensorflow {
typedef Eigen::ThreadPoolDevice CPUDevice;

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, typename T>
class MklAddNOp : public OpKernel {
Expand Down Expand Up @@ -285,7 +285,7 @@ class MklAddNOp : public OpKernel {
} MklAddNOpContext;
};

#else // INTEL_MKL_DNN
#else // INTEL_MKL_ML
template <typename Device, typename T>
class MklAddNOp : public OpKernel {
public:
Expand Down
16 changes: 11 additions & 5 deletions tensorflow/core/kernels/mkl_avgpooling_op.cc
Expand Up @@ -24,7 +24,7 @@

#include "tensorflow/core/kernels/mkl_pooling_ops_common.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"
using mkldnn::algorithm;
using mkldnn::engine;
Expand All @@ -40,8 +40,7 @@ namespace tensorflow {

typedef Eigen::ThreadPoolDevice CPUDevice;

// For now, MKL-ML is default. So making MKL-DNN not a default choice.
#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, typename T>
class MklAvgPoolingOp : public OpKernel {
Expand Down Expand Up @@ -429,7 +428,10 @@ class MklAvgPoolingGradOp : public OpKernel {
TensorFormat data_format_;
}; // MklAvgPoolingGradOp

#else // INTEL_MKL_DNN is defined


#else


template <typename Device, typename T>
class MklAvgPoolingOp : public MklPoolingForwardOpBase<T> {
Expand Down Expand Up @@ -678,7 +680,11 @@ class MklAvgPoolingGradOp : public MklPoolingBackwardOpBase<T> {
}
}; // MklAvgPoolingGradOp

#endif // INTEL_MKL_DNN



#endif // INTEL_MKL_ML


REGISTER_KERNEL_BUILDER(Name("_MklAvgPool")
.Device(DEVICE_CPU)
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_concat_op.cc
Expand Up @@ -30,7 +30,7 @@ limitations under the License.
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::concat;
Expand Down Expand Up @@ -62,7 +62,7 @@ class EigenConcatBaseOp : public OpKernel {
// we need to have empty Compute because Compute is pure virtual function.
void Compute(OpKernelContext* c) {}

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

void Compute(OpKernelContext* c, const std::vector<Tensor>& values) {
const Tensor* concat_dim_tensor;
Expand Down Expand Up @@ -230,7 +230,7 @@ class EigenConcatBaseOp : public OpKernel {
#endif
};

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

// --------------------------------------------------------------------------
// Mkl Concat Op
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc
Expand Up @@ -42,7 +42,7 @@ limitations under the License.
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::convolution_backward_weights;
Expand All @@ -55,7 +55,7 @@ namespace tensorflow {

typedef Eigen::ThreadPoolDevice CPUDevice;

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, class T>
class MklConv2DCustomBackpropFilterOp : public OpKernel {
Expand Down Expand Up @@ -655,7 +655,7 @@ class MklConv2DCustomBackpropFilterOp
TF_CALL_float(REGISTER_MKL_FILTER_KERNELS);
#undef REGISTER_MKL_FILTER_KERNELS

#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

} // namespace tensorflow

Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_conv_grad_input_ops.cc
Expand Up @@ -44,7 +44,7 @@ limitations under the License.
#include "tensorflow/core/util/use_cudnn.h"
#include "tensorflow/core/util/work_sharder.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::convolution_backward_data;
Expand All @@ -56,7 +56,7 @@ namespace tensorflow {

typedef Eigen::ThreadPoolDevice CPUDevice;

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, class T>
class MklConv2DCustomBackpropInputOp : public OpKernel {
Expand Down Expand Up @@ -493,7 +493,7 @@ class MklConv2DCustomBackpropInputOp
}
};

#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

#define REGISTER_MKL_CPU_KERNELS(T) \
REGISTER_KERNEL_BUILDER(Name("_MklConv2DBackpropInput") \
Expand Down
9 changes: 6 additions & 3 deletions tensorflow/core/kernels/mkl_conv_ops.cc
Expand Up @@ -41,7 +41,10 @@ limitations under the License.

#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN


#ifndef INTEL_MKL_ML

#include "mkldnn.hpp"

using mkldnn::prop_kind;
Expand All @@ -58,8 +61,8 @@ namespace tensorflow {

typedef Eigen::ThreadPoolDevice CPUDevice;

// For now, MKL-ML is default. So making MKL-DNN not a default choice.
#ifndef INTEL_MKL_DNN
// MKL-DNN is now default. MKL-ML must be specified explicitly.
#ifdef INTEL_MKL_ML

template <typename Device, typename T, bool biasEnabled>
class MklConv2DOp : public OpKernel {
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_conv_ops.h
Expand Up @@ -40,7 +40,7 @@ limitations under the License.

#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::prop_kind;
Expand All @@ -52,7 +52,7 @@ using mkldnn::convolution_forward;

namespace tensorflow {

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML

class MklDnnConvUtil {
protected:
Expand Down Expand Up @@ -553,7 +553,7 @@ class MklConv2DBackpropCommonOp : public OpKernel {
Padding padding_;
TensorFormat data_format_;
};
#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

/////////////////////////////////////////////////////////////////////
/// Dummy Mkl op that is just used for operators that are intermediate
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_fused_batch_norm_op.cc
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::batch_normalization_backward;
Expand All @@ -41,7 +41,7 @@ using mkldnn::use_scale_shift;
namespace tensorflow {
using CPUDevice = Eigen::ThreadPoolDevice;

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, typename T>
class MklFusedBatchNormOp : public OpKernel {
Expand Down Expand Up @@ -683,7 +683,7 @@ class MklFusedBatchNormGradOp : public OpKernel {
};
#endif

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML

template <typename Device, typename T>
class MklFusedBatchNormOp : public OpKernel {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_identity_op.cc
Expand Up @@ -28,14 +28,14 @@ limitations under the License.
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"
#endif

namespace tensorflow {
typedef Eigen::ThreadPoolDevice CPUDevice;

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename Device, typename T>
class MklIdentityOp : public OpKernel {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_input_conversion_op.cc
Expand Up @@ -31,7 +31,7 @@ limitations under the License.
#include "tensorflow/core/kernels/mkl_tfconv_op.h"
#include "tensorflow/core/util/mkl_util.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"

using mkldnn::stream;
Expand Down Expand Up @@ -59,7 +59,7 @@ typedef Eigen::ThreadPoolDevice CPUDevice;
// convert the TF format input to MKL format
///////////////////////////////////////////////////////////

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML
template <typename Device, typename T>
class MklInputConversionOp : public OpKernel {
public:
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/mkl_lrn_op.cc
Expand Up @@ -38,7 +38,7 @@ limitations under the License.
#include "tensorflow/core/util/work_sharder.h"
#endif

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include "mkldnn.hpp"
using mkldnn::lrn_across_channels;
using mkldnn::lrn_backward;
Expand Down Expand Up @@ -67,7 +67,7 @@ void GetBandMatrix(int depth, int depth_radius,

} // namespace

#ifndef INTEL_MKL_DNN
#ifdef INTEL_MKL_ML

template <typename T>
class MklLRNOp : public OpKernel {
Expand Down Expand Up @@ -1343,7 +1343,7 @@ class MklLRNGradOp : public OpKernel {
float beta_;
};

#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

#define REGISTER_MKL_LRN_CPU(T) \
REGISTER_KERNEL_BUILDER(Name("_MklLRN") \
Expand Down
10 changes: 5 additions & 5 deletions tensorflow/core/kernels/mkl_maxpooling_op.cc
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
#include "tensorflow/core/util/mkl_util.h"
#include "tensorflow/core/util/padding.h"

#ifdef INTEL_MKL_DNN
#ifndef INTEL_MKL_ML
#include <algorithm>
#include "mkldnn.hpp"
using mkldnn::algorithm;
Expand All @@ -39,8 +39,8 @@ namespace tensorflow {

typedef Eigen::ThreadPoolDevice CPUDevice;

// For now, MKL-ML is default. So making MKL-DNN not a default choice.
#ifndef INTEL_MKL_DNN
// MKL-DNN is now default. MKL-ML must be specified explicitly.
#ifdef INTEL_MKL_ML

// An implementation of MaxPooling (forward).
template <typename Device, typename T>
Expand Down Expand Up @@ -494,7 +494,7 @@ class MklMaxPoolingGradOp : public OpKernel {
bool workspace_enabled_;
}; // MklMaxPoolingGradOp

#else // INTEL_MKL_DNN is defined
#else

// An implementation of MaxPooling (forward).
template <typename Device, typename T>
Expand Down Expand Up @@ -793,7 +793,7 @@ class MklMaxPoolingGradOp : public MklPoolingBackwardOpBase<T> {
}
}; // MklMaxPoolingGradOp

#endif // INTEL_MKL_DNN
#endif // INTEL_MKL_ML

REGISTER_KERNEL_BUILDER(Name("_MklMaxPool")
.Device(DEVICE_CPU)
Expand Down

0 comments on commit e4a628a

Please sign in to comment.