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/07/09 23:04:12 UTC

[GitHub] [incubator-mxnet] anirudh2290 commented on a change in pull request #15167: Pointwise fusion for GPU

anirudh2290 commented on a change in pull request #15167: Pointwise fusion for GPU
URL: https://github.com/apache/incubator-mxnet/pull/15167#discussion_r301822614
 
 

 ##########
 File path: src/operator/fusion/fused_op.cc
 ##########
 @@ -0,0 +1,269 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "./fused_op.h"
+#include "../operator_common.h"
+#include "../../executor/exec_pass.h"
+
+#if MXNET_USE_CUDA
+
+namespace mxnet {
+
+DMLC_REGISTER_PARAMETER(FusedOpConfig);
+
+std::mutex FusedOp::mutex_;
+
+void FusedOpParamParser(nnvm::NodeAttrs* attrs) {
+  FusedOpConfig param;
+  try {
+    param.Init(attrs->dict);
+  } catch (const dmlc::ParamError& e) {
+    std::ostringstream os;
+    os << e.what();
+    os << ", in operator " << attrs->op->name << "("
+       << "name=\"" << attrs->name << "\"";
+    for (const auto& k : attrs->dict) {
+      os << ", " << k.first << "=\"" << k.second << "\"";
+    }
+    os << ")";
+    throw dmlc::ParamError(os.str());
+  }
+  attrs->parsed = FusedOpPtr(new FusedOp(attrs, param));
+}
+
+FusedOp::FusedOp(const nnvm::NodeAttrs* attrs, const FusedOpConfig& config) {
+  this->inputs_ = std::vector<FusedOpEntry>(config.num_inputs);
+  this->outputs_ = std::vector<FusedOpEntry>(config.num_outputs);
+  this->symbol_ = nnvm::Graph();
+  this->symbol_.outputs = attrs->subgraphs[0]->outputs;
+  this->initialized_ = false;
+  this->cc_major_ = -1;
+  this->cc_minor_ = -1;
+}
+
+bool FusedOp::InferShape(const nnvm::NodeAttrs &attrs,
+                         std::vector<mxnet::TShape> *in_attrs,
+                         std::vector<mxnet::TShape> *out_attrs) {
+  this->symbol_.attrs.erase("shape");
+  this->symbol_.attrs.erase("shape_inputs");
+  std::vector<mxnet::TShape> input_shapes(*in_attrs);
+  this->symbol_ = mxnet::exec::InferShape(std::move(this->symbol_),
+                                          std::move(input_shapes),
+                                          "__shape__");
+
+  const auto& g = this->symbol_.indexed_graph();
+  const auto& input_nids = g.input_nodes();
+
+  std::vector<mxnet::TShape> out_shapes;
+  const std::vector<mxnet::TShape> shapes = this->symbol_.GetAttr<mxnet::ShapeVector>("shape");
+  for (auto& e : g.outputs()) {
+    out_shapes.push_back(shapes[g.entry_id(e)]);
+  }
+  CHECK_EQ(out_shapes.size(), out_attrs->size());
+  for (size_t i = 0; i < out_attrs->size(); ++i) {
+    op::shape_assign(&(out_attrs->at(i)), out_shapes[i]);
+  }
+
+  // assign to in_attrs
+  for (size_t i = 0; i < in_attrs->size(); ++i) {
+    const auto eid = g.entry_id(input_nids[i], 0);
+    SHAPE_ASSIGN_CHECK(*in_attrs, i, shapes[eid]);
+  }
+
+  bool inferred = true;
+  for (const auto& attr : *in_attrs) {
+    inferred = inferred && !op::shape_is_none(attr);
+  }
+  for (const auto& attr : *out_attrs) {
+    inferred = inferred && !op::shape_is_none(attr);
+  }
+  return inferred;
+}
+
+bool FusedOp::InferType(const nnvm::NodeAttrs &attrs,
+                        std::vector<int> *in_attrs,
+                        std::vector<int> *out_attrs) {
+  this->symbol_.attrs.erase("dtype");
+  this->symbol_.attrs.erase("dtype_inputs");
+  std::vector<int> input_types(*in_attrs);
+  this->symbol_ = mxnet::exec::InferType(std::move(this->symbol_),
 
 Review comment:
   can we check for number of unknown nodes to be 0 or are there cases where it doenst hold true ?

----------------------------------------------------------------
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