[enco] Check the existence of in/out bag (#1154)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 24 Aug 2018 00:58:03 +0000 (09:58 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 24 Aug 2018 00:58:03 +0000 (09:58 +0900)
* [enco] Check the existence of in/out bag

The current design of enco NNAPI backend does not work if there is an
in/out bag.

This commit introduces a corresponding assert to make it easy to detect
such a case.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Update comment

contrib/enco/core/src/Backend.cpp

index ba7769e..58edd2e 100644 (file)
@@ -5,6 +5,27 @@
 
 #include <stdexcept>
 
+namespace
+{
+
+// has_inout_bag(m) returns true if there is a pair of coco::Input and coco::Output that share
+// the same bag as their backing storage
+bool has_inout_bag(const coco::Module *m)
+{
+  for (uint32_t n = 0; n < m->entity()->bag()->size(); ++n)
+  {
+    auto bag = m->entity()->bag()->at(n);
+
+    if (bag->isInput() && bag->isOutput())
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
+} // namespace
+
 namespace enco
 {
 
@@ -12,6 +33,15 @@ void Backend::compile(coco::Module *m, coco::Data *d)
 {
   Code code{m, d};
 
+  // The current implementation will assign memory region for each bag as follows:
+  //   Bind input bag to the region provided by Network_input_bind
+  //   Bind output bag to the region provided by Network_output_bind
+  //   Bind intermediate bag to the region allocated during execution
+  //
+  // Note that this scheme does not work if there is a pair of input/output
+  // that share the same bag as their underlying bag
+  assert(!has_inout_bag(code.module()));
+
   // TODO Run various transforms over enco::Code
 
   _os << CppCode{&code} << std::endl;