From: 박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Mon, 25 Nov 2019 03:14:09 +0000 (+0900) Subject: [moco-support] Refine error with oops (#9156) X-Git-Tag: submit/tizen/20191205.083104~152 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9922469e30de97310ce76e601ffadaaccefa18f5;p=platform%2Fcore%2Fml%2Fnnfw.git [moco-support] Refine error with oops (#9156) * [moco-support] Refine error with oops This will refine error messages with oops Signed-off-by: SaeHie Park * use InternalExn * use macro --- diff --git a/compiler/moco/support/CMakeLists.txt b/compiler/moco/support/CMakeLists.txt index d0cac86..2a896d4 100644 --- a/compiler/moco/support/CMakeLists.txt +++ b/compiler/moco/support/CMakeLists.txt @@ -5,4 +5,5 @@ target_include_directories(moco_support PRIVATE src) target_include_directories(moco_support PUBLIC include) target_link_libraries(moco_support PUBLIC loco) target_link_libraries(moco_support PUBLIC moco_lang) +target_link_libraries(moco_support PRIVATE oops) install(TARGETS moco_support DESTINATION lib) diff --git a/compiler/moco/support/src/TFShapeInferenceHelper.cpp b/compiler/moco/support/src/TFShapeInferenceHelper.cpp index 0adbb5f..13e514a 100644 --- a/compiler/moco/support/src/TFShapeInferenceHelper.cpp +++ b/compiler/moco/support/src/TFShapeInferenceHelper.cpp @@ -18,6 +18,8 @@ #include +#include + #include namespace @@ -104,7 +106,10 @@ loco::TensorShape expand_dimension(const loco::TensorShape &x, const loco::Tenso // each dimension of x and y should be same or one must be 1 if different if (!((x_dim == y_dim) || (x_dim == 1 || y_dim == 1))) - throw std::runtime_error("Cannot produce expand_dimension of two shapes"); + { + // TODO may need to refine message + INTERNAL_EXN("ShapeInference: Input shapes don't match"); + } output_shape.dim(axis) = std::max(x_dim, y_dim); } @@ -175,7 +180,7 @@ loco::TensorShape as_tensor_shape(const loco::FeatureShape &feature_shape, else { // TODO support for other data_layout if needed - throw std::runtime_error("as_tensor_shape: only supports NHWC or NCHW"); + INTERNAL_EXN_V("ShapeInference: Unknown data_format", data_layout); } return tensor_shape; @@ -192,14 +197,14 @@ loco::FeatureShape as_feature_shape(const loco::NodeShape &nodeshape, // only convert from tensor to feature if (nodeshape.domain() != loco::Domain::Tensor) { - throw std::runtime_error("as_feature_shape: domain is not tensor"); + INTERNAL_EXN("ShapeInference: Invalid shape information"); } loco::TensorShape tensor_shape = nodeshape.as(); if (tensor_shape.rank() != 4) { - throw std::runtime_error("as_feature_shape: rank is not 4"); + INTERNAL_EXN("ShapeInference: Rank is not 4"); } if (data_layout == "NHWC") @@ -219,7 +224,7 @@ loco::FeatureShape as_feature_shape(const loco::NodeShape &nodeshape, else { // TODO support for other data_layout if needed - throw std::runtime_error("as_feature_shape: only supports NHWC or NCHW"); + INTERNAL_EXN_V("ShapeInference: Unknown data_format", data_layout); } return feature_shape; @@ -266,7 +271,8 @@ DataLayout as_data_layout(const std::string &tf_layout_str) else if (tf_layout_str == "NCHW") return DataLayout::NCHW; else - throw std::runtime_error("unknown data layout"); + /// @note data layout tag in TensorFlow is 'data_format' + INTERNAL_EXN_V("ShapeInference: Unknown data_format", tf_layout_str); } } // namespace @@ -289,6 +295,11 @@ loco::Stride<2> stride_of(const TFStrides &strides, const TFDataLayout &datalayo stride.vertical(strides[2]); stride.horizontal(strides[3]); } + else + { + // TODO add more datalayout supports if needed + INTERNAL_EXN("ShapeInference: Unknown data_format"); + } return stride; } @@ -308,6 +319,11 @@ loco::Window<2> window_of(const TFKSize &ksize, const TFDataLayout &datalayout) window.vertical(ksize[2]); window.horizontal(ksize[3]); } + else + { + // TODO add more datalayout supports if needed + INTERNAL_EXN("ShapeInference: Unknown data_format"); + } return window; } @@ -329,7 +345,7 @@ loco::Window<2> window_of(const loco::TensorShape &shape, const TFDataLayout &da else { // TODO add more datalayout supports if needed - assert(false); + INTERNAL_EXN_V("ShapeInference: Unknown data_format", datalayout); } return window;