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:
jignparm 2019-02-21 11:34:44 -08:00 committed by GitHub
parent 62bbe8de40
commit 9d14cbdb1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()