mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-11-30 05:22:08 +01:00
90163087a0
* PPTC vs. giant ExeFS. * InternalVersion = 2168 * Add new heuristic algorithm for calculating the number of threads for parallel translations that also takes into account the user's free physical memory and not just the number of CPU cores. * Nit. * Add an outer Header structure and add the hashes for both this new structure and the existing "inner" Header structure. * InternalVersion = 2169
50 lines
No EOL
1.4 KiB
C#
50 lines
No EOL
1.4 KiB
C#
using System;
|
|
|
|
namespace ARMeilleure.Translation.PTC
|
|
{
|
|
class DegreeOfParallelism
|
|
{
|
|
public double GiBRef { get; } // GiB.
|
|
public double WeightRef { get; } // %.
|
|
public double IncrementByGiB { get; } // %.
|
|
private double _coefficient;
|
|
|
|
public DegreeOfParallelism(double gibRef, double weightRef, double incrementByGiB)
|
|
{
|
|
GiBRef = gibRef;
|
|
WeightRef = weightRef;
|
|
IncrementByGiB = incrementByGiB;
|
|
|
|
_coefficient = weightRef - (incrementByGiB * gibRef);
|
|
}
|
|
|
|
public int GetDegreeOfParallelism(int min, int max)
|
|
{
|
|
double degreeOfParallelism = (GetProcessorCount() * GetWeight(GetAvailableMemoryGiB())) / 100d;
|
|
|
|
return Math.Clamp((int)Math.Round(degreeOfParallelism), min, max);
|
|
}
|
|
|
|
public static double GetProcessorCount()
|
|
{
|
|
return (double)Environment.ProcessorCount;
|
|
}
|
|
|
|
public double GetWeight(double gib)
|
|
{
|
|
return (IncrementByGiB * gib) + _coefficient;
|
|
}
|
|
|
|
public static double GetAvailableMemoryGiB()
|
|
{
|
|
GCMemoryInfo gcMemoryInfo = GC.GetGCMemoryInfo();
|
|
|
|
return FromBytesToGiB(gcMemoryInfo.TotalAvailableMemoryBytes - gcMemoryInfo.MemoryLoadBytes);
|
|
}
|
|
|
|
private static double FromBytesToGiB(long bytes)
|
|
{
|
|
return Math.ScaleB((double)bytes, -30);
|
|
}
|
|
}
|
|
} |