Cleanup C# bindings to add EP (#8810)

Fix C# add EP bindings.
Add stubs to ORT so that if EP is not included in the build we return a graceful error message.
Move declaration of stubs into C API and out for EP so they're in one place and are easier to use (no extra header required in the C/C++ world and consistent with the CUDA EP setup).
Fix inconsistency in ROCM EP.
Cleanup a few other things.
This commit is contained in:
Scott McKay 2021-08-26 13:59:40 +10:00 committed by GitHub
parent 613a600471
commit b21ea00020
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 473 additions and 13930 deletions

4
.gitignore vendored
View file

@ -52,4 +52,6 @@ onnxruntime/python/version_info.py
/tools/perf_util/target/classes
/tools/perf_util/src/main/resources
/orttraining/orttraining/eager/ort_aten.g.cpp
/orttraining/orttraining/eager/ort_customops.g.cpp
/orttraining/orttraining/eager/ort_customops.g.cpp
/csharp/tools/Microsoft.ML.OnnxRuntime.PerfTool/OnnxMl.cs
/csharp/test/Microsoft.ML.OnnxRuntime.Tests/OnnxMl.cs

View file

@ -16,7 +16,7 @@ endif()
# This macro is to get the path of header files for mobile packaging, for iOS and Android
macro(get_mobile_api_headers _HEADERS)
# include both c and cxx api
# include both c and cxx api, and stubs to provide graceful error if EP is not included in build
set(${_HEADERS}
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_c_api.h"
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_cxx_api.h"
@ -41,6 +41,7 @@ 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")
endforeach()
list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/session/symbols.txt")
add_custom_command(OUTPUT ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c
COMMAND ${Python_EXECUTABLE} "${REPO_ROOT}/tools/ci_build/gen_def.py"

View file

@ -18,22 +18,34 @@ if (onnxruntime_USE_DNNL)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_DNNL,")
endif()
if (onnxruntime_USE_TENSORRT)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_TENSORRT,")
if (onnxruntime_USE_DML)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_DML,")
endif()
if (onnxruntime_USE_MIGRAPHX)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_MIGRAPHX,")
endif()
if (onnxruntime_USE_OPENVINO)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_OPENVINO,")
if (onnxruntime_USE_NNAPI_BUILTIN)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_NNAPI,")
endif()
if (onnxruntime_USE_NUPHAR)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_NUPHAR,")
endif()
if (onnxruntime_USE_OPENVINO)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_OPENVINO,")
endif()
if (onnxruntime_USE_ROCM)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_ROCM,")
endif()
if (onnxruntime_USE_TENSORRT)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_TENSORRT,")
endif()
include(CSharpUtilities)
include_external_msproject(Microsoft.ML.OnnxRuntime
@ -57,7 +69,8 @@ include_external_msproject(Microsoft.ML.OnnxRuntime.PerfTool
#Exclude them from the ALL_BUILD target, otherwise it will trigger errors like:
#"Error : Project 'cmake\..\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj' targets 'netstandard1.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.0'."
#We can't fix it because cmake only supports the "TargetFrameworkVersion" property, not "TargetFramework".
set_target_properties(Microsoft.ML.OnnxRuntime Microsoft.ML.OnnxRuntime.InferenceSample Microsoft.ML.OnnxRuntime.Tests Microsoft.ML.OnnxRuntime.PerfTool PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(Microsoft.ML.OnnxRuntime Microsoft.ML.OnnxRuntime.InferenceSample Microsoft.ML.OnnxRuntime.Tests
Microsoft.ML.OnnxRuntime.PerfTool PROPERTIES EXCLUDE_FROM_ALL 1)
# generate Directory.Build.props
set(DIRECTORY_BUILD_PROPS_COMMENT "WARNING: This is a generated file, please do not check it in!")

View file

@ -5,6 +5,7 @@ file(GLOB onnxruntime_session_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_INCLUDE_DIR}/core/session/*.h"
"${ONNXRUNTIME_ROOT}/core/session/*.h"
"${ONNXRUNTIME_ROOT}/core/session/*.cc"
"${ONNXRUNTIME_ROOT}/core/session/symbols.txt"
)
if (onnxruntime_MINIMAL_BUILD)

View file

@ -24,22 +24,23 @@ namespace Microsoft.ML.OnnxRuntime
/// <summary>
/// A pointer to a underlying native instance of OrtSession
/// </summary>
protected IntPtr _nativeHandle;
private IntPtr _nativeHandle;
/// <summary>
/// Dictionary that represents input metadata
/// </summary>
protected Dictionary<string, NodeMetadata> _inputMetadata;
private Dictionary<string, NodeMetadata> _inputMetadata;
/// <summary>
/// Dictionary that represent output metadata
/// </summary>
protected Dictionary<string, NodeMetadata> _outputMetadata;
private Dictionary<string, NodeMetadata> _outputMetadata;
/// <summary>
/// Dictionary that represents overridableInitializers metadata
/// </summary>
protected Dictionary<string, NodeMetadata> _overridableInitializerMetadata;
private Dictionary<string, NodeMetadata> _overridableInitializerMetadata;
private SessionOptions _builtInSessionOptions = null;
private RunOptions _builtInRunOptions = null;
private ModelMetadata _modelMetadata = null;

View file

@ -206,6 +206,23 @@ namespace Microsoft.ML.OnnxRuntime
public IntPtr UpdateTensorRTProviderOptions;
public IntPtr GetTensorRTProviderOptionsAsString;
public IntPtr ReleaseTensorRTProviderOptions;
public IntPtr EnableOrtCustomOps;
public IntPtr RegisterAllocator;
public IntPtr UnregisterAllocator;
public IntPtr IsSparseTensor;
public IntPtr CreateSparseTensorAsOrtValue;
public IntPtr FillSparseTensorCoo;
public IntPtr FillSparseTensorCsr;
public IntPtr FillSparseTensorBlockSparse;
public IntPtr CreateSparseTensorWithValuesAsOrtValue;
public IntPtr UseCooIndices;
public IntPtr UseCsrIndices;
public IntPtr UseBlockSparseIndices;
public IntPtr GetSparseTensorFormat;
public IntPtr GetSparseTensorValuesTypeAndShape;
public IntPtr GetSparseTensorValues;
public IntPtr GetSparseTensorIndicesTypeShape;
public IntPtr GetSparseTensorIndices;
}
internal static class NativeMethods
@ -453,7 +470,7 @@ namespace Microsoft.ML.OnnxRuntime
IntPtr /* (OrtEnv*) */ environment,
//[MarshalAs(UnmanagedType.LPStr)]string modelPath
byte[] modelPath,
IntPtr /* (OrtSessionOptions*) */sessopnOptions,
IntPtr /* (OrtSessionOptions*) */sessionOptions,
out IntPtr /**/ session);
public static DOrtCreateSession OrtCreateSession;
@ -672,14 +689,15 @@ namespace Microsoft.ML.OnnxRuntime
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_CUDA(IntPtr /*(OrtSessionOptions*) */ options, int device_id);
[DllImport(nativeLib, CharSet = charSet)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_ROCM(IntPtr /*(OrtSessionOptions*) */ options, int device_id);
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_ROCM(
IntPtr /*(OrtSessionOptions*) */ options, int device_id, UIntPtr gpu_mem_limit);
[DllImport(nativeLib, CharSet = charSet)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_DML(IntPtr /*(OrtSessionOptions*) */ options, int device_id);
[DllImport(nativeLib, CharSet = charSet)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_OpenVINO(
IntPtr /*(OrtSessionOptions*)*/ options, IntPtr /*(const char*)*/ device_id);
IntPtr /*(OrtSessionOptions*)*/ options, IntPtr /*(const char*)*/ device_id);
[DllImport(nativeLib, CharSet = charSet)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_Tensorrt(IntPtr /*(OrtSessionOptions*)*/ options, int device_id);

View file

@ -52,16 +52,6 @@ namespace Microsoft.ML.OnnxRuntime
NativeApiStatus.VerifySuccess(NativeMethods.OrtCreateSessionOptions(out handle));
}
/// <summary>
/// A helper method to construct a SessionOptions object for CUDA execution.
/// Use only if CUDA is installed and you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <returns>A SessionsOptions() object configured for execution on deviceId=0</returns>
public static SessionOptions MakeSessionOptionWithCudaProvider()
{
return MakeSessionOptionWithCudaProvider(0);
}
/// <summary>
/// A helper method to construct a SessionOptions object for CUDA execution.
/// Use only if CUDA is installed and you have the onnxruntime package specific to this Execution Provider.
@ -151,22 +141,14 @@ namespace Microsoft.ML.OnnxRuntime
/// A helper method to construct a SessionOptions object for ROCM execution.
/// Use only if ROCM is installed and you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <returns>A SessionsOptions() object configured for execution on deviceId=0</returns>
public static SessionOptions MakeSessionOptionWithRocmProvider()
{
return MakeSessionOptionWithRocmProvider(0);
}
/// <summary>
/// A helper method to construct a SessionOptions object for ROCM execution.
/// Use only if ROCM is installed and you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId"></param>
/// <param name="deviceId">Device Id</param>
/// <param name="gpuMemLimit">GPU memory limit. Defaults to no limit.</param>
/// <returns>A SessionsOptions() object configured for execution on deviceId</returns>
public static SessionOptions MakeSessionOptionWithRocmProvider(int deviceId = 0)
public static SessionOptions MakeSessionOptionWithRocmProvider(int deviceId = 0, UIntPtr gpuMemLimit = default)
{
SessionOptions options = new SessionOptions();
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_ROCM(options.Handle, deviceId));
NativeApiStatus.VerifySuccess(
NativeMethods.OrtSessionOptionsAppendExecutionProvider_ROCM(options.Handle, deviceId, gpuMemLimit));
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_CPU(options.Handle, 1));
return options;
}
@ -178,7 +160,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Appends CPU EP to a list of available execution providers for the session.
/// </summary>
/// <param name="useArena">1 - use arena, 0 - do not use arena</param>
public void AppendExecutionProvider_CPU(int useArena)
public void AppendExecutionProvider_CPU(int useArena = 1)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_CPU(handle, useArena));
}
@ -187,7 +169,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="useArena">1 - use allocation arena, 0 - otherwise</param>
public void AppendExecutionProvider_Dnnl(int useArena)
public void AppendExecutionProvider_Dnnl(int useArena = 1)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_Dnnl(handle, useArena));
}
@ -196,7 +178,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId">integer device ID</param>
public void AppendExecutionProvider_CUDA(int deviceId)
public void AppendExecutionProvider_CUDA(int deviceId = 0)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_CUDA(handle, deviceId));
}
@ -205,7 +187,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId">device identification</param>
public void AppendExecutionProvider_DML(int deviceId)
public void AppendExecutionProvider_DML(int deviceId = 0)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_DML(handle, deviceId));
}
@ -228,7 +210,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId">device identification</param>
public void AppendExecutionProvider_Tensorrt(int deviceId)
public void AppendExecutionProvider_Tensorrt(int deviceId = 0)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_Tensorrt(handle, deviceId));
}
@ -246,17 +228,19 @@ namespace Microsoft.ML.OnnxRuntime
/// <summary>
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId">integer device ID</param>
public void AppendExecutionProvider_ROCM(int deviceId)
/// <param name="deviceId">Device Id</param>
/// <param name="gpuMemLimit">GPU memory limit. Defaults to no limit.</param>
public void AppendExecutionProvider_ROCM(int deviceId = 0, UIntPtr gpuMemLimit = default)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_ROCM(handle, deviceId));
NativeApiStatus.VerifySuccess(
NativeMethods.OrtSessionOptionsAppendExecutionProvider_ROCM(handle, deviceId, gpuMemLimit));
}
/// <summary>
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="deviceId">device identification</param>
public void AppendExecutionProvider_MIGraphX(int deviceId)
public void AppendExecutionProvider_MIGraphX(int deviceId = 0)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_MIGraphX(handle, deviceId));
}
@ -265,7 +249,7 @@ namespace Microsoft.ML.OnnxRuntime
/// Use only if you have the onnxruntime package specific to this Execution Provider.
/// </summary>
/// <param name="nnapi_flags">nnapi specific flag mask</param>
public void AppendExecutionProvider_Nnapi(uint nnapi_flags)
public void AppendExecutionProvider_Nnapi(uint nnapi_flags = 0)
{
NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_Nnapi(handle, nnapi_flags));
}
@ -707,8 +691,6 @@ namespace Microsoft.ML.OnnxRuntime
}
return true;
}
#endregion
#region SafeHandle
/// <summary>

