[moco-tf] Use oops for error msg (#9171)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 25 Nov 2019 09:18:21 +0000 (18:18 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 25 Nov 2019 09:18:21 +0000 (18:18 +0900)
* [moco-tf] Use oops for error msg

This will update to use oops for error msg and refines some error messages

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

compiler/moco-tf/CMakeLists.txt
compiler/moco-tf/requires.cmake
compiler/moco-tf/src/Canonicalization/ConstCanonicalizer.cpp
compiler/moco-tf/src/Canonicalization/ReshapeCanonicalizer.cpp
compiler/moco-tf/src/Frontend.cpp
compiler/moco-tf/src/Op/COpCall.cpp
compiler/moco-tf/src/TFFormattedGraph.cpp

index 224c12c..9bcb433 100644 (file)
@@ -28,6 +28,7 @@ target_link_libraries(moco_tf_frontend PRIVATE locomotiv)
 target_link_libraries(moco_tf_frontend PRIVATE plier_tf)
 target_link_libraries(moco_tf_frontend PRIVATE locoex_customop)
 target_link_libraries(moco_tf_frontend PRIVATE logo)
+target_link_libraries(moco_tf_frontend PRIVATE oops)
 install(TARGETS moco_tf_frontend DESTINATION lib)
 
 if(NOT ENABLE_TEST)
index 9b400ec..5099ae1 100644 (file)
@@ -11,3 +11,4 @@ require("mio-tf")
 require("plier-tf")
 require("locoex-customop")
 require("logo")
+require("oops")
index 0e0fdc9..60629cd 100644 (file)
@@ -21,6 +21,8 @@
 #include <moco/Names.h>
 #include <moco/Log.h>
 
+#include <oops/UserExn.h>
+
 namespace
 {
 
@@ -98,7 +100,7 @@ bool canonicalize_const(loco::Graph *graph, moco::TFConst *node)
       break;
     }
     default:
-      throw std::runtime_error("NYI for this DataType");
+      throw oops::UserExn("Const has unsupported data type", node->name());
   }
 
   // update graph
index 3fa6aae..b944568 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <moco/Log.h>
 #include <plier/tf/Convert.h>
+#include <oops/UserExn.h>
 
 #include <cassert>
 
@@ -53,7 +54,10 @@ template <typename ConstNode> bool is_fixed_shape_input(ConstNode *const_shape_i
       // has wildcard dimension, i.e. dynamic reshape
       return false;
     }
-    assert(shape_dim >= 1 && "Unknown behavior: New shape of Reshape has invalid dimension");
+    if (!(shape_dim >= 1))
+    {
+      throw oops::UserExn("New shape of Reshape has invalid dimension");
+    }
   }
   return true;
 }
@@ -105,7 +109,10 @@ bool canonicalize_reshape(loco::Graph *graph, moco::TFReshape *node)
   {
     // Only support fixed reshape
     // TODO support dynamic reshape
-    assert(is_fixed_shape_input(tfconst_shape_input));
+    if (!(is_fixed_shape_input(tfconst_shape_input)))
+    {
+      throw oops::UserExn("Supports only fixed reshape", node->name());
+    }
 
     auto rank = tfconst_shape_input->dim(0).value();
     fixed_reshape->rank(rank);
@@ -117,7 +124,10 @@ bool canonicalize_reshape(loco::Graph *graph, moco::TFReshape *node)
   else if (constgen_shape_input)
   {
     // ditto
-    assert(is_fixed_shape_input(constgen_shape_input));
+    if (!(is_fixed_shape_input(constgen_shape_input)))
+    {
+      throw oops::UserExn("Supports only fixed reshape", node->name());
+    }
 
     auto rank = constgen_shape_input->dim(0).value();
     fixed_reshape->rank(rank);
@@ -129,7 +139,7 @@ bool canonicalize_reshape(loco::Graph *graph, moco::TFReshape *node)
   else
   {
     // TODO support dynamic reshape from not const node
-    throw std::runtime_error("ReshapeCanonicalizer: only support const node as input shape");
+    throw oops::UserExn("Supports only const node as input shape", node->name());
   }
 
   // replace
index 30814c7..a446bff 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <cwrap/Fildes.h>
 #include <stdex/Memory.h>
+#include <oops/UserExn.h>
 
 #include <google/protobuf/io/coded_stream.h>
 #include <google/protobuf/io/zero_copy_stream_impl.h>
@@ -85,14 +86,14 @@ void load_tf(const std::string &path, moco::tf::Frontend::FileType type,
 
   if (fildes.get() < 0)
   {
-    throw std::runtime_error{"Error: " + path + " not found"};
+    throw oops::UserExn("File not found", path);
   }
 
   bool result = (type == moco::tf::Frontend::FileType::Text) ? load_text(fildes, graph_def)
                                                              : load_binary(fildes, graph_def);
   if (!result)
   {
-    throw std::runtime_error{"Error: Failed to parse prototxt " + path};
+    throw oops::UserExn("Failed to parse prototxt file", path);
   }
 }
 
@@ -103,7 +104,7 @@ void load_tf(std::istream *stream, moco::tf::Frontend::FileType type,
                                                              : load_binary(stream, graph_def);
   if (!result)
   {
-    throw std::runtime_error{"Error: Failed to parse prototxt from stream"};
+    throw oops::UserExn("Failed to parse prototxt from stream");
   }
 }
 
index e10ac51..801196f 100644 (file)
@@ -24,6 +24,7 @@
 #include <moco/tf/Frontend.h>
 #include <loco.h>
 #include <stdex/Memory.h>
+#include <oops/UserExn.h>
 
 #include <vector>
 #include <cassert>
@@ -102,7 +103,7 @@ void COpCallGraphBuilder::build(const tensorflow::NodeDef &tf_node,
       // TODO define more types
       else
       {
-        throw std::runtime_error("not supported attribute type");
+        throw oops::UserExn("Unsupported attribute type", tf_node.name());
       }
     }
   }
index fb4042b..c26a413 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <pepper/str.h>
 #include <locoex/Service/COpFormattedGraph.h>
+#include <oops/InternalExn.h>
 
 #include <sstream>
 
@@ -189,7 +190,7 @@ bool TFNodeSummaryBuilder::summary(const TFConst *node, locop::NodeSummary &s) c
       ss << node->size<loco::DataType::FLOAT32>();
       break;
     default:
-      throw std::runtime_error("NYI for this DataType");
+      INTERNAL_EXN_V("Unsupported data type", node->name());
   }
   s.args().append("size", ss.str());
   s.state(locop::NodeSummary::State::PartiallyKnown);