Refactor job API: add JobExecutionContext, update tests

Major breaking change: job interfaces now use JobExecutionContext
instead of threadIndex, enabling thread-aware and dynamic job
dispatching. Updated all job system, SPMD, and test code to match.
Collections improved with new methods and clearer enumerators.
Renamed IJobScheduler.WaitComplete to Wait. Incremented project
versions. Includes bug fixes, documentation, and style updates.
This commit is contained in:
2026-03-04 11:43:39 +09:00
parent b9ca71834f
commit 37d548085e
31 changed files with 652 additions and 207 deletions

View File

@@ -6,7 +6,7 @@ namespace Misaki.HighPerformance.Mathematics.SPMD;
public interface IJobSPMD<TNumber>
where TNumber : unmanaged, INumber<TNumber>, IBinaryNumber<TNumber>, IMinMaxValue<TNumber>, IBitwiseOperators<TNumber, TNumber, TNumber>
{
void Execute<TLane>(int baseIndex, int threadIndex)
void Execute<TLane>(int baseIndex, ref readonly JobExecutionContext ctx)
where TLane : ISPMD<TLane, TNumber>;
}
@@ -17,20 +17,20 @@ internal struct SPMDJobWrapper<T, TNumber> : IJobParallelFor
public T innerJob;
public int totalCount;
public void Execute(int loopIndex, int threadIndex)
public void Execute(int loopIndex, ref readonly JobExecutionContext ctx)
{
var baseIndex = loopIndex * WideLane<TNumber>.LaneWidth;
var remaining = totalCount - baseIndex;
if (remaining >= WideLane<TNumber>.LaneWidth)
{
innerJob.Execute<WideLane<TNumber>>(baseIndex, threadIndex);
innerJob.Execute<WideLane<TNumber>>(baseIndex, in ctx);
}
else
{
for (var j = 0; j < remaining; j++)
{
innerJob.Execute<ScalarLane<TNumber>>(baseIndex + j, threadIndex);
innerJob.Execute<ScalarLane<TNumber>>(baseIndex + j, in ctx);
}
}
}
@@ -43,15 +43,15 @@ internal struct SPMDScalerJobWrapper<T, TNumber> : IJobParallelFor
public T innerJob;
public int totalCount;
public void Execute(int loopIndex, int threadIndex)
public void Execute(int loopIndex, ref readonly JobExecutionContext ctx)
{
innerJob.Execute<ScalarLane<TNumber>>(loopIndex, threadIndex);
innerJob.Execute<ScalarLane<TNumber>>(loopIndex, in ctx);
}
}
public static class IJobParallelForSPMDExtensions
{
public static void Run<T, TNumber>(this ref T job, int totalCount, int threadIndex)
public static void Run<T, TNumber>(this ref T job, int totalCount, ref readonly JobExecutionContext ctx)
where T : struct, IJobSPMD<TNumber>
where TNumber : unmanaged, INumber<TNumber>, IBinaryNumber<TNumber>, IMinMaxValue<TNumber>, IBitwiseOperators<TNumber, TNumber, TNumber>
{
@@ -65,13 +65,13 @@ public static class IJobParallelForSPMDExtensions
if (remaining >= WideLane<TNumber>.LaneWidth)
{
job.Execute<WideLane<TNumber>>(baseIndex, threadIndex);
job.Execute<WideLane<TNumber>>(baseIndex, in ctx);
}
else
{
for (var i = 0; i < remaining; i++)
{
job.Execute<ScalarLane<TNumber>>(baseIndex + i, threadIndex);
job.Execute<ScalarLane<TNumber>>(baseIndex + i, in ctx);
}
}
}
@@ -80,7 +80,7 @@ public static class IJobParallelForSPMDExtensions
{
for (var loopIndex = 0; loopIndex < totalCount; loopIndex++)
{
job.Execute<ScalarLane<TNumber>>(loopIndex, threadIndex);
job.Execute<ScalarLane<TNumber>>(loopIndex, in ctx);
}
}
}