View file

@ -30,6 +30,9 @@ namespace Microsoft.ML.OnnxRuntime.Tests
[Fact]
public void TestSessionOptions()
{
// get instance to setup logging
var ortEnvInstance = OrtEnv.Instance();
using (SessionOptions opt = new SessionOptions())
{
Assert.NotNull(opt);
@ -90,15 +93,20 @@ namespace Microsoft.ML.OnnxRuntime.Tests
Assert.Contains("[ErrorCode:InvalidArgument] Config key is empty", ex.Message);
opt.AppendExecutionProvider_CPU(1);
#if USE_DNNL
opt.AppendExecutionProvider_Dnnl(0);
#endif
#if USE_CUDA
opt.AppendExecutionProvider_CUDA(0);
#else
try
{
opt.AppendExecutionProvider_CUDA(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("Failed to load shared library", ortEx.Message);
}
#endif
#if USE_ROCM
opt.AppendExecutionProvider_ROCM(0);
#endif
#if USE_DML
// Explicitly set dll probe path so that the (potentially) stale system DirectML.dll
// doesn't get loaded by the test process when it is eventually delay loaded by onnruntime.dll
@ -110,22 +118,113 @@ namespace Microsoft.ML.OnnxRuntime.Tests
// Restore the default dll search order
SetDllDirectory(null);
#else
try
{
opt.AppendExecutionProvider_DML(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("is not enabled in this build", ortEx.Message);
}
#endif
#if USE_DNNL
opt.AppendExecutionProvider_Dnnl(0);
#else
try
{
opt.AppendExecutionProvider_Dnnl(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("Failed to load shared library", ortEx.Message);
}
#endif
#if USE_OPENVINO
opt.AppendExecutionProvider_OpenVINO();
#endif
#if USE_TENSORRT
opt.AppendExecutionProvider_Tensorrt(0);
#endif
#if USE_MIGRAPHX
opt.AppendExecutionProvider_MIGraphX(0);
#else
try
{
opt.AppendExecutionProvider_MIGraphX(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("is not enabled in this build", ortEx.Message);
}
#endif
#if USE_NNAPI
opt.AppendExecutionProvider_Nnapi(0);
#else
try
{
opt.AppendExecutionProvider_Nnapi(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("is not enabled in this build", ortEx.Message);
}
#endif
#if USE_NUPHAR
opt.AppendExecutionProvider_Nuphar();
#else
try
{
opt.AppendExecutionProvider_Nnapi();
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("is not enabled in this build", ortEx.Message);
}
#endif
#if USE_OPENVINO
opt.AppendExecutionProvider_OpenVINO();
#else
try
{
opt.AppendExecutionProvider_OpenVINO();
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("Failed to load shared library", ortEx.Message);
}
#endif
#if USE_ROCM
opt.AppendExecutionProvider_ROCM(0);
#else
try
{
var gpuMemLimit = new UIntPtr(10*1024);
opt.AppendExecutionProvider_ROCM(0, gpuMemLimit);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("is not enabled in this build", ortEx.Message);
}
#endif
#if USE_TENSORRT
opt.AppendExecutionProvider_Tensorrt(0);
#else
try
{
opt.AppendExecutionProvider_Dnnl(0);
}
catch (OnnxRuntimeException ortEx)
{
Assert.Contains("Failed to load shared library", ortEx.Message);
}
#endif
}
}

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<OnnxRuntimeCsharpRoot>..\..</OnnxRuntimeCsharpRoot>
<OnnxRuntimeCsharpRoot>$(ProjectDir)..\..</OnnxRuntimeCsharpRoot>
<Platforms>AnyCPU;x86</Platforms>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLinuxBuild Condition="'$(IsLinuxBuild)' == ''">false</IsLinuxBuild>
@ -72,30 +72,35 @@
<ProjectReference Include="$(OnnxRuntimeCsharpRoot)\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" />
</ItemGroup>
<Target Name="ProtoGen" BeforeTargets="Build">
<!-- generate OnnxMl.cs from ONNX protobuf definition -->
<Target Name="ProtoGen" BeforeTargets="BeforeBuild">
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx-ml.proto3" ContinueOnError="false"></Exec>
</Target>
<ItemGroup>
<!-- manually include if we're going to generate in this build. otherwise it's automatically included. -->
<Compile Include="$(ProjectDir)\OnnxMl.cs" Condition="!Exists('$(ProjectDir)\OnnxMl.cs')"/>
</ItemGroup>
<ItemGroup>
<None Include="$(NativeBuildOutputDir)\*.dll;$(NativeBuildOutputDir)\*.pdb;$(NativeBuildOutputDir)\libcustom*.so;$(NativeBuildOutputDir)\libcustom*.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(OnnxRuntimeCSharpRoot)\testdata\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\overridable_initializer.onnx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\capi_symbolic_dims.onnx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\custom_op_library\custom_op_test.onnx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<BuildEnvVars Include="OnnxRuntimeBuildDirectory=$(OnnxRuntimeBuildDirectory)" />

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<Platforms>AnyCPU;x86</Platforms>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OnnxRuntimeCsharpRoot>..\..</OnnxRuntimeCsharpRoot>
<OnnxRuntimeCsharpRoot>$(ProjectDir)..\..</OnnxRuntimeCsharpRoot>
<SignAssembly>false</SignAssembly>
<Configurations>Debug;Release;RelWithDebInfo</Configurations>
<IsLinuxBuild Condition="'$(IsLinuxBuild)' == ''">false</IsLinuxBuild>
@ -29,27 +29,35 @@
<ItemGroup>
<None Include="$(NativeBuildOutputDir)\libonnxruntime.so" Condition="'$(IsLinuxBuild)'=='true'">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\onnxruntime.dll" Condition="'$(IsLinuxBuild)'=='false'">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\onnxruntime.pdb" Condition="'$(IsLinuxBuild)'=='false'And Exists('$(NativeBuildOutputDir)\onnxruntime.pdb')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="$(NativeBuildOutputDir)\onnxruntime.pdb" Condition="'$(IsLinuxBuild)'=='false' And Exists('$(NativeBuildOutputDir)\onnxruntime.pdb')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\dnnl.dll" Condition="Exists('$(NativeBuildOutputDir)\dnnl.dll')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="$(NativeBuildOutputDir)\libonnxruntime_providers_*.so" Condition="'$(IsLinuxBuild)'=='true' And Exists('$(NativeBuildOutputDir)\libonnxruntime_providers_shared.so')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\libdnnl.so.1" Condition="Exists('$(NativeBuildOutputDir)\libdnnl.so.1')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="$(NativeBuildOutputDir)\onnxruntime_providers_*.dll" Condition="'$(IsLinuxBuild)'=='false' And Exists('$(NativeBuildOutputDir)\onnxruntime_providers_shared.dll')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\libdnnl.so.1" Condition="'$(IsLinuxBuild)'=='true' And Exists('$(NativeBuildOutputDir)\libdnnl.so.1')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(NativeBuildOutputDir)\dnnl.dll" Condition="'$(IsLinuxBuild)'=='false' And Exists('$(NativeBuildOutputDir)\dnnl.dll')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(OnnxRuntimeCSharpRoot)\testdata\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
@ -61,8 +69,13 @@
<PackageReference Include="Google.Protobuf" Version="3.13.0" />
</ItemGroup>
<Target Name="ProtoGen" BeforeTargets="Build">
<!-- create OnnxMl.cs and add to project -->
<Target Name="ProtoGen" BeforeTargets="BeforeBuild">
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx-ml.proto3" ContinueOnError="false"></Exec>
</Target>
<ItemGroup>
<!-- manually include if we're going to generate in this build. otherwise it's automatically included. -->
<Compile Include="$(ProjectDir)\OnnxMl.cs" Condition="!Exists('$(ProjectDir)\OnnxMl.cs')"/>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load diff

View file

@ -28,7 +28,9 @@ extern "C" {
* IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
* primary display GPU installed on the system. A negative device_id is invalid.
*/
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
// declared in include/onnxruntime/core/session/onnxruntime_c_api.h for convenience and so we can provide a graceful
// error message if not enabled.
// ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
/**
* Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12

View file

@ -6,7 +6,9 @@
extern "C" {
#endif
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
// declared in include/onnxruntime/core/session/onnxruntime_c_api.h for convenience and so we can provide a graceful
// error message if not enabled.
// ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
#ifdef __cplusplus
}

View file

@ -44,8 +44,10 @@ enum NNAPIFlags {
extern "C" {
#endif
ORT_EXPORT ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nnapi,
_In_ OrtSessionOptions* options, uint32_t nnapi_flags);
// declared in include/onnxruntime/core/session/onnxruntime_c_api.h for convenience and so we can provide a graceful
// error message if not enabled.
// ORT_EXPORT ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nnapi,
// _In_ OrtSessionOptions* options, uint32_t nnapi_flags);
#ifdef __cplusplus
}

View file

@ -10,7 +10,10 @@ extern "C" {
* \param device_id nuphar device id, starts from zero.
* \param settings_str Nuphar settings string.
*/
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nuphar, _In_ OrtSessionOptions* options, int allow_unaligned_buffers, _In_ const char* settings_str);
// declared in include/onnxruntime/core/session/onnxruntime_c_api.h for convenience and so we can provide a graceful
// error message if not enabled.
// ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nuphar, _In_ OrtSessionOptions* options,
// int allow_unaligned_buffers, _In_ const char* settings_str);
#ifdef __cplusplus
}

View file

@ -10,7 +10,9 @@ extern "C" {
/**
* \param device_id hip device id, starts from zero.
*/
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id, size_t gpu_mem_limit);
// declared in include/onnxruntime/core/session/onnxruntime_c_api.h for convenience and so we can provide a graceful
// error message if not enabled.
//ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id, size_t gpu_mem_limit);
#ifdef __cplusplus
}

View file

@ -1798,6 +1798,23 @@ struct OrtCustomOp {
*/
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);
// EPs that provider_bridge_ort.cc handles. Function implementation is there.
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Dnnl, _In_ OrtSessionOptions* options, int use_arena);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_OpenVINO, _In_ OrtSessionOptions* options,
_In_ const char* device_type);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Tensorrt, _In_ OrtSessionOptions* options, int device_id);
// EPs conditionally included in the build that are exposed in the C# bindings.
// Function implementation is in the EP code if enabled, or in onnxruntime/core/session/provider_stubs.cc if not.
// If not enabled the function will return an error message saying so.
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_ROCM,
_In_ OrtSessionOptions* options, int device_id, size_t gpu_mem_limit);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nnapi, _In_ OrtSessionOptions* options, uint32_t nnapi_flags);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Nuphar,
_In_ OrtSessionOptions* options, int allow_unaligned_buffers, _In_ const char* settings);
#ifdef __cplusplus
}
#endif

