Skip to content

Commit 7aef8a1

Browse files
committed
Sync with internal master.
1 parent ba470c2 commit 7aef8a1

File tree

65 files changed

+2460
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2460
-1345
lines changed

cmake/onnxruntime.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ else()
1010
endif()
1111

1212

13+
#If you want to verify if there is any extra line in symbols.txt, run
14+
# nm -C -g --defined libonnxruntime.so |grep -v '\sA\s' | cut -f 3 -d ' ' | sort
15+
# after build
16+
1317
list(APPEND SYMBOL_FILES "${REPO_ROOT}/tools/ci_build/gen_def.py")
1418
foreach(f ${ONNXRUNTIME_PROVIDER_NAMES})
1519
list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/providers/${f}/symbols.txt")

cmake/onnxruntime_common.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ target_include_directories(onnxruntime_common PRIVATE ${ONNXRUNTIME_ROOT} ${date
4444
# logging uses date. threadpool uses eigen
4545
add_dependencies(onnxruntime_common date eigen gsl)
4646

47-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/common)
47+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
4848
set_target_properties(onnxruntime_common PROPERTIES LINKER_LANGUAGE CXX)
4949
set_target_properties(onnxruntime_common PROPERTIES FOLDER "ONNXRuntime")
5050

cmake/onnxruntime_framework.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
1818
# need onnx to build to create headers that this project includes
1919
add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES})
2020

21-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/framework)
21+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
2222
if (WIN32)
2323
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
2424
set_target_properties(onnxruntime_framework PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/ConfigureVisualStudioCodeAnalysis.props)

cmake/onnxruntime_graph.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ onnxruntime_add_include_to_target(onnxruntime_graph onnx protobuf::libprotobuf)
1717
target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
1818
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
1919
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
20-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/graph)
20+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
2121
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
2222

2323
if (WIN32)

cmake/onnxruntime_providers.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ add_library(onnxruntime_providers ${onnxruntime_providers_common_srcs} ${onnxrun
3434
onnxruntime_add_include_to_target(onnxruntime_providers onnx protobuf::libprotobuf)
3535
target_include_directories(onnxruntime_providers PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
3636
add_dependencies(onnxruntime_providers eigen gsl onnx)
37-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cpu DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/cpu)
37+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cpu DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
3838
set_target_properties(onnxruntime_providers PROPERTIES LINKER_LANGUAGE CXX)
3939
set_target_properties(onnxruntime_providers PROPERTIES FOLDER "ONNXRuntime")
4040

@@ -61,7 +61,7 @@ if (onnxruntime_USE_CUDA)
6161
onnxruntime_add_include_to_target(onnxruntime_providers_cuda onnx protobuf::libprotobuf)
6262
add_dependencies(onnxruntime_providers_cuda eigen ${onnxruntime_EXTERNAL_DEPENDENCIES} ${onnxruntime_tvm_dependencies})
6363
target_include_directories(onnxruntime_providers_cuda PRIVATE ${ONNXRUNTIME_ROOT} ${onnxruntime_CUDNN_HOME}/include ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES})
64-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cuda DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/cuda)
64+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cuda DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
6565
set_target_properties(onnxruntime_providers_cuda PROPERTIES LINKER_LANGUAGE CUDA)
6666
set_target_properties(onnxruntime_providers_cuda PROPERTIES FOLDER "ONNXRuntime")
6767
if (WIN32)
@@ -95,7 +95,7 @@ if (onnxruntime_USE_MKLDNN)
9595
add_dependencies(onnxruntime_providers_mkldnn eigen ${onnxruntime_EXTERNAL_DEPENDENCIES})
9696
set_target_properties(onnxruntime_providers_mkldnn PROPERTIES FOLDER "ONNXRuntime")
9797
target_include_directories(onnxruntime_providers_mkldnn PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
98-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/mkldnn DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/mkldnn)
98+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/mkldnn DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
9999
set_target_properties(onnxruntime_providers_mkldnn PROPERTIES LINKER_LANGUAGE CXX)
100100
endif()
101101

