Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTEL MKL] Remove unnecessary MKL build macros and bug fixes #47375

Merged
merged 5 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions tensorflow/core/common_runtime/mkl_cpu_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ limitations under the License.
#include "tensorflow/core/platform/mem.h"
#include "tensorflow/core/platform/numa.h"

#ifndef INTEL_MKL_DNN_ONLY
#include "i_malloc.h"
#endif

#ifdef _WIN32
typedef unsigned int uint;
#endif
Expand Down Expand Up @@ -186,14 +182,6 @@ class MklCPUAllocator : public Allocator {
new MklSmallSizeAllocator(sub_allocator_, max_mem_bytes, kName);
large_size_allocator_ =
new BFCAllocator(sub_allocator_, max_mem_bytes, kAllowGrowth, kName);
#ifndef INTEL_MKL_DNN_ONLY
// For redirecting all allocations from MKL to this allocator
// From: http://software.intel.com/en-us/node/528565
i_malloc = MallocHook;
i_calloc = CallocHook;
i_realloc = ReallocHook;
i_free = FreeHook;
#endif
return Status::OK();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ Status AutoMixedPrecision::Optimize(Cluster* cluster, const GrapplerItem& item,
return errors::InvalidArgument("cluster == nullptr");
}

#if !defined(INTEL_MKL) || !defined(ENABLE_INTEL_MKL_BFLOAT16)
#if !defined(INTEL_MKL)
if (mode_ == AutoMixedPrecisionMode::MKL) {
return errors::Unimplemented(
"The auto_mixed_precision_mkl optimizer cannot be used since "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM || \
(INTEL_MKL && defined(ENABLE_INTEL_MKL_BFLOAT16))
#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM || INTEL_MKL

#include "tensorflow/core/grappler/optimizers/auto_mixed_precision.h"

Expand Down Expand Up @@ -1178,7 +1177,6 @@ TEST_F(AutoMixedPrecisionTest, TanhOp) {
#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM

#if INTEL_MKL
#ifdef ENABLE_INTEL_MKL_BFLOAT16

class AutoMixedPrecisionMklTest : public GrapplerTest {
protected:
Expand Down Expand Up @@ -1354,12 +1352,10 @@ TEST_F(AutoMixedPrecisionMklTest, TensorListSetGet) {
}
}

#endif // ENABLE_INTEL_MKL_BFLOAT16
#endif // INTEL_MKL

} // namespace
} // namespace grappler
} // namespace tensorflow

#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM || (INTEL_MKL &&
// defined(ENABLE_INTEL_MKL_BFLOAT16))
#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM || INTEL_MKL
24 changes: 4 additions & 20 deletions tensorflow/core/grappler/optimizers/remapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,9 @@ bool IsCpuCompatibleDataType(const NodeDef* contraction,
const string& type_attr = "T") {
DataType dtype = GetDataTypeFromAttr(*contraction, type_attr);
#if defined(INTEL_MKL)
#if defined(ENABLE_INTEL_MKL_BFLOAT16)
if (IsConv2D(*contraction) || IsDepthwiseConv2dNative(*contraction) ||
IsMatMul(*contraction)) {
return dtype == DT_FLOAT || dtype == DT_BFLOAT16;
#else
if (IsConv2D(*contraction) || IsDepthwiseConv2dNative(*contraction) ||
IsMatMul(*contraction)) {
return dtype == DT_FLOAT;
#endif // ENABLE_INTEL_MKL_BFLOAT16
#else
if (IsConv2D(*contraction)) {
return dtype == DT_FLOAT || dtype == DT_DOUBLE;
Expand Down Expand Up @@ -677,14 +671,9 @@ bool FindContractionWithBiasAddAndAdd(const RemapperContext& ctx,
const auto* node_def = node_view.node();
if (!IsAddN(*node_def) && !IsAddWithNoBroadcast(ctx, *node_def)) return false;

#ifdef ENABLE_INTEL_MKL_BFLOAT16
// MKL AddN ops only support float and bfloat16 data types.
if (!HasDataType(node_def, DT_FLOAT) && !HasDataType(node_def, DT_BFLOAT16))
return false;
#else
// MKL AddN ops only support float data type.
if (!HasDataType(node_def, DT_FLOAT)) return false;
#endif // ENABLE_INTEL_MKL_BFLOAT16

ContractionWithBiasAdd base;
matched->port_id = 0;
Expand Down Expand Up @@ -730,14 +719,9 @@ bool FindContractionWithBiasAndAddActivation(
// Currently, Contraction + Bias + Add + Tanh pattern is not supported
if (IsTanh(*node_def)) return false;

#ifdef ENABLE_INTEL_MKL_BFLOAT16
// MKL activation op only supports float and bfloat16 data types.
if (!HasDataType(node_def, DT_FLOAT) && !HasDataType(node_def, DT_BFLOAT16))
return false;
#else
// MKL activation op only supports float data type.
if (!HasDataType(node_def, DT_FLOAT)) return false;
#endif // ENABLE_INTEL_MKL_BFLOAT16

// And input to activation must match ContractionWithBiasAddAndAdd pattern.
if (node_view->NumRegularFanins() < 1) return false;
Expand Down Expand Up @@ -843,15 +827,15 @@ bool FindFusedBatchNormEx(const RemapperContext& ctx, int node_index,
const auto* fused_batch_norm_node_def = fused_batch_norm.node();
if (!IsFusedBatchNorm(*fused_batch_norm_node_def)) return false;

#ifndef ENABLE_MKLDNN_V1
#ifndef INTEL_MKL
// We fuse FusedBatchNorm on GPU or MKL CPU.
if (!NodeIsOnGpu(fused_batch_norm_node_def)) return false;
#else
if (DisableMKL()) return false;
#endif

DataType t_dtype = GetDataTypeFromAttr(*fused_batch_norm_node_def, "T");
#ifndef ENABLE_MKLDNN_V1
#ifndef INTEL_MKL
if (t_dtype != DT_FLOAT && t_dtype != DT_HALF) return false;
#else
if (t_dtype != DT_FLOAT && t_dtype != DT_BFLOAT16) return false;
Expand Down Expand Up @@ -919,7 +903,7 @@ bool FindFusedBatchNormEx(const RemapperContext& ctx, int node_index,
if (IsAdd(*relu_fanin_0_node_def)) {
// Currently no CPU implementation for "FusedBatchNorm + SideInput +
// <Activation>""
#ifdef ENABLE_MKLDNN_V1
#ifdef INTEL_MKL
return false;
#endif

Expand Down Expand Up @@ -1022,7 +1006,7 @@ void CopyFusedBatchNormAttributes(const NodeDef& fused_batch_norm,
if (fused_batch_norm.op() != "FusedBatchNorm") {
SetAttrValue(src_attr.at("U"), &(*attr)["U"]);
} else {
#ifndef ENABLE_MKLDNN_V1
#ifndef INTEL_MKL
SetAttrValue(src_attr.at("T"), &(*attr)["U"]);
#else
SetAttrValue(DT_FLOAT, &(*attr)["U"]);
Expand Down
8 changes: 4 additions & 4 deletions tensorflow/core/grappler/optimizers/remapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ class RemapperFuseMatMulWithBiasTest : public RemapperTest {
TEST_F(RemapperFuseMatMulWithBiasTest, F32) { RunTest<DT_FLOAT>(); }

TEST_F(RemapperFuseMatMulWithBiasTest, Bf16) {
#if !defined(INTEL_MKL) || !defined(ENABLE_INTEL_MKL_BFLOAT16)
#if !defined(INTEL_MKL)
GTEST_SKIP() << "Intel MKL with bfloat16 support is not enabled, skipping "
"FuseMatMulWithBias with bfloat16.";
#endif // !defined(INTEL_MKL) || !defined(ENABLE_INTEL_MKL_BFLOAT16)
#endif // !defined(INTEL_MKL)
RunTest<DT_BFLOAT16>(); // NOLINT
}

Expand Down Expand Up @@ -742,10 +742,10 @@ TEST_F(RemapperFuseMatMulWithBiasAndActivationTest, F32) {
}

TEST_F(RemapperFuseMatMulWithBiasAndActivationTest, Bf16) {
#if !defined(INTEL_MKL) || !defined(ENABLE_INTEL_MKL_BFLOAT16)
#if !defined(INTEL_MKL)
GTEST_SKIP() << "Intel MKL with bfloat16 support is not enabled, skipping "
"FuseMatMulWithBiasAndActivation with bfloat16.";
#endif // !defined(INTEL_MKL) || !defined(ENABLE_INTEL_MKL_BFLOAT16)
#endif // !defined(INTEL_MKL)
RunTest<DT_BFLOAT16>(); // NOLINT
}

Expand Down
24 changes: 0 additions & 24 deletions tensorflow/core/kernels/mkl/mkl_conv_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ limitations under the License.
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"

#if defined(INTEL_MKL_DNN_ONLY)
#include "tensorflow/core/util/mkl_util.h"
#endif

// TODO(ezhulenev): Add numerical tests that will compare results of default
// (aka Eigen) convolutions with MKL convolutions.
Expand Down Expand Up @@ -123,7 +120,6 @@ static Graph* DefaultConv2D(const Conv2DDimensions& dims) {
return graph;
}

#if defined(INTEL_MKL_DNN_ONLY)
static Graph* MklConv2D(const Conv2DDimensions& dims) {
auto* graph = new Graph(OpRegistry::Global());

Expand All @@ -150,7 +146,6 @@ static Graph* MklConv2D(const Conv2DDimensions& dims) {

return graph;
}
#endif

static Graph* DefaultConv2DBwdInput(const Conv2DDimensions& dims) {
auto* graph = new Graph(OpRegistry::Global());
Expand Down Expand Up @@ -179,7 +174,6 @@ static Graph* DefaultConv2DBwdInput(const Conv2DDimensions& dims) {
return graph;
}

#if defined(INTEL_MKL_DNN_ONLY)
static Graph* MklConv2DBwdInput(const Conv2DDimensions& dims) {
auto* graph = new Graph(OpRegistry::Global());

Expand Down Expand Up @@ -213,7 +207,6 @@ static Graph* MklConv2DBwdInput(const Conv2DDimensions& dims) {

return graph;
}
#endif

static Graph* DefaultConv2DBwdFilter(const Conv2DDimensions& dims) {
auto* graph = new Graph(OpRegistry::Global());
Expand Down Expand Up @@ -243,7 +236,6 @@ static Graph* DefaultConv2DBwdFilter(const Conv2DDimensions& dims) {
return graph;
}

#if defined(INTEL_MKL_DNN_ONLY)
static Graph* MklConv2DBwdFilter(const Conv2DDimensions& dims) {
Graph* graph = new Graph(OpRegistry::Global());

Expand Down Expand Up @@ -278,7 +270,6 @@ static Graph* MklConv2DBwdFilter(const Conv2DDimensions& dims) {

return graph;
}
#endif

// Macro arguments names: --------------------------------------------------- //
// N: batch size
Expand Down Expand Up @@ -311,14 +302,9 @@ static Graph* MklConv2DBwdFilter(const Conv2DDimensions& dims) {
} \
BENCHMARK(BM_NAME(Conv2D_##kind, type, N, H, W, C, FC, FH, FW))

#if defined(INTEL_MKL_DNN_ONLY)
#define BM_Conv2D(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DT(Default, N, H, W, C, FC, FH, FW, type, LABEL); \
BM_Conv2DT(Mkl, N, H, W, C, FC, FH, FW, type, LABEL);
#else
#define BM_Conv2D(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DT(Default, N, H, W, C, FC, FH, FW, type, LABEL);
#endif

#define BM_Conv2DBwdInputT(kind, N, H, W, C, FC, FH, FW, type, LABEL) \
static void BM_NAME(Conv2DBwdInput_##kind, type, N, H, W, C, FC, FH, \
Expand All @@ -334,14 +320,9 @@ static Graph* MklConv2DBwdFilter(const Conv2DDimensions& dims) {
} \
BENCHMARK(BM_NAME(Conv2DBwdInput_##kind, type, N, H, W, C, FC, FH, FW))

#if defined(INTEL_MKL_DNN_ONLY)
#define BM_Conv2DBwdInput(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DBwdInputT(Default, N, H, W, C, FC, FH, FW, type, LABEL); \
BM_Conv2DBwdInputT(Mkl, N, H, W, C, FC, FH, FW, type, LABEL);
#else
#define BM_Conv2DBwdInput(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DBwdInputT(Default, N, H, W, C, FC, FH, FW, type, LABEL);
#endif

#define BM_Conv2DBwdFilterT(kind, N, H, W, C, FC, FH, FW, type, LABEL) \
static void BM_NAME(Conv2DBwdFilter_##kind, type, N, H, W, C, FC, FH, \
Expand All @@ -357,14 +338,9 @@ static Graph* MklConv2DBwdFilter(const Conv2DDimensions& dims) {
} \
BENCHMARK(BM_NAME(Conv2DBwdFilter_##kind, type, N, H, W, C, FC, FH, FW))

#if defined(INTEL_MKL_DNN_ONLY)
#define BM_Conv2DBwdFilter(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DBwdFilterT(Default, N, H, W, C, FC, FH, FW, type, LABEL); \
BM_Conv2DBwdFilterT(Mkl, N, H, W, C, FC, FH, FW, type, LABEL);
#else
#define BM_Conv2DBwdFilter(N, H, W, C, FC, FH, FW, type, LABEL) \
BM_Conv2DBwdFilterT(Default, N, H, W, C, FC, FH, FW, type, LABEL);
#endif

// ImageNet Convolutions ---------------------------------------------------- //

Expand Down
4 changes: 0 additions & 4 deletions tensorflow/core/kernels/mkl/mkl_fused_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,7 @@ TYPED_TEST_P(FusedPadConvOpTest, PaddingConvTestNchw) { this->Run("NCHW"); }
REGISTER_TYPED_TEST_SUITE_P(FusedPadConvOpTest, PaddingConvTest,
PaddingConvTestNchw);

#ifdef ENABLE_INTEL_MKL_BFLOAT16
using FusedPadConvDataTypes = ::testing::Types<float, bfloat16>;
#else
using FusedPadConvDataTypes = ::testing::Types<float>;
#endif
INSTANTIATE_TYPED_TEST_SUITE_P(Test, FusedPadConvOpTest, FusedPadConvDataTypes);

class FilterCacheTest : public OpsTestBase {
Expand Down
4 changes: 0 additions & 4 deletions tensorflow/core/kernels/mkl/mkl_matmul_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class MklMatMulOp : public OpKernel {
#endif // ENABLE_MKLDNN_THREADPOOL
}

#ifdef ENABLE_INTEL_MKL_BFLOAT16
void MklBlasGemm(OpKernelContext* ctx, bool transa, bool transb, const int m,
const int n, const int k, const bfloat16* a, const int lda,
const bfloat16* b, const int ldb, bfloat16* c,
Expand All @@ -181,7 +180,6 @@ class MklMatMulOp : public OpKernel {
dnnl_gemm<bfloat16>(ftrans[index_transa], ftrans[index_transb], m, n, k,
alpha, a, lda, b, ldb, beta, c, ldc, ctx);
}
#endif // ENABLE_INTEL_MKL_BFLOAT16
};

#define REGISTER_CPU(T) \
Expand All @@ -196,9 +194,7 @@ class MklMatMulOp : public OpKernel {
// TODO(inteltf) Consider template specialization when adding/removing
// additional types
TF_CALL_float(REGISTER_CPU);
#ifdef ENABLE_INTEL_MKL_BFLOAT16
TF_CALL_bfloat16(REGISTER_CPU);
#endif // ENABLE_INTEL_MKL_BFLOAT16
#endif // ENABLE_MKL
} // namespace tensorflow
#endif // INTEL_MKL
11 changes: 5 additions & 6 deletions tensorflow/core/kernels/mkl/mkl_matmul_ops_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ struct MklDnnMatMulFwdParams {
};
std::vector<PostOpParam> post_op_params;

MklDnnMatMulFwdParams(
memory::dims src_dims, memory::dims weight_dims, memory::dims bias_dims,
memory::dims dst_dims,
memory::format_tag src_format = memory::format_tag::any,
memory::format_tag weight_format = memory::format_tag::any,
memory::format_tag dst_format = memory::format_tag::any)
MklDnnMatMulFwdParams(memory::dims src_dims, memory::dims weight_dims,
memory::dims bias_dims, memory::dims dst_dims,
memory::format_tag src_format = memory::format_tag::any,
memory::format_tag weight_format = memory::format_tag::any,
memory::format_tag dst_format = memory::format_tag::any)
: src_dims(src_dims),
weight_dims(weight_dims),
bias_dims(bias_dims),
Expand Down
4 changes: 0 additions & 4 deletions tensorflow/core/kernels/mkl/mkl_tmp_bf16_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ limitations under the License.
#include "tensorflow/core/framework/register_types.h"
#include "tensorflow/core/kernels/no_op.h"

#ifdef ENABLE_INTEL_MKL_BFLOAT16

namespace tensorflow {

// This file contains temporary registrations for some of the Eigen CPU backend
Expand Down Expand Up @@ -62,5 +60,3 @@ TF_CALL_bfloat16(REGISTER_CPU);
#undef REGISTER_CPU

} // namespace tensorflow

#endif // ENABLE_INTEL_MKL_BFLOAT16
Loading