View file

@ -38,10 +38,11 @@ std::shared_ptr<IExecutionProviderFactory> CreateExecutionProviderFactory_ROCM(c
} // namespace onnxruntime
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options, int device_id) {
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_ROCM, _In_ OrtSessionOptions* options,
int device_id, size_t gpu_mem_limit) {
ROCMExecutionProviderInfo info{};
info.device_id = gsl::narrow<OrtDevice::DeviceId>(device_id);
info.gpu_mem_limit = gpu_mem_limit;
options->provider_factories.push_back(onnxruntime::CreateExecutionProviderFactory_ROCM(info));
return nullptr;
@ -59,4 +60,3 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_ROCM,
return nullptr;
}

View file

@ -1934,42 +1934,6 @@ ORT_API_STATUS_IMPL(OrtApis::SessionGetProfilingStartTimeNs, _In_ const OrtSessi
// End support for non-tensor types
#ifndef USE_ROCM
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_ROCM,
_In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(rocm_options);
return CreateStatus(ORT_FAIL, "ROCM execution provider is not enabled.");
}
#endif
#if defined(ORT_MINIMAL_BUILD)
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_OpenVINO,
_In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(provider_options);
return CreateStatus(ORT_FAIL, "OpenVINO execution provider is not enabled.");
}
#endif
#if defined(ORT_MINIMAL_BUILD)
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* provider_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(provider_options);
return CreateStatus(ORT_FAIL, "CUDA execution provider is not enabled.");
}
ORT_API_STATUS_IMPL(OrtApis::GetCurrentGpuDeviceId, _In_ int* device_id) {
ORT_UNUSED_PARAMETER(device_id);
return CreateStatus(ORT_FAIL, "CUDA execution provider is not enabled.");
}
ORT_API_STATUS_IMPL(OrtApis::SetCurrentGpuDeviceId, _In_ int device_id) {
ORT_UNUSED_PARAMETER(device_id);
return CreateStatus(ORT_FAIL, "CUDA execution provider is not enabled.");
}
#endif
ORT_API_STATUS_IMPL(OrtApis::CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes,
int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out) {
API_IMPL_BEGIN
@ -2077,51 +2041,6 @@ ORT_API_STATUS_IMPL(OrtApis::CreateSessionFromArrayWithPrepackedWeightsContainer
API_IMPL_END
}
#if defined(ORT_MINIMAL_BUILD)
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_TensorRT,
_In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(tensorrt_options);
return CreateStatus(ORT_FAIL, "TensorRT execution provider is not enabled.");
}
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_TensorRT_V2,
_In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(tensorrt_options);
return CreateStatus(ORT_FAIL, "TensorRT execution provider is not enabled.");
}
ORT_API_STATUS_IMPL(OrtApis::CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out) {
ORT_UNUSED_PARAMETER(out);
return CreateStatus(ORT_FAIL, "TensorRT execution provider is not enabled in this build.");
}
ORT_API_STATUS_IMPL(OrtApis::UpdateTensorRTProviderOptions,
_Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options,
_In_reads_(num_keys) const char* const* provider_options_keys,
_In_reads_(num_keys) const char* const* provider_options_values,
size_t num_keys) {
ORT_UNUSED_PARAMETER(tensorrt_options);
ORT_UNUSED_PARAMETER(provider_options_keys);
ORT_UNUSED_PARAMETER(provider_options_values);
ORT_UNUSED_PARAMETER(num_keys);
return CreateStatus(ORT_FAIL, "TensorRT execution provider is not enabled in this build.");
}
ORT_API_STATUS_IMPL(OrtApis::GetTensorRTProviderOptionsAsString, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _Inout_ OrtAllocator* allocator,
_Outptr_ char** ptr) {
ORT_UNUSED_PARAMETER(tensorrt_options);
ORT_UNUSED_PARAMETER(allocator);
ORT_UNUSED_PARAMETER(ptr);
return CreateStatus(ORT_FAIL, "TensorRT execution provider is not enabled in this build.");
}
ORT_API(void, OrtApis::ReleaseTensorRTProviderOptions, _Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* ptr) {
ORT_UNUSED_PARAMETER(ptr);
}
#endif
static constexpr OrtApiBase ort_api_base = {
&OrtApis::GetApi,
&OrtApis::GetVersionString,
@ -2148,22 +2067,22 @@ but isn't visible in public headers.
So for example, if we wanted to just add some new members to the ort_api_1_to_2, we'd take the following steps:
In include\onnxruntime\core\session\onnxruntime_c_api.h we'd just add the members to the end of the structure
In include\onnxruntime\core\session\onnxruntime_c_api.h we'd just add the members to the end of the structure
In this file, we'd correspondingly add the member values to the end of the ort_api_1_to_2 structure, and also rename
it to ort_api_1_to_3.
In this file, we'd correspondingly add the member values to the end of the ort_api_1_to_2 structure, and also rename
it to ort_api_1_to_3.
Then in GetApi we'd make it return ort_api_1_to_3 for versions 1 through 3.
Then in GetApi we'd make it return ort_api_1_to_3 for versions 1 through 3.
Second example, if we wanted to add and remove some members, we'd do this:
In include\onnxruntime\core\session\onnxruntime_c_api.h we'd make a copy of the OrtApi structure and name the
old one OrtApi1to2. In the new OrtApi we'd add or remove any members that we desire.
In include\onnxruntime\core\session\onnxruntime_c_api.h we'd make a copy of the OrtApi structure and name the
old one OrtApi1to2. In the new OrtApi we'd add or remove any members that we desire.
In this file, we'd create a new copy of ort_api_1_to_2 called ort_api_3 and make the corresponding changes that were
made to the new OrtApi.
In this file, we'd create a new copy of ort_api_1_to_2 called ort_api_3 and make the corresponding changes that were
made to the new OrtApi.
In GetApi we now make it return ort_api_3 for version 3.
In GetApi we now make it return ort_api_3 for version 3.
*/
static constexpr OrtApi ort_api_1_to_9 = {

View file

@ -213,13 +213,12 @@ struct ProviderHostImpl : ProviderHost {
const AllocatorPtr& dst_allocator, Tensor& dst) override {
return sparse_utils::SparseCooToDenseTensor(data_manager, src, cpu_allocator, dst_allocator, dst);
}
#endif // ORT_MINIMAL_BUILD
#endif // ORT_MINIMAL_BUILD
Status sparse_utils__DenseTensorToSparseCoo(const DataTransferManager& data_manager, const Tensor& src, const AllocatorPtr& cpu_allocator,
const AllocatorPtr& dst_allocator, bool linear_indexs, SparseTensor& dst) override {
return sparse_utils::DenseTensorToSparseCoo(data_manager, src, cpu_allocator, dst_allocator, linear_indexs, dst);
}
// IAllocator (direct)
bool IAllocator__CalcMemSizeForArrayWithAlignment(size_t nmemb, size_t size, size_t alignment, size_t* out) override { return IAllocator::CalcMemSizeForArrayWithAlignment(nmemb, size, alignment, out); }
@ -1117,7 +1116,8 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_OpenVINO, _In
API_IMPL_END
}
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_OpenVINO, _In_ OrtSessionOptions* options, _In_ const char* device_type) {
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_OpenVINO, _In_ OrtSessionOptions* options,
_In_ const char* device_type) {
OrtOpenVINOProviderOptions provider_options{};
provider_options.device_type = device_type;
return OrtApis::SessionOptionsAppendExecutionProvider_OpenVINO(options, &provider_options);

View file

@ -0,0 +1,170 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include <string>
#include "core/common/common.h"
#include "core/session/onnxruntime_c_api.h"
#include "core/session/ort_apis.h"
static OrtStatus* CreateNotEnabledStatus(const std::string& ep) {
return OrtApis::CreateStatus(ORT_FAIL, (ep + " execution provider is not enabled in this build. ").c_str());
}
#ifdef __cplusplus
extern "C" {
#endif
#ifndef USE_DML
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(device_id);
return CreateNotEnabledStatus("DML");
}
#endif
#ifndef USE_MIGRAPHX
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_MIGraphX,
_In_ OrtSessionOptions* options, int device_id) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(device_id);
return CreateNotEnabledStatus("MIGraphX");
}
#endif
#ifndef USE_ROCM
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_ROCM,
_In_ OrtSessionOptions* options, int device_id, size_t gpu_mem_limit) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(device_id);
ORT_UNUSED_PARAMETER(gpu_mem_limit);
return CreateNotEnabledStatus("ROCM");
}
#endif
#ifndef USE_NNAPI
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_Nnapi,
_In_ OrtSessionOptions* options, uint32_t nnapi_flags) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(nnapi_flags);
return CreateNotEnabledStatus("NNAPI");
}
#endif
#ifndef USE_NUPHAR
ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_Nuphar,
_In_ OrtSessionOptions* options, int allow_unaligned_buffers, _In_ const char* settings) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(allow_unaligned_buffers);
ORT_UNUSED_PARAMETER(settings);
return CreateNotEnabledStatus("Nuphar");
}
#endif
/* see provider_bridge_ort.cc for these:
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Dnnl, _In_ OrtSessionOptions* options, int use_arena);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_OpenVINO, _In_ OrtSessionOptions* options,
_In_ const char* device_type);
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_Tensorrt, _In_ OrtSessionOptions* options, int device_id);
*/
#ifdef __cplusplus
}
#endif
/*
OrtApis::SessionOptionsAppendExecutionProvider_<EP> stubs for EPs not included in this build.
2 cases:
1) EP is included in ORT via build settings. Need to include stub if EP not enabled.
2) EP is built as separate library and uses the provider bridge. Need to include in a minimal build
as the provider bridge is excluded in that case.
TODO: When the NNAPI or CoreML EPs are setup to use the provider bridge the source code for that will be included
in a minimal build and these stubs should move to provider_bridge_ort.cc.
*/
// EPs in the first case
#ifndef USE_ROCM
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_ROCM,
_In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(rocm_options);
return CreateNotEnabledStatus("ROCM");
}
#endif
// EPs in the second case
#if defined(ORT_MINIMAL_BUILD)
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_CUDA,
_In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* provider_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(provider_options);
return CreateNotEnabledStatus("CUDA");
}
ORT_API_STATUS_IMPL(OrtApis::GetCurrentGpuDeviceId, _In_ int* device_id) {
ORT_UNUSED_PARAMETER(device_id);
return CreateNotEnabledStatus("CUDA");
}
ORT_API_STATUS_IMPL(OrtApis::SetCurrentGpuDeviceId, _In_ int device_id) {
ORT_UNUSED_PARAMETER(device_id);
return CreateNotEnabledStatus("CUDA");
}
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_OpenVINO,
_In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(provider_options);
return CreateNotEnabledStatus("OpenVINO");
}
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_TensorRT,
_In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(tensorrt_options);
return CreateNotEnabledStatus("TensorRT");
}
ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider_TensorRT_V2,
_In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options) {
ORT_UNUSED_PARAMETER(options);
ORT_UNUSED_PARAMETER(tensorrt_options);
return CreateNotEnabledStatus("TensorRT");
}
ORT_API_STATUS_IMPL(OrtApis::CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out) {
ORT_UNUSED_PARAMETER(out);
return CreateNotEnabledStatus("TensorRT");
}
ORT_API_STATUS_IMPL(OrtApis::UpdateTensorRTProviderOptions,
_Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options,
_In_reads_(num_keys) const char* const* provider_options_keys,
_In_reads_(num_keys) const char* const* provider_options_values,
size_t num_keys) {
ORT_UNUSED_PARAMETER(tensorrt_options);
ORT_UNUSED_PARAMETER(provider_options_keys);
ORT_UNUSED_PARAMETER(provider_options_values);
ORT_UNUSED_PARAMETER(num_keys);
return CreateNotEnabledStatus("TensorRT");
}
ORT_API_STATUS_IMPL(OrtApis::GetTensorRTProviderOptionsAsString,
_In_ const OrtTensorRTProviderOptionsV2* tensorrt_options,
_Inout_ OrtAllocator* allocator,
_Outptr_ char** ptr) {
ORT_UNUSED_PARAMETER(tensorrt_options);
ORT_UNUSED_PARAMETER(allocator);
ORT_UNUSED_PARAMETER(ptr);
return CreateNotEnabledStatus("TensorRT");
}
ORT_API(void, OrtApis::ReleaseTensorRTProviderOptions, _Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* ptr) {
ORT_UNUSED_PARAMETER(ptr);
}
#endif

