tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] alexbooth commented on a change in pull request #5272: [BYOC] Add example of Composite + Annotate for DNNL fused op
Date Wed, 08 Apr 2020 22:09:04 GMT
alexbooth commented on a change in pull request #5272: [BYOC] Add example of Composite + Annotate
for DNNL fused op
URL: https://github.com/apache/incubator-tvm/pull/5272#discussion_r405843653
 
 

 ##########
 File path: src/relay/backend/utils.h
 ##########
 @@ -152,8 +152,35 @@ inline bool IsOp(const CallNode* call, const std::string& op_name)
{
   Op op = GetRef<Op>(op_node);
   return op == Op::Get(op_name);
 }
+
+/*!
+ * \brief Retrieve the "root" conv2d op nested inside a fused call, such as conv2d + relu.
+ * \param call A Relay call node. Typically nn.relu when called the first time.
+ * \param depth The number of calls before conv2d call, counting from current_call.
+ * \param expected_op_names The names of ops in this fused call. Example: {"nn.conv2d", "add",
+ * "nn.relu"}
+ * \return conv2d op at the root
+ */
+
+inline const CallNode* GetRootConv2DCall(const CallNode* current_call, int depth,
+                                         const std::vector<std::string>& expected_op_names)
{
+  CHECK(current_call && depth >= 0);
+
+  if (depth == 0) {
+    CHECK(IsOp(current_call, "nn.conv2d"));
+    return current_call;
+  }
+
+  CHECK(depth < expected_op_names.size() && IsOp(current_call, expected_op_names[depth]));
+  CHECK_GT(current_call->args.size(), 0);
+
+  const auto* next_call = current_call->args[0].as<CallNode>();
+  return GetRootConv2DCall(next_call, depth - 1, expected_op_names);
+}
 
 Review comment:
   I'm not incredibly familiar with majority of relay ops, but would it be safe to also modify
this "GetRootCall" in the case where the root composite call is something other than "nn.conv2d"
("nn.dense" for example) ?

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

Mime
View raw message