[enco] Emit Network_???_count and Network_???_bind (#1138)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 22 Aug 2018 10:39:50 +0000 (19:39 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 22 Aug 2018 10:39:50 +0000 (19:39 +0900)
This commit revises C++ code emitter to emit the implementation of the
following functions:
 - Network_input_count
 - Network_input_bind
 - Network_output_count
 - Network_output_bind

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/CppCode.cpp

index 28b4a87..e0cf9ed 100644 (file)
@@ -11,6 +11,8 @@ namespace enco
 
 void CppCode::dump(std::ostream &os) const
 {
+  auto m = _code->module();
+
   //
   // Generate full C++ source code with code snippet
   //
@@ -27,8 +29,27 @@ void CppCode::dump(std::ostream &os) const
   {
     net_def.append("struct ", name, " {");
     net_def.indent();
+    net_def.append("struct Input {");
+    net_def.indent();
+    net_def.append("const uint8_t *ptr;");
+    net_def.append("unsigned len;");
+    net_def.unindent();
+    net_def.append("};");
+    net_def.append("struct Output {");
+    net_def.indent();
+    net_def.append("uint8_t *ptr;");
+    net_def.append("unsigned len;");
+    net_def.unindent();
+    net_def.append("};");
+    net_def.append();
     net_def.append(name, "();");
     net_def.append("~", name, "();");
+
+    net_def.append();
+
+    net_def.append("std::array<Input, ", m->input()->size(), "> inputs;");
+    net_def.append("std::array<Output, ", m->output()->size(), "> outputs;");
+
     net_def.unindent();
     net_def.append("};");
   }
@@ -67,33 +88,55 @@ void CppCode::dump(std::ostream &os) const
 
   source.append();
 
-  source.append("unsigned ", name, "_input_count(const ", name, " *net) { assert(\"NYI\"); }");
+  // Emit Network_input_count function
+  source.append("unsigned ", name, "_input_count(const ", name, " *net) {");
+  source.indent();
+  source.append("net->inputs.size();");
+  source.unindent();
+  source.append("}");
+
+  source.append();
+
   source.append("const char *", name, "_input_name(const ", name,
                 " *net, unsigned n) { assert(\"NYI\"); }");
   source.append("unsigned ", name, "_input_rank(const ", name,
                 " *net, unsigned n) { assert(\"NYI\"); }");
   source.append("unsigned ", name, "_input_dim(const ", name,
                 " *net, unsigned n, unsigned axis) { assert(\"NYI\"); }");
+
+  // Emit Network_input_bind function
   source.append("void ", name, "_input_bind(", name,
                 " *net, unsigned n, const void *ptr, unsigned len) {");
   source.indent();
-  source.append("assert(\"NYI\");");
+  source.append("net->inputs.at(n).ptr = reinterpret_cast<const uint8_t *>(ptr);");
+  source.append("net->inputs.at(n).len = len;");
+  source.unindent();
+  source.append("}");
+
+  source.append();
+
+  // Emit Network_output_count function
+  source.append("unsigned ", name, "_output_count(const ", name, " *net) {");
+  source.indent();
+  source.append("net->outputs.size();");
   source.unindent();
   source.append("}");
 
   source.append();
 
-  source.append("unsigned ", name, "_output_count(const ", name, " *net) { assert(\"NYI\"); }");
   source.append("const char *", name, "_output_name(const ", name,
                 " *net, unsigned n) { assert(\"NYI\"); }");
   source.append("unsigned ", name, "_output_rank(const ", name,
                 " *net, unsigned n) { assert(\"NYI\"); }");
   source.append("unsigned ", name, "_output_dim(const ", name,
                 " *net, unsigned n, unsigned axis) { assert(\"NYI\"); }");
+
+  // Emit Network_output_bind function
   source.append("void ", name, "_output_bind(", name,
                 " *net, unsigned n, void *ptr, unsigned len) {");
   source.indent();
-  source.append("assert(\"NYI\");");
+  source.append("net->outputs.at(n).ptr = reinterpret_cast<uint8_t *>(ptr);");
+  source.append("net->outputs.at(n).len = len;");
   source.unindent();
   source.append("}");