Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Baballonia.Desktop/Baballonia.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

<!-- Windows-specific -->
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260302" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu.Windows" Version="1.24.3" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="3.119.2" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="DirectShowLib" Version="1.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />

Expand All @@ -48,7 +49,7 @@

<PackageReference Include="Project-Babble.OpenCvSharp4.mini.runtime.ubuntu.22.04-arm64" Version="4.11.0.1" Condition="$([MSBuild]::IsOSPlatform('Linux')) And
$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().Contains('Arm'))" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.22.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu.Linux" Version="1.22.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="Xaml.Behaviors.Interactions.Draggable" Version="11.3.9.5" />
<ProjectReference Include="..\Baballonia.LibV4L2Capture\Baballonia.LibV4L2Capture.csproj" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
Expand Down
33 changes: 20 additions & 13 deletions src/Baballonia/Services/DefaultInferenceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,38 @@ private void ConfigurePlatformSpecificGpu(SessionOptions sessionOptions, string

// If the user's system does not support DirectML (for whatever reason,
// it's shipped with Windows 10, version 1903(10.0; Build 18362)+
// Fallback on good ol' CUDA
// Fallback on CUDA (also, if you're on Linux)
OrtCUDAProviderOptions cudaProviderOptions = null!;
try
{
sessionOptions.AppendExecutionProvider_CUDA();
cudaProviderOptions = new OrtCUDAProviderOptions();
var providerOptionsDict = new Dictionary<string, string>
{
["device_id"] = "0",
["gpu_mem_limit"] = "2147483648",
// Overkill options
// ["arena_extend_strategy"] = "kSameAsRequested",
// ["cudnn_conv_algo_search"] = "DEFAULT",
// ["do_copy_in_default_stream"] = "1",
// ["cudnn_conv_use_max_workspace"] = "1",
// ["cudnn_conv1d_pad_to_nc1d"] = "1"
};
cudaProviderOptions.UpdateOptions(providerOptionsDict);
sessionOptions = SessionOptions.MakeSessionOptionWithCudaProvider(cudaProviderOptions);
_logger.LogInformation("Initialized ExecutionProvider: CUDA for {ModelName}", modelName);
return;
}
catch (Exception)
{
_logger.LogWarning("Failed to create CUDA Execution Provider.");
}

// And, if CUDA fails (or we have an AMD card)
// Try one more time with MiGraphX/ROCm
try
finally
{
sessionOptions.AppendExecutionProvider_ROCm();
_logger.LogInformation("Initialized ExecutionProvider: ROCm for {ModelName}", modelName);
return;
}
catch (Exception)
{
_logger.LogWarning("Failed to create ROCm Execution Provider.");
cudaProviderOptions.Dispose();
}

// And, if CUDA fails (or we have an AMD card)
// Try one more time with MiGraphX
try
{
sessionOptions.AppendExecutionProvider_MIGraphX();
Expand Down
Loading