---
title: "Check GPU compute limits before dispatch in C#"
url: https://recursiveai.org/onegpu/cookbook/check-compute-device-capabilities/
description: "Read a Vulkan GPU’s OneGpu compute limits in C#, check a proposed workgroup and dispatch size, and test support for packed int8 dot products."
version: "1.0.0"
---

# Check GPU compute limits before dispatch in C#

**OneGpu** is a free, open-source GPU compute library for .NET from Recursive AI. MIT or Apache-2.0, no bundled native binaries.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneGpu.Backends) · [GitHub](https://github.com/recursive-ai-oss/onegpu-csharp) · [Docs](https://recursiveai.org/onegpu/docs/) · [Download example (.zip)](https://recursiveai.org/onegpu/cookbook/check-compute-device-capabilities/check-compute-device-capabilities.zip)

On Vulkan 1.3, read `Capabilities.Compute` to check the dispatch size, and use `Int8DotProduct` as an example of checking for an optional shader feature.

```shell
dotnet add package RecursiveAI.OneGpu.Backends
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using System;
using RecursiveAI.OneGpu;

using var gpu = GpuBackends.CreateDevice(
    new() { Adapter = "discrete" });
var caps = gpu.Capabilities.Compute;
const uint threads = 128, groups = 32;
// A 1D group still needs one thread on Y and Z.
bool fits = threads <= caps.MaxWorkgroupSizeX
    && caps.MaxWorkgroupSizeY >= 1
    && caps.MaxWorkgroupSizeZ >= 1
    && threads <= caps.MaxWorkgroupInvocations
    && groups <= caps.MaxWorkgroupCount;
bool useDot = fits && caps.Int8DotProduct;
Console.WriteLine($"Grid fits: {fits}");
Console.WriteLine(
    $"Use packed int8 dot: {useDot}");
```

Unzip [the example](https://recursiveai.org/onegpu/cookbook/check-compute-device-capabilities/check-compute-device-capabilities.zip), then `dotnet run`.

Prints:

```text
Grid fits: True
Use packed int8 dot: True
```

For integrated Vulkan graphics, use `Adapter = "integrated"`; `CreateDevice` throws `GpuUnsupportedException` if no adapter matches or the selected backend is unavailable, and browser WebGPU requires `CreateDeviceAsync` instead.

## The full program

The zip prints the adapter and limits as well as the decision. It checks a proposed one-dimensional dispatch of 32 groups with 128 threads each. It doesn’t load or dispatch a shader. If the checks fail, choose a supported shader or a different grid before recording the dispatch.

```csharp
using System;
using RecursiveAI.OneGpu;

using var gpu = GpuBackends.CreateDevice(
    new() { Adapter = "discrete" });
var caps = gpu.Capabilities.Compute;
Console.WriteLine($"{gpu.Backend}: {gpu.Adapter.Name}");
Console.WriteLine($"Max threads along X: {caps.MaxWorkgroupSizeX}");
Console.WriteLine($"Max threads per group: {caps.MaxWorkgroupInvocations}");
Console.WriteLine($"Max workgroups (any axis): {caps.MaxWorkgroupCount}");
Console.WriteLine($"Packed int8 dot supported: {caps.Int8DotProduct}");

const uint threads = 128, groups = 32;
bool fits = threads <= caps.MaxWorkgroupSizeX
    && caps.MaxWorkgroupSizeY >= 1
    && caps.MaxWorkgroupSizeZ >= 1
    && threads <= caps.MaxWorkgroupInvocations
    && groups <= caps.MaxWorkgroupCount;
bool useDot = fits && caps.Int8DotProduct;
Console.WriteLine($"Grid fits: {fits}");
Console.WriteLine($"Use packed int8 dot: {useDot}");
```

Output:

```text
Vulkan: NVIDIA GeForce RTX 4070
Max threads along X: 1024
Max threads per group: 1024
Max workgroups (any axis): 65535
Packed int8 dot supported: True
Grid fits: True
Use packed int8 dot: True
```

## Variations

### Reject a workgroup that exceeds the limit

Change the constants in the snippet at the top to test 2,048 threads in one group:

```csharp
const uint threads = 2048, groups = 32;
```

On the same adapter, the grid now fails the size check even though the dot-product feature is present:


```text
Grid fits: False
Use packed int8 dot: False
```

## Related recipes

- [Pick a Vulkan device](https://recursiveai.org/onegpu/cookbook/pick-a-vulkan-device/)
- [Run a compute shader in C#](https://recursiveai.org/onegpu/cookbook/run-a-compute-shader-in-csharp/)

## The short answer

Read `gpu.Capabilities.Compute` after you open the adapter. Check the shader’s local size against the X, Y and Z limits and the product of those dimensions against `MaxWorkgroupInvocations`. Separately check the number of groups per dispatch axis against `MaxWorkgroupCount`. Gate any optional shader variant on the features that variant actually requires.

## What’s the difference between workgroup size and dispatch count?

The [Vulkan Guide](https://docs.vulkan.org/guide/latest/compute_shaders.html#workgroup-size) calls the threads within a group *invocations*. The workgroup size is the number of threads the shader puts in each group. The dispatch count is how many groups the host asks the GPU to run. A shader with a `128 × 1 × 1` local size dispatched as `32 × 1 × 1` launches 4,096 invocations, but the per-group limit is checked against 128, not 4,096. Changing the dispatch count doesn’t change the shader’s local size.

For a two-dimensional shader, check both axes *and* their product. For example, a `64 × 32 × 1` group has 2,048 threads, so it would fail the 1,024-invocation limit printed above even if each dimension passed on its own. On Vulkan, OneGpu reports the smallest of the three hardware dispatch-count limits as `MaxWorkgroupCount`, so the same bound can be used along every axis.

## How do you check what a Vulkan compute shader can use?

Look at the selected device’s reported capabilities rather than guessing from the GPU name. In this example, `Int8DotProduct` gates a variant that needs the packed operation. If that variant also needs 8-bit values in storage buffers, check `Integer8` separately. For shared memory and storage buffers, check `MaxWorkgroupMemoryBytes` and `MaxStorageBufferBindingBytes` against your shader and its bindings. A zero numeric limit means unreported, not unlimited.

OneGpu’s [compute docs](https://recursiveai.org/onegpu/docs/compute/#kernels) describe an additional check: `CreateComputeKernel` checks reflected requirements such as local size, scalar types and subgroup operations before creating the pipeline. The preflight here lets your application choose a variant before making that call; it isn’t a substitute for checking all requirements of the shader you choose.