View file

@ -0,0 +1,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
# we provide stubs for these functions for EPs that are enabled via C# so that we can return a graceful error message
# if they are not enabled in the onnxruntime library being used. the C# bindings don't know what will be available
# until runtime so must include the ability to call these functions in all builds.
OrtSessionOptionsAppendExecutionProvider_CUDA
OrtSessionOptionsAppendExecutionProvider_DML
OrtSessionOptionsAppendExecutionProvider_Dnnl
OrtSessionOptionsAppendExecutionProvider_MIGraphX
OrtSessionOptionsAppendExecutionProvider_Nnapi
OrtSessionOptionsAppendExecutionProvider_Nuphar
OrtSessionOptionsAppendExecutionProvider_OpenVINO
OrtSessionOptionsAppendExecutionProvider_ROCM
OrtSessionOptionsAppendExecutionProvider_Tensorrt

View file

@ -14,6 +14,21 @@ def parse_arguments():
return parser.parse_args()
def read_symbols(filename: str, allow_dups: bool = False):
with open(filename, 'r') as file:
for line in file:
line = line.strip()
if len(line) == 0 or line.startswith('#'):
continue
if line in symbols:
if not allow_dups:
print("dup symbol: %s", line)
exit(-1)
else:
symbols.add(line)
args = parse_arguments()
print("Generating symbol file for %s" % str(args.config))
with open(args.version_file, 'r') as f:
@ -25,12 +40,13 @@ symbols = set()
for c in args.config:
file_name = os.path.join(args.src_root, 'core', 'providers', c, 'symbols.txt')
with open(file_name, 'r') as file:
for line in file:
line = line.strip()
if line in symbols:
print("dup symbol: %s", line)
exit(-1)
symbols.add(line)
read_symbols(file_name)
# add stubs from session to provide graceful error message if EP isn't included in the build.
# this will have dups for EPs that are enabled in the build which is fine as we #ifdef out the stubs
# in the ORT C API implementation if that is the case
read_symbols(os.path.join(args.src_root, 'core', 'session', 'symbols.txt'), allow_dups=True)
symbols = sorted(symbols)
symbol_index = 1
@ -59,13 +75,13 @@ with open(args.output, 'w') as file:
file.write("}; \n")
with open(args.output_source, 'w') as file:
file.write("#include <onnxruntime_c_api.h>\n")
file.write('#include "core/session/onnxruntime_c_api.h"\n')
for c in args.config:
# WinML adapter should not be exported in platforms other than Windows.
# Exporting OrtGetWinMLAdapter is exported without issues using .def file when compiling for Windows
# so it isn't necessary to include it in generated_source.c
if c != "winml" and c != "cuda":
file.write("#include <core/providers/%s/%s_provider_factory.h>\n" % (c, c))
file.write('#include "core/providers/%s/%s_provider_factory.h"\n' % (c, c))
file.write("void* GetFunctionEntryByName(const char* name){\n")
for symbol in symbols:
if symbol != "OrtGetWinMLAdapter":