haojin2 commented on a change in pull request #10550: [MXNET-320] Support 
elemwise_add/sub between dense and csr tensors
URL: https://github.com/apache/incubator-mxnet/pull/10550#discussion_r182837308
 
 

 ##########
 File path: src/operator/elemwise_op_common.h
 ##########
 @@ -102,6 +102,48 @@ inline bool ElemwiseStorageType(const nnvm::NodeAttrs& 
attrs,
                                                  in_attrs, out_attrs);
 }
 
+template<bool cpu_only, bool rsp, bool csr>
+inline bool ElemwisePreferDenseStorageType(const nnvm::NodeAttrs& attrs,
+                                           const int dev_mask,
+                                           DispatchMode* dispatch_mode,
+                                           std::vector<int> *in_attrs,
+                                           std::vector<int> *out_attrs) {
+  using namespace common;
+  CHECK_EQ(in_attrs->size(), 2);
+  CHECK_EQ(out_attrs->size(), 1);
+  const auto lhs_stype = (*in_attrs)[0];
+  const auto rhs_stype = (*in_attrs)[1];
+  bool dispatched = false;
+  const bool invalid_ctx = cpu_only && dev_mask != mshadow::cpu::kDevMask;
+  const auto dispatch_ex = invalid_ctx ? DispatchMode::kFComputeFallback :
+                                         DispatchMode::kFComputeEx;
+  if (!dispatched && common::ContainsOnlyStorage(*in_attrs, kDefaultStorage)) {
+    // dns, dns ... -> dns
+    dispatched = storage_type_assign(out_attrs, kDefaultStorage,
+                                     dispatch_mode, DispatchMode::kFCompute);
+  }
+  if (!dispatched && rsp && ContainsOnlyStorage(*in_attrs, kRowSparseStorage)) 
{
+    // rsp, rsp, ... -> rsp
+    dispatched = storage_type_assign(out_attrs, kRowSparseStorage,
+                                     dispatch_mode, dispatch_ex);
+  }
+  if (!dispatched && csr && common::ContainsOnlyStorage(*in_attrs, 
kCSRStorage)) {
 
 Review comment:
   Done

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


With regards,
Apache Git Services

Reply via email to