Add Fensalir lowering benchmark
This commit is contained in:
parent
98dc490aac
commit
e0b6e31a3d
5 changed files with 127 additions and 13 deletions
|
|
@ -70,6 +70,12 @@ if (args.Any(arg => string.Equals(arg, "--perfect-machine-manifest", StringCompa
|
|||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--perfect-machine-lowering-benchmark", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunPerfectMachineLoweringBenchmark(
|
||||
ParseIntOption(args, "--iterations", 10_000));
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--standalone-chirp-bin-self-test", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunStandaloneChirpBinSelfTest(
|
||||
|
|
@ -1187,6 +1193,90 @@ static async Task<int> WritePerfectMachineManifestAsync(string outputPath)
|
|||
: 1;
|
||||
}
|
||||
|
||||
static int RunPerfectMachineLoweringBenchmark(int iterations)
|
||||
{
|
||||
iterations = Math.Max(1, iterations);
|
||||
var buffers = new List<MimirRollingStreamBuffer>();
|
||||
foreach (var profile in MimirNativeCaptureConfigurations.LocalSixCameraProfiles)
|
||||
{
|
||||
var buffer = new MimirRollingStreamBuffer(
|
||||
new MimirStreamDescriptor(profile.Id, MimirStreamKind.Video, MimirStreamOrigin.LocalDevice),
|
||||
TimeSpan.FromSeconds(profile.RollingBufferSeconds));
|
||||
buffer.Append(new MimirStreamSample(
|
||||
profile.Id,
|
||||
MimirStreamKind.Video,
|
||||
MimirStreamOrigin.LocalDevice,
|
||||
TimestampNs: 1_000_000_000L,
|
||||
ArrivalNs: 1_000_000_050L,
|
||||
Sequence: 1,
|
||||
PayloadHandle: 0,
|
||||
VideoFrame: new MimirVideoFrameDescriptor(
|
||||
Math.Max(1, profile.PreferredWidth),
|
||||
Math.Max(1, profile.PreferredHeight),
|
||||
profile.Id.Contains("leap", StringComparison.OrdinalIgnoreCase) ? MimirVideoPixelFormat.LeapStereoIr : MimirVideoPixelFormat.Bgra8,
|
||||
Math.Max(1, profile.PreferredWidth) * 4,
|
||||
1_000_000_000L,
|
||||
NativeHandle: (ulong)(100 + buffers.Count),
|
||||
NativeHandleKind: "benchmark-shared-texture")));
|
||||
buffers.Add(buffer);
|
||||
}
|
||||
|
||||
var states = new[]
|
||||
{
|
||||
new MimirAudioSynchronizationState(
|
||||
"loopback-scarlett-speakers",
|
||||
"scarlett-input-1",
|
||||
192_000,
|
||||
41.50,
|
||||
41.50,
|
||||
0.216,
|
||||
0.30,
|
||||
0.91,
|
||||
[],
|
||||
1_000_000_000L,
|
||||
1,
|
||||
1),
|
||||
new MimirAudioSynchronizationState(
|
||||
"loopback-scarlett-speakers",
|
||||
"raven-scarlett-input-1",
|
||||
192_000,
|
||||
225.00,
|
||||
225.00,
|
||||
1.172,
|
||||
-0.45,
|
||||
0.78,
|
||||
[],
|
||||
1_000_000_000L,
|
||||
1,
|
||||
1)
|
||||
};
|
||||
var lowerer = new MimirFensalirFieldLowering();
|
||||
_ = lowerer.BuildGpuSensorFrame(buffers);
|
||||
_ = lowerer.BuildAcousticFieldFrame(states);
|
||||
|
||||
var allocatedBefore = GC.GetAllocatedBytesForCurrentThread();
|
||||
var stamp = Stopwatch.GetTimestamp();
|
||||
var cameras = 0;
|
||||
var constraints = 0;
|
||||
for (var iteration = 0; iteration < iterations; iteration++)
|
||||
{
|
||||
var gpuFrame = lowerer.BuildGpuSensorFrame(buffers);
|
||||
var acousticFrame = lowerer.BuildAcousticFieldFrame(states);
|
||||
cameras += gpuFrame.Cameras.Count;
|
||||
constraints += acousticFrame.Constraints.Count;
|
||||
}
|
||||
|
||||
var elapsed = Stopwatch.GetElapsedTime(stamp);
|
||||
var allocatedBytes = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore;
|
||||
var perIterationUs = elapsed.TotalMilliseconds * 1000.0 / iterations;
|
||||
var allocatedPerIteration = allocatedBytes / (double)iterations;
|
||||
Console.WriteLine(
|
||||
$"perfect-machine-lowering-benchmark iterations={iterations} camerasPer={cameras / (double)iterations:0.0} constraintsPer={constraints / (double)iterations:0.0} elapsedMs={elapsed.TotalMilliseconds:0.000} perIterationUs={perIterationUs:0.000} allocatedPerIterationBytes={allocatedPerIteration:0.0}");
|
||||
return perIterationUs < 250.0 && allocatedPerIteration < 10_000.0
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
||||
static int RenderBioacousticFloat32(string outputPath, int sampleRate, double seconds)
|
||||
{
|
||||
var segmentCount = Math.Max(1, (int)Math.Ceiling(seconds / MimirBioacousticTimeline.SegmentSeconds));
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
|
||||
public AquariumGpuSensorFrame BuildGpuSensorFrame(IEnumerable<MimirRollingStreamBuffer> buffers)
|
||||
{
|
||||
var textures = new List<AquariumExternalGpuTexture>();
|
||||
var cameras = new List<AquariumGpuSensorCamera>();
|
||||
var capacity = buffers.TryGetNonEnumeratedCount(out var count) ? count : 0;
|
||||
var textures = new List<AquariumExternalGpuTexture>(capacity);
|
||||
var cameras = new List<AquariumGpuSensorCamera>(capacity);
|
||||
foreach (var buffer in buffers)
|
||||
{
|
||||
if (buffer.Descriptor.Kind != MimirStreamKind.Video || buffer.Latest?.VideoFrame is not { } frame)
|
||||
|
|
@ -62,21 +63,39 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
|
||||
public AquariumAcousticFieldFrame BuildAcousticFieldFrame(IEnumerable<MimirAudioSynchronizationState> states)
|
||||
{
|
||||
var orderedStates = states
|
||||
.OrderByDescending(state => state.Confidence)
|
||||
.ThenBy(state => state.SourceId, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
var constraints = orderedStates
|
||||
.Where(state => state.Confidence > 0.0)
|
||||
.Select(state => new AquariumAcousticConstraint(
|
||||
var capacity = states.TryGetNonEnumeratedCount(out var count) ? count : 0;
|
||||
var orderedStates = new List<MimirAudioSynchronizationState>(capacity);
|
||||
foreach (var state in states)
|
||||
{
|
||||
orderedStates.Add(state);
|
||||
}
|
||||
|
||||
orderedStates.Sort(static (left, right) =>
|
||||
{
|
||||
var confidence = right.Confidence.CompareTo(left.Confidence);
|
||||
return confidence != 0
|
||||
? confidence
|
||||
: string.Compare(left.SourceId, right.SourceId, StringComparison.Ordinal);
|
||||
});
|
||||
|
||||
var constraints = new List<AquariumAcousticConstraint>(orderedStates.Count);
|
||||
foreach (var state in orderedStates)
|
||||
{
|
||||
if (state.Confidence <= 0.0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
constraints.Add(new AquariumAcousticConstraint(
|
||||
$"{state.ReferenceSourceId}->{state.SourceId}",
|
||||
AquariumAcousticConstraintKind.SpeakerProbe,
|
||||
Vector3.Zero,
|
||||
Vector3.Zero,
|
||||
RadiusMeters: 0.10f,
|
||||
Confidence: (float)Math.Clamp(state.Confidence, 0.0, 1.0),
|
||||
TimestampNs: state.UpdatedAtNs))
|
||||
.ToArray();
|
||||
TimestampNs: state.UpdatedAtNs));
|
||||
}
|
||||
|
||||
var oracle = orderedStates.FirstOrDefault();
|
||||
return new AquariumAcousticFieldFrame
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue