[loco] Revise shape inference condition (#7161)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 4 Sep 2019 22:30:46 +0000 (07:30 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 4 Sep 2019 22:30:46 +0000 (07:30 +0900)
* [loco] Revise shape inference condition

This will add condition to ShapeInference to infer when target node shape is unknown and input(s) shape is ready

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
* remove print code

compiler/loco/src/Service/ShapeInference.cpp

index 8b86d48..025376b 100644 (file)
 
 #include <stdex/Memory.h>
 
+namespace
+{
+
+bool inputs_shape_ready(loco::Node *node)
+{
+  assert(node != nullptr);
+
+  for (uint32_t arity = 0; arity < node->arity(); ++arity)
+  {
+    if (!loco::ShapeInference::known(node->arg(arity)))
+    {
+      return false;
+    }
+  }
+  return true;
+}
+
+} // namespace
+
 //
 // Infrastructure
 //
@@ -57,10 +76,13 @@ bool ShapeInferenceSession::to(Graph *g) const
     {
       loco::NodeShape shape;
 
-      if (_rule->infer(node, shape))
+      if (!shape_known(node) && inputs_shape_ready(node))
       {
-        node->annot(stdex::make_unique<ShapeAnnotation>(shape));
-        changed = true;
+        if (_rule->infer(node, shape))
+        {
+          node->annot(stdex::make_unique<ShapeAnnotation>(shape));
+          changed = true;
+        }
       }
     }
   }