GPU の誤差のモデルと ULP の距離を追加する

このコミットが含まれているのは:
routersys committed 2026-10-02 13:05:39 +09:00
1 親 31b4402894
コミット 7736bd544c
1ファイル変更
+46
+46
ファイルの表示
@@ -0,0 +1,46 @@
namespace ComputeGuard;
internal static class ComputeErrorModel
{
public static readonly double GpuOperationError = Math.ScaleB(1d, -23);
public static readonly double CpuOperationError = Math.ScaleB(1d, -24);
public static readonly double UnitInLastPlace = Math.ScaleB(1d, -23);
public static readonly double FlushLimit = Math.ScaleB(1d, -126);
public static double Gamma(int operations, double operationError)
{
ArgumentOutOfRangeException.ThrowIfNegative(operations);
if (!double.IsFinite(operationError) || operationError < 0d)
{
throw new ArgumentOutOfRangeException(nameof(operationError));
}
var product = operations * operationError;
if (product >= 1d)
{
throw new ArgumentOutOfRangeException(nameof(operations));
}
return product / (1d - product);
}
public static long UlpDistance(float first, float second)
{
if (float.IsNaN(first) || float.IsNaN(second))
{
return long.MaxValue;
}
return Math.Abs((long)Ordered(first) - Ordered(second));
}
private static int Ordered(float value)
{
var bits = BitConverter.SingleToInt32Bits(value);
return bits < 0 ? int.MinValue - bits : bits;
}
}