diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index cee030896f81d..a3d2337729ebb 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. -bool 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(); @@ -221,7 +221,9 @@ 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; + { + throw "GPU plugin doesn't support 1D and 5D input"; + } } } @@ -231,7 +233,9 @@ 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; + { + throw "GPU plugin doesn't support 5D output"; + } } } @@ -241,7 +245,10 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string //Check if the Operation is Supported by OpenVINO if (!IsOpSupported(node->OpType())) { - return false; + + { + throw "Operation is not supported by OpenVINO"; + } } auto node_inputs = node->InputDefs(); @@ -251,7 +258,10 @@ 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; + { + throw "node_input is zero dimension"; + } + } } @@ -261,7 +271,9 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "BatchNormalization"){ if(GetInputCount(node,initializers) > 1) - return false; + { + throw "BatchNormalization cannot take more than 1 input"; + } } @@ -269,7 +281,9 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "Conv"){ if(GetInputCount(node,initializers) > 1) - return false; + { + throw "Conv cannot take more than 1 input"; + } } @@ -279,29 +293,38 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string int input_count = GetInputCount(node,initializers); if(input_count > 1) - return false; + { + 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) - return false; + { + throw "Myriad and HDDL plugins do not support Reshape with two initializers "; + } if(!IsDimensionSupported(node,dev_id)){ - return false; + throw "Reshape operation: Dimension is not supported"; } } if(node->OpType() == "Flatten"){ if(!IsDimensionSupported(node,dev_id)) - return false; + { + throw "Flatten operation: Dimension is not supported"; + } //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; + { + throw "Only default axis is supported for MYRIAD and HDDL plugins"; + } + } } @@ -309,26 +332,33 @@ 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; + + throw "Matmul is Susported if it is followed by Add"; + + } } auto iter = node->OutputNodesBegin(); if (iter == node->OutputNodesEnd()) { - return false; + throw "iteration reached end"; } for (auto it = node->OutputNodesBegin(); it != node->OutputNodesEnd(); ++it) { const auto out_node = graph_viewer.GetNode((*it).Index()); if (out_node->OpType() != "Add") { - return false; + { + throw "Outnode optype is not Add"; + } } } if(!IsDimensionSupported(node,dev_id)) - return false; + { + throw "Dimension is not supported"; + } } @@ -338,7 +368,9 @@ 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; + { + throw "Dropout, Identity and Concat can't have graph inputs"; + } } } } @@ -350,30 +382,43 @@ 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; + { + 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) - return false; + { + throw "Auto pad shouldn't be SAME_UPPER and stride_ints shouldn't be Zero at same time"; + } + //Dilations have to be 1 auto dilations_ints = attributes["dilations"].ints(); if (dilations_ints.size() != 0) { if (dilations_ints[0] > 1) - return false; + { + throw "dilations_ints size is not equal to zero and greater than one. The value should be one"; + } } //Don't support ceil_mode = 1 auto ceil_mode = attributes["ceil_mode"].i(); if (ceil_mode != 0) - return false; + { + 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) - return false; + { + throw "Multiple outputs for Pooling"; + } if(!IsDimensionSupported(node,dev_id)) - return false; + { + throw "From Max Pool or Average Pool. Dimension is not supported"; + } } //Only support 4D and 5D blobs for CPU,GPU @@ -381,7 +426,9 @@ bool IsGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::string if(node->OpType() == "GlobalMaxPool" || node->OpType() == "GlobalAveragePool"){ if(!IsDimensionSupported(node,dev_id)) - return false; + { + throw "Only support 4D and 5D blobs for CPU,GPU, Only support 3D and 4D blobs for MYRIAD and HDDL"; + } } //Transpose with no attr is not supported @@ -389,52 +436,63 @@ 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; + 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) { - return false; - } + 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)) - return false; + { + throw "Transpose:Dimension is not supported "; + } } if (node->OpType() == "Unsqueeze") { if(!IsDimensionSupported(node,dev_id)) - return false; + { + 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) - return false; + { + throw "Unsqueeze:tensor prototype mismatch "; + } } //Only support 2D input and axis 1 if (node->OpType() == "Softmax") { if(!IsDimensionSupported(node,dev_id)) - return false; + { + throw "Softmax:Dimension is not supported "; + } auto attributes = node->GetAttributes(); auto axis = attributes["axis"].i(); if (axis != 1) - return false; + { + throw "Softmax:axis is not 1 "; + } } //Don't support only one input if(node->OpType() == "Sum"){ if(node->InputDefs().size() == 1) - return false; + { + throw "Sum:Doesn't support only one input "; + } } } - return true; - } std::vector> OpenVINOExecutionProvider::GetCapability( @@ -464,16 +522,19 @@ std::vector> OpenVINOExecutionProvider::GetCa #endif int counter = 0; + 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."; - return result; - } + + try{ + CheckGraphSupported(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);