From 9ce5b29bff2bb3ad6c3605a053a99d1d7648a61a Mon Sep 17 00:00:00 2001 From: Yaohui Liu Date: Tue, 16 May 2023 02:41:19 +0800 Subject: [PATCH] feat: add check for redist backend. --- src/TensorFlowNET.Core/APIs/c_api.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index 10f678e0..587470e3 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -45,6 +45,21 @@ namespace Tensorflow { public const string TensorFlowLibName = "tensorflow"; + static c_api() + { + try + { + var handle = TF_Version(); + } + catch (DllNotFoundException) + { + throw new RuntimeError("Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: " + + "SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU. For more details, " + + "please visit https://github.com/SciSharp/TensorFlow.NET. If it still not work after installing the backend, please submit an " + + "issue to https://github.com/SciSharp/TensorFlow.NET/issues"); + } + } + public static string StringPiece(IntPtr handle) { return handle == IntPtr.Zero ? String.Empty : Marshal.PtrToStringAnsi(handle);