You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/24 07:42:34 UTC

[GitHub] [incubator-mxnet] wuxun-zhang commented on a change in pull request #16258: [mkldnn-v1.0] Add MKL-DNN reshape&flatten&expand_dims

wuxun-zhang commented on a change in pull request #16258: [mkldnn-v1.0] Add MKL-DNN reshape&flatten&expand_dims
URL: https://github.com/apache/incubator-mxnet/pull/16258#discussion_r327469657
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_reshape.cc
 ##########
 @@ -89,42 +88,31 @@ MKLDNNReshapeFwd::MKLDNNReshapeFwd(const OpReqType &req,
 }
 
 int MKLDNNReshapeFwd::GetWorkspaceSize() {
-  return temp_ ? temp_->get_primitive_desc().get_size() : 0;
-}
-
-void MKLDNNReshapeFwd::SetNewMem(const NDArray &input,
-                                 const NDArray &output,
-                                 void* workspace) {
-  if (input.IsMKLDNNData()) {
-    this->data_->set_data_handle(input.GetMKLDNNData()->get_data_handle());
-  } else {
-    MSHADOW_TYPE_SWITCH(input.dtype(), DTYPE, {
-      this->data_->set_data_handle(input.data().dptr<DTYPE>());
-    })
-  }
-
-  if (output.IsMKLDNNData()) {
-    this->out_->set_data_handle(output.GetMKLDNNData()->get_data_handle());
-  } else {
-    MSHADOW_TYPE_SWITCH(output.dtype(), DTYPE, {
-      this->out_->set_data_handle(output.data().dptr<DTYPE>());
-    })
-  }
-
-  if (workspace) {
-    this->temp_->set_data_handle(workspace);
-  }
+  return temp_ ? temp_->get_desc().get_size() : 0;
 }
 
 void MKLDNNReshapeFwd::Execute(const NDArray &input,
                                const NDArray &output,
                                void* workspace) {
-  // set memory handles
-  SetNewMem(input, output, workspace);
-  // register primitives
   auto stream = MKLDNNStream::Get();
-  for (auto &v : this->prims_) {
-    stream->RegisterPrim(v);
+  auto in_mem = input.GetMKLDNNData();
+  auto in_md = in_mem->get_desc();
+  // register primitives and arguments
+  size_t prims_size = prims_.size();
+  if (prims_size == 1) {
+    args_map_.push_back({{MKLDNN_ARG_FROM, *in_mem},
+                         {MKLDNN_ARG_TO, *output.GetMKLDNNData()}});
+  } else if (prims_size == 2) {
+    auto temp_md = GetDesc(in_md, GetDefaultFormat(in_md));
+    temp_ = std::make_shared<mkldnn::memory>(temp_md, CpuEngine::Get()->get_engine(),
+              workspace);
+    args_map_.push_back({{MKLDNN_ARG_FROM, *in_mem},
+                        {MKLDNN_ARG_TO, *temp_}});
+    args_map_.push_back({{MKLDNN_ARG_FROM, *temp_},
+                        {MKLDNN_ARG_TO, *output.GetMKLDNNData()}});
+  }
 
 Review comment:
   Yes. Will try to add.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services