feat: add GPU status indicator and device probe

- GpuEvaluatorFactory probes for CUDA/OpenCL devices at startup
- Status bar shows "GPU : <device name>" (green) or "GPU : None (CPU)" (gray)
- Factory skips GPU evaluator creation entirely when no device found
- Logs actual exception message on failure for debugging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 18:33:10 -05:00
parent 5bebfcb612
commit 7ed4572f8a
3 changed files with 95 additions and 5 deletions

View File

@@ -59,6 +59,7 @@
this.mnuViewZoomIn = new System.Windows.Forms.ToolStripMenuItem();
this.mnuViewZoomOut = new System.Windows.Forms.ToolStripMenuItem();
this.mnuTools = new System.Windows.Forms.ToolStripMenuItem();
this.mnuToolsBestFitViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuToolsMeasureArea = new System.Windows.Forms.ToolStripMenuItem();
this.mnuToolsAlign = new System.Windows.Forms.ToolStripMenuItem();
this.mnuToolsAlignLeft = new System.Windows.Forms.ToolStripMenuItem();
@@ -129,6 +130,7 @@
this.plateIndexStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.plateSizeStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.plateQtyStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.gpuStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.btnNew = new System.Windows.Forms.ToolStripButton();
this.btnOpen = new System.Windows.Forms.ToolStripButton();
@@ -412,6 +414,7 @@
//
this.mnuTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuToolsMeasureArea,
this.mnuToolsBestFitViewer,
this.mnuToolsAlign,
this.toolStripMenuItem14,
this.mnuSetOffsetIncrement,
@@ -428,7 +431,14 @@
this.mnuToolsMeasureArea.Size = new System.Drawing.Size(214, 22);
this.mnuToolsMeasureArea.Text = "Measure Area";
this.mnuToolsMeasureArea.Click += new System.EventHandler(this.MeasureArea_Click);
//
//
// mnuToolsBestFitViewer
//
this.mnuToolsBestFitViewer.Name = "mnuToolsBestFitViewer";
this.mnuToolsBestFitViewer.Size = new System.Drawing.Size(214, 22);
this.mnuToolsBestFitViewer.Text = "Best-Fit Viewer";
this.mnuToolsBestFitViewer.Click += new System.EventHandler(this.BestFitViewer_Click);
//
// mnuToolsAlign
//
this.mnuToolsAlign.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -909,7 +919,8 @@
this.spacerLabel,
this.plateIndexStatusLabel,
this.plateSizeStatusLabel,
this.plateQtyStatusLabel});
this.plateQtyStatusLabel,
this.gpuStatusLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 543);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1098, 24);
@@ -961,7 +972,14 @@
this.plateQtyStatusLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.plateQtyStatusLabel.Size = new System.Drawing.Size(55, 19);
this.plateQtyStatusLabel.Text = "Qty : 0";
//
//
// gpuStatusLabel
//
this.gpuStatusLabel.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Left;
this.gpuStatusLabel.Name = "gpuStatusLabel";
this.gpuStatusLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.gpuStatusLabel.Size = new System.Drawing.Size(55, 19);
//
// toolStrip1
//
this.toolStrip1.AutoSize = false;
@@ -1287,7 +1305,9 @@
private System.Windows.Forms.ToolStripMenuItem manualSequenceToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem autoSequenceAllPlatesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem mnuToolsMeasureArea;
private System.Windows.Forms.ToolStripMenuItem mnuToolsBestFitViewer;
private System.Windows.Forms.ToolStripButton btnSaveAs;
private System.Windows.Forms.ToolStripMenuItem centerPartsToolStripMenuItem;
private System.Windows.Forms.ToolStripStatusLabel gpuStatusLabel;
}
}

View File

@@ -39,6 +39,7 @@ namespace OpenNest.Forms
LoadPosts();
EnableCheck();
UpdateStatus();
UpdateGpuStatus();
}
private string GetNestName(DateTime date, int id)
@@ -191,6 +192,20 @@ namespace OpenNest.Forms
UpdatePlateStatus();
}
private void UpdateGpuStatus()
{
if (GpuEvaluatorFactory.GpuAvailable)
{
gpuStatusLabel.Text = $"GPU : {GpuEvaluatorFactory.DeviceName}";
gpuStatusLabel.ForeColor = Color.DarkGreen;
}
else
{
gpuStatusLabel.Text = "GPU : None (CPU)";
gpuStatusLabel.ForeColor = Color.Gray;
}
}
private void UpdateLocationMode()
{
if (activeForm == null)

View File

@@ -1,4 +1,7 @@
using System;
using System.Diagnostics;
using ILGPU;
using ILGPU.Runtime;
using OpenNest.Engine.BestFit;
using OpenNest.Gpu;
@@ -6,17 +9,69 @@ namespace OpenNest
{
internal static class GpuEvaluatorFactory
{
private static bool _probed;
private static bool _gpuAvailable;
private static string _deviceName;
public static bool GpuAvailable
{
get
{
if (!_probed) Probe();
return _gpuAvailable;
}
}
public static string DeviceName
{
get
{
if (!_probed) Probe();
return _deviceName ?? "None";
}
}
public static IPairEvaluator Create(Drawing drawing, double spacing)
{
if (!GpuAvailable)
return null;
try
{
return new GpuPairEvaluator(drawing, spacing);
}
catch
catch (Exception ex)
{
Debug.WriteLine("[GpuEvaluatorFactory] GPU not available, falling back to CPU");
Debug.WriteLine($"[GpuEvaluatorFactory] GPU evaluator failed: {ex.Message}");
return null;
}
}
private static void Probe()
{
_probed = true;
try
{
using var context = Context.CreateDefault();
foreach (var device in context.Devices)
{
if (device.AcceleratorType == AcceleratorType.Cuda ||
device.AcceleratorType == AcceleratorType.OpenCL)
{
_gpuAvailable = true;
_deviceName = device.Name;
Debug.WriteLine($"[GpuEvaluatorFactory] GPU found: {device.Name} ({device.AcceleratorType})");
return;
}
}
Debug.WriteLine("[GpuEvaluatorFactory] No GPU device found");
}
catch (Exception ex)
{
Debug.WriteLine($"[GpuEvaluatorFactory] GPU probe failed: {ex.Message}");
}
}
}
}