Replaces unsafe pointer-based job data with JobDataPool<T> and ConcurrentSlotMap<T> for safer, type-safe management. JobInfo now references job data by (dataID, dataGeneration). JobExecutor and JobScheduler updated to use the new pool-based approach, requiring T : struct. Removed FreeList and pointer logic. WorkerThread now uses reference counting to prevent use-after-free. Updated all scheduling APIs and benchmarks to match new signatures. Improved documentation and inlining. Bumped assembly version to 3.0.0 due to breaking changes.
100 lines
2.2 KiB
C#
100 lines
2.2 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
using Misaki.HighPerformance.Jobs;
|
|
using Misaki.HighPerformance.Mathematics.SPMD;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Misaki.HighPerformance.Test.Benchmark;
|
|
|
|
public unsafe class SPMDBenchmark
|
|
{
|
|
private const int _SIZE = 512;
|
|
|
|
private JobScheduler _scheduler = null!;
|
|
private float* _buf;
|
|
|
|
[GlobalSetup]
|
|
public void Setup()
|
|
{
|
|
_scheduler = new JobScheduler(Environment.ProcessorCount);
|
|
_buf = (float*)NativeMemory.Alloc(sizeof(float) * _SIZE * _SIZE);
|
|
}
|
|
|
|
[GlobalCleanup]
|
|
public void Cleanup()
|
|
{
|
|
_scheduler.Dispose();
|
|
NativeMemory.Free(_buf);
|
|
}
|
|
|
|
[Benchmark(Baseline = true)]
|
|
public void SPMDNoise()
|
|
{
|
|
var job = new Jobs.NoiseJobMathSPMD
|
|
{
|
|
buffers = _buf,
|
|
width = _SIZE,
|
|
height = _SIZE,
|
|
};
|
|
|
|
var handle = _scheduler.ScheduleParallelSPDM<Jobs.NoiseJobMathSPMD, float>(ref job, _SIZE * _SIZE, 64, -1);
|
|
_scheduler.Wait(handle);
|
|
}
|
|
|
|
[Benchmark]
|
|
public void JobNoise()
|
|
{
|
|
var job = new Jobs.NoiseJobVectorFor
|
|
{
|
|
buffers = _buf,
|
|
width = _SIZE,
|
|
height = _SIZE,
|
|
};
|
|
|
|
var handle = _scheduler.ScheduleParallelFor(ref job, _SIZE * _SIZE, 64, -1);
|
|
_scheduler.Wait(handle);
|
|
}
|
|
|
|
//[Benchmark]
|
|
public void MathJobNoise()
|
|
{
|
|
var job = new Jobs.NoiseJobMath
|
|
{
|
|
buffers = _buf,
|
|
width = _SIZE,
|
|
height = _SIZE,
|
|
};
|
|
|
|
var handle = _scheduler.ScheduleParallel(ref job, _SIZE * _SIZE, 64, -1);
|
|
_scheduler.Wait(handle);
|
|
}
|
|
|
|
//[Benchmark]
|
|
public void ParallelNoise()
|
|
{
|
|
var job = new Jobs.NoiseJobVectorFor
|
|
{
|
|
buffers = _buf,
|
|
width = _SIZE,
|
|
height = _SIZE,
|
|
};
|
|
|
|
Parallel.For(0, _SIZE * _SIZE, (i) =>
|
|
{
|
|
job.Execute(i, default);
|
|
});
|
|
}
|
|
|
|
[Benchmark]
|
|
public void SingleThreadNoise()
|
|
{
|
|
var job = new Jobs.NoiseJobVectorFor
|
|
{
|
|
buffers = _buf,
|
|
width = _SIZE,
|
|
height = _SIZE,
|
|
};
|
|
|
|
job.Run(_SIZE * _SIZE, default);
|
|
}
|
|
}
|