bgawrych commented on a change in pull request #20712:
URL: https://github.com/apache/incubator-mxnet/pull/20712#discussion_r754030114



##########
File path: src/operator/subgraph/dnnl/dnnl_identity_property.h
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_identity_property.cc
+ * \brief Graph property for removing identity operators
+ */
+
+#ifndef MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_IDENTITY_PROPERTY_H_
+#define MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_IDENTITY_PROPERTY_H_
+#if MXNET_USE_ONEDNN == 1
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "../common.h"
+#include "../../nn/dropout-inl.h"
+#include "dnnl_subgraph_base-inl.h"
+
+namespace mxnet {
+namespace op {
+
+class SgDNNLIdentitySelector : public SubgraphSelectorV2 {
+  enum class InStatus { kFail = 0, kStart, kSuccess };
+
+ private:
+  std::vector<const BiDirectedNode*> matched_list_;
+  InStatus in_status{};
+
+ public:
+  bool Select(const BiDirectedNode& seed_node,
+              const std::shared_ptr<NodeAttr>& node_attr) override {
+    bool status = false;
+    if (seed_node.node->op() == Op::Get("_npi_copy")) {
+      status = true;
+    }
+
+    if (seed_node.node->op() == Op::Get("Dropout")) {
+      auto const& dropout_param = 
nnvm::get<DropoutParam>(seed_node.node->attrs.parsed);
+      if (dropout_param.mode == dropout::kTraining) {
+        status = true;
+      }
+    }
+
+    if (status) {
+      in_status = InStatus::kStart;
+      matched_list_.clear();
+      matched_list_.emplace_back(&seed_node);
+      return true;
+    }
+    return false;
+  }
+
+  bool SelectInput(const BiDirectedNode& n, const BiDirectedNode& input_node) 
override {
+    if (in_status == InStatus::kFail || in_status == InStatus::kSuccess ||
+        input_node.node->is_variable()) {
+      return false;
+    }
+
+    switch (in_status) {
+      case InStatus::kStart:
+        if (input_node.node->op()) {
+          in_status = InStatus::kSuccess;
+          matched_list_.emplace_back(&input_node);
+          return true;
+        }
+      default:
+        return false;
+    }
+    return false;
+  }
+
+  bool SelectOutput(const BiDirectedNode& n, const BiDirectedNode& 
output_node) override {
+    return false;
+  }
+
+  std::vector<BiDirectedNode*> Filter(const std::vector<BiDirectedNode*>& 
candidates) override {
+    if (in_status == InStatus::kFail || in_status != InStatus::kSuccess) {

Review comment:
       As it is simple fuse I decided to remove this state machine




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to