[C#] Address the concern of append EP throw (#15973)

This commit is contained in:
cloudhan 2023-05-18 11:53:54 +08:00 committed by GitHub
parent 6d46007028
commit 5a8b892bdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,8 +66,16 @@ namespace Microsoft.ML.OnnxRuntime
{
CheckCudaExecutionProviderDLLs();
SessionOptions options = new SessionOptions();
options.AppendExecutionProvider_CUDA(deviceId);
return options;
try
{
options.AppendExecutionProvider_CUDA(deviceId);
return options;
}
catch (Exception)
{
options.Dispose();
throw;
}
}
/// <summary>
@ -148,9 +156,16 @@ namespace Microsoft.ML.OnnxRuntime
public static SessionOptions MakeSessionOptionWithTvmProvider(String settings = "")
{
SessionOptions options = new SessionOptions();
options.AppendExecutionProvider_Tvm(settings);
return options;
try
{
options.AppendExecutionProvider_Tvm(settings);
return options;
}
catch (Exception)
{
options.Dispose();
throw;
}
}
/// <summary>