cmake/onnxruntime_session.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ file(GLOB onnxruntime_session_srcs
1010
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_session_srcs})
1111

1212
add_library(onnxruntime_session ${onnxruntime_session_srcs})
13-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/session)
13+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
1414
onnxruntime_add_include_to_target(onnxruntime_session onnx protobuf::libprotobuf)
1515
target_include_directories(onnxruntime_session PRIVATE ${ONNXRUNTIME_ROOT})
1616
add_dependencies(onnxruntime_session ${onnxruntime_EXTERNAL_DEPENDENCIES})

cmake/onnxruntime_unittests.cmake

+11-12
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,17 @@ if (onnxruntime_BUILD_SHARED_LIB)
525525
# this program shouldn't have direct depedency on CUDA
526526
# CUDA is part of ${ONNX_DLL}
527527
set (ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR "${ONNXRUNTIME_ROOT}/test/shared_lib")
528-
add_executable(onnxruntime_shared_lib_test
529-
${ONNXRUNTIME_ROOT}/test/util/test_allocator.cc
530-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
531-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc
532-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_session_options.cc
533-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_run_options.cc
534-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_allocator.cc
535-
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc)
528+
set (onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_ROOT}/test/util/test_allocator.cc
529+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
530+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc
531+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_session_options.cc
532+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_run_options.cc
533+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_allocator.cc
534+
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc)
535+
if(onnxruntime_RUN_ONNX_TESTS)
536+
list(APPEND onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_io_types.cc)
537+
endif()
538+
add_executable(onnxruntime_shared_lib_test ${onnxruntime_shared_lib_test_SRC})
536539
onnxruntime_add_include_to_target(onnxruntime_shared_lib_test onnxruntime_test_utils)
537540
target_include_directories(onnxruntime_shared_lib_test PRIVATE "${TEST_SRC_DIR}/util/include" "${PROJECT_SOURCE_DIR}/include")
538541
if(WIN32)
@@ -557,7 +560,3 @@ add_executable(onnxruntime_mlas_test ${TEST_SRC_DIR}/mlas/unittest.cpp)
557560
target_include_directories(onnxruntime_mlas_test PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc)
558561
target_link_libraries(onnxruntime_mlas_test PRIVATE onnxruntime_mlas)
559562
set_target_properties(onnxruntime_mlas_test PROPERTIES FOLDER "ONNXRuntimeTest")
560-
561-
if (onnxruntime_ENABLE_MICROSOFT_INTERNAL)
562-
include(onnxruntime_standalone_tests_internal.cmake)
563-
endif()

csharp/sample/Microsoft.ML.OnnxRuntime.InferenceSample/Program.cs

+13-27
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ static void UseApi()
2828
using (var session = new InferenceSession(modelPath))
2929
{
3030
var inputMeta = session.InputMetadata;
31+
var container = new List<NamedOnnxValue>();
3132

32-
// User should be able to detect input name/type/shape from the metadata.
33-
// Currently InputMetadata implementation is inclomplete, so assuming Tensor<flot> of predefined dimension.
34-
35-
var shape0 = new int[] { 1, 3, 224, 224 };
36-
float[] inputData0 = LoadInputsFloat();
37-
var tensor = new DenseTensor<float>(inputData0, shape0);
33+
float[] inputData = LoadTensorFromFile(@"bench.in"); // this is the data for only one input tensor for this model
3834

39-
var container = new List<NamedOnnxValue>();
40-
container.Add(new NamedOnnxValue("data_0", tensor));
35+
foreach (var name in inputMeta.Keys)
36+
{
37+
var tensor = new DenseTensor<float>(inputData, inputMeta[name].Dimensions);
38+
container.Add(new NamedOnnxValue(name, tensor));
39+
}
4140

4241
// Run the inference
4342
var results = session.Run(container); // results is an IReadOnlyList<NamedOnnxValue> container
@@ -49,40 +48,27 @@ static void UseApi()
4948
Console.WriteLine(r.AsTensor<float>().GetArrayString());
5049
}
5150

