Added validity test fo benchmark project
このコミットが含まれているのは:
1 親
9798fb03d6
コミット
cb5e919f50
2ファイル変更
+28
-5
検索条件に一致するファイルはありません
@@ -85,10 +85,10 @@ namespace ComputeSharp.Benchmark
|
||||
B = CreateRandomArray(P);
|
||||
Y = CreateRandomArray(C * N * P);
|
||||
|
||||
BufferX = ComputeSharp.Gpu.Default.AllocateReadOnlyBuffer(X);
|
||||
BufferW = ComputeSharp.Gpu.Default.AllocateReadOnlyBuffer(W);
|
||||
BufferB = ComputeSharp.Gpu.Default.AllocateReadOnlyBuffer(B);
|
||||
BufferY = ComputeSharp.Gpu.Default.AllocateReadWriteBuffer(Y);
|
||||
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
|
||||
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
|
||||
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
|
||||
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -133,6 +133,29 @@ namespace ComputeSharp.Benchmark
|
||||
y.GetData(Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not thhe CPU and GPU implementations produce the same output
|
||||
/// </summary>
|
||||
public bool EnsureImplementationsMatch()
|
||||
{
|
||||
// Run the CPU implementation and copy the result
|
||||
Cpu();
|
||||
float[] y_cpu = new float[Y.Length];
|
||||
Y.AsSpan().CopyTo(y_cpu);
|
||||
|
||||
// Run the GPU implementation with temporary buffers
|
||||
GpuWithTemporaryBuffers();
|
||||
|
||||
// Compare the two results
|
||||
ref float r_cpu = ref y_cpu[0];
|
||||
ref float r_gpu = ref Y[0];
|
||||
for (int i = 0; i < Y.Length; i++)
|
||||
if (MathF.Abs(Unsafe.Add(ref r_cpu, i) - Unsafe.Add(ref r_gpu, i)) > 0.0001f)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ComputeSharp.Benchmark
|
||||
using var benchmark = new FullyConnectedLayerBenchmark();
|
||||
|
||||
Console.WriteLine("======== WARMUP ========");
|
||||
benchmark.GpuWithNoTemporaryBuffers(); // Warmup
|
||||
if (benchmark.EnsureImplementationsMatch()) throw new InvalidOperationException("CPU and GPU code don't match");
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("======== GPU with temporary buffer ========");
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする