This is an automated email from the ASF dual-hosted git repository.

marcoabreu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 148a50a  Revert "[MXNET-351] Fix a bug in the MKLDNN integration." 
(#10718)
148a50a is described below

commit 148a50acedb9a066f10ae4af3cd325e3b9fc5a61
Author: Marco de Abreu <marcoab...@users.noreply.github.com>
AuthorDate: Fri Apr 27 07:45:21 2018 -0700

    Revert "[MXNET-351] Fix a bug in the MKLDNN integration." (#10718)
    
    * Revert "test Jenkins."
    
    This reverts commit 1d33fc798231f27d8f7c19e517955d91890faf3a.
    
    * Revert "test jenkins."
    
    This reverts commit 652a8953c44585f831f4e220c8ae82d402be1576.
    
    * Revert "Fix Jenkins."
    
    This reverts commit e5549995b9bac8194826503985b4e3292d271cc8.
    
    * Revert "Fix jenkins."
    
    This reverts commit 608583158557a40668705a5c090dd0f9fe7a89e8.
    
    * Revert "test in jenkins."
    
    This reverts commit 07819ad72268370b459b42f4f7b6a011c5dfcdfe.
    
    * Revert "Reorganize test code."
    
    This reverts commit 9e90090f0b64906d191d1e3fa99802c8be2ba5cf.
    
    * Revert "add comments for the test code."
    
    This reverts commit 99bd17f917a8e1ba533567a543ed8f5bd147e60f.
    
    * Revert "Add more test cases."
    
    This reverts commit 2bd669172526307a94943daf8f4d409962e44c64.
    
    * Revert "Fix lint error."
    
    This reverts commit 9d1b9dc89f9a59b8ca3ee982786f64210a697085.
    
    * Revert "Unit tests on GetMKLDNNDataReorder."
    
    This reverts commit 7d6e8e0b3adb4ff039a7585e01b19f88498a9f89.
    
    * Revert "Fix a minor bug."
    
    This reverts commit deeeea42e4c1590b3ca16b028056295116c6ae9e.
    
    * Revert "Add C++ unit test for NDArray."
    
    This reverts commit 29cd215d29594583733cf50c19957775278f13df.
    
    * Revert "avoid unnecessary message."
    
    This reverts commit 3713ead5133d076ebfcd76413d965999cd380e08.
    
    * Revert "Handle all cases for GetMKLDNNDataReorder"
    
    This reverts commit a1cb6a6c152731067622aff101a8b66b383698ec.
    
    * Revert "Update comments."
    
    This reverts commit d62f138d7fc27f775befa7c61072caff0ceac718.
    
    * Revert "Fix a bug in GetMKLDNNData()."
    
    This reverts commit 76a102989af0c4b635083437b9ef133435710fd8.
    
    * Revert "test inference multiple times."
    
    This reverts commit 0a664ef842f5c3ecc9400af2e37921b2a81b49fb.
---
 Jenkinsfile                                  |   5 +-
 src/ndarray/ndarray.cc                       |  48 ++----
 src/operator/nn/mkldnn/mkldnn_base-inl.h     |  31 +---
 src/operator/nn/mkldnn/mkldnn_base.cc        |  12 +-
 tests/cpp/operator/mkldnn.cc                 | 248 ---------------------------
 tests/python/gpu/test_gluon_model_zoo_gpu.py |  19 +-
 6 files changed, 34 insertions(+), 329 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 1402e8e..5601c52 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -26,7 +26,7 @@ mx_lib = 'lib/libmxnet.so, lib/libmxnet.a, 
3rdparty/dmlc-core/libdmlc.a, 3rdpart
 mx_dist_lib = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 
3rdparty/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, 
deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a'
 // mxnet cmake libraries, in cmake builds we do not produce a libnvvm static 
library by default.
 mx_cmake_lib = 'build/libmxnet.so, build/libmxnet.a, 
build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, 
build/3rdparty/openmp/runtime/src/libomp.so'
-mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, 
build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, 
build/3rdparty/openmp/runtime/src/libomp.so, build/libmkldnn.so.0'
+mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, 
build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, 
build/3rdparty/openmp/runtime/src/libomp.so, 
build/3rdparty/mkldnn/src/libmkldnn.so, 
build/3rdparty/mkldnn/src/libmkldnn.so.0'
 mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, 
lib/libmkldnn.so.0, lib/libmklml_intel.so, 3rdparty/dmlc-core/libdmlc.a, 
3rdparty/nnvm/lib/libnnvm.a'
 // command to start a docker container
 docker_run = 'tests/ci_build/ci_build.sh'
@@ -288,7 +288,6 @@ try {
           timeout(time: max_time, unit: 'MINUTES') {
             init_git()
             sh "ci/build.py --platform ubuntu_gpu /work/runtime_functions.sh 
build_ubuntu_gpu_cmake_mkldnn" //build_cuda
-            sh "cp build/3rdparty/mkldnn/src/libmkldnn.so.0 build/"
             pack_lib('cmake_mkldnn_gpu', mx_cmake_mkldnn_lib)
           }
         }
@@ -569,7 +568,7 @@ try {
         ws('workspace/ut-cpp-gpu') {
           timeout(time: max_time, unit: 'MINUTES') {
             init_git()
-            unpack_lib('cmake_mkldnn_gpu', mx_cmake_mkldnn_lib)
+            unpack_lib('cmake_gpu', mx_cmake_lib)
             sh "ci/build.py --nvidiadocker --platform ubuntu_gpu 
/work/runtime_functions.sh unittest_ubuntu_gpu_cpp"
           }
         }
diff --git a/src/ndarray/ndarray.cc b/src/ndarray/ndarray.cc
index 82de094..b428c2c 100644
--- a/src/ndarray/ndarray.cc
+++ b/src/ndarray/ndarray.cc
@@ -485,8 +485,8 @@ const mkldnn::memory *NDArray::GetMKLDNNData(
 }
 
 const mkldnn::memory *NDArray::GetMKLDNNDataReorder(
-    const mkldnn::memory::primitive_desc &new_pd) const {
-  if (new_pd.get_size() != shape().Size() * GetTypeSize(dtype_)) {
+    const mkldnn::memory::primitive_desc &desc) const {
+  if (desc.get_size() != shape().Size() * GetTypeSize(dtype_)) {
     LOG(FATAL) << "The size of NDArray doesn't match the requested MKLDNN 
memory desc";
     return nullptr;
   }
@@ -495,41 +495,24 @@ const mkldnn::memory *NDArray::GetMKLDNNDataReorder(
   const mkldnn::memory *mem = GetMKLDNNData();
   // If the memory descriptor matches, it's easy.
   MKLDNNStream *stream = MKLDNNStream::Get();
-  if (mem->get_primitive_desc() == new_pd) {
-    return GetMKLDNNExact(mem, new_pd);
+  if (mem->get_primitive_desc() == desc) {
+    return GetMKLDNNExact(mem, desc);
   }
 
-  mkldnn::memory::primitive_desc _pd = new_pd;
-  mkldnn::memory::desc desc1 = mem->get_primitive_desc().desc();
-  mkldnn::memory::desc desc2 = _pd.desc();
+  mkldnn::memory::primitive_desc _desc = desc;
   // Now we need to determine if we should reorder the memory.
   // If both use the default formats, we think we don't need to reorder.
+  mkldnn::memory::desc desc1 = mem->get_primitive_desc().desc();
+  mkldnn::memory::desc desc2 = _desc.desc();
   if (desc1.data.format == GetDefaultFormat(desc1) &&
       desc2.data.format == GetDefaultFormat(desc2)) {
-    mkldnn_mem_ptr ret(new mkldnn::memory(new_pd, mem->get_data_handle()));
+    mkldnn_mem_ptr ret(new mkldnn::memory(desc, mem->get_data_handle()));
     stream->RegisterMem(ret);
     return ret.get();
-  } else if (same_shape(desc1, desc2)) {
-    // If they have the same shape, we can reorder data directly.
-    mkldnn::memory *ret = TmpMemMgr::Get()->Alloc(new_pd);
+  } else {
+    mkldnn::memory *ret = TmpMemMgr::Get()->Alloc(desc);
     stream->RegisterPrim(mkldnn::reorder(*mem, *ret));
     return ret;
-  } else {
-    // If they have different shapes, we need to reshape the array first.
-    // Since this method will only be used inside an operator, we can call
-    // MKLDNNDataReshape to reshape an array.
-    TShape required_shape(desc2.data.ndims);
-    for (int i = 0; i < desc2.data.ndims; i++)
-      required_shape[i] = desc2.data.dims[i];
-    NDArray reshaped = MKLDNNDataReshape(required_shape);
-    const mkldnn::memory *ret = reshaped.GetMKLDNNData();
-    if (ret->get_primitive_desc() == new_pd) {
-      return GetMKLDNNExact(ret, new_pd);
-    } else {
-      mkldnn::memory *ret2 = TmpMemMgr::Get()->Alloc(new_pd);
-      stream->RegisterPrim(mkldnn::reorder(*ret, *ret2));
-      return ret2;
-    }
   }
 }
 
@@ -583,15 +566,10 @@ void NDArray::MKLDNNDataReorderAsync(const 
mkldnn::memory::primitive_desc &desc)
 
 const mkldnn::memory *NDArray::GetMKLDNNData() const {
   CHECK(storage_type() == kDefaultStorage);
-  if (IsMKLDNNData()) {
-    // If this array uses MKLDNN layout, we have to make sure it's not a view.
-    // Otherwise, we'll have to change the layout inside the array.
+  // If this array uses MKLDNN layout, we have to make sure it's not a view.
+  // Otherwise, we'll have to change the layout inside the array.
+  if (IsMKLDNNData())
     CHECK(!IsView());
-    MKLDNNStream::Get()->RegisterMem(ptr_->mkl_mem_->GetMem());
-    // If this array uses MKLDNN format, we should return now. Otherwise,
-    // SetMKLMem may mess up mkl_mem_.
-    return ptr_->mkl_mem_->GetRaw();
-  }
   ptr_->SetMKLMem(IsView() ? ptr_->storage_shape : shape_, dtype_);
   MKLDNNStream::Get()->RegisterMem(ptr_->mkl_mem_->GetMem());
   if (IsView()) {
diff --git a/src/operator/nn/mkldnn/mkldnn_base-inl.h 
b/src/operator/nn/mkldnn/mkldnn_base-inl.h
index f47a051..489351e 100644
--- a/src/operator/nn/mkldnn/mkldnn_base-inl.h
+++ b/src/operator/nn/mkldnn/mkldnn_base-inl.h
@@ -272,12 +272,13 @@ class MKLDNNStream {
   std::vector<std::shared_ptr<const mkldnn::memory> > mem_holder;
 
  public:
-  static MKLDNNStream *Get();
-
-  void RegisterPrim(const mkldnn::primitive &prim) {
-    net.push_back(prim);
+  static MKLDNNStream *Get() {
+    static thread_local MKLDNNStream stream;
+    return &stream;
   }
 
+  void RegisterPrim(const mkldnn::primitive &prim) { net.push_back(prim); }
+
   void RegisterMem(std::shared_ptr<const mkldnn::memory> mem) {
     mem_holder.push_back(mem);
   }
@@ -286,16 +287,10 @@ class MKLDNNStream {
     return !net.empty();
   }
 
-  void Submit(bool cleanup = true) {
-    if (!net.empty()) {
+  void Submit() {
+    if (!net.empty())
       mkldnn::stream(mkldnn::stream::kind::eager).submit(net).wait();
-      net.clear();
-    }
-    if (cleanup)
-      Cleanup();
-  }
-
-  void Cleanup() {
+    net.clear();
     mem_holder.clear();
     TmpMemMgr::Get()->Reset();
   }
@@ -353,16 +348,6 @@ inline bool same_shape(const TShape &shape, const 
mkldnn_dims_t dims, int ndims)
   return true;
 }
 
-inline bool same_shape(const mkldnn::memory::desc &desc1,
-                       const mkldnn::memory::desc &desc2) {
-  if (desc1.data.ndims != desc2.data.ndims)
-    return false;
-  for (int i = 0; i < desc1.data.ndims; i++)
-    if (desc1.data.dims[i] != desc2.data.dims[i])
-      return false;
-  return true;
-}
-
 inline bool same_shape(const TShape &shape, int dtype,
                        const mkldnn::memory::desc &desc) {
   return same_shape(shape, desc.data.dims, desc.data.ndims)
diff --git a/src/operator/nn/mkldnn/mkldnn_base.cc 
b/src/operator/nn/mkldnn/mkldnn_base.cc
index c0e1ee6..df37db5 100644
--- a/src/operator/nn/mkldnn/mkldnn_base.cc
+++ b/src/operator/nn/mkldnn/mkldnn_base.cc
@@ -25,11 +25,6 @@
 
 namespace mxnet {
 
-MKLDNNStream *MKLDNNStream::Get() {
-  static thread_local MKLDNNStream stream;
-  return &stream;
-}
-
 void *AlignMem(void *mem, size_t size, size_t alignment, size_t *space) {
   if (size > *space)
     return nullptr;
@@ -62,11 +57,8 @@ mkldnn::memory *TmpMemMgr::Alloc(const 
mkldnn::memory::primitive_desc &pd) {
     this->curr_mem = static_cast<char *>(mem) + pd.get_size();
     return ret.get();
   } else {
-    // If curr_mem has been initialized and we still reach here. It means
-    // the current allocated memory isn't enough.
-    if (this->curr_mem)
-      LOG(WARNING) << "Allocate " << pd.get_size()
-          << " bytes with malloc directly";
+    LOG(WARNING) << "Allocate " << pd.get_size()
+        << " bytes with malloc directly";
     mkldnn_mem_ptr ret(new mkldnn::memory(pd));
     MKLDNNStream::Get()->RegisterMem(ret);
     return ret.get();
diff --git a/tests/cpp/operator/mkldnn.cc b/tests/cpp/operator/mkldnn.cc
index 58ad894..9d4b982 100644
--- a/tests/cpp/operator/mkldnn.cc
+++ b/tests/cpp/operator/mkldnn.cc
@@ -28,8 +28,6 @@
 #include "gtest/gtest.h"
 #include "../../src/operator/nn/mkldnn/mkldnn_base-inl.h"
 
-using namespace mxnet;
-
 #if __GNUC__ >= 5
 bool test_mem_align(void *mem, size_t size, size_t alignment, size_t space) {
   void *ret1, *ret2;
@@ -86,250 +84,4 @@ TEST(MKLDNN_UTIL_FUNC, MemFormat) {
   CHECK_EQ(mkldnn_nchw, 5);
   CHECK_EQ(mkldnn_oihw, 12);
 }
-
-// Init arrays with the default layout.
-static void InitArray(NDArray *arr) {
-  const TBlob &blob = arr->data();
-  mshadow::default_real_t *data = blob.dptr<mshadow::default_real_t>();
-  size_t size = blob.Size();
-  for (size_t i = 0; i < size; i++)
-    data[i] = i;
-}
-
-// Init arrays with the specified layout.
-static void InitMKLDNNArray(NDArray *arr, const mkldnn::memory::primitive_desc 
&pd) {
-  const TBlob &blob = arr->data();
-  mshadow::default_real_t *data = blob.dptr<mshadow::default_real_t>();
-  size_t size = blob.Size();
-  for (size_t i = 0; i < size; i++)
-    data[i] = i;
-  arr->MKLDNNDataReorderAsync(pd);
-  arr->WaitToRead();
-}
-
-static void VerifyDefMem(const mkldnn::memory &mem) {
-  mkldnn::memory::primitive_desc pd = mem.get_primitive_desc();
-  mshadow::default_real_t *data
-      = static_cast<mshadow::default_real_t *>(mem.get_data_handle());
-  size_t size = pd.get_size() / sizeof(mshadow::default_real_t);
-  size_t num_same = 0;
-  for (size_t i = 0; i < size; i++)
-    num_same += data[i] == static_cast<mshadow::default_real_t>(i);
-  EXPECT_EQ(num_same, size);
-}
-
-static void VerifyMem(const mkldnn::memory &mem) {
-  mkldnn::memory::primitive_desc pd = mem.get_primitive_desc();
-
-  if (pd.desc().data.format == GetDefaultFormat(pd.desc())) {
-    VerifyDefMem(mem);
-  } else {
-    mkldnn::memory::dims dims(pd.desc().data.ndims);
-    for (size_t i = 0; i < dims.size(); i++)
-      dims[i] = pd.desc().data.dims[i];
-    mkldnn::memory::desc desc{dims,
-                              
static_cast<mkldnn::memory::data_type>(pd.desc().data.data_type),
-                              
static_cast<mkldnn::memory::format>(GetDefaultFormat(pd.desc()))};
-    mkldnn::memory::primitive_desc new_pd(desc, 
CpuEngine::Get()->get_engine());
-    mkldnn::memory new_mem(new_pd);
-
-    std::vector<mkldnn::primitive> net;
-    net.push_back(mkldnn::reorder(mem, new_mem));
-    mkldnn::stream(mkldnn::stream::kind::eager).submit(net).wait();
-    VerifyDefMem(new_mem);
-  }
-}
-
-static mkldnn::memory::primitive_desc GetMemPD(const TShape s, int dtype,
-                                               mkldnn::memory::format format) {
-  mkldnn::memory::dims dims(s.ndim());
-  for (size_t i = 0; i < dims.size(); i++)
-    dims[i] = s[i];
-  mkldnn::memory::desc desc{dims, get_mkldnn_type(dtype), format};
-  return mkldnn::memory::primitive_desc(desc, CpuEngine::Get()->get_engine());
-}
-
-// This function gets special MKLDNN formats without knowing the specific
-// hardware configuration. Certainly, it potentially misses some format if
-// it's specific for certain array shapes. It covers at least one special 
format
-// for each of the formats: nchw, oihw, goihw.
-// To test the logic of the code in NDArray, these formats should be enough.
-static std::vector<mkldnn::memory::format> GetMKLDNNFormat(size_t num_dims, 
int dtype) {
-  if (num_dims == 4) {
-    mkldnn::memory::dims data_dims{1, 3, 224, 224};
-    mkldnn::memory::desc data_md{data_dims, get_mkldnn_type(dtype),
-                                 mkldnn::memory::format::any};
-    mkldnn::memory::dims weight_dims{96, 3, 11, 11};
-    mkldnn::memory::desc weight_md{weight_dims, get_mkldnn_type(dtype),
-                                   mkldnn::memory::format::any};
-    mkldnn::memory::dims output_dims{1, 96, 54, 54};
-    mkldnn::memory::desc out_md{output_dims, get_mkldnn_type(dtype),
-                                mkldnn::memory::format::any};
-    mkldnn::memory::dims strides{4, 4};
-    mkldnn::memory::dims padding{0, 0};
-
-    mkldnn::convolution_forward::desc desc(mkldnn::prop_kind::forward_training,
-                                           
mkldnn::algorithm::convolution_direct,
-                                           data_md, weight_md, out_md, strides,
-                                           padding, padding, 
mkldnn::padding_kind::zero);
-    mkldnn::convolution_forward::primitive_desc pd(desc, 
CpuEngine::Get()->get_engine());
-    std::vector<mkldnn::memory::format> ret(2);
-    ret[0] = 
static_cast<mkldnn::memory::format>(pd.dst_primitive_desc().desc().data.format);
-    ret[1] = 
static_cast<mkldnn::memory::format>(pd.weights_primitive_desc().desc().data.format);
-    printf("format: %d, %d\n", ret[0], ret[1]);
-    return ret;
-  } else if (num_dims == 5) {
-    mkldnn::memory::dims data_dims{1, 32, 112, 112};
-    mkldnn::memory::desc data_md{data_dims, get_mkldnn_type(dtype),
-                                 mkldnn::memory::format::any};
-    mkldnn::memory::dims weight_dims{32, 1, 1, 3, 3};
-    mkldnn::memory::desc weight_md{weight_dims, get_mkldnn_type(dtype),
-                                   mkldnn::memory::format::any};
-    mkldnn::memory::dims output_dims{1, 32, 112, 112};
-    mkldnn::memory::desc out_md{output_dims, get_mkldnn_type(dtype),
-                                mkldnn::memory::format::any};
-    mkldnn::memory::dims strides{1, 1};
-    mkldnn::memory::dims padding{1, 1};
-
-    mkldnn::convolution_forward::desc desc(mkldnn::prop_kind::forward_training,
-                                           
mkldnn::algorithm::convolution_direct,
-                                           data_md, weight_md, out_md, strides,
-                                           padding, padding, 
mkldnn::padding_kind::zero);
-    mkldnn::convolution_forward::primitive_desc pd(desc, 
CpuEngine::Get()->get_engine());
-    std::vector<mkldnn::memory::format> ret(1);
-    ret[0] = 
static_cast<mkldnn::memory::format>(pd.weights_primitive_desc().desc().data.format);
-    printf("format: %d\n", ret[0]);
-    return ret;
-  } else {
-    return std::vector<mkldnn::memory::format>();
-  }
-}
-
-struct TestArrayShapes {
-  std::vector<TShape> shapes;
-  std::vector<mkldnn::memory::primitive_desc> pds;
-};
-
-static TestArrayShapes GetTestArrayShapes() {
-  int dtype = mshadow::DataType<mshadow::default_real_t>::kFlag;
-  std::vector<TShape> shapes;
-  std::vector<mkldnn::memory::primitive_desc> pds;
-  {
-    // 1D
-    TShape s(1);
-    s[0] = 279936;
-    shapes.push_back(s);
-    pds.push_back(GetMemPD(s, dtype, mkldnn::memory::format::x));
-    s[0] = 34848;
-    shapes.push_back(s);
-    pds.push_back(GetMemPD(s, dtype, mkldnn::memory::format::x));
-  }
-  {
-    // 2D
-    TShape s(2);
-    s[0] = 96;
-    s[1] = 2916;
-    shapes.push_back(s);
-    pds.push_back(GetMemPD(s, dtype, mkldnn::memory::format::nc));
-    s[0] = 96;
-    s[1] = 363;
-    shapes.push_back(s);
-    pds.push_back(GetMemPD(s, dtype, mkldnn::memory::format::nc));
-  }
-  {
-    // 4D
-    TShape s1(4);
-    s1[0] = 1; s1[1] = 96; s1[2] = 54; s1[3] = 54;
-    shapes.push_back(s1);
-    pds.push_back(GetMemPD(s1, dtype, mkldnn::memory::format::nchw));
-
-    TShape s2(4);
-    s2[0] = 96; s2[1] = 3; s2[2] = 11; s2[3] = 11;
-    shapes.push_back(s2);
-    pds.push_back(GetMemPD(s2, dtype, mkldnn::memory::format::oihw));
-
-    std::vector<mkldnn::memory::format> formats = GetMKLDNNFormat(4, dtype);
-    pds.push_back(GetMemPD(s1, dtype, formats[0]));
-    pds.push_back(GetMemPD(s2, dtype, formats[1]));
-  }
-  {
-    // 5D
-    TShape s(5);
-    s[0] = 96; s[1] = 1; s[2] = 3; s[3] = 11; s[4] = 11;
-    shapes.push_back(s);
-    pds.push_back(GetMemPD(s, dtype, mkldnn::memory::format::goihw));
-
-    std::vector<mkldnn::memory::format> formats = GetMKLDNNFormat(5, dtype);
-    pds.push_back(GetMemPD(s, dtype, formats[0]));
-  }
-
-  TestArrayShapes ret;
-  ret.shapes = shapes;
-  ret.pds = pds;
-  return ret;
-}
-
-TEST(MKLDNN_NDArray, GetDataReorder) {
-  TestArrayShapes tas = GetTestArrayShapes();
-  std::vector<TShape> shapes = tas.shapes;
-  std::vector<mkldnn::memory::primitive_desc> pds = tas.pds;
-
-
-  // Reorder from the default to any other layout.
-  for (auto s : shapes) {
-    NDArray arr(s, Context());
-    InitArray(&arr);
-    for (auto pd : pds) {
-      if (s.Size() == pd.get_size() / sizeof(mshadow::default_real_t)) {
-        const mkldnn::memory *mem = arr.GetMKLDNNDataReorder(pd);
-        printf("reorder from (");
-        for (size_t i = 0; i < s.ndim(); i++)
-          printf("%ld, ", s[i]);
-        printf(") to (");
-        for (int i = 0; i < pd.desc().data.ndims; i++)
-          printf("%d, ", pd.desc().data.dims[i]);
-        printf("), format: %d\n", pd.desc().data.format);
-        MKLDNNStream::Get()->Submit(false);
-        VerifyMem(*mem);
-        MKLDNNStream::Get()->Cleanup();
-      }
-    }
-  }
-
-  // Reorder from a special layout to another layout.
-  for (auto s : shapes) {
-    for (auto from_pd : pds) {
-      if (from_pd.get_size() / sizeof(mshadow::default_real_t) == s.Size()) {
-        NDArray arr(s, Context());
-        // There is possibility that the dimensions of an NDArray doesn't match
-        // with the MKLDNN memory inside.
-        printf("Init array (");
-        for (size_t i = 0; i < s.ndim(); i++)
-          printf("%ld, ", s[i]);
-        printf(") with MKLDNN memory (");
-        for (int i = 0; i < from_pd.desc().data.ndims; i++)
-          printf("%d, ", from_pd.desc().data.dims[i]);
-        printf("), format: %d\n", from_pd.desc().data.format);
-        InitMKLDNNArray(&arr, from_pd);
-        for (auto to_pd : pds) {
-          if (to_pd.get_size() / sizeof(mshadow::default_real_t) == s.Size()) {
-            const mkldnn::memory *mem = arr.GetMKLDNNDataReorder(to_pd);
-            printf("reorder from (");
-            for (size_t i = 0; i < s.ndim(); i++)
-              printf("%ld, ", s[i]);
-            printf("), format: %d to (",
-                   
arr.GetMKLDNNData()->get_primitive_desc().desc().data.format);
-            for (int i = 0; i < to_pd.desc().data.ndims; i++)
-              printf("%d, ", to_pd.desc().data.dims[i]);
-            printf("), format: %d\n", to_pd.desc().data.format);
-            MKLDNNStream::Get()->Submit(false);
-            VerifyMem(*mem);
-            MKLDNNStream::Get()->Cleanup();
-          }
-        }
-      }
-    }
-  }
-}
-
 #endif
diff --git a/tests/python/gpu/test_gluon_model_zoo_gpu.py 
b/tests/python/gpu/test_gluon_model_zoo_gpu.py
index 273ad3d..378a822 100644
--- a/tests/python/gpu/test_gluon_model_zoo_gpu.py
+++ b/tests/python/gpu/test_gluon_model_zoo_gpu.py
@@ -81,16 +81,15 @@ def test_inference():
             gpu_param = gpu_params.get(k)
             gpu_param.set_data(cpu_param.data().as_in_context(mx.gpu()))
 
-        for i in range(5):
-            # Run inference.
-            with autograd.record(train_mode=False):
-                cpu_out = cpu_model(mx.nd.array(data, ctx=mx.cpu()))
-                gpu_out = gpu_model(gpu_data)
-            out = cpu_out.asnumpy()
-            max_val = np.max(np.abs(out))
-            gpu_max_val = np.max(np.abs(gpu_out.asnumpy()))
-            eprint(model_name + ": CPU " + str(max_val) + ", GPU " + 
str(gpu_max_val))
-            assert_almost_equal(out / max_val, gpu_out.asnumpy() / max_val, 
rtol=1e-3, atol=1e-3)
+        # Run inference.
+        with autograd.record(train_mode=False):
+            cpu_out = cpu_model(mx.nd.array(data, ctx=mx.cpu()))
+            gpu_out = gpu_model(gpu_data)
+        out = cpu_out.asnumpy()
+        max_val = np.max(np.abs(out))
+        gpu_max_val = np.max(np.abs(gpu_out.asnumpy()))
+        eprint(model_name + ": CPU " + str(max_val) + ", GPU " + 
str(gpu_max_val))
+        assert_almost_equal(out / max_val, gpu_out.asnumpy() / max_val, 
rtol=1e-3, atol=1e-3)
 
 def get_nn_model(name):
     if "densenet" in name:

-- 
To stop receiving notification emails like this one, please contact
marcoab...@apache.org.

Reply via email to