diff --git a/cgmanifest.json b/cgmanifest.json index cdcfeefaa2ca1..782db27f7c8d0 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -247,7 +247,7 @@ "component": { "type": "git", "git": { - "commitHash": "48cb18e5c419ddd23d9badcfe4e9df7bde1979b2", + "commitHash": "fe1790ca0df67173702f70d5646b82f48f412b99", "repositoryUrl": "https://github.com/protocolbuffers/protobuf.git" } } diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 655b14792f731..7da78a539ddd8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -270,10 +270,14 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) # use protobuf as a submodule +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf tests" FORCE) +endif() + add_subdirectory(${PROJECT_SOURCE_DIR}/external/protobuf/cmake EXCLUDE_FROM_ALL) set_target_properties(libprotobuf PROPERTIES FOLDER "External/Protobuf") set_target_properties(libprotobuf-lite PROPERTIES FOLDER "External/Protobuf") -set_target_properties(libprotoc PROPERTIES FOLDER "External/Protobuf") +set_target_properties(libprotoc PROPERTIES FOLDER "External/Protobuf") set_target_properties(protoc PROPERTIES FOLDER "External/Protobuf") if (onnxruntime_USE_FULL_PROTOBUF) add_library(protobuf::libprotobuf ALIAS libprotobuf) @@ -286,7 +290,6 @@ if(UNIX AND onnxruntime_ENABLE_LTO) #https://github.com/protocolbuffers/protobuf/issues/5923 target_link_options(protoc PRIVATE "-Wl,--no-as-needed") endif() - include(protobuf_function.cmake) if (onnxruntime_DISABLE_CONTRIB_OPS) @@ -413,6 +416,14 @@ if (onnxruntime_USE_TVM) list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES tvm nnvm_compiler) endif() +if (APPLE) + #onnx/onnx/proto_utils.h:34:16: error: 'SetTotalBytesLimit' is deprecated: Please use the single + #parameter version of SetTotalBytesLimit(). The second parameter is ignored. + # coded_stream.SetTotalBytesLimit((2048LL << 20) - 1, 512LL << 20); + #TODO: fix the warning in ONNX and re-enable this flag + string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated") + string(APPEND CMAKE_C_FLAGS " -Wno-deprecated") +endif() # ONNX add_subdirectory(onnx) @@ -487,6 +498,7 @@ else() endif() check_cxx_compiler_flag(-Wunused-but-set-variable HAS_UNUSED_BUT_SET_VARIABLE) check_cxx_compiler_flag(-Wunused-parameter HAS_UNUSED_PARAMETER) + check_cxx_compiler_flag(-Wunused-variable HAS_UNUSED_VARIABLE) check_cxx_compiler_flag(-Wcast-function-type HAS_CAST_FUNCTION_TYPE) check_cxx_compiler_flag(-Wparentheses HAS_PARENTHESES) check_cxx_compiler_flag(-Wuseless-cast HAS_USELESS_CAST) diff --git a/cmake/external/protobuf b/cmake/external/protobuf index 48cb18e5c419d..7bb8b108d1625 160000 --- a/cmake/external/protobuf +++ b/cmake/external/protobuf @@ -1 +1 @@ -Subproject commit 48cb18e5c419ddd23d9badcfe4e9df7bde1979b2 +Subproject commit 7bb8b108d16252d0ed053673d70ea6d2020ec7ff diff --git a/cmake/onnx/CMakeLists.txt b/cmake/onnx/CMakeLists.txt index 3c7e6b3d7064e..1048c90bd2c5c 100644 --- a/cmake/onnx/CMakeLists.txt +++ b/cmake/onnx/CMakeLists.txt @@ -6,7 +6,11 @@ target_include_directories(onnx_proto PUBLIC $) onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${ONNXRUNTIME_ROOT}/core/protobuf TARGET onnx_proto) if (WIN32) - target_compile_options(onnx_proto PRIVATE /wd4146) # unary minus operator applied to unsigned type + target_compile_options(onnx_proto PRIVATE "/wd4146" "/wd4125" "/wd4456" "/wd4267") +else() + if(HAS_UNUSED_VARIABLE) + target_compile_options(onnx_proto PRIVATE "-Wno-unused-variable") + endif() endif() # Cpp Tests were added and they require googletest # since we have our own copy, try using that diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index d3564feffb719..6bb562abf8be3 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -480,16 +480,23 @@ if(WIN32) endif() add_library(onnx_test_data_proto ${TEST_SRC_DIR}/proto/tml.proto) -if(WIN32) - target_compile_options(onnx_test_data_proto PRIVATE "/wd4125" "/wd4456" "/wd4100") -endif() add_dependencies(onnx_test_data_proto onnx_proto ${onnxruntime_EXTERNAL_DEPENDENCIES}) -if(NOT WIN32) +if(WIN32) + target_compile_options(onnx_test_data_proto PRIVATE "/wd4125" "/wd4456" "/wd4100" "/wd4267") +else() if(HAS_UNUSED_PARAMETER) - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/tml.pb.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + target_compile_options(onnx_test_data_proto PRIVATE "-Wno-unused-parameter") + endif() + if(HAS_UNUSED_VARIABLE) + target_compile_options(onnx_test_data_proto PRIVATE "-Wno-unused-variable") + endif() + if(HAS_UNUSED_BUT_SET_VARIABLE) + target_compile_options(onnx_test_data_proto PRIVATE "-Wno-unused-but-set-variable") endif() endif() +add_dependencies(onnx_test_data_proto onnx_proto ${onnxruntime_EXTERNAL_DEPENDENCIES}) + onnxruntime_add_include_to_target(onnx_test_data_proto onnx_proto) target_include_directories(onnx_test_data_proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx) set_target_properties(onnx_test_data_proto PROPERTIES FOLDER "ONNXRuntimeTest") diff --git a/cmake/patches/ngraph/ngraph_protobuf.patch b/cmake/patches/ngraph/ngraph_protobuf.patch index 87b7b5bd39f19..57bf85a881d7a 100644 --- a/cmake/patches/ngraph/ngraph_protobuf.patch +++ b/cmake/patches/ngraph/ngraph_protobuf.patch @@ -11,7 +11,7 @@ index 32217f5d6..d33e9c631 100644 # This version of PROTOBUF is required by Microsoft ONNX Runtime. set(NGRAPH_PROTOBUF_GIT_REPO_URL "https://github.com/protocolbuffers/protobuf") -set(NGRAPH_PROTOBUF_GIT_TAG "v3.5.2") -+set(NGRAPH_PROTOBUF_GIT_TAG "v3.6.1") ++set(NGRAPH_PROTOBUF_GIT_TAG "v3.11.2") if (WIN32) ExternalProject_Add( diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj index ea268580165f4..c4cc6a526da36 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj @@ -173,7 +173,7 @@ - + diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj index e2ffae1c4cb4e..19ba6724e8ca8 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj @@ -13,7 +13,7 @@ Microsoft.ML.OnnxRuntime - + diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/Microsoft.ML.OnnxRuntime.Tests.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/Microsoft.ML.OnnxRuntime.Tests.csproj index 5a74dd3674fb0..04c8a1cffa639 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/Microsoft.ML.OnnxRuntime.Tests.csproj +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/Microsoft.ML.OnnxRuntime.Tests.csproj @@ -47,7 +47,7 @@ - + diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/OnnxMl.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/OnnxMl.cs index dc04a19a2de5a..57df68e12e6d5 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/OnnxMl.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/OnnxMl.cs @@ -109,24 +109,24 @@ static OnnxMlReflection() { "EhAKDEVYUEVSSU1FTlRBTBAAEgoKBlNUQUJMRRABYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, - new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Onnx.Version), typeof(global::Onnx.OperatorStatus), }, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.AttributeProto), global::Onnx.AttributeProto.Parser, new[]{ "Name", "RefAttrName", "DocString", "Type", "F", "I", "S", "T", "G", "SparseTensor", "Floats", "Ints", "Strings", "Tensors", "Graphs", "SparseTensors" }, null, new[]{ typeof(global::Onnx.AttributeProto.Types.AttributeType) }, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.ValueInfoProto), global::Onnx.ValueInfoProto.Parser, new[]{ "Name", "Type", "DocString" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.NodeProto), global::Onnx.NodeProto.Parser, new[]{ "Input", "Output", "Name", "OpType", "Domain", "Attribute", "DocString" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.ModelProto), global::Onnx.ModelProto.Parser, new[]{ "IrVersion", "OpsetImport", "ProducerName", "ProducerVersion", "Domain", "ModelVersion", "DocString", "Graph", "Functions", "MetadataProps" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.StringStringEntryProto), global::Onnx.StringStringEntryProto.Parser, new[]{ "Key", "Value" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorAnnotation), global::Onnx.TensorAnnotation.Parser, new[]{ "TensorName", "QuantParameterTensorNames" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.GraphProto), global::Onnx.GraphProto.Parser, new[]{ "Node", "Name", "Initializer", "SparseInitializer", "DocString", "Input", "Output", "ValueInfo", "QuantizationAnnotation" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorProto), global::Onnx.TensorProto.Parser, new[]{ "Dims", "DataType", "Segment", "FloatData", "Int32Data", "StringData", "Int64Data", "Name", "DocString", "RawData", "ExternalData", "DataLocation", "DoubleData", "Uint64Data" }, null, new[]{ typeof(global::Onnx.TensorProto.Types.DataType), typeof(global::Onnx.TensorProto.Types.DataLocation) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorProto.Types.Segment), global::Onnx.TensorProto.Types.Segment.Parser, new[]{ "Begin", "End" }, null, null, null)}), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.SparseTensorProto), global::Onnx.SparseTensorProto.Parser, new[]{ "Values", "Indices", "Dims" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorShapeProto), global::Onnx.TensorShapeProto.Parser, new[]{ "Dim" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorShapeProto.Types.Dimension), global::Onnx.TensorShapeProto.Types.Dimension.Parser, new[]{ "DimValue", "DimParam", "Denotation" }, new[]{ "Value" }, null, null)}), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto), global::Onnx.TypeProto.Parser, new[]{ "TensorType", "SequenceType", "MapType", "SparseTensorType", "OpaqueType", "Denotation" }, new[]{ "Value" }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Tensor), global::Onnx.TypeProto.Types.Tensor.Parser, new[]{ "ElemType", "Shape" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Sequence), global::Onnx.TypeProto.Types.Sequence.Parser, new[]{ "ElemType" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Map), global::Onnx.TypeProto.Types.Map.Parser, new[]{ "KeyType", "ValueType" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.SparseTensor), global::Onnx.TypeProto.Types.SparseTensor.Parser, new[]{ "ElemType", "Shape" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Opaque), global::Onnx.TypeProto.Types.Opaque.Parser, new[]{ "Domain", "Name" }, null, null, null)}), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.OperatorSetIdProto), global::Onnx.OperatorSetIdProto.Parser, new[]{ "Domain", "Version" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.FunctionProto), global::Onnx.FunctionProto.Parser, new[]{ "Name", "SinceVersion", "Status", "Input", "Output", "Attribute", "Node", "DocString" }, null, null, null) + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Onnx.Version), typeof(global::Onnx.OperatorStatus), }, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.AttributeProto), global::Onnx.AttributeProto.Parser, new[]{ "Name", "RefAttrName", "DocString", "Type", "F", "I", "S", "T", "G", "SparseTensor", "Floats", "Ints", "Strings", "Tensors", "Graphs", "SparseTensors" }, null, new[]{ typeof(global::Onnx.AttributeProto.Types.AttributeType) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.ValueInfoProto), global::Onnx.ValueInfoProto.Parser, new[]{ "Name", "Type", "DocString" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.NodeProto), global::Onnx.NodeProto.Parser, new[]{ "Input", "Output", "Name", "OpType", "Domain", "Attribute", "DocString" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.ModelProto), global::Onnx.ModelProto.Parser, new[]{ "IrVersion", "OpsetImport", "ProducerName", "ProducerVersion", "Domain", "ModelVersion", "DocString", "Graph", "Functions", "MetadataProps" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.StringStringEntryProto), global::Onnx.StringStringEntryProto.Parser, new[]{ "Key", "Value" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorAnnotation), global::Onnx.TensorAnnotation.Parser, new[]{ "TensorName", "QuantParameterTensorNames" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.GraphProto), global::Onnx.GraphProto.Parser, new[]{ "Node", "Name", "Initializer", "SparseInitializer", "DocString", "Input", "Output", "ValueInfo", "QuantizationAnnotation" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorProto), global::Onnx.TensorProto.Parser, new[]{ "Dims", "DataType", "Segment", "FloatData", "Int32Data", "StringData", "Int64Data", "Name", "DocString", "RawData", "ExternalData", "DataLocation", "DoubleData", "Uint64Data" }, null, new[]{ typeof(global::Onnx.TensorProto.Types.DataType), typeof(global::Onnx.TensorProto.Types.DataLocation) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorProto.Types.Segment), global::Onnx.TensorProto.Types.Segment.Parser, new[]{ "Begin", "End" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.SparseTensorProto), global::Onnx.SparseTensorProto.Parser, new[]{ "Values", "Indices", "Dims" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorShapeProto), global::Onnx.TensorShapeProto.Parser, new[]{ "Dim" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TensorShapeProto.Types.Dimension), global::Onnx.TensorShapeProto.Types.Dimension.Parser, new[]{ "DimValue", "DimParam", "Denotation" }, new[]{ "Value" }, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto), global::Onnx.TypeProto.Parser, new[]{ "TensorType", "SequenceType", "MapType", "SparseTensorType", "OpaqueType", "Denotation" }, new[]{ "Value" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Tensor), global::Onnx.TypeProto.Types.Tensor.Parser, new[]{ "ElemType", "Shape" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Sequence), global::Onnx.TypeProto.Types.Sequence.Parser, new[]{ "ElemType" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Map), global::Onnx.TypeProto.Types.Map.Parser, new[]{ "KeyType", "ValueType" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.SparseTensor), global::Onnx.TypeProto.Types.SparseTensor.Parser, new[]{ "ElemType", "Shape" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.TypeProto.Types.Opaque), global::Onnx.TypeProto.Types.Opaque.Parser, new[]{ "Domain", "Name" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.OperatorSetIdProto), global::Onnx.OperatorSetIdProto.Parser, new[]{ "Domain", "Version" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Onnx.FunctionProto), global::Onnx.FunctionProto.Parser, new[]{ "Name", "SinceVersion", "Status", "Input", "Output", "Attribute", "Node", "DocString" }, null, null, null, null) })); } #endregion @@ -304,7 +304,7 @@ public string DocString { /// Field number for the "type" field. public const int TypeFieldNumber = 20; - private global::Onnx.AttributeProto.Types.AttributeType type_ = 0; + private global::Onnx.AttributeProto.Types.AttributeType type_ = global::Onnx.AttributeProto.Types.AttributeType.Undefined; /// /// The type field MUST be present for this version of the IR. /// For 0.0.1 versions of the IR, this field was not defined, and @@ -521,7 +521,7 @@ public override int GetHashCode() { if (Name.Length != 0) hash ^= Name.GetHashCode(); if (RefAttrName.Length != 0) hash ^= RefAttrName.GetHashCode(); if (DocString.Length != 0) hash ^= DocString.GetHashCode(); - if (Type != 0) hash ^= Type.GetHashCode(); + if (Type != global::Onnx.AttributeProto.Types.AttributeType.Undefined) hash ^= Type.GetHashCode(); if (F != 0F) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(F); if (I != 0L) hash ^= I.GetHashCode(); if (S.Length != 0) hash ^= S.GetHashCode(); @@ -580,7 +580,7 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(106); output.WriteString(DocString); } - if (Type != 0) { + if (Type != global::Onnx.AttributeProto.Types.AttributeType.Undefined) { output.WriteRawTag(160, 1); output.WriteEnum((int) Type); } @@ -610,7 +610,7 @@ public int CalculateSize() { if (DocString.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(DocString); } - if (Type != 0) { + if (Type != global::Onnx.AttributeProto.Types.AttributeType.Undefined) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) Type); } if (F != 0F) { @@ -657,7 +657,7 @@ public void MergeFrom(AttributeProto other) { if (other.DocString.Length != 0) { DocString = other.DocString; } - if (other.Type != 0) { + if (other.Type != global::Onnx.AttributeProto.Types.AttributeType.Undefined) { Type = other.Type; } if (other.F != 0F) { @@ -671,19 +671,19 @@ public void MergeFrom(AttributeProto other) { } if (other.t_ != null) { if (t_ == null) { - t_ = new global::Onnx.TensorProto(); + T = new global::Onnx.TensorProto(); } T.MergeFrom(other.T); } if (other.g_ != null) { if (g_ == null) { - g_ = new global::Onnx.GraphProto(); + G = new global::Onnx.GraphProto(); } G.MergeFrom(other.G); } if (other.sparseTensor_ != null) { if (sparseTensor_ == null) { - sparseTensor_ = new global::Onnx.SparseTensorProto(); + SparseTensor = new global::Onnx.SparseTensorProto(); } SparseTensor.MergeFrom(other.SparseTensor); } @@ -722,16 +722,16 @@ public void MergeFrom(pb::CodedInputStream input) { } case 42: { if (t_ == null) { - t_ = new global::Onnx.TensorProto(); + T = new global::Onnx.TensorProto(); } - input.ReadMessage(t_); + input.ReadMessage(T); break; } case 50: { if (g_ == null) { - g_ = new global::Onnx.GraphProto(); + G = new global::Onnx.GraphProto(); } - input.ReadMessage(g_); + input.ReadMessage(G); break; } case 58: @@ -761,7 +761,7 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 160: { - type_ = (global::Onnx.AttributeProto.Types.AttributeType) input.ReadEnum(); + Type = (global::Onnx.AttributeProto.Types.AttributeType) input.ReadEnum(); break; } case 170: { @@ -770,9 +770,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 178: { if (sparseTensor_ == null) { - sparseTensor_ = new global::Onnx.SparseTensorProto(); + SparseTensor = new global::Onnx.SparseTensorProto(); } - input.ReadMessage(sparseTensor_); + input.ReadMessage(SparseTensor); break; } case 186: { @@ -978,7 +978,7 @@ public void MergeFrom(ValueInfoProto other) { } if (other.type_ != null) { if (type_ == null) { - type_ = new global::Onnx.TypeProto(); + Type = new global::Onnx.TypeProto(); } Type.MergeFrom(other.Type); } @@ -1002,9 +1002,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 18: { if (type_ == null) { - type_ = new global::Onnx.TypeProto(); + Type = new global::Onnx.TypeProto(); } - input.ReadMessage(type_); + input.ReadMessage(Type); break; } case 26: { @@ -1673,7 +1673,7 @@ public void MergeFrom(ModelProto other) { } if (other.graph_ != null) { if (graph_ == null) { - graph_ = new global::Onnx.GraphProto(); + Graph = new global::Onnx.GraphProto(); } Graph.MergeFrom(other.Graph); } @@ -1716,9 +1716,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 58: { if (graph_ == null) { - graph_ = new global::Onnx.GraphProto(); + Graph = new global::Onnx.GraphProto(); } - input.ReadMessage(graph_); + input.ReadMessage(Graph); break; } case 66: { @@ -2627,7 +2627,7 @@ public string DocString { /// Field number for the "data_location" field. public const int DataLocationFieldNumber = 14; - private global::Onnx.TensorProto.Types.DataLocation dataLocation_ = 0; + private global::Onnx.TensorProto.Types.DataLocation dataLocation_ = global::Onnx.TensorProto.Types.DataLocation.Default; /// /// If value not set, data is stored in raw_data (if set) otherwise in type-specified field. /// @@ -2717,7 +2717,7 @@ public override int GetHashCode() { if (DocString.Length != 0) hash ^= DocString.GetHashCode(); if (RawData.Length != 0) hash ^= RawData.GetHashCode(); hash ^= externalData_.GetHashCode(); - if (DataLocation != 0) hash ^= DataLocation.GetHashCode(); + if (DataLocation != global::Onnx.TensorProto.Types.DataLocation.Default) hash ^= DataLocation.GetHashCode(); hash ^= doubleData_.GetHashCode(); hash ^= uint64Data_.GetHashCode(); if (_unknownFields != null) { @@ -2761,7 +2761,7 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteString(DocString); } externalData_.WriteTo(output, _repeated_externalData_codec); - if (DataLocation != 0) { + if (DataLocation != global::Onnx.TensorProto.Types.DataLocation.Default) { output.WriteRawTag(112); output.WriteEnum((int) DataLocation); } @@ -2794,7 +2794,7 @@ public int CalculateSize() { size += 1 + pb::CodedOutputStream.ComputeBytesSize(RawData); } size += externalData_.CalculateSize(_repeated_externalData_codec); - if (DataLocation != 0) { + if (DataLocation != global::Onnx.TensorProto.Types.DataLocation.Default) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) DataLocation); } size += doubleData_.CalculateSize(_repeated_doubleData_codec); @@ -2816,7 +2816,7 @@ public void MergeFrom(TensorProto other) { } if (other.segment_ != null) { if (segment_ == null) { - segment_ = new global::Onnx.TensorProto.Types.Segment(); + Segment = new global::Onnx.TensorProto.Types.Segment(); } Segment.MergeFrom(other.Segment); } @@ -2834,7 +2834,7 @@ public void MergeFrom(TensorProto other) { RawData = other.RawData; } externalData_.Add(other.externalData_); - if (other.DataLocation != 0) { + if (other.DataLocation != global::Onnx.TensorProto.Types.DataLocation.Default) { DataLocation = other.DataLocation; } doubleData_.Add(other.doubleData_); @@ -2861,9 +2861,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 26: { if (segment_ == null) { - segment_ = new global::Onnx.TensorProto.Types.Segment(); + Segment = new global::Onnx.TensorProto.Types.Segment(); } - input.ReadMessage(segment_); + input.ReadMessage(Segment); break; } case 34: @@ -2912,7 +2912,7 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 112: { - dataLocation_ = (global::Onnx.TensorProto.Types.DataLocation) input.ReadEnum(); + DataLocation = (global::Onnx.TensorProto.Types.DataLocation) input.ReadEnum(); break; } } @@ -3327,13 +3327,13 @@ public void MergeFrom(SparseTensorProto other) { } if (other.values_ != null) { if (values_ == null) { - values_ = new global::Onnx.TensorProto(); + Values = new global::Onnx.TensorProto(); } Values.MergeFrom(other.Values); } if (other.indices_ != null) { if (indices_ == null) { - indices_ = new global::Onnx.TensorProto(); + Indices = new global::Onnx.TensorProto(); } Indices.MergeFrom(other.Indices); } @@ -3351,16 +3351,16 @@ public void MergeFrom(pb::CodedInputStream input) { break; case 10: { if (values_ == null) { - values_ = new global::Onnx.TensorProto(); + Values = new global::Onnx.TensorProto(); } - input.ReadMessage(values_); + input.ReadMessage(Values); break; } case 18: { if (indices_ == null) { - indices_ = new global::Onnx.TensorProto(); + Indices = new global::Onnx.TensorProto(); } - input.ReadMessage(indices_); + input.ReadMessage(Indices); break; } case 26: @@ -4240,7 +4240,7 @@ public void MergeFrom(Tensor other) { } if (other.shape_ != null) { if (shape_ == null) { - shape_ = new global::Onnx.TensorShapeProto(); + Shape = new global::Onnx.TensorShapeProto(); } Shape.MergeFrom(other.Shape); } @@ -4261,9 +4261,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 18: { if (shape_ == null) { - shape_ = new global::Onnx.TensorShapeProto(); + Shape = new global::Onnx.TensorShapeProto(); } - input.ReadMessage(shape_); + input.ReadMessage(Shape); break; } } @@ -4386,7 +4386,7 @@ public void MergeFrom(Sequence other) { } if (other.elemType_ != null) { if (elemType_ == null) { - elemType_ = new global::Onnx.TypeProto(); + ElemType = new global::Onnx.TypeProto(); } ElemType.MergeFrom(other.ElemType); } @@ -4403,9 +4403,9 @@ public void MergeFrom(pb::CodedInputStream input) { break; case 10: { if (elemType_ == null) { - elemType_ = new global::Onnx.TypeProto(); + ElemType = new global::Onnx.TypeProto(); } - input.ReadMessage(elemType_); + input.ReadMessage(ElemType); break; } } @@ -4556,7 +4556,7 @@ public void MergeFrom(Map other) { } if (other.valueType_ != null) { if (valueType_ == null) { - valueType_ = new global::Onnx.TypeProto(); + ValueType = new global::Onnx.TypeProto(); } ValueType.MergeFrom(other.ValueType); } @@ -4577,9 +4577,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 18: { if (valueType_ == null) { - valueType_ = new global::Onnx.TypeProto(); + ValueType = new global::Onnx.TypeProto(); } - input.ReadMessage(valueType_); + input.ReadMessage(ValueType); break; } } @@ -4724,7 +4724,7 @@ public void MergeFrom(SparseTensor other) { } if (other.shape_ != null) { if (shape_ == null) { - shape_ = new global::Onnx.TensorShapeProto(); + Shape = new global::Onnx.TensorShapeProto(); } Shape.MergeFrom(other.Shape); } @@ -4745,9 +4745,9 @@ public void MergeFrom(pb::CodedInputStream input) { } case 18: { if (shape_ == null) { - shape_ = new global::Onnx.TensorShapeProto(); + Shape = new global::Onnx.TensorShapeProto(); } - input.ReadMessage(shape_); + input.ReadMessage(Shape); break; } } @@ -5170,7 +5170,7 @@ public long SinceVersion { /// Field number for the "status" field. public const int StatusFieldNumber = 3; - private global::Onnx.OperatorStatus status_ = 0; + private global::Onnx.OperatorStatus status_ = global::Onnx.OperatorStatus.Experimental; /// /// This field indicates whether the syntax, semantics, or presence /// of this function is in an experimental or stable stage. Once an @@ -5281,7 +5281,7 @@ public override int GetHashCode() { int hash = 1; if (Name.Length != 0) hash ^= Name.GetHashCode(); if (SinceVersion != 0L) hash ^= SinceVersion.GetHashCode(); - if (Status != 0) hash ^= Status.GetHashCode(); + if (Status != global::Onnx.OperatorStatus.Experimental) hash ^= Status.GetHashCode(); hash ^= input_.GetHashCode(); hash ^= output_.GetHashCode(); hash ^= attribute_.GetHashCode(); @@ -5308,7 +5308,7 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(16); output.WriteInt64(SinceVersion); } - if (Status != 0) { + if (Status != global::Onnx.OperatorStatus.Experimental) { output.WriteRawTag(24); output.WriteEnum((int) Status); } @@ -5334,7 +5334,7 @@ public int CalculateSize() { if (SinceVersion != 0L) { size += 1 + pb::CodedOutputStream.ComputeInt64Size(SinceVersion); } - if (Status != 0) { + if (Status != global::Onnx.OperatorStatus.Experimental) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status); } size += input_.CalculateSize(_repeated_input_codec); @@ -5361,7 +5361,7 @@ public void MergeFrom(FunctionProto other) { if (other.SinceVersion != 0L) { SinceVersion = other.SinceVersion; } - if (other.Status != 0) { + if (other.Status != global::Onnx.OperatorStatus.Experimental) { Status = other.Status; } input_.Add(other.input_); @@ -5391,7 +5391,7 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 24: { - status_ = (global::Onnx.OperatorStatus) input.ReadEnum(); + Status = (global::Onnx.OperatorStatus) input.ReadEnum(); break; } case 34: { diff --git a/onnxruntime/core/framework/path_lib.h b/onnxruntime/core/framework/path_lib.h index 89cfaef4188e7..1339450c9a664 100644 --- a/onnxruntime/core/framework/path_lib.h +++ b/onnxruntime/core/framework/path_lib.h @@ -34,11 +34,14 @@ ptrdiff_t OrtStrToPtrDiff(const T* nptr, T** endptr); template <> inline ptrdiff_t OrtStrToPtrDiff(const wchar_t* nptr, wchar_t** endptr) { #ifdef _WIN32 - // TODO: on x86_32, it should be wcstol +#ifdef _M_AMD64 return _wcstoi64(nptr, endptr, 10); #else return wcstol(nptr, endptr, 10); #endif +#else + return wcstol(nptr, endptr, 10); +#endif } template @@ -57,11 +60,14 @@ inline size_t OrtStrftime(wchar_t* strDest, size_t maxsize, const wchar template <> inline ptrdiff_t OrtStrToPtrDiff(const char* nptr, char** endptr) { #ifdef _WIN32 - // TODO: on x86_32, it should be strtol +#ifdef _M_AMD64 return _strtoi64(nptr, endptr, 10); #else return strtol(nptr, endptr, 10); #endif +#else + return strtol(nptr, endptr, 10); +#endif } template <> diff --git a/onnxruntime/core/graph/model.cc b/onnxruntime/core/graph/model.cc index f8711e0c91481..a91d5a7772396 100644 --- a/onnxruntime/core/graph/model.cc +++ b/onnxruntime/core/graph/model.cc @@ -428,7 +428,7 @@ Status Model::Load(int fd, ONNX_NAMESPACE::ModelProto& model_proto) { CodedInputStream cis(&fs); // Allows protobuf library versions < 3.2.0 to parse messages greater than 64MB. - cis.SetTotalBytesLimit(INT_MAX, INT_MAX); + cis.SetTotalBytesLimit(INT_MAX); if (!model_proto->ParseFromCodedStream(&cis)) { return Status(ONNXRUNTIME, INVALID_PROTOBUF, "Protobuf parsing failed."); } diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 983889f93a561..3a3dab335bcfa 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -245,7 +245,7 @@ OrtStatus* CreateTensorImpl(MLDataType ml_type, const int64_t* shape, size_t sha size_t elem_count = 1; std::vector shapes(shape_len); for (size_t i = 0; i != shape_len; ++i) { - elem_count *= shape[i]; + elem_count *= static_cast(shape[i]); shapes[i] = shape[i]; } @@ -971,28 +971,31 @@ static OrtStatus* OrtGetValueImplMapHelper(const OrtValue* p_ml_value, int index using TVal = typename T::mapped_type; auto& data = p_ml_value->Get(); int64_t num_kv_pairs = data.size(); +#if defined(_WIN32) && !defined(_M_AMD64) + ORT_ENFORCE(static_cast(num_kv_pairs) < std::numeric_limits::max()); +#endif switch (index) { case 0: { // user is requesting keys std::vector vec; - vec.reserve(num_kv_pairs); + vec.reserve(static_cast(num_kv_pairs)); for (const auto& kv : data) { vec.push_back(kv.first); } std::vector dims{num_kv_pairs}; OrtStatus* st = OrtApis::CreateTensorAsOrtValue(allocator, dims.data(), dims.size(), GetONNXTensorElementDataType(), out); - return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs, sizeof(TKey)); + return st ? st : PopulateTensorWithData(*out, vec.data(), static_cast(num_kv_pairs), sizeof(TKey)); } case 1: { // user is requesting values std::vector vec; - vec.reserve(num_kv_pairs); + vec.reserve(static_cast(num_kv_pairs)); for (const auto& kv : data) { vec.push_back(kv.second); } std::vector dims{num_kv_pairs}; OrtStatus* st = OrtApis::CreateTensorAsOrtValue(allocator, dims.data(), dims.size(), GetONNXTensorElementDataType(), out); - return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs, sizeof(TVal)); + return st ? st : PopulateTensorWithData(*out, vec.data(), static_cast(num_kv_pairs), sizeof(TVal)); } default: return OrtApis::CreateStatus(ORT_FAIL, "Invalid index requested for map type."); @@ -1200,7 +1203,9 @@ static OrtStatus* OrtCreateMapMLValue(const Tensor& key_tensor, const Tensor& va // iterate through the key and value tensors and populate map auto key_data = key_tensor.Data(); auto value_data = value_tensor.Data(); - size_t num_kv_pairs = key_tensor.Shape().Size(); + auto len = key_tensor.Shape().Size(); + ORT_ENFORCE(len >= 0 && static_cast(len) < std::numeric_limits::max()); + size_t num_kv_pairs = static_cast(key_tensor.Shape().Size()); for (size_t n = 0; n < num_kv_pairs; ++n, ++key_data, ++value_data) { map_ptr->insert({*key_data, *value_data}); } diff --git a/onnxruntime/core/util/protobuf_parsing_utils.cc b/onnxruntime/core/util/protobuf_parsing_utils.cc deleted file mode 100644 index 7cdf60bb783a3..0000000000000 --- a/onnxruntime/core/util/protobuf_parsing_utils.cc +++ /dev/null @@ -1,481 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -// Modifications Copyright (c) Microsoft. -// Introduced this file based on suggestion by Kenton Varda as seen here -// https://groups.google.com/forum/#!topic/protobuf/J3H0GSlrfIo -// The idea is to retain the same efficiency of loading models. - -#ifndef _MSC_VER -#include -#include -#include -#include -#endif -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -#include -#endif -#include "protobuf_parsing_utils.h" -#include - -namespace google { -namespace protobuf { -namespace io { - -#ifdef _WIN32 -// Win32 lseek is broken: If invoked on a non-seekable file descriptor, its -// return value is undefined. We re-define it to always produce an error. -#define lseek(fd, offset, origin) ((off_t)-1) -// DO NOT include , instead create functions in io_win32.{h,cc} and import -// them like we do below. -using google::protobuf::internal::win32::access; -using google::protobuf::internal::win32::close; -using google::protobuf::internal::win32::open; -using google::protobuf::internal::win32::read; -using google::protobuf::internal::win32::write; -#endif - -namespace { - -// EINTR sucks. -int close_no_eintr(int fd) { - int result; - do { - result = close(fd); - } while (result < 0 && errno == EINTR); - return result; -} - -} // namespace - -// =================================================================== - -FileInputStream::FileInputStream(int file_descriptor, int block_size) - : copying_input_(file_descriptor), - impl_(©ing_input_, block_size) { -} - -bool FileInputStream::Close() { - return copying_input_.Close(); -} - -bool FileInputStream::Next(const void** data, int* size) { - return impl_.Next(data, size); -} - -void FileInputStream::BackUp(int count) { - impl_.BackUp(count); -} - -bool FileInputStream::Skip(int count) { - return impl_.Skip(count); -} - -int64 FileInputStream::ByteCount() const { - return impl_.ByteCount(); -} - -FileInputStream::CopyingFileInputStream::CopyingFileInputStream( - int file_descriptor) - : file_(file_descriptor), - close_on_delete_(false), - is_closed_(false), - errno_(0), - previous_seek_failed_(false) { -} - -FileInputStream::CopyingFileInputStream::~CopyingFileInputStream() { - if (close_on_delete_) { - if (!Close()) { -#ifdef _WIN32 - const size_t errmsglen = 100; // strerrorlen_s not available on MSVC, https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strerror-s-strerror-s-wcserror-s-wcserror-s?view=vs-2017 - char errmsg[errmsglen]; - strerror_s(errmsg, errmsglen, errno); - GOOGLE_LOG(ERROR) << "close() failed: " << errmsg; -#else // POSIX - char* e_msg = strerror(errno); - GOOGLE_LOG(ERROR) << "close() failed: " << e_msg; -#endif - } - } -} - -bool FileInputStream::CopyingFileInputStream::Close() { - GOOGLE_CHECK(!is_closed_); - - is_closed_ = true; - if (close_no_eintr(file_) != 0) { - // The docs on close() do not specify whether a file descriptor is still - // open after close() fails with EIO. However, the glibc source code - // seems to indicate that it is not. - errno_ = errno; - return false; - } - - return true; -} - -int FileInputStream::CopyingFileInputStream::Read(void* buffer, int size) { - GOOGLE_CHECK(!is_closed_); - - int result; - do { - result = read(file_, buffer, size); - } while (result < 0 && errno == EINTR); - - if (result < 0) { - // Read error (not EOF). - errno_ = errno; - } - - return result; -} - -int FileInputStream::CopyingFileInputStream::Skip(int count) { - GOOGLE_CHECK(!is_closed_); - - if (!previous_seek_failed_ && lseek(file_, count, SEEK_CUR) != static_cast(-1)) { - // Seek succeeded. - return count; - } - // Failed to seek. - - // Note to self: Don't seek again. This file descriptor doesn't - // support it. - previous_seek_failed_ = true; - - // Use the default implementation. - return CopyingInputStream::Skip(count); -} - -// =================================================================== - -FileOutputStream::FileOutputStream(int file_descriptor, int block_size) - : copying_output_(file_descriptor), - impl_(©ing_output_, block_size) { -} - -FileOutputStream::~FileOutputStream() { - impl_.Flush(); -} - -bool FileOutputStream::Close() { - bool flush_succeeded = impl_.Flush(); - return copying_output_.Close() && flush_succeeded; -} - -bool FileOutputStream::Flush() { - return impl_.Flush(); -} - -bool FileOutputStream::Next(void** data, int* size) { - return impl_.Next(data, size); -} - -void FileOutputStream::BackUp(int count) { - impl_.BackUp(count); -} - -int64 FileOutputStream::ByteCount() const { - return impl_.ByteCount(); -} - -FileOutputStream::CopyingFileOutputStream::CopyingFileOutputStream( - int file_descriptor) - : file_(file_descriptor), - close_on_delete_(false), - is_closed_(false), - errno_(0) { -} - -FileOutputStream::CopyingFileOutputStream::~CopyingFileOutputStream() { - if (close_on_delete_) { - if (!Close()) { -#ifdef _WIN32 - // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strerror-s-strerror-s-wcserror-s-wcserror-s?view=vs-2017 - const size_t errmsglen = 100; //strerrorlen_s not available on MSVC - char errmsg[errmsglen]; - strerror_s(errmsg, errmsglen, errno); - GOOGLE_LOG(ERROR) << "close() failed: " << errmsg; -#else // POSIX - char* e_msg = strerror(errno); - GOOGLE_LOG(ERROR) << "close() failed: " << e_msg; -#endif - } - } -} - -bool FileOutputStream::CopyingFileOutputStream::Close() { - GOOGLE_CHECK(!is_closed_); - - is_closed_ = true; - if (close_no_eintr(file_) != 0) { - // The docs on close() do not specify whether a file descriptor is still - // open after close() fails with EIO. However, the glibc source code - // seems to indicate that it is not. - errno_ = errno; - return false; - } - - return true; -} - -bool FileOutputStream::CopyingFileOutputStream::Write( - const void* buffer, int size) { - GOOGLE_CHECK(!is_closed_); - int total_written = 0; - - const uint8* buffer_base = reinterpret_cast(buffer); - - while (total_written < size) { - int bytes; - do { - bytes = write(file_, buffer_base + total_written, size - total_written); - } while (bytes < 0 && errno == EINTR); - - if (bytes <= 0) { - // Write error. - - // FIXME(kenton): According to the man page, if write() returns zero, - // there was no error; write() simply did not write anything. It's - // unclear under what circumstances this might happen, but presumably - // errno won't be set in this case. I am confused as to how such an - // event should be handled. For now I'm treating it as an error, since - // retrying seems like it could lead to an infinite loop. I suspect - // this never actually happens anyway. - - if (bytes < 0) { - errno_ = errno; - } - return false; - } - total_written += bytes; - } - - return true; -} - -// =================================================================== - -IstreamInputStream::IstreamInputStream(std::istream* input, int block_size) - : copying_input_(input), impl_(©ing_input_, block_size) {} - -bool IstreamInputStream::Next(const void** data, int* size) { - return impl_.Next(data, size); -} - -void IstreamInputStream::BackUp(int count) { - impl_.BackUp(count); -} - -bool IstreamInputStream::Skip(int count) { - return impl_.Skip(count); -} - -int64 IstreamInputStream::ByteCount() const { - return impl_.ByteCount(); -} - -IstreamInputStream::CopyingIstreamInputStream::CopyingIstreamInputStream( - std::istream* input) - : input_(input) {} - -IstreamInputStream::CopyingIstreamInputStream::~CopyingIstreamInputStream() = default; - -int IstreamInputStream::CopyingIstreamInputStream::Read( - void* buffer, int size) { - input_->read(reinterpret_cast(buffer), size); - int result = static_cast(input_->gcount()); - if (result == 0 && input_->fail() && !input_->eof()) { - return -1; - } - return result; -} - -// =================================================================== - -OstreamOutputStream::OstreamOutputStream(std::ostream* output, int block_size) - : copying_output_(output), impl_(©ing_output_, block_size) {} - -OstreamOutputStream::~OstreamOutputStream() { - impl_.Flush(); -} - -bool OstreamOutputStream::Next(void** data, int* size) { - return impl_.Next(data, size); -} - -void OstreamOutputStream::BackUp(int count) { - impl_.BackUp(count); -} - -int64 OstreamOutputStream::ByteCount() const { - return impl_.ByteCount(); -} - -OstreamOutputStream::CopyingOstreamOutputStream::CopyingOstreamOutputStream( - std::ostream* output) - : output_(output) {} - -OstreamOutputStream::CopyingOstreamOutputStream::~CopyingOstreamOutputStream() = default; - -bool OstreamOutputStream::CopyingOstreamOutputStream::Write( - const void* buffer, int size) { - output_->write(reinterpret_cast(buffer), size); - return output_->good(); -} - -// =================================================================== - -ConcatenatingInputStream::ConcatenatingInputStream( - ZeroCopyInputStream* const streams[], int count) - : streams_(streams), stream_count_(count), bytes_retired_(0) { -} - -bool ConcatenatingInputStream::Next(const void** data, int* size) { - while (stream_count_ > 0) { - if (streams_[0]->Next(data, size)) return true; - - // That stream is done. Advance to the next one. - bytes_retired_ += streams_[0]->ByteCount(); - ++streams_; - --stream_count_; - } - - // No more streams. - return false; -} - -void ConcatenatingInputStream::BackUp(int count) { - if (stream_count_ > 0) { - streams_[0]->BackUp(count); - } else { - GOOGLE_LOG(DFATAL) << "Can't BackUp() after failed Next()."; - } -} - -bool ConcatenatingInputStream::Skip(int count) { - while (stream_count_ > 0) { - // Assume that ByteCount() can be used to find out how much we actually - // skipped when Skip() fails. - int64 target_byte_count = streams_[0]->ByteCount() + count; - if (streams_[0]->Skip(count)) return true; - - // Hit the end of the stream. Figure out how many more bytes we still have - // to skip. - int64 final_byte_count = streams_[0]->ByteCount(); - GOOGLE_DCHECK_LT(final_byte_count, target_byte_count); - count = static_cast(target_byte_count - final_byte_count); - - // That stream is done. Advance to the next one. - bytes_retired_ += final_byte_count; - ++streams_; - --stream_count_; - } - - return false; -} - -int64 ConcatenatingInputStream::ByteCount() const { - if (stream_count_ == 0) { - return bytes_retired_; - } - return bytes_retired_ + streams_[0]->ByteCount(); -} - -// =================================================================== - -LimitingInputStream::LimitingInputStream(ZeroCopyInputStream* input, - int64 limit) - : input_(input), limit_(limit) { - prior_bytes_read_ = input_->ByteCount(); -} - -LimitingInputStream::~LimitingInputStream() { - // If we overshot the limit, back up. - if (limit_ < 0) input_->BackUp(static_cast(-limit_)); -} - -bool LimitingInputStream::Next(const void** data, int* size) { - if (limit_ <= 0) return false; - if (!input_->Next(data, size)) return false; - - limit_ -= *size; - if (limit_ < 0) { - // We overshot the limit. Reduce *size to hide the rest of the buffer. - *size += static_cast(limit_); - } - return true; -} - -void LimitingInputStream::BackUp(int count) { - if (limit_ < 0) { - input_->BackUp(static_cast(count - limit_)); - limit_ = count; - } else { - input_->BackUp(count); - limit_ += count; - } -} - -bool LimitingInputStream::Skip(int count) { - if (count > limit_) { - if (limit_ < 0) return false; - input_->Skip(static_cast(limit_)); - limit_ = 0; - return false; - } - if (!input_->Skip(count)) return false; - limit_ -= count; - return true; -} - -int64 LimitingInputStream::ByteCount() const { - if (limit_ < 0) { - return input_->ByteCount() + limit_ - prior_bytes_read_; - } - return input_->ByteCount() - prior_bytes_read_; -} - -// =================================================================== - -} // namespace io -} // namespace protobuf -} // namespace google diff --git a/onnxruntime/core/util/protobuf_parsing_utils.h b/onnxruntime/core/util/protobuf_parsing_utils.h index 34c261b79f41e..4c97562653f04 100644 --- a/onnxruntime/core/util/protobuf_parsing_utils.h +++ b/onnxruntime/core/util/protobuf_parsing_utils.h @@ -1,41 +1,3 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains common implementations of the interfaces defined in -// zero_copy_stream.h which are only included in the full (non-lite) -// protobuf library. These implementations include Unix file descriptors -// and C++ iostreams. See also: zero_copy_stream_impl_lite.h #pragma once @@ -317,30 +279,6 @@ class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); }; -// =================================================================== - -// A ZeroCopyInputStream which wraps some other stream and limits it to -// a particular byte count. -class LIBPROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream { - public: - LimitingInputStream(ZeroCopyInputStream* input, int64 limit); - ~LimitingInputStream() override; - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size) override; - void BackUp(int count) override; - bool Skip(int count) override; - int64 ByteCount() const override; - - private: - ZeroCopyInputStream* input_; - int64 limit_; // Decreases as we go, becomes negative if we overshoot. - int64 prior_bytes_read_; // Bytes read on underlying stream at construction - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); -}; - -// =================================================================== } // namespace io } // namespace protobuf diff --git a/onnxruntime/test/ir/onnx_model_test.cc b/onnxruntime/test/ir/onnx_model_test.cc index 77b45d7261f99..9a6da3a52e607 100644 --- a/onnxruntime/test/ir/onnx_model_test.cc +++ b/onnxruntime/test/ir/onnx_model_test.cc @@ -74,7 +74,7 @@ TEST(ONNXModelsTest1, bvlc_alexnet_1) { std::unique_ptr raw_input(new FileInputStream(fd)); std::unique_ptr coded_input(new CodedInputStream(raw_input.get())); // Allows protobuf library versions < 3.2.0 to parse messages greater than 64MB. - coded_input->SetTotalBytesLimit(INT_MAX, INT_MAX); + coded_input->SetTotalBytesLimit(INT_MAX); ModelProto model_proto; bool result = model_proto.ParseFromCodedStream(coded_input.get()); coded_input.reset(); @@ -124,7 +124,7 @@ TEST_P(ONNXModelsTest, LoadFromProtobuf) { ASSERT_TRUE(fd > 0); std::unique_ptr raw_input(new FileInputStream(fd)); std::unique_ptr coded_input(new CodedInputStream(raw_input.get())); - coded_input->SetTotalBytesLimit(INT_MAX, INT_MAX); + coded_input->SetTotalBytesLimit(INT_MAX); std::unique_ptr model_proto = onnxruntime::make_unique(); bool result = model_proto->ParseFromCodedStream(coded_input.get()); coded_input.reset(); diff --git a/onnxruntime/test/onnx/TestCase.cc b/onnxruntime/test/onnx/TestCase.cc index de09b17df8dcd..9b6e661c8cc50 100644 --- a/onnxruntime/test/onnx/TestCase.cc +++ b/onnxruntime/test/onnx/TestCase.cc @@ -203,12 +203,13 @@ class OnnxModelInfo : public TestModelInfo { if (!st.IsOK()) { ORT_THROW(st.ErrorMessage()); } - google::protobuf::io::FileInputStream f(model_fd); - f.SetCloseOnDelete(true); + ONNX_NAMESPACE::ModelProto model_pb; - if (!model_pb.ParseFromZeroCopyStream(&f)) { + if (!model_pb.ParseFromFileDescriptor(model_fd)) { + (void)Env::Default().FileClose(model_fd); ORT_THROW("Failed to load model because protobuf parsing failed."); } + (void)Env::Default().FileClose(model_fd); #ifdef __GNUG__ const RE2::Anchor re2_anchor = RE2::UNANCHORED; re2::StringPiece text(model_url); @@ -233,6 +234,7 @@ class OnnxModelInfo : public TestModelInfo { if (!init.has_name()) continue; initializer_names.insert(init.name()); } + //Ignore the inputs that are already in initializers for (const auto& p : graph.input()) { if (!p.has_name()) ORT_THROW("input without name??"); if (initializer_names.find(p.name()) == initializer_names.end()) input_value_info_.push_back(p); diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index d8bd447e099aa..6fa0b30456d03 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -354,14 +354,16 @@ int real_main(int argc, char* argv[], Ort::Env& env) { sf.SetGraphOptimizationLevel(graph_optimization_level); } - static const char* cuda_flaky_tests[] = {"fp16_inception_v1", "fp16_shufflenet", "fp16_tiny_yolov2"}; - static const char* dml_disabled_tests[] = {"mlperf_ssd_resnet34_1200", "mlperf_ssd_mobilenet_300", "mask_rcnn_keras", "mask_rcnn", "faster_rcnn"}; - static const char* dnnl_disabled_tests[] = {"test_densenet121", "test_resnet18v2", "test_resnet34v2", "test_resnet50v2", "test_resnet101v2", - "test_resnet101v2", "test_vgg19", "tf_inception_resnet_v2", "tf_inception_v1", "tf_inception_v3", "tf_inception_v4", "tf_mobilenet_v1_1.0_224", - "tf_mobilenet_v2_1.0_224", "tf_mobilenet_v2_1.4_224", "tf_nasnet_large", "tf_pnasnet_large", "tf_resnet_v1_50", "tf_resnet_v1_101", "tf_resnet_v1_101", - "tf_resnet_v2_101", "tf_resnet_v2_152"}; - - std::unordered_set all_disabled_tests; + static const ORTCHAR_T* cuda_flaky_tests[] = { + ORT_TSTR("fp16_inception_v1"), + ORT_TSTR("fp16_shufflenet"), ORT_TSTR("fp16_tiny_yolov2")}; + static const ORTCHAR_T* dml_disabled_tests[] = {ORT_TSTR("mlperf_ssd_resnet34_1200"), ORT_TSTR("mlperf_ssd_mobilenet_300"), ORT_TSTR("mask_rcnn_keras"), ORT_TSTR("mask_rcnn"), ORT_TSTR("faster_rcnn")}; + static const ORTCHAR_T* dnnl_disabled_tests[] = {ORT_TSTR("test_densenet121"), ORT_TSTR("test_resnet18v2"), ORT_TSTR("test_resnet34v2"), ORT_TSTR("test_resnet50v2"), ORT_TSTR("test_resnet101v2"), + ORT_TSTR("test_resnet101v2"), ORT_TSTR("test_vgg19"), ORT_TSTR("tf_inception_resnet_v2"), ORT_TSTR("tf_inception_v1"), ORT_TSTR("tf_inception_v3"), ORT_TSTR("tf_inception_v4"), ORT_TSTR("tf_mobilenet_v1_1.0_224"), + ORT_TSTR("tf_mobilenet_v2_1.0_224"), ORT_TSTR("tf_mobilenet_v2_1.4_224"), ORT_TSTR("tf_nasnet_large"), ORT_TSTR("tf_pnasnet_large"), ORT_TSTR("tf_resnet_v1_50"), ORT_TSTR("tf_resnet_v1_101"), ORT_TSTR("tf_resnet_v1_101"), + ORT_TSTR("tf_resnet_v2_101"), ORT_TSTR("tf_resnet_v2_152")}; + + std::unordered_set > all_disabled_tests; if (enable_cuda) { all_disabled_tests.insert(std::begin(cuda_flaky_tests), std::end(cuda_flaky_tests)); } @@ -373,25 +375,15 @@ int real_main(int argc, char* argv[], Ort::Env& env) { // This will be removed after LRU implementation all_disabled_tests.insert(std::begin(dnnl_disabled_tests), std::end(dnnl_disabled_tests)); } -#if defined(__amd64__) || defined(_M_AMD64) -#else +#if !defined(__amd64__) && !defined(_M_AMD64) //out of memory - static const char* x86_disabled_tests[] = {"mlperf_ssd_resnet34_1200", "mask_rcnn_keras", "mask_rcnn", "faster_rcnn", "vgg19"}; + static const ORTCHAR_T* x86_disabled_tests[] = {ORT_TSTR("mlperf_ssd_resnet34_1200"), ORT_TSTR("mask_rcnn_keras"), ORT_TSTR("mask_rcnn"), ORT_TSTR("faster_rcnn"), ORT_TSTR("vgg19")}; all_disabled_tests.insert(std::begin(x86_disabled_tests), std::end(x86_disabled_tests)); #endif std::vector tests; - LoadTests(data_dirs, whitelisted_test_cases, per_sample_tolerance, relative_per_sample_tolerance, + LoadTests(data_dirs, whitelisted_test_cases, per_sample_tolerance, relative_per_sample_tolerance, all_disabled_tests, [&tests](ITestCase* l) { tests.push_back(l); }); - for (auto it = tests.begin(); it != tests.end();) { - auto iter = all_disabled_tests.find((*it)->GetTestCaseName()); - if (iter != all_disabled_tests.end()) { - delete *it; - it = tests.erase(it); - } else { - ++it; - } - } TestEnv args(tests, stat, env, sf); Status st = RunTests(args, p_models, concurrent_session_runs, static_cast(repeat_count), diff --git a/onnxruntime/test/onnx/runner.cc b/onnxruntime/test/onnx/runner.cc index d8942fc222138..3356f3b1b90fd 100644 --- a/onnxruntime/test/onnx/runner.cc +++ b/onnxruntime/test/onnx/runner.cc @@ -284,6 +284,7 @@ Status RunTests(TestEnv& env, int p_models, int concurrent_runs, size_t repeat_c void LoadTests(const std::vector>& input_paths, const std::vector>& whitelisted_test_cases, double default_per_sample_tolerance, double default_relative_per_sample_tolerance, + const std::unordered_set>& disabled_tests, const std::function& process_function) { std::vector> paths(input_paths); while (!paths.empty()) { @@ -302,10 +303,13 @@ void LoadTests(const std::vector>& input_paths std::basic_string test_case_name = my_dir_name; if (test_case_name.compare(0, 5, ORT_TSTR("test_")) == 0) test_case_name = test_case_name.substr(5); + if (!whitelisted_test_cases.empty() && std::find(whitelisted_test_cases.begin(), whitelisted_test_cases.end(), test_case_name) == whitelisted_test_cases.end()) { return true; } + if (disabled_tests.find(test_case_name) != disabled_tests.end()) return true; + std::basic_string p = ConcatPathComponent(node_data_root_path, filename_str); ITestCase* l = CreateOnnxTestCase(ToMBString(test_case_name), TestModelInfo::LoadOnnxModel(p.c_str()), diff --git a/onnxruntime/test/onnx/runner.h b/onnxruntime/test/onnx/runner.h index 9a26496b454f1..5f07b6bd78849 100644 --- a/onnxruntime/test/onnx/runner.h +++ b/onnxruntime/test/onnx/runner.h @@ -130,6 +130,7 @@ struct DataTask { void LoadTests(const std::vector>& input_paths, const std::vector>& whitelisted_test_cases, double default_per_sample_tolerance, double default_relative_per_sample_tolerance, + const std::unordered_set>& disabled_tests, const std::function& process_function); //Do not run this function in the thread pool passed in diff --git a/onnxruntime/test/util/compare_ortvalue.cc b/onnxruntime/test/util/compare_ortvalue.cc index cfeaa11363185..958597997733c 100644 --- a/onnxruntime/test/util/compare_ortvalue.cc +++ b/onnxruntime/test/util/compare_ortvalue.cc @@ -5,11 +5,39 @@ #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#else +#pragma warning(push) +#pragma warning(disable : 4018) /*'expression' : signed/unsigned mismatch */ +#pragma warning(disable : 4065) /*switch statement contains 'default' but no 'case' labels*/ +#pragma warning(disable : 4100) +#pragma warning(disable : 4146) /*unary minus operator applied to unsigned type, result still unsigned*/ +#pragma warning(disable : 4244) /*'conversion' conversion from 'type1' to 'type2', possible loss of data*/ +#pragma warning(disable : 4251) /*'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'*/ +#pragma warning(disable : 4267) /*'var' : conversion from 'size_t' to 'type', possible loss of data*/ +#pragma warning(disable : 4305) /*'identifier' : truncation from 'type1' to 'type2'*/ +#pragma warning(disable : 4307) /*'operator' : integral constant overflow*/ +#pragma warning(disable : 4309) /*'conversion' : truncation of constant value*/ +#pragma warning(disable : 4334) /*'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)*/ +#pragma warning(disable : 4355) /*'this' : used in base member initializer list*/ +#pragma warning(disable : 4506) /*no definition for inline function 'function'*/ +#pragma warning(disable : 4800) /*'type' : forcing value to bool 'true' or 'false' (performance warning)*/ +#pragma warning(disable : 4996) /*The compiler encountered a deprecated declaration.*/ +#endif #ifdef USE_FULL_PROTOBUF #include #else #include #endif +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#else +#pragma warning(pop) +#endif + #include "core/graph/onnx_protobuf.h" #include "core/framework/tensorprotoutils.h"