mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
Throw friendly error message when Linux distribution has libc version < 2.23 (#493)
* Add check for linux version supporting glibc 2.23 or higher * Refactor the libc check to SessionOptions * removed whitespace * Update SessionOptions.cs
This commit is contained in:
parent
62bbe8de40
commit
9d14cbdb1a
1 changed files with 28 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ namespace Microsoft.ML.OnnxRuntime
|
|||
|
||||
private static SessionOptions MakeSessionOptionWithCpuProvider()
|
||||
{
|
||||
CheckLibcVersionGreaterThanMinimum();
|
||||
SessionOptions options = new SessionOptions();
|
||||
NativeMethods.OrtSessionOptionsAppendExecutionProvider_CPU(options._nativePtr, 1);
|
||||
return options;
|
||||
|
|
@ -69,6 +70,7 @@ namespace Microsoft.ML.OnnxRuntime
|
|||
/// <returns>A SessionsOptions() object configured for execution on deviceId</returns>
|
||||
public static SessionOptions MakeSessionOptionWithCudaProvider(int deviceId=0)
|
||||
{
|
||||
CheckLibcVersionGreaterThanMinimum();
|
||||
CheckCudaExecutionProviderDLLs();
|
||||
SessionOptions options = new SessionOptions();
|
||||
NativeMethods.OrtSessionOptionsAppendExecutionProvider_CUDA(options._nativePtr, deviceId);
|
||||
|
|
@ -103,6 +105,32 @@ namespace Microsoft.ML.OnnxRuntime
|
|||
return true;
|
||||
}
|
||||
|
||||
[DllImport("libc", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr gnu_get_libc_version();
|
||||
|
||||
private static void CheckLibcVersionGreaterThanMinimum()
|
||||
{
|
||||
// require libc version 2.23 or higher
|
||||
var minVersion = new Version(2, 23);
|
||||
var curVersion = new Version(0, 0);
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
try
|
||||
{
|
||||
curVersion = Version.Parse(Marshal.PtrToStringAnsi(gnu_get_libc_version()));
|
||||
if (curVersion >= minVersion)
|
||||
return;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// trap any obscure exception
|
||||
}
|
||||
throw new OnnxRuntimeException(ErrorCode.RuntimeException,
|
||||
$"libc.so version={curVersion} does not meet the minimun of 2.23 required by OnnxRuntime. " +
|
||||
"Linux distribution should be similar to Ubuntu 16.04 or higher");
|
||||
}
|
||||
}
|
||||
|
||||
#region destructors disposers
|
||||
|
||||
~SessionOptions()
|
||||
|
|
|
|||
Loading…
Reference in a new issue