Unified fallback device initialization

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-02 17:28:46 +01:00
1 親 f0e1a6ded7
コミット 606faa70c9
3ファイル変更
+4 -88

検索条件に一致するファイルはありません

-52
ファイルの表示
@@ -72,26 +72,6 @@ namespace ComputeSharp.Benchmark
/// </summary>
private ReadWriteBuffer<float> BufferY;
/// <summary>
/// The input tensor (CPU).
/// </summary>
private ReadOnlyBuffer<float> FallbackBufferX;
/// <summary>
/// The weights tensor (CPU).
/// </summary>
private ReadOnlyBuffer<float> FallbackBufferW;
/// <summary>
/// The bias tensor (CPU).
/// </summary>
private ReadOnlyBuffer<float> FallbackBufferB;
/// <summary>
/// The result tensor (CPU).
/// </summary>
private ReadWriteBuffer<float> FallbackBufferY;
/// <summary>
/// A <see cref="System.Random"/> instance to initialize the tensors.
/// </summary>
@@ -125,11 +105,6 @@ namespace ComputeSharp.Benchmark
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
FallbackBufferX = Gpu.Fallback.AllocateReadOnlyBuffer(X);
FallbackBufferW = Gpu.Fallback.AllocateReadOnlyBuffer(W);
FallbackBufferB = Gpu.Fallback.AllocateReadOnlyBuffer(B);
FallbackBufferY = Gpu.Fallback.AllocateReadWriteBuffer(Y);
}
/// <summary>
@@ -147,11 +122,6 @@ namespace ComputeSharp.Benchmark
BufferW.Dispose();
BufferB.Dispose();
BufferY.Dispose();
FallbackBufferX.Dispose();
FallbackBufferW.Dispose();
FallbackBufferB.Dispose();
FallbackBufferY.Dispose();
}
/// <summary>
@@ -181,27 +151,5 @@ namespace ComputeSharp.Benchmark
y.GetData(Y);
}
/// <summary>
/// Runs a fully connected forward operation on the fallback device.
/// </summary>
[Benchmark]
public void FallbackWithNoTemporaryBuffers() => Dnn.FullyConnectedForwardGpu(Gpu.Fallback, C, N, M, P, FallbackBufferX, FallbackBufferW, FallbackBufferB, FallbackBufferY);
/// <summary>
/// Runs a fully connected forward operation on the fallback device, creating temporary buffers to perform the operations.
/// </summary>
[Benchmark]
public void FallbackWithTemporaryBuffers()
{
using ReadOnlyBuffer<float> x = Gpu.Fallback.AllocateReadOnlyBuffer(X);
using ReadOnlyBuffer<float> w = Gpu.Fallback.AllocateReadOnlyBuffer(W);
using ReadOnlyBuffer<float> b = Gpu.Fallback.AllocateReadOnlyBuffer(B);
using ReadWriteBuffer<float> y = Gpu.Fallback.AllocateReadWriteBuffer(Y);
Dnn.FullyConnectedForwardGpu(Gpu.Fallback, C, N, M, P, x, w, b, y);
y.GetData(Y);
}
}
}
+4 -22
ファイルの表示
@@ -23,7 +23,7 @@ namespace ComputeSharp.Graphics.Helpers
{
DXGI_ADAPTER_DESC1 dxgiDescription1;
return TryGetDefaultDevice(null, &dxgiDescription1);
return TryGetDefaultDevice(null, &dxgiDescription1) || TryGetWarpDevice(null, &dxgiDescription1);
}
/// <summary>
@@ -36,7 +36,7 @@ namespace ComputeSharp.Graphics.Helpers
{
DXGI_ADAPTER_DESC1 dxgiDescription1;
_ = TryGetDefaultDevice(null, &dxgiDescription1);
_ = TryGetDefaultDevice(null, &dxgiDescription1) || TryGetWarpDevice(null, &dxgiDescription1);
return Luid.FromLUID(dxgiDescription1.AdapterLuid);
}
@@ -52,7 +52,8 @@ namespace ComputeSharp.Graphics.Helpers
DXGI_ADAPTER_DESC1 dxgiDescription1;
if (TryGetDefaultDevice(d3D12Device.GetAddressOf(), &dxgiDescription1))
if (TryGetDefaultDevice(d3D12Device.GetAddressOf(), &dxgiDescription1) ||
TryGetWarpDevice(d3D12Device.GetAddressOf(), &dxgiDescription1))
{
return GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
}
@@ -60,25 +61,6 @@ namespace ComputeSharp.Graphics.Helpers
return ThrowHelper.ThrowNotSupportedException<GraphicsDevice>("There isn't a supported GPU device on the current machine");
}
/// <summary>
/// Gets the warp <see cref="GraphicsDevice"/> instance.
/// </summary>
/// <returns>The default <see cref="GraphicsDevice"/> instance supporting at least DX12.0.</returns>
/// <exception cref="NotSupportedException">Thrown when a default device is not available.</exception>
public static unsafe GraphicsDevice GetWarpDevice()
{
using ComPtr<ID3D12Device> d3D12Device = default;
DXGI_ADAPTER_DESC1 dxgiDescription1;
if (TryGetWarpDevice(d3D12Device.GetAddressOf(), &dxgiDescription1))
{
return GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
}
return ThrowHelper.ThrowNotSupportedException<GraphicsDevice>("There isn't a supported device on the current machine");
}
/// <summary>
/// Tries to check or create a default <see cref="ID3D12Device"/> object.
/// </summary>
-14
ファイルの表示
@@ -16,11 +16,6 @@ namespace ComputeSharp
/// </summary>
private static readonly Lazy<GraphicsDevice> DefaultFactory = new(DeviceHelper.GetDefaultDevice);
/// <summary>
/// The <see cref="Lazy{T}"/> instance used to produce the warp device for <see cref="Fallback"/>.
/// </summary>
private static readonly Lazy<GraphicsDevice> WarpFactory = new(DeviceHelper.GetWarpDevice);
/// <summary>
/// Gets whether or not the <see cref="Gpu"/> APIs can be used on the
/// current machine (ie. if there is at least a supported GPU device).
@@ -36,15 +31,6 @@ namespace ComputeSharp
/// <remarks>Make sure to check <see cref="IsSupported"/> before accessing this property.</remarks>
public static GraphicsDevice Default => DefaultFactory.Value;
/// <summary>
/// Gets the fallback <see cref="GraphicsDevice"/> instance for the current machine.
/// This is a software version of a device that can be used when no supported GPU is available.
/// This instance cannot be manually disposed - attempting to do so is safe and it will
/// not cause an exception, but it will simply do nothing and not dispose the device.
/// </summary>
/// <exception cref="NotSupportedException">Thrown when a fallback device is not available.</exception>
public static GraphicsDevice Fallback => WarpFactory.Value;
/// <summary>
/// Enumerates all the currently available DX12.0 devices. Note that creating a device is a relatively
/// expensive operation, so consider using <see cref="QueryDevices"/> to be able to filter the available