[neurun] Implement nnfw_input_size and nnfw_output_size (#6495)
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>
Tue, 13 Aug 2019 01:51:50 +0000 (10:51 +0900)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 13 Aug 2019 01:51:50 +0000 (10:51 +0900)
* [neurun] Implement nnfw_input_size and nnfw_output_size

This patch implements nnfw_input_size and nnfw_output_size.

Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
* [neurun] Update int to uint32_t for input/output_size

This patch updates int to uint32_t for input/output_size.

Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
runtimes/neurun/frontend/api/nnfw_dev.cc
runtimes/neurun/frontend/api/wrapper/nnfw_api.cc
runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp

index 88d5aaa..629642b 100644 (file)
@@ -106,3 +106,30 @@ NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE typ
 {
   return session->set_output(index, type, buffer, length);
 }
+
+/*
+ * Get the number of inputs
+ *
+ * @param[in] session session from input information is to be extracted
+ * @param[out] number variable which the number of inputs is put into
+ *
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+
+NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number)
+{
+  return session->input_size(number);
+}
+
+/*
+ * Get the number of outputs
+ *
+ * @param[in] session session from output information is to be extracted
+ * @param[out] number variable which the number of outputs is put into
+ *
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number)
+{
+  return session->output_size(number);
+}
index 4fcdf55..06c44be 100644 (file)
@@ -20,6 +20,8 @@
 #include <iostream>
 #include <string>
 #include <dirent.h>
+#include <limits.h>
+#include <stdint.h>
 
 nnfw_session::nnfw_session() : _graph{nullptr}, _execution{nullptr}
 {
@@ -129,3 +131,43 @@ NNFW_STATUS nnfw_session::set_output(uint32_t index, NNFW_TYPE /*type*/, void *b
   }
   return NNFW_STATUS_NO_ERROR;
 }
+
+NNFW_STATUS nnfw_session::input_size(uint32_t *number)
+{
+  try
+  {
+    if (number == nullptr)
+    {
+      std::cerr << "Error during nnfw_session::input_size, number is null pointer." << std::endl;
+      return NNFW_STATUS_ERROR;
+    }
+    uint32_t sz = _graph->getInputs().size();
+    *number = sz;
+  }
+  catch (...)
+  {
+    std::cerr << "Error during nnfw_session::input_size" << std::endl;
+    return NNFW_STATUS_ERROR;
+  }
+  return NNFW_STATUS_NO_ERROR;
+}
+
+NNFW_STATUS nnfw_session::output_size(uint32_t *number)
+{
+  try
+  {
+    if (number == nullptr)
+    {
+      std::cerr << "Error during nnfw_session::output_size, number is null pointer." << std::endl;
+      return NNFW_STATUS_ERROR;
+    }
+    uint32_t sz = _graph->getOutputs().size();
+    *number = sz;
+  }
+  catch (...)
+  {
+    std::cerr << "Error during nnfw_session::output_size" << std::endl;
+    return NNFW_STATUS_ERROR;
+  }
+  return NNFW_STATUS_NO_ERROR;
+}
index 75db5e8..977e0d8 100644 (file)
@@ -34,6 +34,9 @@ public:
   NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer, size_t length);
   NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
 
+  NNFW_STATUS input_size(uint32_t *number);
+  NNFW_STATUS output_size(uint32_t *number);
+
 private:
   std::shared_ptr<neurun::graph::Graph> _graph;
   std::shared_ptr<neurun::exec::Execution> _execution;