L4 completely add support for multi predictor, working on ver 5 mat para

This commit is contained in:
Youmu Liu
2026-04-10 18:05:40 +08:00
parent b5bee5c442
commit 8a66c1697a
16 changed files with 602 additions and 191 deletions
@@ -28,6 +28,7 @@
using StgSharp.Common.Collections;
using StgSharp.Mathematics.Memory;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -40,14 +41,16 @@ namespace StgSharp.HighPerformance.Memory
private ConcurrentBufferStack<int> _idReuse = new(32);
private ConcurrentFlexibleArray<IL4Predict> _predictions = new(32);
private ConcurrentFlexibleArray<IL4Predict> _predictors = new(32);
private int _largestId = 0;
private ConcurrentQueue<int> _predictionQueue = new();
private Queue<int> _predictionQueue = [];
private int _largestId ;
private IL4Predict CurrentPredict { get; set; }
private int CurrentPredictIndex { get; set; }
public int RegisterPredict(
IL4Predict predict
)
@@ -58,7 +61,7 @@ namespace StgSharp.HighPerformance.Memory
if (!_idReuse.TryPop(out int id)) {
id = _largestId++;
}
_predictions[id] = predict;
_predictors[id] = predict;
_predictionQueue.Enqueue(id);
return id;
}
@@ -70,29 +73,30 @@ namespace StgSharp.HighPerformance.Memory
if (id < 0) {
return null;
}
IL4Predict p = _predictions[id];
IL4Predict p = _predictors[id];
if (p == null) {
return p;
}
_predictions[id] = null!;
// TODO: scan and write back
_predictors[id] = null!;
_idReuse.Push(id);
return p;
}
private void UseNewPredict()
private bool TryGetNextPredict(
)
{
if (_predictionQueue.Count == 0) {
return;
if (_predictionQueue.IsEmpty) {
return false;
}
if (_predictionQueue.TryDequeue(out int id))
{
IL4Predict predict = _predictions[id] ??
IL4Predict predict = _predictors[id] ??
throw new L4PredictUnregisteredException(id);
CurrentPredict = predict;
CurrentPredictIndex = id;
return true;
}
return false;
}
}