aisop/src/SopHelper.Engine/Inference/CudaRuntime.cs

17 lines
654 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Runtime.InteropServices;
namespace SopHelper.Engine.Inference;
internal static class CudaRuntime
{
// ORT 的 provider 位于 runtimes/win-x64/native,而随应用提供的 cuDNN 位于输出根目录。
// 显式加载其绝对路径,避免依赖当前工作目录或系统 PATH,句柄保留到进程结束。
private static readonly Lazy<nint> BundledCudnn = new(() =>
{
var path = Path.Combine(AppContext.BaseDirectory, "cudnn64_9.dll");
return OperatingSystem.IsWindows() && File.Exists(path) ? NativeLibrary.Load(path) : 0;
});
internal static void Prepare() => _ = BundledCudnn.Value;
}