mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-07 17:15:29 +00:00
parent
b40a85a0e8
commit
90b708f8a9
21 changed files with 183 additions and 665 deletions
|
|
@ -247,7 +247,7 @@
|
|||
"component": {
|
||||
"type": "git",
|
||||
"git": {
|
||||
"commitHash": "48cb18e5c419ddd23d9badcfe4e9df7bde1979b2",
|
||||
"commitHash": "fe1790ca0df67173702f70d5646b82f48f412b99",
|
||||
"repositoryUrl": "https://github.com/protocolbuffers/protobuf.git"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
2
cmake/external/protobuf
vendored
2
cmake/external/protobuf
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 48cb18e5c419ddd23d9badcfe4e9df7bde1979b2
|
||||
Subproject commit 7bb8b108d16252d0ed053673d70ea6d2020ec7ff
|
||||
|
|
@ -6,7 +6,11 @@ target_include_directories(onnx_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprot
|
|||
target_compile_definitions(onnx_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_COMPILE_DEFINITIONS>)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -480,16 +480,23 @@ if(WIN32)
|
|||
endif()
|
||||
|
||||
add_library(onnx_test_data_proto ${TEST_SRC_DIR}/proto/tml.proto)
|
||||
add_dependencies(onnx_test_data_proto onnx_proto ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
||||
|
||||
if(WIN32)
|
||||
target_compile_options(onnx_test_data_proto PRIVATE "/wd4125" "/wd4456" "/wd4100")
|
||||
target_compile_options(onnx_test_data_proto PRIVATE "/wd4125" "/wd4456" "/wd4100" "/wd4267")
|
||||
else()
|
||||
if(HAS_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})
|
||||
|
||||
if(NOT WIN32)
|
||||
if(HAS_UNUSED_PARAMETER)
|
||||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/tml.pb.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
|
||||
endif()
|
||||
endif()
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@
|
|||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
|
||||
<PackageReference Include="System.Memory" Version="4.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<PackageName Condition="'$(PackageName)' == ''">Microsoft.ML.OnnxRuntime</PackageName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.Targets" Version="2.1.0"/>
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2"/>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
|
|
|
|||
|
|
@ -109,24 +109,24 @@ namespace Onnx {
|
|||
"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 @@ namespace Onnx {
|
|||
|
||||
/// <summary>Field number for the "type" field.</summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// 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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
|
||||
/// <summary>Field number for the "data_location" field.</summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// If value not set, data is stored in raw_data (if set) otherwise in type-specified field.
|
||||
/// </summary>
|
||||
|
|
@ -2717,7 +2717,7 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
break;
|
||||
}
|
||||
case 112: {
|
||||
dataLocation_ = (global::Onnx.TensorProto.Types.DataLocation) input.ReadEnum();
|
||||
DataLocation = (global::Onnx.TensorProto.Types.DataLocation) input.ReadEnum();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -3327,13 +3327,13 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
}
|
||||
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 @@ namespace Onnx {
|
|||
|
||||
/// <summary>Field number for the "status" field.</summary>
|
||||
public const int StatusFieldNumber = 3;
|
||||
private global::Onnx.OperatorStatus status_ = 0;
|
||||
private global::Onnx.OperatorStatus status_ = global::Onnx.OperatorStatus.Experimental;
|
||||
/// <summary>
|
||||
/// 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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
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 @@ namespace Onnx {
|
|||
break;
|
||||
}
|
||||
case 24: {
|
||||
status_ = (global::Onnx.OperatorStatus) input.ReadEnum();
|
||||
Status = (global::Onnx.OperatorStatus) input.ReadEnum();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
|
|
|
|||
|
|
@ -34,11 +34,14 @@ ptrdiff_t OrtStrToPtrDiff(const T* nptr, T** endptr);
|
|||
template <>
|
||||
inline ptrdiff_t OrtStrToPtrDiff<wchar_t>(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 <typename T>
|
||||
|
|
@ -57,11 +60,14 @@ inline size_t OrtStrftime<wchar_t>(wchar_t* strDest, size_t maxsize, const wchar
|
|||
template <>
|
||||
inline ptrdiff_t OrtStrToPtrDiff<char>(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 <>
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ OrtStatus* CreateTensorImpl(MLDataType ml_type, const int64_t* shape, size_t sha
|
|||
size_t elem_count = 1;
|
||||
std::vector<int64_t> shapes(shape_len);
|
||||
for (size_t i = 0; i != shape_len; ++i) {
|
||||
elem_count *= shape[i];
|
||||
elem_count *= static_cast<size_t>(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<T>();
|
||||
int64_t num_kv_pairs = data.size();
|
||||
#if defined(_WIN32) && !defined(_M_AMD64)
|
||||
ORT_ENFORCE(static_cast<uint64_t>(num_kv_pairs) < std::numeric_limits<size_t>::max());
|
||||
#endif
|
||||
switch (index) {
|
||||
case 0: { // user is requesting keys
|
||||
std::vector<TKey> vec;
|
||||
vec.reserve(num_kv_pairs);
|
||||
vec.reserve(static_cast<size_t>(num_kv_pairs));
|
||||
for (const auto& kv : data) {
|
||||
vec.push_back(kv.first);
|
||||
}
|
||||
std::vector<int64_t> dims{num_kv_pairs};
|
||||
OrtStatus* st = OrtApis::CreateTensorAsOrtValue(allocator, dims.data(), dims.size(),
|
||||
GetONNXTensorElementDataType<TKey>(), out);
|
||||
return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs, sizeof(TKey));
|
||||
return st ? st : PopulateTensorWithData(*out, vec.data(), static_cast<size_t>(num_kv_pairs), sizeof(TKey));
|
||||
}
|
||||
case 1: { // user is requesting values
|
||||
std::vector<TVal> vec;
|
||||
vec.reserve(num_kv_pairs);
|
||||
vec.reserve(static_cast<size_t>(num_kv_pairs));
|
||||
for (const auto& kv : data) {
|
||||
vec.push_back(kv.second);
|
||||
}
|
||||
std::vector<int64_t> dims{num_kv_pairs};
|
||||
OrtStatus* st = OrtApis::CreateTensorAsOrtValue(allocator, dims.data(), dims.size(),
|
||||
GetONNXTensorElementDataType<TVal>(), out);
|
||||
return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs, sizeof(TVal));
|
||||
return st ? st : PopulateTensorWithData(*out, vec.data(), static_cast<size_t>(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<KeyType>();
|
||||
auto value_data = value_tensor.Data<ValueType>();
|
||||
size_t num_kv_pairs = key_tensor.Shape().Size();
|
||||
auto len = key_tensor.Shape().Size();
|
||||
ORT_ENFORCE(len >= 0 && static_cast<uint64_t>(len) < std::numeric_limits<size_t>::max());
|
||||
size_t num_kv_pairs = static_cast<size_t>(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});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/stubs/stl_util.h>
|
||||
#ifdef _WIN32
|
||||
#include <google/protobuf/stubs/io_win32.h>
|
||||
#endif
|
||||
#include "protobuf_parsing_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
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 <io.h>, 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<off_t>(-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<const uint8*>(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<char*>(buffer), size);
|
||||
int result = static_cast<int>(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<const char*>(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<int>(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<int>(-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<int>(limit_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void LimitingInputStream::BackUp(int count) {
|
||||
if (limit_ < 0) {
|
||||
input_->BackUp(static_cast<int>(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<int>(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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ TEST(ONNXModelsTest1, bvlc_alexnet_1) {
|
|||
std::unique_ptr<ZeroCopyInputStream> raw_input(new FileInputStream(fd));
|
||||
std::unique_ptr<CodedInputStream> 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<ZeroCopyInputStream> raw_input(new FileInputStream(fd));
|
||||
std::unique_ptr<CodedInputStream> coded_input(new CodedInputStream(raw_input.get()));
|
||||
coded_input->SetTotalBytesLimit(INT_MAX, INT_MAX);
|
||||
coded_input->SetTotalBytesLimit(INT_MAX);
|
||||
std::unique_ptr<ModelProto> model_proto = onnxruntime::make_unique<ModelProto>();
|
||||
bool result = model_proto->ParseFromCodedStream(coded_input.get());
|
||||
coded_input.reset();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<std::string> 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<std::basic_string<ORTCHAR_T> > 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<ITestCase*> 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<size_t>(repeat_count),
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ Status RunTests(TestEnv& env, int p_models, int concurrent_runs, size_t repeat_c
|
|||
void LoadTests(const std::vector<std::basic_string<PATH_CHAR_TYPE>>& input_paths,
|
||||
const std::vector<std::basic_string<PATH_CHAR_TYPE>>& whitelisted_test_cases,
|
||||
double default_per_sample_tolerance, double default_relative_per_sample_tolerance,
|
||||
const std::unordered_set<std::basic_string<ORTCHAR_T>>& disabled_tests,
|
||||
const std::function<void(ITestCase*)>& process_function) {
|
||||
std::vector<std::basic_string<PATH_CHAR_TYPE>> paths(input_paths);
|
||||
while (!paths.empty()) {
|
||||
|
|
@ -302,10 +303,13 @@ void LoadTests(const std::vector<std::basic_string<PATH_CHAR_TYPE>>& input_paths
|
|||
|
||||
std::basic_string<PATH_CHAR_TYPE> 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<PATH_CHAR_TYPE> p = ConcatPathComponent<PATH_CHAR_TYPE>(node_data_root_path, filename_str);
|
||||
|
||||
ITestCase* l = CreateOnnxTestCase(ToMBString(test_case_name), TestModelInfo::LoadOnnxModel(p.c_str()),
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ struct DataTask {
|
|||
void LoadTests(const std::vector<std::basic_string<PATH_CHAR_TYPE>>& input_paths,
|
||||
const std::vector<std::basic_string<PATH_CHAR_TYPE>>& whitelisted_test_cases,
|
||||
double default_per_sample_tolerance, double default_relative_per_sample_tolerance,
|
||||
const std::unordered_set<std::basic_string<ORTCHAR_T>>& disabled_tests,
|
||||
const std::function<void(ITestCase*)>& process_function);
|
||||
|
||||
//Do not run this function in the thread pool passed in
|
||||
|
|
|
|||
|
|
@ -5,11 +5,39 @@
|
|||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#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 <google/protobuf/message.h>
|
||||
#else
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#else
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
#include "core/graph/onnx_protobuf.h"
|
||||
#include "core/framework/tensorprotoutils.h"
|
||||
|
|
|
|||
Loading…
Reference in a new issue