52-
// Just try some GC collect
53-
results = null;
54-
container = null;
55-
56-
GC.Collect();
57-
GC.WaitForPendingFinalizers();
5851
}
5952
}
6053

61-
static int[] LoadInputsInt32()
54+
static float[] LoadTensorFromFile(string filename)
6255
{
63-
return null;
64-
}
65-
66-
static float[] LoadInputsFloat()
67-
{
68-
// input: data_0 = float32[1,3,224,224] for squeezenet model
69-
// output: softmaxout_1 = float32[1,1000,1,1]
70-
uint size = 1 * 3 * 224 * 224;
71-
float[] tensor = new float[size];
56+
var tensorData = new List<float>();
7257

7358
// read data from file
74-
using (var inputFile = new System.IO.StreamReader(@"bench.in"))
59+
using (var inputFile = new System.IO.StreamReader(filename))
7560
{
7661
inputFile.ReadLine(); //skip the input name
7762
string[] dataStr = inputFile.ReadLine().Split(new char[] { ',', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
7863
for (int i = 0; i < dataStr.Length; i++)
7964
{
80-
tensor[i] = Single.Parse(dataStr[i]);
65+
tensorData.Add(Single.Parse(dataStr[i]));
8166
}
8267
}
8368

84-
return tensor;
69+
return tensorData.ToArray();
8570
}
8671

72+
8773
}
8874
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Runtime.InteropServices;
5+
6+
namespace Microsoft.ML.OnnxRuntime
7+
{
8+
9+
internal class CpuExecutionProviderFactory: NativeOnnxObjectHandle
10+
{
11+
protected static readonly Lazy<CpuExecutionProviderFactory> _default = new Lazy<CpuExecutionProviderFactory>(() => new CpuExecutionProviderFactory());
12+
13+
public CpuExecutionProviderFactory(bool useArena=true)
14+
:base(IntPtr.Zero)
15+
{
16+
int useArenaInt = useArena ? 1 : 0;
17+
try
18+
{
19+
NativeApiStatus.VerifySuccess(NativeMethods.ONNXRuntimeCreateCpuExecutionProviderFactory(useArenaInt, out handle));
20+
}
21+
catch(OnnxRuntimeException e)
22+
{
23+
if (IsInvalid)
24+
{
25+
ReleaseHandle();
26+
handle = IntPtr.Zero;
27+
}
28+
throw e;
29+
}
30+
}
31+
32+
public static CpuExecutionProviderFactory Default
33+
{
34+
get
35+
{
36+
return _default.Value;
37+
}
38+
}
39+
}
40+
41+
internal class MklDnnExecutionProviderFactory : NativeOnnxObjectHandle
42+
{
43+
protected static readonly Lazy<MklDnnExecutionProviderFactory> _default = new Lazy<MklDnnExecutionProviderFactory>(() => new MklDnnExecutionProviderFactory());
44+
45+
public MklDnnExecutionProviderFactory(bool useArena = true)
46+
:base(IntPtr.Zero)
47+
{
48+
int useArenaInt = useArena ? 1 : 0;
49+
try
50+
{
51+
NativeApiStatus.VerifySuccess(NativeMethods.ONNXRuntimeCreateMkldnnExecutionProviderFactory(useArenaInt, out handle));
52+
}
53+
catch (OnnxRuntimeException e)
54+
{
55+
if (IsInvalid)
56+
{
57+
ReleaseHandle();
58+
handle = IntPtr.Zero;
59+
}
60+
throw e;
61+
}
62+
}
63+
64+
public static MklDnnExecutionProviderFactory Default
65+
{
66+
get
67+
{
68+
return _default.Value;
69+
}
70+
}
71+
}
72+
73+
74+
75+
76+
}

0 commit comments

Comments
 (0)