Files
even-perfect-numbers-scanner/PerfectNumbers.Core/Gpu/SharedGpuContext.cs
T
Marek Lemańczyk 4c4d4243fb Merge remote-tracking branch 'github/codex/optimize-evenperfectbitscanner-for-static-arrays-khd9w8' into work
# Conflicts:
#	PerfectNumbers.Core/Gpu/GpuContextPool.cs
#	PerfectNumbers.Core/Gpu/GpuKernelLease.cs
#	PerfectNumbers.Core/Gpu/GpuKernelPool.cs
#	PerfectNumbers.Core/Gpu/GpuStaticTableInitializer.cs
#	PerfectNumbers.Core/Gpu/Kernels/PrimeOrderSpecialMaxKernels.cs
#	PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs
#	PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs
#	PerfectNumbers.Core/PrimeTester.cs
2025-11-03 23:59:12 +01:00

20 lines
796 B
C#

using System;
using System.Threading;
using ILGPU;
using ILGPU.Runtime;
namespace PerfectNumbers.Core.Gpu;
internal static class SharedGpuContext
{
private static readonly Lazy<Context> s_context = new(() => ILGPU.Context.CreateDefault(), LazyThreadSafetyMode.ExecutionAndPublication);
private static readonly Lazy<Device> s_device = new(() => s_context.Value.GetPreferredDevice(false), LazyThreadSafetyMode.ExecutionAndPublication);
private static readonly Lazy<Accelerator> s_accelerator = new(() => s_device.Value.CreateAccelerator(s_context.Value), LazyThreadSafetyMode.ExecutionAndPublication);
internal static Context Context => s_context.Value;
internal static Device Device => s_device.Value;
internal static Accelerator Accelerator => s_accelerator.Value;
}