[enco] Emit input/output metadata API (#1176)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 24 Aug 2018 02:30:46 +0000 (11:30 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 24 Aug 2018 02:30:46 +0000 (11:30 +0900)
With this commit, enco now emits the implementation of input/ouput
metadata API.

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

index 93063b6..266ebf3 100644 (file)
@@ -139,12 +139,27 @@ void CppCode::dump(std::ostream &os) const
 
   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_name function
+  source.append("const char *", name, "_input_name(const ", name, " *net, unsigned n) {");
+  source.indent();
+  source.append("return net->inputs.at(n).name;");
+  source.unindent();
+  source.append("}");
+
+  // Emit Network_input_rank function
+  source.append("unsigned ", name, "_input_rank(const ", name, " *net, unsigned n) {");
+  source.indent();
+  source.append("return net->inputs.at(n).shape.rank;");
+  source.unindent();
+  source.append("}");
+
+  // Emit Network_input_dim function
+  source.append("unsigned ", name, "_input_dim(const ", name, " *net, unsigned n, unsigned axe)");
+  source.append("{");
+  source.indent();
+  source.append("return net->inputs.at(n).shape.dims[axe];");
+  source.unindent();
+  source.append("}");
 
   // Emit Network_input_bind function
   source.append("void ", name, "_input_bind(", name,
@@ -166,12 +181,27 @@ void CppCode::dump(std::ostream &os) const
 
   source.append();
 
-  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_name function
+  source.append("const char *", name, "_output_name(const ", name, " *net, unsigned n) {");
+  source.indent();
+  source.append("return net->outputs.at(n).name;");
+  source.unindent();
+  source.append("}");
+
+  // Emit Network_output_rank function
+  source.append("unsigned ", name, "_output_rank(const ", name, " *net, unsigned n) {");
+  source.indent();
+  source.append("return net->outputs.at(n).shape.rank;");
+  source.unindent();
+  source.append("}");
+
+  // Emit Network_output_dim function
+  source.append("unsigned ", name, "_output_dim(const ", name, " *net, unsigned n, unsigned axe)");
+  source.append("{");
+  source.indent();
+  source.append("return net->outputs.at(n).shape.dims[axe];");
+  source.unindent();
+  source.append("}");
 
   // Emit Network_output_bind function
   source.append("void ", name, "_output_bind(", name,