Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/onnxruntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ else()
endif()


#If you want to verify if there is any extra line in symbols.txt, run
# nm -C -g --defined libonnxruntime.so |grep -v '\sA\s' | cut -f 3 -d ' ' | sort
# after build

list(APPEND SYMBOL_FILES "${REPO_ROOT}/tools/ci_build/gen_def.py")
foreach(f ${ONNXRUNTIME_PROVIDER_NAMES})
list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/providers/${f}/symbols.txt")
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ target_include_directories(onnxruntime_common PRIVATE ${ONNXRUNTIME_ROOT} ${date
# logging uses date. threadpool uses eigen
add_dependencies(onnxruntime_common date eigen gsl)

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

Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_framework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
# need onnx to build to create headers that this project includes
add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES})

install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/framework)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
if (WIN32)
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
set_target_properties(onnxruntime_framework PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/ConfigureVisualStudioCodeAnalysis.props)
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ onnxruntime_add_include_to_target(onnxruntime_graph onnx protobuf::libprotobuf)
target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/graph)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})

if (WIN32)
Expand Down
6 changes: 3 additions & 3 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ add_library(onnxruntime_providers ${onnxruntime_providers_common_srcs} ${onnxrun
onnxruntime_add_include_to_target(onnxruntime_providers onnx protobuf::libprotobuf)
target_include_directories(onnxruntime_providers PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
add_dependencies(onnxruntime_providers eigen gsl onnx)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cpu DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/cpu)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cpu DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
set_target_properties(onnxruntime_providers PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(onnxruntime_providers PROPERTIES FOLDER "ONNXRuntime")

Expand All @@ -61,7 +61,7 @@ if (onnxruntime_USE_CUDA)
onnxruntime_add_include_to_target(onnxruntime_providers_cuda onnx protobuf::libprotobuf)
add_dependencies(onnxruntime_providers_cuda eigen ${onnxruntime_EXTERNAL_DEPENDENCIES} ${onnxruntime_tvm_dependencies})
target_include_directories(onnxruntime_providers_cuda PRIVATE ${ONNXRUNTIME_ROOT} ${onnxruntime_CUDNN_HOME}/include ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cuda DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/cuda)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/cuda DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
set_target_properties(onnxruntime_providers_cuda PROPERTIES LINKER_LANGUAGE CUDA)
set_target_properties(onnxruntime_providers_cuda PROPERTIES FOLDER "ONNXRuntime")
if (WIN32)
Expand Down Expand Up @@ -95,7 +95,7 @@ if (onnxruntime_USE_MKLDNN)
add_dependencies(onnxruntime_providers_mkldnn eigen ${onnxruntime_EXTERNAL_DEPENDENCIES})
set_target_properties(onnxruntime_providers_mkldnn PROPERTIES FOLDER "ONNXRuntime")
target_include_directories(onnxruntime_providers_mkldnn PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/mkldnn DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers/mkldnn)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/mkldnn DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers)
set_target_properties(onnxruntime_providers_mkldnn PROPERTIES LINKER_LANGUAGE CXX)
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_session.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file(GLOB onnxruntime_session_srcs
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_session_srcs})

add_library(onnxruntime_session ${onnxruntime_session_srcs})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/session)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
onnxruntime_add_include_to_target(onnxruntime_session onnx protobuf::libprotobuf)
target_include_directories(onnxruntime_session PRIVATE ${ONNXRUNTIME_ROOT})
add_dependencies(onnxruntime_session ${onnxruntime_EXTERNAL_DEPENDENCIES})
Expand Down
23 changes: 11 additions & 12 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,17 @@ if (onnxruntime_BUILD_SHARED_LIB)
# this program shouldn't have direct depedency on CUDA
# CUDA is part of ${ONNX_DLL}
set (ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR "${ONNXRUNTIME_ROOT}/test/shared_lib")
add_executable(onnxruntime_shared_lib_test
${ONNXRUNTIME_ROOT}/test/util/test_allocator.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_session_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_run_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_allocator.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc)
set (onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_ROOT}/test/util/test_allocator.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_session_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_run_options.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_allocator.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_inference.cc)
if(onnxruntime_RUN_ONNX_TESTS)
list(APPEND onnxruntime_shared_lib_test_SRC ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_io_types.cc)
endif()
add_executable(onnxruntime_shared_lib_test ${onnxruntime_shared_lib_test_SRC})
onnxruntime_add_include_to_target(onnxruntime_shared_lib_test onnxruntime_test_utils)
target_include_directories(onnxruntime_shared_lib_test PRIVATE "${TEST_SRC_DIR}/util/include" "${PROJECT_SOURCE_DIR}/include")
if(WIN32)
Expand All @@ -557,7 +560,3 @@ add_executable(onnxruntime_mlas_test ${TEST_SRC_DIR}/mlas/unittest.cpp)
target_include_directories(onnxruntime_mlas_test PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc)
target_link_libraries(onnxruntime_mlas_test PRIVATE onnxruntime_mlas)
set_target_properties(onnxruntime_mlas_test PROPERTIES FOLDER "ONNXRuntimeTest")

