From 1417ab822ca81291a577507a9cce4692f234620b Mon Sep 17 00:00:00 2001 From: Aravind Date: Tue, 16 Jul 2019 13:24:37 -0700 Subject: [PATCH 1/4] Add debug messages for failure --- .../openvino/openvino_execution_provider.cc | 159 ++++++++++++++---- 1 file changed, 126 insertions(+), 33 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index cee030896f81d..1763b28cc091e 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -201,7 +201,7 @@ bool IsOpSupported(std::string name){ //Checks if the entire graph is supported by OpenVINO EP and returns false if it is not. -bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id){ +bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id, std::string &error_msg){ const auto& initializers = graph_viewer.GetAllInitializedTensors(); @@ -221,7 +221,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string input_dims = graph_proto->input(i).type().tensor_type().shape().dim_size(); if(input_dims == 1 || input_dims == 5) - return false; + { + error_msg = "Error because GPU plugin doesn't support 1D and 5D input"; + return false; + } } } @@ -231,7 +234,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string output_dims = graph_proto->output(i).type().tensor_type().shape().dim_size(); if(output_dims == 5) - return false; + { + error_msg = "Error because GPU plugin doesn't support 5D output"; + return false; + } } } @@ -241,7 +247,11 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string //Check if the Operation is Supported by OpenVINO if (!IsOpSupported(node->OpType())) { - return false; + + { + error_msg = "Error because Operation is not supported by OpenVINO"; + return false; + } } auto node_inputs = node->InputDefs(); @@ -251,7 +261,11 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node_inputs[i]->Shape() != nullptr){ if(node_inputs[i]->Shape()->dim_size() == 0) - return false; + { + error_msg = "Error from Zero dimension check"; + return false; + } + } } @@ -261,7 +275,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "BatchNormalization"){ if(GetInputCount(node,initializers) > 1) - return false; + { + error_msg = "Error: BatchNormalization cannot take more than 1 input"; + return false; + } } @@ -269,7 +286,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "Conv"){ if(GetInputCount(node,initializers) > 1) - return false; + { + error_msg = "Error: Conv cannot take more than 1 input"; + return false; + } } @@ -279,29 +299,43 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string int input_count = GetInputCount(node,initializers); if(input_count > 1) - return false; + { + error_msg = "Error: Input count is greater than one from Reshape operation"; + return false; + } //Myriad and HDDL plugins do not support Reshape with two initializers if(dev_id == "MYRIAD" || dev_id == "HDDL") if(input_count == 0) - return false; + { + error_msg = "Error: Myriad and HDDL plugins do not support Reshape with two initializers "; + return false; + } if(!IsDimensionSupported(node,dev_id)){ - return false; + error_msg = "Error: Dimension is not supported from Reshape operation"; + return false; } } if(node->OpType() == "Flatten"){ if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error: Dimension is not supported from Flatten operation"; + return false; + } //Only default axis is supported for MYRIAD and HDDL plugins auto attributes = node->GetAttributes(); auto axis = attributes["axis"].i(); if (dev_id == "MYRIAD" || dev_id == "HDDL") { if (axis != 1) - return false; + { + error_msg = "Error: Only default axis is supported for MYRIAD and HDDL plugins"; + return false; + } + } } @@ -309,7 +343,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (node->OpType() == "MatMul") { for (size_t i = 0; i < node->InputDefs().size(); i++) { if (node->InputDefs()[i]->TypeAsProto()->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) { - return false; + + error_msg = "Error: Matmul is only supported if it is followed by Add"; + return false; + } } @@ -323,12 +360,18 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string const auto out_node = graph_viewer.GetNode((*it).Index()); if (out_node->OpType() != "Add") { - return false; + { + error_msg = "Error: Outnode optyoe is not Add"; + return false; + } } } if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error: Dimension is not supported"; + return false; + } } @@ -338,7 +381,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string for (const auto& input : node->InputDefs()) { auto it = find(graph_inputs.begin(), graph_inputs.end(), input); if (it != graph_inputs.end()) { - return false; + { + error_msg = "Error: Dropout, Identity and Concat can't have graph inputs"; + return false; + } } } } @@ -350,30 +396,49 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto attributes = node->GetAttributes(); auto auto_pad = attributes["auto_pad"].s(); if (auto_pad == "" || auto_pad == "SAME_LOWER") - return false; + { + error_msg = "Error: Auto pad shouldn't be empty or SAME_LOWER for MaxPool and AVerage Pool"; + return false; + } auto strides_ints = attributes["strides"].ints(); if(auto_pad == "SAME_UPPER" && strides_ints.size() == 0) - return false; + { + error_msg = "Error: Auto pad shouldn't be SAME_UPPER and stride_ints shouldn't be Zero at same time"; + return false; + } + //Dilations have to be 1 auto dilations_ints = attributes["dilations"].ints(); if (dilations_ints.size() != 0) { if (dilations_ints[0] > 1) - return false; + { + error_msg = "dilations_ints size is not equal to zero and greater than one. The value should be one"; + return false; + } } //Don't support ceil_mode = 1 auto ceil_mode = attributes["ceil_mode"].i(); if (ceil_mode != 0) - return false; + { + error_msg = "Error: Ceil_mode is not 0. Don't Support for ceil_mode is 1 "; + return false; + } //Don't support multiple outputs for Pooling if (node->OutputDefs().size() > 1) - return false; + { + error_msg = "Error: Multiple outputs for Pooling"; + return false; + } if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error: From Max Pool or Average Pool. Dimension is not supported"; + return false; + } } //Only support 4D and 5D blobs for CPU,GPU @@ -381,7 +446,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "GlobalMaxPool" || node->OpType() == "GlobalAveragePool"){ if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error=: Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; + return false; + } } //Transpose with no attr is not supported @@ -389,46 +457,70 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto attributes = node->GetAttributes(); auto perm = attributes["perm"].ints(); if (perm.size() == 0 || perm.size() > 5) { - return false; + { + error_msg = "Error from operation Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; + return false; + } } //String data type is not supported const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_STRING) { - return false; + { + error_msg = "Error from operation Transpose:String data type is not supported "; + return false; + } } if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error from operation Transpose:Dimension is not supported "; + return false; + } } if (node->OpType() == "Unsqueeze") { if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error from operation Unsqueeze:Dimension is not supported "; + return false; + } const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) - return false; + { + error_msg = "Error from operation Unsqueeze:tensor prototype mismatch "; + return false; + } } //Only support 2D input and axis 1 if (node->OpType() == "Softmax") { if(!IsDimensionSupported(node,dev_id)) - return false; + { + error_msg = "Error from operation Softmax:Dimension is not supported "; + return false; + } auto attributes = node->GetAttributes(); auto axis = attributes["axis"].i(); if (axis != 1) - return false; + { + error_msg = "Error from operation Softmax:axis is not 1 "; + return false; + } } //Don't support only one input if(node->OpType() == "Sum"){ if(node->InputDefs().size() == 1) - return false; + { + error_msg = "Error from operation Sum:Doesn't support only one input "; + return false; + } } } @@ -464,14 +556,15 @@ std::vector> OpenVINOExecutionProvider::GetCa #endif int counter = 0; + std::string error_msg = ""; std::unique_ptr sub_graph = std::make_unique(); auto model_proto = GetModelProtoFromFusedNode(graph_viewer); std::set fused_inputs, fused_outputs; - if (!IsGraphSupported(graph_viewer,device_id)) { - LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations."; + if (!IsGraphSupported(graph_viewer,device_id, error_msg)) { + LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations." << error_msg; return result; } From a6ad0f0577299bcad92232b1ac839fb328661c89 Mon Sep 17 00:00:00 2001 From: garavind309 Date: Wed, 17 Jul 2019 12:52:01 -0700 Subject: [PATCH 2/4] Try catch included. Return type of Isgraphsupported function changed to void --- .../openvino/openvino_execution_provider.cc | 134 ++++++++++-------- 1 file changed, 71 insertions(+), 63 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 1763b28cc091e..3448519f91044 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -201,7 +201,7 @@ bool IsOpSupported(std::string name){ //Checks if the entire graph is supported by OpenVINO EP and returns false if it is not. -bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id, std::string &error_msg){ +void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id){ const auto& initializers = graph_viewer.GetAllInitializedTensors(); @@ -210,6 +210,7 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto model_proto = GetModelProtoFromFusedNode(graph_viewer); auto graph_proto = model_proto.mutable_graph(); + std::string error_msg = ""; int input_dims = 0; int output_dims = 0; int num_inputs = graph_viewer.GetInputs().size(); @@ -222,8 +223,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(input_dims == 1 || input_dims == 5) { - error_msg = "Error because GPU plugin doesn't support 1D and 5D input"; - return false; + error_msg = "GPU plugin doesn't support 1D and 5D input"; + throw error_msg; } } } @@ -235,8 +236,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(output_dims == 5) { - error_msg = "Error because GPU plugin doesn't support 5D output"; - return false; + error_msg = "GPU plugin doesn't support 5D output"; + throw error_msg; } } } @@ -249,8 +250,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (!IsOpSupported(node->OpType())) { { - error_msg = "Error because Operation is not supported by OpenVINO"; - return false; + error_msg = "Operation is not supported by OpenVINO"; + throw error_msg; } } @@ -262,8 +263,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node_inputs[i]->Shape()->dim_size() == 0) { - error_msg = "Error from Zero dimension check"; - return false; + error_msg = "node_input is zero dimension"; + throw error_msg; } } @@ -276,8 +277,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(GetInputCount(node,initializers) > 1) { - error_msg = "Error: BatchNormalization cannot take more than 1 input"; - return false; + error_msg = "BatchNormalization cannot take more than 1 input"; + throw error_msg; } } @@ -287,8 +288,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(GetInputCount(node,initializers) > 1) { - error_msg = "Error: Conv cannot take more than 1 input"; - return false; + error_msg = "Conv cannot take more than 1 input"; + throw error_msg; } } @@ -300,21 +301,21 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(input_count > 1) { - error_msg = "Error: Input count is greater than one from Reshape operation"; - return false; + error_msg = "Reshape operation: Input count is greater than one"; + throw error_msg; } //Myriad and HDDL plugins do not support Reshape with two initializers if(dev_id == "MYRIAD" || dev_id == "HDDL") if(input_count == 0) { - error_msg = "Error: Myriad and HDDL plugins do not support Reshape with two initializers "; - return false; + error_msg = "Myriad and HDDL plugins do not support Reshape with two initializers "; + throw error_msg; } if(!IsDimensionSupported(node,dev_id)){ - error_msg = "Error: Dimension is not supported from Reshape operation"; - return false; + error_msg = "Reshape operation: Dimension is not supported"; + throw error_msg; } } @@ -322,8 +323,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error: Dimension is not supported from Flatten operation"; - return false; + error_msg = "Flatten operation: Dimension is not supported"; + throw error_msg; } //Only default axis is supported for MYRIAD and HDDL plugins @@ -332,8 +333,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (dev_id == "MYRIAD" || dev_id == "HDDL") { if (axis != 1) { - error_msg = "Error: Only default axis is supported for MYRIAD and HDDL plugins"; - return false; + error_msg = "Only default axis is supported for MYRIAD and HDDL plugins"; + throw error_msg; } } @@ -344,8 +345,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string for (size_t i = 0; i < node->InputDefs().size(); i++) { if (node->InputDefs()[i]->TypeAsProto()->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) { - error_msg = "Error: Matmul is only supported if it is followed by Add"; - return false; + error_msg = "Matmul is Susported if it is followed by Add"; + throw error_msg; } } @@ -353,7 +354,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto iter = node->OutputNodesBegin(); if (iter == node->OutputNodesEnd()) { - return false; + error_msg = "iteration reached end"; + throw error_msg; } for (auto it = node->OutputNodesBegin(); it != node->OutputNodesEnd(); ++it) { @@ -361,16 +363,16 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (out_node->OpType() != "Add") { { - error_msg = "Error: Outnode optyoe is not Add"; - return false; + error_msg = "Outnode optype is not Add"; + throw error_msg; } } } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error: Dimension is not supported"; - return false; + error_msg = "Dimension is not supported"; + throw error_msg; } } @@ -382,8 +384,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto it = find(graph_inputs.begin(), graph_inputs.end(), input); if (it != graph_inputs.end()) { { - error_msg = "Error: Dropout, Identity and Concat can't have graph inputs"; - return false; + error_msg = "Dropout, Identity and Concat can't have graph inputs"; + throw error_msg; } } } @@ -398,14 +400,14 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (auto_pad == "" || auto_pad == "SAME_LOWER") { error_msg = "Error: Auto pad shouldn't be empty or SAME_LOWER for MaxPool and AVerage Pool"; - return false; + throw error_msg; } auto strides_ints = attributes["strides"].ints(); if(auto_pad == "SAME_UPPER" && strides_ints.size() == 0) { error_msg = "Error: Auto pad shouldn't be SAME_UPPER and stride_ints shouldn't be Zero at same time"; - return false; + throw error_msg; } @@ -415,7 +417,7 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (dilations_ints[0] > 1) { error_msg = "dilations_ints size is not equal to zero and greater than one. The value should be one"; - return false; + throw error_msg; } } @@ -423,21 +425,21 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto ceil_mode = attributes["ceil_mode"].i(); if (ceil_mode != 0) { - error_msg = "Error: Ceil_mode is not 0. Don't Support for ceil_mode is 1 "; - return false; + error_msg = "Ceil_mode is not 0. Don't Support for ceil_mode is 1 "; + throw error_msg; } //Don't support multiple outputs for Pooling if (node->OutputDefs().size() > 1) { error_msg = "Error: Multiple outputs for Pooling"; - return false; + throw error_msg; } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error: From Max Pool or Average Pool. Dimension is not supported"; - return false; + error_msg = "From Max Pool or Average Pool. Dimension is not supported"; + throw error_msg; } } @@ -447,8 +449,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error=: Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; - return false; + error_msg = "Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; + throw error_msg; } } @@ -458,8 +460,8 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto perm = attributes["perm"].ints(); if (perm.size() == 0 || perm.size() > 5) { { - error_msg = "Error from operation Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; - return false; + error_msg = " Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; + throw error_msg; } } @@ -467,15 +469,15 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_STRING) { { - error_msg = "Error from operation Transpose:String data type is not supported "; - return false; + error_msg = "Transpose:String data type is not supported "; + throw error_msg; } } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error from operation Transpose:Dimension is not supported "; - return false; + error_msg = "Transpose:Dimension is not supported "; + throw error_msg; } } @@ -484,14 +486,14 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error from operation Unsqueeze:Dimension is not supported "; - return false; + error_msg = "Unsqueeze:Dimension is not supported "; + throw error_msg; } const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) { - error_msg = "Error from operation Unsqueeze:tensor prototype mismatch "; - return false; + error_msg = "Unsqueeze:tensor prototype mismatch "; + throw error_msg; } } @@ -500,16 +502,16 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Error from operation Softmax:Dimension is not supported "; - return false; + error_msg = "Softmax:Dimension is not supported "; + throw error_msg; } auto attributes = node->GetAttributes(); auto axis = attributes["axis"].i(); if (axis != 1) { - error_msg = "Error from operation Softmax:axis is not 1 "; - return false; + error_msg = "Softmax:axis is not 1 "; + throw error_msg; } } @@ -518,15 +520,13 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->InputDefs().size() == 1) { - error_msg = "Error from operation Sum:Doesn't support only one input "; - return false; + error_msg = "Sum:Doesn't support only one input "; + throw error_msg; } } } - return true; - } std::vector> OpenVINOExecutionProvider::GetCapability( @@ -556,17 +556,25 @@ std::vector> OpenVINOExecutionProvider::GetCa #endif int counter = 0; - std::string error_msg = ""; + std::unique_ptr sub_graph = std::make_unique(); auto model_proto = GetModelProtoFromFusedNode(graph_viewer); std::set fused_inputs, fused_outputs; - if (!IsGraphSupported(graph_viewer,device_id, error_msg)) { + /* if (!IsGraphSupported(graph_viewer,device_id, error_msg)) { LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations." << error_msg; return result; - } + } */ +try +{ + IsGraphSupported(graph_viewer, device_id); +} +catch(const char* error_msg) +{ + LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations." << error_msg; +} std::string model_proto_strbuf; model_proto.SerializeToString(&model_proto_strbuf); From 0f730ed6e5e740346a7328551dbd2f181c978142 Mon Sep 17 00:00:00 2001 From: garavind309 Date: Wed, 17 Jul 2019 13:35:42 -0700 Subject: [PATCH 3/4] Removed error_msg variable and commented code --- .../openvino/openvino_execution_provider.cc | 108 ++++++------------ 1 file changed, 37 insertions(+), 71 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 3448519f91044..987b3289d1b04 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -199,9 +199,9 @@ bool IsOpSupported(std::string name){ } -//Checks if the entire graph is supported by OpenVINO EP and returns false if it is not. +//Checks if the entire graph is supported by OpenVINO EP and throws eception if any. -void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id){ +void CheckGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string dev_id){ const auto& initializers = graph_viewer.GetAllInitializedTensors(); @@ -210,7 +210,6 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto model_proto = GetModelProtoFromFusedNode(graph_viewer); auto graph_proto = model_proto.mutable_graph(); - std::string error_msg = ""; int input_dims = 0; int output_dims = 0; int num_inputs = graph_viewer.GetInputs().size(); @@ -223,8 +222,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(input_dims == 1 || input_dims == 5) { - error_msg = "GPU plugin doesn't support 1D and 5D input"; - throw error_msg; + throw "GPU plugin doesn't support 1D and 5D input"; } } } @@ -236,8 +234,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(output_dims == 5) { - error_msg = "GPU plugin doesn't support 5D output"; - throw error_msg; + throw "GPU plugin doesn't support 5D output"; } } } @@ -250,8 +247,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (!IsOpSupported(node->OpType())) { { - error_msg = "Operation is not supported by OpenVINO"; - throw error_msg; + throw "Operation is not supported by OpenVINO"; } } @@ -263,8 +259,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node_inputs[i]->Shape()->dim_size() == 0) { - error_msg = "node_input is zero dimension"; - throw error_msg; + throw "node_input is zero dimension"; } } @@ -277,8 +272,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(GetInputCount(node,initializers) > 1) { - error_msg = "BatchNormalization cannot take more than 1 input"; - throw error_msg; + throw "BatchNormalization cannot take more than 1 input"; } } @@ -288,8 +282,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(GetInputCount(node,initializers) > 1) { - error_msg = "Conv cannot take more than 1 input"; - throw error_msg; + throw "Conv cannot take more than 1 input"; } } @@ -301,21 +294,18 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(input_count > 1) { - error_msg = "Reshape operation: Input count is greater than one"; - throw error_msg; + throw "Reshape operation: Input count is greater than one"; } //Myriad and HDDL plugins do not support Reshape with two initializers if(dev_id == "MYRIAD" || dev_id == "HDDL") if(input_count == 0) { - error_msg = "Myriad and HDDL plugins do not support Reshape with two initializers "; - throw error_msg; + throw "Myriad and HDDL plugins do not support Reshape with two initializers "; } if(!IsDimensionSupported(node,dev_id)){ - error_msg = "Reshape operation: Dimension is not supported"; - throw error_msg; + throw "Reshape operation: Dimension is not supported"; } } @@ -323,8 +313,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Flatten operation: Dimension is not supported"; - throw error_msg; + throw "Flatten operation: Dimension is not supported"; } //Only default axis is supported for MYRIAD and HDDL plugins @@ -333,8 +322,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (dev_id == "MYRIAD" || dev_id == "HDDL") { if (axis != 1) { - error_msg = "Only default axis is supported for MYRIAD and HDDL plugins"; - throw error_msg; + throw "Only default axis is supported for MYRIAD and HDDL plugins"; } } @@ -345,8 +333,8 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string for (size_t i = 0; i < node->InputDefs().size(); i++) { if (node->InputDefs()[i]->TypeAsProto()->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) { - error_msg = "Matmul is Susported if it is followed by Add"; - throw error_msg; + throw "Matmul is Susported if it is followed by Add"; + } } @@ -354,8 +342,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto iter = node->OutputNodesBegin(); if (iter == node->OutputNodesEnd()) { - error_msg = "iteration reached end"; - throw error_msg; + throw "iteration reached end"; } for (auto it = node->OutputNodesBegin(); it != node->OutputNodesEnd(); ++it) { @@ -363,17 +350,15 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (out_node->OpType() != "Add") { { - error_msg = "Outnode optype is not Add"; - throw error_msg; + throw "Outnode optype is not Add"; } } } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Dimension is not supported"; - throw error_msg; - } + throw "Dimension is not supported"; + } } @@ -384,8 +369,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto it = find(graph_inputs.begin(), graph_inputs.end(), input); if (it != graph_inputs.end()) { { - error_msg = "Dropout, Identity and Concat can't have graph inputs"; - throw error_msg; + throw "Dropout, Identity and Concat can't have graph inputs"; } } } @@ -399,15 +383,13 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto auto_pad = attributes["auto_pad"].s(); if (auto_pad == "" || auto_pad == "SAME_LOWER") { - error_msg = "Error: Auto pad shouldn't be empty or SAME_LOWER for MaxPool and AVerage Pool"; - throw error_msg; + throw "Auto pad shouldn't be empty or SAME_LOWER for MaxPool and AVerage Pool"; } auto strides_ints = attributes["strides"].ints(); if(auto_pad == "SAME_UPPER" && strides_ints.size() == 0) { - error_msg = "Error: Auto pad shouldn't be SAME_UPPER and stride_ints shouldn't be Zero at same time"; - throw error_msg; + throw "Auto pad shouldn't be SAME_UPPER and stride_ints shouldn't be Zero at same time"; } @@ -416,8 +398,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if (dilations_ints.size() != 0) { if (dilations_ints[0] > 1) { - error_msg = "dilations_ints size is not equal to zero and greater than one. The value should be one"; - throw error_msg; + throw "dilations_ints size is not equal to zero and greater than one. The value should be one"; } } @@ -425,21 +406,18 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto ceil_mode = attributes["ceil_mode"].i(); if (ceil_mode != 0) { - error_msg = "Ceil_mode is not 0. Don't Support for ceil_mode is 1 "; - throw error_msg; + throw "Ceil_mode is not 0. Don't Support for ceil_mode is 1 "; } //Don't support multiple outputs for Pooling if (node->OutputDefs().size() > 1) { - error_msg = "Error: Multiple outputs for Pooling"; - throw error_msg; + throw "Multiple outputs for Pooling"; } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "From Max Pool or Average Pool. Dimension is not supported"; - throw error_msg; + throw "From Max Pool or Average Pool. Dimension is not supported"; } } @@ -449,8 +427,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; - throw error_msg; + throw "Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; } } @@ -460,8 +437,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string auto perm = attributes["perm"].ints(); if (perm.size() == 0 || perm.size() > 5) { { - error_msg = " Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; - throw error_msg; + throw " Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; } } @@ -469,15 +445,13 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_STRING) { { - error_msg = "Transpose:String data type is not supported "; - throw error_msg; + throw "Transpose:String data type is not supported "; } } if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Transpose:Dimension is not supported "; - throw error_msg; + throw "Transpose:Dimension is not supported "; } } @@ -486,14 +460,12 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Unsqueeze:Dimension is not supported "; - throw error_msg; + throw "Unsqueeze:Dimension is not supported "; } const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); if (type_proto->tensor_type().elem_type() != ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_FLOAT) { - error_msg = "Unsqueeze:tensor prototype mismatch "; - throw error_msg; + throw "Unsqueeze:tensor prototype mismatch "; } } @@ -502,16 +474,14 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(!IsDimensionSupported(node,dev_id)) { - error_msg = "Softmax:Dimension is not supported "; - throw error_msg; + throw "Softmax:Dimension is not supported "; } auto attributes = node->GetAttributes(); auto axis = attributes["axis"].i(); if (axis != 1) { - error_msg = "Softmax:axis is not 1 "; - throw error_msg; + throw "Softmax:axis is not 1 "; } } @@ -520,8 +490,7 @@ void IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->InputDefs().size() == 1) { - error_msg = "Sum:Doesn't support only one input "; - throw error_msg; + throw "Sum:Doesn't support only one input "; } } @@ -563,13 +532,10 @@ std::vector> OpenVINOExecutionProvider::GetCa std::set fused_inputs, fused_outputs; - /* if (!IsGraphSupported(graph_viewer,device_id, error_msg)) { - LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations." << error_msg; - return result; - } */ + try { - IsGraphSupported(graph_viewer, device_id); + CheckGraphSupported(graph_viewer, device_id); } catch(const char* error_msg) { From d7bea9d128afc3a7d9a995a82517b8f6e27b7bd4 Mon Sep 17 00:00:00 2001 From: garavind309 Date: Wed, 17 Jul 2019 16:02:13 -0700 Subject: [PATCH 4/4] formatting cleanup --- .../openvino/openvino_execution_provider.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 987b3289d1b04..a3d2337729ebb 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -436,18 +436,15 @@ void CheckGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::stri auto attributes = node->GetAttributes(); auto perm = attributes["perm"].ints(); if (perm.size() == 0 || perm.size() > 5) { - { - throw " Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; - } + throw " Transpose:Tranpose with no attr is not supported. perm size shouldn't be zero or greater than five"; } //String data type is not supported const auto* type_proto = node->InputDefs()[0]->TypeAsProto(); - if (type_proto->tensor_type().elem_type() == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_STRING) { + if (type_proto->tensor_type().elem_type() == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_STRING) { throw "Transpose:String data type is not supported "; } - } if(!IsDimensionSupported(node,dev_id)) { @@ -533,12 +530,9 @@ std::vector> OpenVINOExecutionProvider::GetCa std::set fused_inputs, fused_outputs; -try -{ + try{ CheckGraphSupported(graph_viewer, device_id); -} -catch(const char* error_msg) -{ +} catch(const char* error_msg) { LOGS_DEFAULT(WARNING) << openvino_ep::OpenVINOGraph::log_tag << "Rejecting as graph has unsupported operations." << error_msg; }