Skip to content

Commit

Permalink
Remove EIGEN_USE_LIBXSMM support from Tensorflow.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 264222375
  • Loading branch information
ezhulenev authored and tensorflower-gardener committed Aug 19, 2019
1 parent 1454690 commit afe53b5
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 175 deletions.
4 changes: 2 additions & 2 deletions tensorflow/core/grappler/clusters/utils.cc
Expand Up @@ -27,7 +27,7 @@ limitations under the License.
#include "rocm/include/hip/hip_runtime.h"
#endif

#ifdef EIGEN_USE_LIBXSMM
#ifdef TENSORFLOW_USE_LIBXSMM
#include "include/libxsmm.h"
#endif

Expand Down Expand Up @@ -67,7 +67,7 @@ DeviceProperties GetLocalCPUInfo() {

(*device.mutable_environment())["eigen"] = strings::StrCat(
EIGEN_WORLD_VERSION, ".", EIGEN_MAJOR_VERSION, ".", EIGEN_MINOR_VERSION);
#ifdef EIGEN_USE_LIBXSMM
#ifdef TENSORFLOW_USE_LIBXSMM
(*device.mutable_environment())["libxsmm"] = LIBXSMM_VERSION;
#endif

Expand Down
19 changes: 0 additions & 19 deletions tensorflow/core/grappler/optimizers/remapper.cc
Expand Up @@ -64,15 +64,6 @@ constexpr char kIsTraining[] = "is_training";

constexpr int kMissingIndex = -1;

// TODO(b/119765980): Upgrade upstream Eigen to set `m_can_use_xsmm=false` for
// contractions with non-default contraction output kernels.
bool EigenSupportsContractionOutputKernel() {
#if defined(EIGEN_USE_LIBXSMM)
return false;
#endif
return true;
}

struct RemapperContext {
explicit RemapperContext(GrapplerItem* item, Status* status)
: nodes_to_preserve(item->NodesToPreserve()),
Expand Down Expand Up @@ -353,8 +344,6 @@ inline bool HasAtMostOneFanoutAtPort0(const utils::MutableNodeView& node_view) {
bool FindContractionWithBias(const RemapperContext& ctx, int node_index,
ContractionWithBiasAdd* matched,
bool check_device_compatible = true) {
if (!EigenSupportsContractionOutputKernel()) return false;

const auto* node_view = ctx.graph_view.GetNode(node_index);
// Root of the pattern must be a BiasAdd.
// TODO(lyandy): Forward controls for patterns with control dependencies.
Expand Down Expand Up @@ -394,8 +383,6 @@ bool FindContractionWithBias(const RemapperContext& ctx, int node_index,
bool FindContractionWithBiasAndActivation(
const RemapperContext& ctx, int node_index,
ContractionWithBiasAddAndActivation* matched) {
if (!EigenSupportsContractionOutputKernel()) return false;

const auto* node_view = ctx.graph_view.GetNode(node_index);
// Root of the pattern must be an activation node.
// TODO(lyandy): Forward controls for patterns with control dependencies.
Expand Down Expand Up @@ -431,8 +418,6 @@ bool FindContractionWithBiasAndActivation(

bool FindConv2DWithSqueezeAndBias(const RemapperContext& ctx, int node_index,
ContractionWithSqueezeAndBiasAdd* matched) {
if (!EigenSupportsContractionOutputKernel()) return false;

const auto* node_view = ctx.graph_view.GetNode(node_index);
// TODO(lyandy): Forward controls for patterns with control dependencies.
if (HasControlFaninOrFanout(*node_view)) return false;
Expand Down Expand Up @@ -488,8 +473,6 @@ bool FindConv2DWithSqueezeAndBias(const RemapperContext& ctx, int node_index,

bool FindConv2DWithBatchNorm(const RemapperContext& ctx, int node_index,
ContractionWithBatchNorm* matched) {
if (!EigenSupportsContractionOutputKernel()) return false;

const auto* node_view = ctx.graph_view.GetNode(node_index);
const auto* node_def = node_view->node();
// Root of the pattern must be a FusedBatchNorm.
Expand Down Expand Up @@ -539,8 +522,6 @@ bool FindConv2DWithBatchNorm(const RemapperContext& ctx, int node_index,
bool FindConv2DWithBatchNormAndActivation(
const RemapperContext& ctx, int node_index,
ContractionWithBatchNormAndActivation* matched) {
if (!EigenSupportsContractionOutputKernel()) return false;

const auto* node_view = ctx.graph_view.GetNode(node_index);
// TODO(lyandy): Forward controls for patterns with control dependencies.
if (HasControlFaninOrFanout(*node_view)) return false;
Expand Down
23 changes: 0 additions & 23 deletions tensorflow/core/grappler/optimizers/remapper_test.cc
Expand Up @@ -37,15 +37,6 @@ class RemapperTest : public GrapplerTest {
// This is a requirement for fusing FusedBatchNorm + SideInput + Activation.
setenv("TF_USE_CUDNN_BATCHNORM_SPATIAL_PERSISTENT", "1", 1 /* replace */);
}

// TODO(b/119765980): Upgrade upstream Eigen to set `m_can_use_xsmm=false` for
// contractions with non-default contraction output kernels.
bool EigenSupportsContractionOutputKernel() {
#if defined(EIGEN_USE_LIBXSMM)
return false;
#endif
return true;
}
};

TEST_F(RemapperTest, FusedBatchNorm) {
Expand Down Expand Up @@ -336,8 +327,6 @@ TEST_F(RemapperTest, FuseBatchNormWithAddAndRelu) {
}

TEST_F(RemapperTest, FuseConv2DWithBias) {
if (!EigenSupportsContractionOutputKernel()) return;

using ::tensorflow::ops::Placeholder;

tensorflow::Scope s = tensorflow::Scope::NewRootScope();
Expand Down Expand Up @@ -400,8 +389,6 @@ TEST_F(RemapperTest, FuseConv2DWithBias) {
}

TEST_F(RemapperTest, FuseMatMulWithBias) {
if (!EigenSupportsContractionOutputKernel()) return;

using ::tensorflow::ops::Placeholder;

tensorflow::Scope s = tensorflow::Scope::NewRootScope();
Expand Down Expand Up @@ -463,8 +450,6 @@ TEST_F(RemapperTest, FuseMatMulWithBias) {
}

TEST_F(RemapperTest, FuseConv2DWithBiasAndActivation) {
if (!EigenSupportsContractionOutputKernel()) return;

using ::tensorflow::ops::Placeholder;

for (const string& activation : {"Relu", "Relu6", "Elu"}) {
Expand Down Expand Up @@ -545,8 +530,6 @@ TEST_F(RemapperTest, FuseConv2DWithBiasAndActivation) {
}

TEST_F(RemapperTest, FuseMatMulWithBiasAndActivation) {
if (!EigenSupportsContractionOutputKernel()) return;

using ::tensorflow::ops::Placeholder;

for (const string& activation : {"Relu", "Relu6", "Elu"}) {
Expand Down Expand Up @@ -625,8 +608,6 @@ TEST_F(RemapperTest, FuseMatMulWithBiasAndActivation) {
}

TEST_F(RemapperTest, FuseConv2DWithBatchNorm) {
if (!EigenSupportsContractionOutputKernel()) return;

using ops::Placeholder;

tensorflow::Scope s = tensorflow::Scope::NewRootScope();
Expand Down Expand Up @@ -705,8 +686,6 @@ TEST_F(RemapperTest, FuseConv2DWithBatchNorm) {
}

TEST_F(RemapperTest, FuseConv2DWithBatchNormAndActivation) {
if (!EigenSupportsContractionOutputKernel()) return;

using ops::Placeholder;

for (const string& activation : {"Relu", "Relu6", "Elu"}) {
Expand Down Expand Up @@ -802,8 +781,6 @@ TEST_F(RemapperTest, FuseConv2DWithBatchNormAndActivation) {
}

TEST_F(RemapperTest, FuseConv2DWithSqueezeAndBias) {
if (!EigenSupportsContractionOutputKernel()) return;

using ops::Placeholder;

tensorflow::Scope s = tensorflow::Scope::NewRootScope();
Expand Down
12 changes: 2 additions & 10 deletions tensorflow/core/kernels/BUILD
Expand Up @@ -3783,10 +3783,7 @@ tf_kernel_library(
],
hdrs = ["matmul_op.h"],
defines = select({
":xsmm": [
"TENSORFLOW_USE_LIBXSMM",
"EIGEN_USE_LIBXSMM",
],
":xsmm": ["TENSORFLOW_USE_LIBXSMM"],
"//conditions:default": [],
}),
deps = MATH_DEPS + [
Expand Down Expand Up @@ -4209,12 +4206,7 @@ tf_kernel_library(
"//conditions:default": [],
}),
defines = select({
":xsmm_convolutions": [
"TENSORFLOW_USE_LIBXSMM_CONVOLUTIONS",
],
"//conditions:default": [],
}) + select({
":xsmm": ["EIGEN_USE_LIBXSMM"],
":xsmm_convolutions": ["TENSORFLOW_USE_LIBXSMM_CONVOLUTIONS"],
"//conditions:default": [],
}) + select({
":xsmm_backward_convolutions": ["TENSORFLOW_USE_LIBXSMM_BACKWARD_CONVOLUTIONS"],
Expand Down
4 changes: 1 addition & 3 deletions tensorflow/core/kernels/conv_ops_fused_double.cc
Expand Up @@ -23,9 +23,7 @@ namespace tensorflow {

// If we're using the alternative GEMM-based implementation of Conv2D for the
// CPU implementation, don't register this EigenTensor-based version.
// TODO(b/119765980): Upgrade upstream Eigen to set `m_can_use_xsmm=false` for
// contractions with non-default contraction output kernels.
#if !defined(USE_GEMM_FOR_CONV) && !defined(EIGEN_USE_LIBXSMM)
#if !defined(USE_GEMM_FOR_CONV)
TF_CALL_double(REGISTER_FUSED_CPU_CONV2D);
#endif // !USE_GEMM_FOR_CONV

Expand Down
4 changes: 1 addition & 3 deletions tensorflow/core/kernels/conv_ops_fused_float.cc
Expand Up @@ -23,9 +23,7 @@ namespace tensorflow {

// If we're using the alternative GEMM-based implementation of Conv2D for the
// CPU implementation, don't register this EigenTensor-based version.
// TODO(b/119765980): Upgrade upstream Eigen to set `m_can_use_xsmm=false` for
// contractions with non-default contraction output kernels.
#if !defined(USE_GEMM_FOR_CONV) && !defined(EIGEN_USE_LIBXSMM)
#if !defined(USE_GEMM_FOR_CONV)
TF_CALL_float(REGISTER_FUSED_CPU_CONV2D);
#endif // !USE_GEMM_FOR_CONV

Expand Down
2 changes: 0 additions & 2 deletions tensorflow/core/kernels/matmul_op_fused.cc
Expand Up @@ -189,9 +189,7 @@ class FusedMatMulOp : public OpKernel {
Name("_FusedMatMul").Device(DEVICE_CPU).TypeConstraint<T>("T"), \
FusedMatMulOp<CPUDevice, T>);

#ifndef EIGEN_USE_LIBXSMM
TF_CALL_float(REGISTER_FUSED_CPU_MATMUL);
#endif // !EIGEN_USE_LIBXSMM

#undef REGISTER_FUSED_CPU_MATMUL

Expand Down
Expand Up @@ -70,10 +70,6 @@ typedef unsigned __int64 uint64_t;
#include <time.h>
#endif

// #if defined(EIGEN_USE_LIBXSMM)
// #include "libxsmm.h"
// #endif

#ifdef EIGEN_USE_THREADS
#include "third_party/eigen3/unsupported/Eigen/CXX11/ThreadPool"
#endif
Expand Down
Expand Up @@ -70,10 +70,6 @@ typedef unsigned __int64 uint64_t;
#include <time.h>
#endif

// #if defined(EIGEN_USE_LIBXSMM)
// #include "libxsmm.h"
// #endif

#ifdef EIGEN_USE_THREADS
#include "unsupported/Eigen/CXX11/ThreadPool"
#endif
Expand Down

0 comments on commit afe53b5

Please sign in to comment.