if (onnxruntime_ENABLE_MICROSOFT_INTERNAL)
include(onnxruntime_standalone_tests_internal.cmake)
endif()
40 changes: 13 additions & 27 deletions csharp/sample/Microsoft.ML.OnnxRuntime.InferenceSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ static void UseApi()
using (var session = new InferenceSession(modelPath))
{
var inputMeta = session.InputMetadata;
var container = new List<NamedOnnxValue>();

// User should be able to detect input name/type/shape from the metadata.
// Currently InputMetadata implementation is inclomplete, so assuming Tensor<flot> of predefined dimension.

var shape0 = new int[] { 1, 3, 224, 224 };
float[] inputData0 = LoadInputsFloat();
var tensor = new DenseTensor<float>(inputData0, shape0);
float[] inputData = LoadTensorFromFile(@"bench.in"); // this is the data for only one input tensor for this model

var container = new List<NamedOnnxValue>();
container.Add(new NamedOnnxValue("data_0", tensor));
foreach (var name in inputMeta.Keys)
{
var tensor = new DenseTensor<float>(inputData, inputMeta[name].Dimensions);
container.Add(new NamedOnnxValue(name, tensor));
}

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

// Just try some GC collect
results = null;
container = null;

GC.Collect();
GC.WaitForPendingFinalizers();
}
}

static int[] LoadInputsInt32()
static float[] LoadTensorFromFile(string filename)
{
return null;
}

static float[] LoadInputsFloat()
{
// input: data_0 = float32[1,3,224,224] for squeezenet model
// output: softmaxout_1 = float32[1,1000,1,1]
uint size = 1 * 3 * 224 * 224;
float[] tensor = new float[size];
var tensorData = new List<float>();

// read data from file
using (var inputFile = new System.IO.StreamReader(@"bench.in"))
using (var inputFile = new System.IO.StreamReader(filename))
{
inputFile.ReadLine(); //skip the input name
string[] dataStr = inputFile.ReadLine().Split(new char[] { ',', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < dataStr.Length; i++)
{
tensor[i] = Single.Parse(dataStr[i]);
tensorData.Add(Single.Parse(dataStr[i]));
}
}

return tensor;
return tensorData.ToArray();
}


}
}
76 changes: 76 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/ExecutionProviderFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Microsoft.ML.OnnxRuntime
{

internal class CpuExecutionProviderFactory: NativeOnnxObjectHandle
{
protected static readonly Lazy<CpuExecutionProviderFactory> _default = new Lazy<CpuExecutionProviderFactory>(() => new CpuExecutionProviderFactory());

public CpuExecutionProviderFactory(bool useArena=true)
:base(IntPtr.Zero)
{
int useArenaInt = useArena ? 1 : 0;
try
{
NativeApiStatus.VerifySuccess(NativeMethods.ONNXRuntimeCreateCpuExecutionProviderFactory(useArenaInt, out handle));
}
catch(OnnxRuntimeException e)
{
if (IsInvalid)
{
ReleaseHandle();
handle = IntPtr.Zero;
}
throw e;
}
}

public static CpuExecutionProviderFactory Default
{
get
{
return _default.Value;
}
}
}

internal class MklDnnExecutionProviderFactory : NativeOnnxObjectHandle
{
protected static readonly Lazy<MklDnnExecutionProviderFactory> _default = new Lazy<MklDnnExecutionProviderFactory>(() => new MklDnnExecutionProviderFactory());

public MklDnnExecutionProviderFactory(bool useArena = true)
:base(IntPtr.Zero)
{
int useArenaInt = useArena ? 1 : 0;
try
{
NativeApiStatus.VerifySuccess(NativeMethods.ONNXRuntimeCreateMkldnnExecutionProviderFactory(useArenaInt, out handle));
}
catch (OnnxRuntimeException e)
{
if (IsInvalid)
{
ReleaseHandle();
handle = IntPtr.Zero;
}
throw e;
}
}

public static MklDnnExecutionProviderFactory Default
{
get
{
return _default.Value;
}
}
}




}
Loading