refactor: move GpuEvaluatorFactory to OpenNest.Gpu project
GPU factory logic belongs with the GPU implementation, not the UI. Changed from internal to public and updated namespace to OpenNest.Gpu. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Controls;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Gpu;
|
||||
|
||||
namespace OpenNest.Actions
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Controls;
|
||||
using OpenNest.Gpu;
|
||||
|
||||
namespace OpenNest.Actions
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Actions;
|
||||
using OpenNest.Collections;
|
||||
using OpenNest.Gpu;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.IO;
|
||||
using OpenNest.Properties;
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ILGPU;
|
||||
using ILGPU.Runtime;
|
||||
using OpenNest.Engine.BestFit;
|
||||
using OpenNest.Gpu;
|
||||
|
||||
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 (Exception ex)
|
||||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user